1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 20:03:27 +01:00

add help menu for friendlist

This commit is contained in:
Jfreegman 2014-07-31 13:49:15 -04:00
parent fba0732faa
commit 0254596c73
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
3 changed files with 99 additions and 46 deletions

View File

@ -35,6 +35,7 @@
#include "line_info.h" #include "line_info.h"
#include "settings.h" #include "settings.h"
#include "notify.h" #include "notify.h"
#include "help.h"
#ifdef _AUDIO #ifdef _AUDIO
#include "audio_call.h" #include "audio_call.h"
@ -420,16 +421,16 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const
} }
/* move friendlist/blocklist cursor up and down */ /* move friendlist/blocklist cursor up and down */
static void select_friend(ToxWindow *self, wint_t key, int *selected, int count) static void select_friend(ToxWindow *self, wint_t key, int *selected, int num)
{ {
if (count <= 0) if (num <= 0)
return; return;
if (key == KEY_UP) { if (key == KEY_UP) {
if (--(*selected) < 0) if (--(*selected) < 0)
*selected = count - 1; *selected = num - 1;
} else if (key == KEY_DOWN) { } else if (key == KEY_DOWN) {
*selected = (*selected + 1) % count; *selected = (*selected + 1) % num;
} }
} }
@ -463,7 +464,7 @@ static void del_friend_activate(ToxWindow *self, Tox *m, int32_t f_num)
pendingdelete.num = f_num; pendingdelete.num = f_num;
} }
static void remove_friend_blocked(int32_t bnum); static void delete_blocked_friend(int32_t bnum);
/* deactivates delete friend popup and deletes friend if instructed */ /* deactivates delete friend popup and deletes friend if instructed */
static void del_friend_deactivate(ToxWindow *self, Tox *m, wint_t key) static void del_friend_deactivate(ToxWindow *self, Tox *m, wint_t key)
@ -473,7 +474,7 @@ static void del_friend_deactivate(ToxWindow *self, Tox *m, wint_t key)
delete_friend(m, pendingdelete.num); delete_friend(m, pendingdelete.num);
sort_friendlist_index(); sort_friendlist_index();
} else { } else {
remove_friend_blocked(pendingdelete.num); delete_blocked_friend(pendingdelete.num);
sort_blocklist_index(); sort_blocklist_index();
} }
} }
@ -484,7 +485,7 @@ static void del_friend_deactivate(ToxWindow *self, Tox *m, wint_t key)
refresh(); refresh();
} }
static void draw_popup(void) static void draw_del_popup(void)
{ {
if (!pendingdelete.active) if (!pendingdelete.active)
return; return;
@ -508,7 +509,27 @@ static void draw_popup(void)
wrefresh(pendingdelete.popup); wrefresh(pendingdelete.popup);
} }
/* Deletes friend from friendlist, puts in blocklist */ /* deletes contact from blocked list */
static void delete_blocked_friend(int32_t bnum)
{
memset(&Blocked_Contacts.list[bnum], 0, sizeof(BlockedFriend));
int i;
for (i = Blocked_Contacts.max_index; i >= 0; --i) {
if (Blocked_Contacts.list[i - 1].active)
break;
}
--Blocked_Contacts.num_blocked;
Blocked_Contacts.max_index = i;
save_blocklist(BLOCK_FILE);
if (Blocked_Contacts.num_blocked && Blocked_Contacts.num_selected == Blocked_Contacts.num_blocked)
--Blocked_Contacts.num_selected;
}
/* deletes contact from friendlist and puts in blocklist */
void block_friend(Tox *m, int32_t fnum) void block_friend(Tox *m, int32_t fnum)
{ {
if (Blocked_Contacts.max_index >= MAX_FRIENDS_NUM || num_friends <= 0) if (Blocked_Contacts.max_index >= MAX_FRIENDS_NUM || num_friends <= 0)
@ -540,26 +561,6 @@ void block_friend(Tox *m, int32_t fnum)
} }
} }
/* permanently deletes friend from blocked list */
static void remove_friend_blocked(int32_t bnum)
{
memset(&Blocked_Contacts.list[bnum], 0, sizeof(BlockedFriend));
int i;
for (i = Blocked_Contacts.max_index; i >= 0; --i) {
if (Blocked_Contacts.list[i - 1].active)
break;
}
--Blocked_Contacts.num_blocked;
Blocked_Contacts.max_index = i;
save_blocklist(BLOCK_FILE);
if (Blocked_Contacts.num_blocked && Blocked_Contacts.num_selected == Blocked_Contacts.num_blocked)
--Blocked_Contacts.num_selected;
}
/* removes friend from blocklist, puts back in friendlist */ /* removes friend from blocklist, puts back in friendlist */
static void unblock_friend(Tox *m, int32_t bnum) static void unblock_friend(Tox *m, int32_t bnum)
{ {
@ -574,13 +575,24 @@ static void unblock_friend(Tox *m, int32_t bnum)
} }
friendlist_add_blocked(m, friendnum, bnum); friendlist_add_blocked(m, friendnum, bnum);
remove_friend_blocked(bnum); delete_blocked_friend(bnum);
sort_blocklist_index(); sort_blocklist_index();
sort_friendlist_index(); sort_friendlist_index();
} }
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
{ {
if (self->help->active) {
help_onKey(self, key);
return;
}
if (key == 'h') {
help_init_menu(self);
return;
}
if (!blocklist_view && !num_friends && (key != KEY_RIGHT && key != KEY_LEFT)) if (!blocklist_view && !num_friends && (key != KEY_RIGHT && key != KEY_LEFT))
return; return;
@ -712,7 +724,10 @@ static void blocklist_onDraw(ToxWindow *self, Tox *m, int y2, int x2)
} }
wrefresh(self->window); wrefresh(self->window);
draw_popup(); draw_del_popup();
if (self->help->active)
help_onDraw(self);
} }
static void friendlist_onDraw(ToxWindow *self, Tox *m) static void friendlist_onDraw(ToxWindow *self, Tox *m)
@ -725,20 +740,11 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
bool fix_statuses = x2 != self->x; /* true if window max x value has changed */ bool fix_statuses = x2 != self->x; /* true if window max x value has changed */
wattron(self->window, COLOR_PAIR(CYAN)); wattron(self->window, COLOR_PAIR(CYAN));
wprintw(self->window, " Open a chat window with the"); wprintw(self->window, " Press the");
wattron(self->window, A_BOLD); wattron(self->window, A_BOLD);
wprintw(self->window, " Enter "); wprintw(self->window, " H ");
wattroff(self->window, A_BOLD); wattroff(self->window, A_BOLD);
wprintw(self->window, "key. Delete a contact with the"); wprintw(self->window, "key for help\n\n");
wattron(self->window, A_BOLD);
wprintw(self->window, " Delete ");
wattroff(self->window, A_BOLD);
wprintw(self->window, "key.\n");
wprintw(self->window, " Block a contact with the");
wattron(self->window, A_BOLD);
wprintw(self->window, " b ");
wattroff(self->window, A_BOLD);
wprintw(self->window, "key, toggle blocklist with the.");
wattroff(self->window, COLOR_PAIR(CYAN)); wattroff(self->window, COLOR_PAIR(CYAN));
if (blocklist_view == 1) { if (blocklist_view == 1) {
@ -902,7 +908,10 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
} }
wrefresh(self->window); wrefresh(self->window);
draw_popup(); draw_del_popup();
if (self->help->active)
help_onDraw(self);
} }
void disable_chatwin(int32_t f_num) void disable_chatwin(int32_t f_num)
@ -982,7 +991,13 @@ ToxWindow new_friendlist(void)
#ifdef _SOUND_NOTIFY #ifdef _SOUND_NOTIFY
ret.active_sound = -1; ret.active_sound = -1;
#endif /* _SOUND_NOTIFY */ #endif /* _SOUND_NOTIFY */
Help *help = calloc(1, sizeof(Help));
if (help == NULL)
exit_toxic_err("failed in new_friendlist", FATALERR_MEMORY);
ret.help = help;
strcpy(ret.name, "contacts"); strcpy(ret.name, "contacts");
return ret; return ret;
} }

View File

@ -27,7 +27,7 @@
#include "help.h" #include "help.h"
#include "misc_tools.h" #include "misc_tools.h"
#define HELP_MENU_HEIGHT 7 #define HELP_MENU_HEIGHT 8
#define HELP_MENU_WIDTH 26 #define HELP_MENU_WIDTH 26
void help_init_menu(ToxWindow *self) void help_init_menu(ToxWindow *self)
@ -86,6 +86,11 @@ static void help_draw_menu(ToxWindow *self)
wattroff(win, A_BOLD | COLOR_PAIR(BLUE)); wattroff(win, A_BOLD | COLOR_PAIR(BLUE));
wprintw(win, "hat commands\n"); wprintw(win, "hat commands\n");
wattron(win, A_BOLD | COLOR_PAIR(BLUE));
wprintw(win, " F");
wattroff(win, A_BOLD | COLOR_PAIR(BLUE));
wprintw(win, "riendlist controls\n");
wattron(win, A_BOLD | COLOR_PAIR(BLUE)); wattron(win, A_BOLD | COLOR_PAIR(BLUE));
wprintw(win, " K"); wprintw(win, " K");
wattroff(win, A_BOLD | COLOR_PAIR(BLUE)); wattroff(win, A_BOLD | COLOR_PAIR(BLUE));
@ -209,7 +214,30 @@ static void help_draw_keys(ToxWindow *self)
wprintw(win, " Page Up and Page Down : Scroll window history one line\n"); wprintw(win, " Page Up and Page Down : Scroll window history one line\n");
wprintw(win, " Ctrl+F and Ctrl+V : Scroll window history half a page\n"); wprintw(win, " Ctrl+F and Ctrl+V : Scroll window history half a page\n");
wprintw(win, " Ctrl+H : Move to the bottom of window history\n"); wprintw(win, " Ctrl+H : Move to the bottom of window history\n");
wprintw(win, " Ctrl+[ and Ctrl+] : Scroll peer list in groupchats\n"); wprintw(win, " Ctrl+[ and Ctrl+] : Scroll peer list in groupchats\n\n");
wprintw(win, " (Note: Custom keybindings override these defaults.)\n\n");
help_draw_bottom_menu(win);
box(win, ACS_VLINE, ACS_HLINE);
wrefresh(win);
}
static void help_draw_contacts(ToxWindow *self)
{
WINDOW *win = self->help->win;
wmove(win, 1, 1);
wattron(win, A_BOLD | COLOR_PAIR(RED));
wprintw(win, "Friendlist controls:\n");
wattroff(win, A_BOLD | COLOR_PAIR(RED));
wprintw(win, " Up and Down arrows : Scroll through list\n");
wprintw(win, " Right and Left arrows : Switch between friendlist and blocked list\n");
wprintw(win, " Enter : Open a chat window with selected contact\n");
wprintw(win, " Delete : Permanently delete a contact\n");
wprintw(win, " B : Block or unblock a contact\n");
help_draw_bottom_menu(win); help_draw_bottom_menu(win);
@ -243,8 +271,13 @@ void help_onKey(ToxWindow *self, wint_t key)
self->help->type = HELP_GLOBAL; self->help->type = HELP_GLOBAL;
break; break;
case 'k': case 'f':
help_init_window(self, 10, 80); help_init_window(self, 10, 80);
self->help->type = HELP_CONTACTS;
break;
case 'k':
help_init_window(self, 12, 80);
self->help->type = HELP_KEYS; self->help->type = HELP_KEYS;
break; break;
@ -276,6 +309,10 @@ void help_onDraw(ToxWindow *self)
help_draw_keys(self); help_draw_keys(self);
break; break;
case HELP_CONTACTS:
help_draw_contacts(self);
break;
case HELP_GROUP: case HELP_GROUP:
break; break;
} }

View File

@ -32,6 +32,7 @@ typedef enum {
HELP_CHAT, HELP_CHAT,
HELP_GROUP, HELP_GROUP,
HELP_KEYS, HELP_KEYS,
HELP_CONTACTS,
} HELP_TYPES; } HELP_TYPES;
void help_onDraw(ToxWindow *self); void help_onDraw(ToxWindow *self);