mirror of
https://github.com/Tha14/toxic.git
synced 2025-07-05 05:46:44 +02:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@ -45,6 +45,8 @@ static int num_friends = 0;
|
||||
ToxicFriend friends[MAX_FRIENDS_NUM];
|
||||
static int friendlist_index[MAX_FRIENDS_NUM] = {0};
|
||||
|
||||
static PendingDel pendingdelete;
|
||||
|
||||
#define S_WEIGHT 100
|
||||
|
||||
static int index_name_cmp(const void *n1, const void *n2)
|
||||
@ -78,7 +80,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str,
|
||||
return;
|
||||
|
||||
if (friends[num].chatwin == -1) {
|
||||
if (num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
||||
} else {
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
@ -179,7 +181,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8
|
||||
return;
|
||||
|
||||
if (friends[num].chatwin == -1) {
|
||||
if (num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
||||
} else {
|
||||
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
||||
@ -204,7 +206,7 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *
|
||||
return;
|
||||
|
||||
if (friends[num].chatwin == -1) {
|
||||
if (num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
||||
} else {
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
@ -231,7 +233,7 @@ static void select_friend(ToxWindow *self, Tox *m, wint_t key)
|
||||
}
|
||||
}
|
||||
|
||||
static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
|
||||
static void delete_friend(Tox *m, int f_num)
|
||||
{
|
||||
tox_del_friend(m, f_num);
|
||||
memset(&friends[f_num], 0, sizeof(ToxicFriend));
|
||||
@ -254,6 +256,49 @@ static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
|
||||
store_data(m, DATA_FILE);
|
||||
}
|
||||
|
||||
/* activates delete friend popup */
|
||||
static void del_friend_activate(ToxWindow *self, Tox *m, int f_num)
|
||||
{
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
self->popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8);
|
||||
|
||||
pendingdelete.active = true;
|
||||
pendingdelete.num = f_num;
|
||||
}
|
||||
|
||||
/* deactivates delete friend popup and deletes friend if instructed */
|
||||
static void del_friend_deactivate(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
if (key == 'y')
|
||||
delete_friend(m, pendingdelete.num);
|
||||
|
||||
memset(&pendingdelete, 0, sizeof(PendingDel));
|
||||
delwin(self->popup);
|
||||
self->popup = NULL;
|
||||
clear();
|
||||
refresh();
|
||||
}
|
||||
|
||||
static void draw_popup(ToxWindow *self, Tox *m)
|
||||
{
|
||||
if (self->popup == NULL)
|
||||
return;
|
||||
|
||||
wattron(self->popup, A_BOLD);
|
||||
box(self->popup, ACS_VLINE, ACS_HLINE);
|
||||
wattroff(self->popup, A_BOLD);
|
||||
|
||||
wmove(self->popup, 1, 1);
|
||||
wprintw(self->popup, "Delete contact ");
|
||||
wattron(self->popup, A_BOLD);
|
||||
wprintw(self->popup, "%s", friends[pendingdelete.num].name);
|
||||
wattroff(self->popup, A_BOLD);
|
||||
wprintw(self->popup, "? y/n");
|
||||
|
||||
wrefresh(self->popup);
|
||||
}
|
||||
|
||||
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
if (num_friends == 0)
|
||||
@ -261,11 +306,19 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
|
||||
int f = friendlist_index[num_selected];
|
||||
|
||||
/* lock screen and force decision on deletion popup */
|
||||
if (pendingdelete.active) {
|
||||
if (key == 'y' || key == 'n')
|
||||
del_friend_deactivate(self, m, key);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == '\n') {
|
||||
/* Jump to chat window if already open */
|
||||
if (friends[f].chatwin != -1) {
|
||||
set_active_window(friends[f].chatwin);
|
||||
} else if (num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
} else if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
|
||||
set_active_window(friends[f].chatwin);
|
||||
} else {
|
||||
@ -277,7 +330,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
alert_window(prompt, WINDOW_ALERT_1, true);
|
||||
}
|
||||
} else if (key == KEY_DC) {
|
||||
delete_friend(m, self, f, key);
|
||||
del_friend_activate(self, m, f);
|
||||
} else {
|
||||
select_friend(self, m, key);
|
||||
}
|
||||
@ -307,7 +360,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
wattroff(self->window, COLOR_PAIR(CYAN));
|
||||
|
||||
wattron(self->window, A_BOLD);
|
||||
wprintw(self->window, " Friends: %d/%d \n\n", tox_get_num_online_friends(m), num_friends);
|
||||
wprintw(self->window, " Online: %d/%d \n\n", tox_get_num_online_friends(m), num_friends);
|
||||
wattroff(self->window, A_BOLD);
|
||||
|
||||
if ((y2 - FLIST_OFST) <= 0) /* don't allow division by zero */
|
||||
@ -402,6 +455,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
|
||||
self->x = x2;
|
||||
wrefresh(self->window);
|
||||
draw_popup(self, m);
|
||||
}
|
||||
|
||||
void disable_chatwin(int f_num)
|
||||
|
Reference in New Issue
Block a user