From ef832ce5263cd90ec0458264769f40fad85b877c Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 14 Oct 2015 00:46:16 +0100 Subject: Add preference for showing TLS indicator in titlebar Issue #616 --- src/command/command.c | 12 ++++++++++-- src/command/commands.c | 2 ++ src/config/preferences.c | 4 ++++ src/config/preferences.h | 1 + src/config/theme.c | 1 + src/ui/titlebar.c | 2 +- 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index f1432d90..e6e518fe 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -200,7 +200,8 @@ static struct cmd_t command_defs[] = "/tls revoke ", "/tls certpath", "/tls certpath set ", - "/tls certpath clear") + "/tls certpath clear", + "/tls show on|off") CMD_DESC( "Handle TLS certificates. ") CMD_ARGS( @@ -211,7 +212,8 @@ static struct cmd_t command_defs[] = { "revoke ", "Remove a manually trusted certificate." }, { "certpath", "Show the trusted certificate path." }, { "certpath set ", "Specify filesystem path containing trusted certificates." }, - { "certpath clear", "Clear the trusted certificate path." }) + { "certpath clear", "Clear the trusted certificate path." }, + { "show on|off", "Show or hide the TLS indicator in the titlebar." }) CMD_NOEXAMPLES }, @@ -2158,6 +2160,7 @@ cmd_init(void) autocomplete_add(tls_ac, "trusted"); autocomplete_add(tls_ac, "revoke"); autocomplete_add(tls_ac, "certpath"); + autocomplete_add(tls_ac, "show"); tls_certpath_ac = autocomplete_new(); autocomplete_add(tls_certpath_ac, "set"); @@ -3628,6 +3631,11 @@ _tls_autocomplete(ProfWin *window, const char * const input) return result; } + result = autocomplete_param_with_func(input, "/tls show", prefs_autocomplete_boolean_choice); + if (result) { + return result; + } + result = autocomplete_param_with_ac(input, "/tls", tls_ac, TRUE); if (result) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index c34c7cc3..94e768db 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -237,6 +237,8 @@ cmd_tls(ProfWin *window, const char * const command, gchar **args) } } return TRUE; + } else if (g_strcmp0(args[0], "show") == 0) { + return _cmd_set_boolean_preference(args[1], command, "TLS titlebar indicator", PREF_TLS_SHOW); } else { cons_bad_cmd_usage(command); return TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index 527ed302..9aaa9083 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -602,6 +602,7 @@ _get_group(preference_t pref) case PREF_RESOURCE_MESSAGE: case PREF_ENC_WARN: case PREF_INPBLOCK_DYNAMIC: + case PREF_TLS_SHOW: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -781,6 +782,8 @@ _get_key(preference_t pref) return "log"; case PREF_CERT_PATH: return "certpath"; + case PREF_TLS_SHOW: + return "tls.show"; default: return NULL; } @@ -817,6 +820,7 @@ _get_default_boolean(preference_t pref) case PREF_ROSTER_OFFLINE: case PREF_ROSTER_RESOURCE: case PREF_ROSTER_EMPTY: + case PREF_TLS_SHOW: return TRUE; default: return FALSE; diff --git a/src/config/preferences.h b/src/config/preferences.h index 770e379e..a0b3c06e 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -112,6 +112,7 @@ typedef enum { PREF_ENC_WARN, PREF_PGP_LOG, PREF_CERT_PATH, + PREF_TLS_SHOW, } preference_t; typedef struct prof_alias_t { diff --git a/src/config/theme.c b/src/config/theme.c index e840fab5..0c9a39b7 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -471,6 +471,7 @@ _load_preferences(void) _set_boolean_preference("intype", PREF_INTYPE); _set_boolean_preference("enc.warn", PREF_ENC_WARN); + _set_boolean_preference("tls.show", PREF_TLS_SHOW); if (g_key_file_has_key(theme, "ui", "otr.char", NULL)) { gchar *ch = g_key_file_get_string(theme, "ui", "otr.char", NULL); diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 32ba13b4..41715811 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -282,7 +282,7 @@ _show_self_presence(void) mvwaddch(win, 0, cols - 2, ']'); wattroff(win, bracket_attrs); - if (is_connected) { + if (is_connected && prefs_get_boolean(PREF_TLS_SHOW)) { wattron(win, bracket_attrs); mvwaddch(win, 0, cols - tls_start, '['); wattroff(win, bracket_attrs); -- cgit 1.4.1-2-gfad0