From 56b7482b0817e33286d5a941c0811d05514377d4 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 23 Jan 2020 19:42:22 +0100 Subject: [PATCH] Add option to display MUC name or JID in titlebar Add `/titlebar use [name|jid]`. --- src/command/cmd_ac.c | 13 +++++++++++++ src/command/cmd_defs.c | 14 ++++++++++---- src/command/cmd_funcs.c | 25 +++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + src/config/preferences.c | 5 +++++ src/config/preferences.h | 1 + src/config/theme.c | 1 + src/ui/console.c | 4 ++++ src/ui/titlebar.c | 22 +++++++++++++++++----- 9 files changed, 77 insertions(+), 9 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 6fa92792..db885ceb 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -205,6 +205,7 @@ static Autocomplete pgp_log_ac; static Autocomplete tls_ac; static Autocomplete titlebar_ac; static Autocomplete titlebar_show_ac; +static Autocomplete titlebar_use_ac; static Autocomplete tls_certpath_ac; static Autocomplete script_ac; static Autocomplete script_show_ac; @@ -791,6 +792,7 @@ cmd_ac_init(void) autocomplete_add(titlebar_ac, "down"); autocomplete_add(titlebar_ac, "show"); autocomplete_add(titlebar_ac, "hide"); + autocomplete_add(titlebar_ac, "use"); titlebar_show_ac = autocomplete_new(); autocomplete_add(titlebar_show_ac, "tls"); @@ -798,6 +800,10 @@ cmd_ac_init(void) autocomplete_add(titlebar_show_ac, "resource"); autocomplete_add(titlebar_show_ac, "presence"); + titlebar_use_ac = autocomplete_new(); + autocomplete_add(titlebar_use_ac, "name"); + autocomplete_add(titlebar_use_ac, "jid"); + tls_certpath_ac = autocomplete_new(); autocomplete_add(tls_certpath_ac, "set"); autocomplete_add(tls_certpath_ac, "clear"); @@ -1202,6 +1208,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(tls_ac); autocomplete_reset(titlebar_ac); autocomplete_reset(titlebar_show_ac); + autocomplete_reset(titlebar_use_ac); autocomplete_reset(tls_certpath_ac); autocomplete_reset(console_ac); autocomplete_reset(console_msg_ac); @@ -1343,6 +1350,7 @@ cmd_ac_uninit(void) autocomplete_free(tls_ac); autocomplete_free(titlebar_ac); autocomplete_free(titlebar_show_ac); + autocomplete_free(titlebar_use_ac); autocomplete_free(tls_certpath_ac); autocomplete_free(script_ac); autocomplete_free(script_show_ac); @@ -2964,6 +2972,11 @@ _titlebar_autocomplete(ProfWin *window, const char *const input, gboolean previo return result; } + result = autocomplete_param_with_ac(input, "/titlebar use", titlebar_use_ac, TRUE, previous); + if (result) { + return result; + } + result = autocomplete_param_with_ac(input, "/titlebar", titlebar_ac, TRUE, previous); if (result) { return result; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 5e3e556a..3ed8213e 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1293,7 +1293,8 @@ static struct cmd_t command_defs[] = parse_args, 1, 2, &cons_titlebar_setting, CMD_SUBFUNCS( { "show", cmd_titlebar_show_hide }, - { "hide", cmd_titlebar_show_hide } + { "hide", cmd_titlebar_show_hide }, + { "use", cmd_titlebar_use } ) CMD_MAINFUNC(cmd_titlebar) CMD_TAGS( @@ -1301,7 +1302,9 @@ static struct cmd_t command_defs[] = CMD_SYN( "/titlebar up", "/titlebar down", - "/titlebar show|hide [encwarn|resource|tls]") + "/titlebar show|hide [encwarn|resource|tls]", + "/titlebar use [name|jid]" + ) CMD_DESC( "Titlebar settings.") CMD_ARGS( @@ -1309,12 +1312,15 @@ static struct cmd_t command_defs[] = { "down", "Move the title bar down the screen." }, { "show tls", "Show or hide TLS indicator in the titlebar." }, { "show encwarn", "Enable or disable the unencrypted warning message in the titlebar." }, - { "show resource", "Show or hide the current resource in the titlebar." } + { "show resource", "Show or hide the current resource in the titlebar." }, + { "use name", "In case of a MUC. Use the MUC name as title." }, + { "use jid", "In case of a MUC. Use the JID as title." } ) CMD_EXAMPLES( "/titlebar up", "/titlebar show tls", - "/titlebar hide encwarn") + "/titlebar hide encwarn", + "/titlebar use name") }, { "/mainwin", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 2c85251e..d9fc0ed6 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5942,6 +5942,31 @@ cmd_titlebar_show_hide(ProfWin *window, const char *const command, gchar **args) return TRUE; } +gboolean +cmd_titlebar_use(ProfWin *window, const char *const command, gchar **args) +{ + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "use") == 0) { + if (g_strcmp0(args[1], "jid") == 0) { + cons_show("Using MUC JID in titlebar as title."); + prefs_set_string(PREF_TITLEBAR_MUC_TITLE, "jid"); + } else if (g_strcmp0(args[1], "name") == 0) { + cons_show("Using MUC name in titlebar as title."); + prefs_set_string(PREF_TITLEBAR_MUC_TITLE, "name"); + } else { + cons_bad_cmd_usage(command); + } + } else { + cons_bad_cmd_usage(command); + } + + return TRUE; +} + gboolean cmd_mainwin(ProfWin *window, const char *const command, gchar **args) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 4ce1e284..74cab615 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -146,6 +146,7 @@ gboolean cmd_resource(ProfWin *window, const char *const command, gchar **args); gboolean cmd_inpblock(ProfWin *window, const char *const command, gchar **args); gboolean cmd_titlebar(ProfWin *window, const char *const command, gchar **args); gboolean cmd_titlebar_show_hide(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_titlebar_use(ProfWin *window, const char *const command, gchar **args); gboolean cmd_mainwin(ProfWin *window, const char *const command, gchar **args); gboolean cmd_statusbar(ProfWin *window, const char *const command, gchar **args); gboolean cmd_inputwin(ProfWin *window, const char *const command, gchar **args); diff --git a/src/config/preferences.c b/src/config/preferences.c index 728fb54c..f80eae29 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1719,6 +1719,7 @@ _get_group(preference_t pref) case PREF_STATUSBAR_SELF: case PREF_STATUSBAR_CHAT: case PREF_STATUSBAR_ROOM: + case PREF_TITLEBAR_MUC_TITLE: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -1961,6 +1962,8 @@ _get_key(preference_t pref) return "inpblock.dynamic"; case PREF_ENC_WARN: return "enc.warn"; + case PREF_TITLEBAR_MUC_TITLE: + return "titlebar.muc.title"; case PREF_PGP_LOG: return "log"; case PREF_TLS_CERTPATH: @@ -2087,6 +2090,8 @@ _get_default_string(preference_t pref) return "none"; case PREF_ROSTER_ROOMS_USE_AS_NAME: return "name"; + case PREF_TITLEBAR_MUC_TITLE: + return "name"; case PREF_ROSTER_ROOMS_ORDER: return "name"; case PREF_ROSTER_ROOMS_UNREAD: diff --git a/src/config/preferences.h b/src/config/preferences.h index 99545bdb..3f21aee9 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -137,6 +137,7 @@ typedef enum { PREF_RESOURCE_MESSAGE, PREF_INPBLOCK_DYNAMIC, PREF_ENC_WARN, + PREF_TITLEBAR_MUC_TITLE, PREF_PGP_LOG, PREF_TLS_CERTPATH, PREF_TLS_SHOW, diff --git a/src/config/theme.c b/src/config/theme.c index 56e1fe7b..c254ad8c 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -309,6 +309,7 @@ _load_preferences(void) _set_boolean_preference("presence", PREF_PRESENCE); _set_boolean_preference("intype", PREF_INTYPE); _set_boolean_preference("enc.warn", PREF_ENC_WARN); + _set_boolean_preference("titlebar.muc.title", PREF_TITLEBAR_MUC_TITLE); _set_boolean_preference("tls.show", PREF_TLS_SHOW); _set_boolean_preference("statusbar.show.name", PREF_STATUSBAR_SHOW_NAME); _set_boolean_preference("statusbar.show.number", PREF_STATUSBAR_SHOW_NUMBER); diff --git a/src/ui/console.c b/src/ui/console.c index 820ad93b..49103fcf 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1158,6 +1158,10 @@ cons_titlebar_setting(void) } else { cons_show("Titlebar presence (/titlebar) : OFF"); } + + char *muctitle = prefs_get_string(PREF_TITLEBAR_MUC_TITLE); + cons_show("MUC window title (/titlebar) : %s", muctitle); + prefs_free_string(muctitle); } void diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 87e2fa63..02ac2254 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -190,14 +190,26 @@ _title_bar_draw(void) waddch(win, ' '); } - char *title; + char *title = NULL; if (current && current->type == WIN_MUC) { - ProfMucWin *mucwin = (ProfMucWin*) current; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - title = strdup(mucwin->room_name); - } else { + char *use_as_name = prefs_get_string(PREF_TITLEBAR_MUC_TITLE); + + if ((g_strcmp0(use_as_name, "name") == 0)) { + ProfMucWin *mucwin = (ProfMucWin*) current; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + + if (mucwin->room_name) { + title = strdup(mucwin->room_name); + } + } + + prefs_free_string(use_as_name); + } + + if (title == NULL) { title = win_get_title(current); } + mvwprintw(win, 0, 0, " %s", title); free(title);