From 95b639a21f77c825a36076562363154216cdad05 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 10 Mar 2018 22:16:52 +0000 Subject: [PATCH] WIP add self prefs for statusbar --- src/command/cmd_ac.c | 15 ++++++++ src/command/cmd_defs.c | 19 +++++----- src/command/cmd_funcs.c | 29 +++++++++++++++ src/config/preferences.c | 5 +++ src/config/preferences.h | 1 + src/ui/console.c | 8 +++++ src/ui/core.c | 16 ++++----- src/ui/inputwin.c | 4 +-- src/ui/statusbar.c | 78 ++++++++++++++-------------------------- src/ui/statusbar.h | 8 ++--- 10 files changed, 107 insertions(+), 76 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index de57ac82..c996d814 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -201,6 +201,7 @@ static Autocomplete presence_ac; static Autocomplete presence_setting_ac; static Autocomplete winpos_ac; static Autocomplete statusbar_ac; +static Autocomplete statusbar_self_ac; static Autocomplete statusbar_chat_ac; static Autocomplete statusbar_room_ac; static Autocomplete statusbar_show_ac; @@ -784,9 +785,16 @@ cmd_ac_init(void) autocomplete_add(statusbar_ac, "show"); autocomplete_add(statusbar_ac, "hide"); autocomplete_add(statusbar_ac, "maxtabs"); + autocomplete_add(statusbar_ac, "self"); autocomplete_add(statusbar_ac, "chat"); autocomplete_add(statusbar_ac, "room"); + statusbar_self_ac = autocomplete_new(); + autocomplete_add(statusbar_self_ac, "user"); + autocomplete_add(statusbar_self_ac, "barejid"); + autocomplete_add(statusbar_self_ac, "fulljid"); + autocomplete_add(statusbar_self_ac, "off"); + statusbar_chat_ac = autocomplete_new(); autocomplete_add(statusbar_chat_ac, "user"); autocomplete_add(statusbar_chat_ac, "jid"); @@ -1080,6 +1088,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(presence_setting_ac); autocomplete_reset(winpos_ac); autocomplete_reset(statusbar_ac); + autocomplete_reset(statusbar_self_ac); autocomplete_reset(statusbar_chat_ac); autocomplete_reset(statusbar_room_ac); autocomplete_reset(statusbar_show_ac); @@ -1211,6 +1220,7 @@ cmd_ac_uninit(void) autocomplete_free(presence_setting_ac); autocomplete_free(winpos_ac); autocomplete_free(statusbar_ac); + autocomplete_free(statusbar_self_ac); autocomplete_free(statusbar_chat_ac); autocomplete_free(statusbar_room_ac); autocomplete_free(statusbar_show_ac); @@ -3230,6 +3240,11 @@ _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previ return found; } + found = autocomplete_param_with_ac(input, "/statusbar self", statusbar_self_ac, TRUE, previous); + if (found) { + return found; + } + found = autocomplete_param_with_ac(input, "/statusbar chat", statusbar_chat_ac, TRUE, previous); if (found) { return found; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 5a873309..d6ee9be6 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1361,6 +1361,7 @@ static struct cmd_t command_defs[] = "/statusbar show name|number", "/statusbar hide name|number", "/statusbar maxtabs ", + "/statusbar self user|barejid|fulljid|off", "/statusbar chat user|jid", "/statusbar room room|jid", "/statusbar up", @@ -1368,16 +1369,18 @@ static struct cmd_t command_defs[] = CMD_DESC( "Manage statusbar display preferences.") CMD_ARGS( - { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, - { "show|hide name", "Show or hide names in tabs." }, - { "show|hide number", "Show or hide numbers in tabs." }, - { "chat user|jid", "Show only the users name, or the full jid if no nick is present for chat tabs." }, - { "room room|jid", "Show only the rooms name, or the full jid for room tabs." }, - { "up", "Move the status bar up the screen." }, - { "down", "Move the status bar down the screen." }) + { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, + { "show|hide name", "Show or hide names in tabs." }, + { "show|hide number", "Show or hide numbers in tabs." }, + { "self user|barejid|fulljid", "Show account user name, barejid, fulljid as status bar title." }, + { "self off", "Disable showing self as status bar title." }, + { "chat user|jid", "Show users name, or the fulljid if no nick is present for chat tabs." }, + { "room room|jid", "Show room name, or the fulljid for room tabs." }, + { "up", "Move the status bar up the screen." }, + { "down", "Move the status bar down the screen." }) CMD_EXAMPLES( "/statusbar maxtabs 5", - "/statusbar hide name", + "/statusbar self user", "/statusbar chat jid", "/statusbar hide name") }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 98a08267..11f1f51c 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5846,6 +5846,35 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args) } } + if (g_strcmp0(args[0], "self") == 0) { + if (g_strcmp0(args[1], "barejid") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "barejid"); + cons_show("Using barejid for statusbar title."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "fulljid") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "fulljid"); + cons_show("Using fulljid for statusbar title."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "user") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "user"); + cons_show("Using user for statusbar title."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "off") == 0) { + prefs_set_string(PREF_STATUSBAR_SELF, "off"); + cons_show("Disabling statusbar title."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + if (g_strcmp0(args[0], "chat") == 0) { if (g_strcmp0(args[1], "jid") == 0) { prefs_set_string(PREF_STATUSBAR_CHAT, "jid"); diff --git a/src/config/preferences.c b/src/config/preferences.c index 28883e76..bc97b0a1 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1588,6 +1588,7 @@ _get_group(preference_t pref) case PREF_CONSOLE_CHAT: case PREF_STATUSBAR_SHOW_NAME: case PREF_STATUSBAR_SHOW_NUMBER: + case PREF_STATUSBAR_SELF: case PREF_STATUSBAR_CHAT: case PREF_STATUSBAR_ROOM: return PREF_GROUP_UI; @@ -1847,6 +1848,8 @@ _get_key(preference_t pref) return "statusbar.show.name"; case PREF_STATUSBAR_SHOW_NUMBER: return "statusbar.show.number"; + case PREF_STATUSBAR_SELF: + return "statusbar.self"; case PREF_STATUSBAR_CHAT: return "statusbar.chat"; case PREF_STATUSBAR_ROOM: @@ -1964,6 +1967,8 @@ _get_default_string(preference_t pref) case PREF_CONSOLE_PRIVATE: case PREF_CONSOLE_CHAT: return "all"; + case PREF_STATUSBAR_SELF: + return "fulljid"; case PREF_STATUSBAR_CHAT: return "user"; case PREF_STATUSBAR_ROOM: diff --git a/src/config/preferences.h b/src/config/preferences.h index e1b666a0..808ffafd 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -145,6 +145,7 @@ typedef enum { PREF_ROOM_LIST_CACHE, PREF_STATUSBAR_SHOW_NAME, PREF_STATUSBAR_SHOW_NUMBER, + PREF_STATUSBAR_SELF, PREF_STATUSBAR_CHAT, PREF_STATUSBAR_ROOM, } preference_t; diff --git a/src/ui/console.c b/src/ui/console.c index 60c5c8f5..26c830fc 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1754,6 +1754,14 @@ cons_statusbar_setting(void) cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs()); + char *pref_self = prefs_get_string(PREF_STATUSBAR_SELF); + if (g_strcmp0(pref_self, "off") == 0) { + cons_show("Self statusbar display (/statusbar) : OFF"); + } else { + cons_show("Self statusbar display (/statusbar) : %s", pref_self); + } + prefs_free_string(pref_self); + char *pref_chat = prefs_get_string(PREF_STATUSBAR_CHAT); cons_show("Chat tab display (/statusbar) : %s", pref_chat); prefs_free_string(pref_chat); diff --git a/src/ui/core.c b/src/ui/core.c index af0d55a9..a0ca8495 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -137,7 +137,7 @@ ui_update(void) _ui_draw_term_title(); } title_bar_update_virtual(); - status_bar_update_virtual(); + status_bar_draw(); inp_put_back(); doupdate(); @@ -388,8 +388,7 @@ ui_handle_login_account_success(ProfAccount *account, gboolean secured) title_bar_set_connected(TRUE); title_bar_set_tls(secured); - status_bar_print_message(connection_get_fulljid()); - status_bar_update_virtual(); + status_bar_set_prompt(connection_get_fulljid()); } void @@ -482,8 +481,7 @@ ui_disconnected(void) title_bar_set_connected(FALSE); title_bar_set_tls(FALSE); title_bar_set_presence(CONTACT_OFFLINE); - status_bar_clear_message(); - status_bar_update_virtual(); + status_bar_clear_prompt(); ui_hide_roster(); } @@ -975,15 +973,14 @@ ui_win_unread(int index) char* ui_ask_password(void) { - status_bar_get_password(); - status_bar_update_virtual(); + status_bar_set_prompt("Enter password:"); return inp_get_password(); } char* ui_get_line(void) { - status_bar_update_virtual(); + status_bar_draw(); return inp_get_line(); } @@ -1006,8 +1003,7 @@ ui_ask_pgp_passphrase(const char *hint, int prev_fail) ui_update(); - status_bar_get_password(); - status_bar_update_virtual(); + status_bar_set_prompt("Enter password:"); return inp_get_password(); } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 0173a201..654a4602 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -251,7 +251,7 @@ inp_get_line(void) line = inp_readline(); ui_update(); } - status_bar_clear(); + status_bar_clear_prompt(); return line; } @@ -269,7 +269,7 @@ inp_get_password(void) ui_update(); } get_password = FALSE; - status_bar_clear(); + status_bar_clear_prompt(); return password; } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index af6f49a2..28b20f01 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -61,7 +61,7 @@ typedef struct _status_bar_tab_t { typedef struct _status_bar_t { gchar *time; - char *message; + char *prompt; GHashTable *tabs; int current_tab; } StatusBar; @@ -70,9 +70,8 @@ static GTimeZone *tz; static StatusBar *statusbar; static WINDOW *statusbar_win; -static void _status_bar_draw(void); static int _status_bar_draw_time(int pos); -static void _status_bar_draw_message(int pos); +static void _status_bar_draw_prompt(int pos); static int _status_bar_draw_bracket(gboolean current, int pos, char* ch); static int _status_bar_draw_extended_tabs(int pos); static int _status_bar_draw_tab(StatusBarTab *tab, int pos, int num); @@ -88,7 +87,7 @@ status_bar_init(void) statusbar = malloc(sizeof(StatusBar)); statusbar->time = NULL; - statusbar->message = NULL; + statusbar->prompt = NULL; statusbar->tabs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)_destroy_tab); StatusBarTab *console = malloc(sizeof(StatusBarTab)); console->window_type = WIN_CONSOLE; @@ -100,7 +99,7 @@ status_bar_init(void) int cols = getmaxx(stdscr); statusbar_win = newwin(1, cols, row, 0); - _status_bar_draw(); + status_bar_draw(); } void @@ -113,19 +112,13 @@ status_bar_close(void) if (statusbar->time) { g_free(statusbar->time); } - if (statusbar->message) { - free(statusbar->message); + if (statusbar->prompt) { + free(statusbar->prompt); } free(statusbar); } } -void -status_bar_update_virtual(void) -{ - _status_bar_draw(); -} - void status_bar_resize(void) { @@ -135,7 +128,7 @@ status_bar_resize(void) mvwin(statusbar_win, row, 0); wresize(statusbar_win, 1, cols); - _status_bar_draw(); + status_bar_draw(); } void @@ -153,7 +146,7 @@ status_bar_current(int i) statusbar->current_tab = i; } - _status_bar_draw(); + status_bar_draw(); } void @@ -166,7 +159,7 @@ status_bar_inactive(const int win) g_hash_table_remove(statusbar->tabs, GINT_TO_POINTER(true_win)); - _status_bar_draw(); + status_bar_draw(); } void @@ -183,7 +176,7 @@ status_bar_active(const int win, win_type_t wintype, char *identifier) tab->window_type = wintype; g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab); - _status_bar_draw(); + status_bar_draw(); } void @@ -200,51 +193,34 @@ status_bar_new(const int win, win_type_t wintype, char* identifier) tab->window_type = wintype; g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab); - _status_bar_draw(); + status_bar_draw(); } void -status_bar_get_password(void) +status_bar_set_prompt(const char *const prompt) { - status_bar_print_message("Enter password:"); -} - -void -status_bar_print_message(const char *const msg) -{ - if (statusbar->message) { - free(statusbar->message); - statusbar->message = NULL; + if (statusbar->prompt) { + free(statusbar->prompt); + statusbar->prompt = NULL; } - statusbar->message = strdup(msg); + statusbar->prompt = strdup(prompt); - _status_bar_draw(); + status_bar_draw(); } void -status_bar_clear(void) +status_bar_clear_prompt(void) { - if (statusbar->message) { - free(statusbar->message); - statusbar->message = NULL; + if (statusbar->prompt) { + free(statusbar->prompt); + statusbar->prompt = NULL; } - _status_bar_draw(); + status_bar_draw(); } void -status_bar_clear_message(void) -{ - if (statusbar->message) { - free(statusbar->message); - statusbar->message = NULL; - } - - _status_bar_draw(); -} - -static void -_status_bar_draw(void) +status_bar_draw(void) { werase(statusbar_win); wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT)); @@ -253,7 +229,7 @@ _status_bar_draw(void) pos = _status_bar_draw_time(pos); - _status_bar_draw_message(pos); + _status_bar_draw_prompt(pos); pos = getmaxx(stdscr) - _tabs_width(); gint max_tabs = prefs_get_statusbartabs(); @@ -413,10 +389,10 @@ _status_bar_draw_time(int pos) } static void -_status_bar_draw_message(int pos) +_status_bar_draw_prompt(int pos) { - if (statusbar->message) { - mvwprintw(statusbar_win, 0, pos, statusbar->message); + if (statusbar->prompt) { + mvwprintw(statusbar_win, 0, pos, statusbar->prompt); } } diff --git a/src/ui/statusbar.h b/src/ui/statusbar.h index 370b4bbb..ce1f5482 100644 --- a/src/ui/statusbar.h +++ b/src/ui/statusbar.h @@ -36,13 +36,11 @@ #define UI_STATUSBAR_H void status_bar_init(void); +void status_bar_draw(void); void status_bar_close(void); -void status_bar_update_virtual(void); void status_bar_resize(void); -void status_bar_clear(void); -void status_bar_clear_message(void); -void status_bar_get_password(void); -void status_bar_print_message(const char *const msg); +void status_bar_clear_prompt(void); +void status_bar_set_prompt(const char *const prompt); void status_bar_current(int i); #endif