1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Move tls show to titlebar command

Previously we had `/tls show on|off` to manipulate the UI setting for
the title bar. To decide whether to show TLS info there or not.

This should go into `/titlebar`.

Now we have `/titlebar show|hide tls` for this.

Regards https://github.com/profanity-im/profanity/issues/1116
This commit is contained in:
Michael Vetter 2019-11-05 13:48:26 +01:00
parent 8d2b1b05e7
commit 643d12af44
4 changed files with 72 additions and 23 deletions

View File

@ -94,6 +94,7 @@ static char* _receipts_autocomplete(ProfWin *window, const char *const input, gb
static char* _help_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _wins_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _tls_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _titlebar_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _script_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _subject_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _console_autocomplete(ProfWin *window, const char *const input, gboolean previous);
@ -196,6 +197,8 @@ static Autocomplete receipts_ac;
static Autocomplete pgp_ac;
static Autocomplete pgp_log_ac;
static Autocomplete tls_ac;
static Autocomplete titlebar_ac;
static Autocomplete titlebar_show_ac;
static Autocomplete tls_certpath_ac;
static Autocomplete script_ac;
static Autocomplete script_show_ac;
@ -763,7 +766,15 @@ cmd_ac_init(void)
autocomplete_add(tls_ac, "trusted");
autocomplete_add(tls_ac, "revoke");
autocomplete_add(tls_ac, "certpath");
autocomplete_add(tls_ac, "show");
titlebar_ac = autocomplete_new();
autocomplete_add(titlebar_ac, "up");
autocomplete_add(titlebar_ac, "down");
autocomplete_add(titlebar_ac, "show");
autocomplete_add(titlebar_ac, "hide");
titlebar_show_ac = autocomplete_new();
autocomplete_add(titlebar_show_ac, "tls");
tls_certpath_ac = autocomplete_new();
autocomplete_add(tls_certpath_ac, "set");
@ -1140,6 +1151,8 @@ cmd_ac_reset(ProfWin *window)
autocomplete_reset(pgp_ac);
autocomplete_reset(pgp_log_ac);
autocomplete_reset(tls_ac);
autocomplete_reset(titlebar_ac);
autocomplete_reset(titlebar_show_ac);
autocomplete_reset(tls_certpath_ac);
autocomplete_reset(console_ac);
autocomplete_reset(console_msg_ac);
@ -1273,6 +1286,8 @@ cmd_ac_uninit(void)
autocomplete_free(pgp_ac);
autocomplete_free(pgp_log_ac);
autocomplete_free(tls_ac);
autocomplete_free(titlebar_ac);
autocomplete_free(titlebar_show_ac);
autocomplete_free(tls_certpath_ac);
autocomplete_free(script_ac);
autocomplete_free(script_show_ac);
@ -1493,8 +1508,8 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
}
}
gchar *cmds[] = { "/prefs", "/disco", "/room", "/autoping", "/titlebar", "/mainwin", "/inputwin" };
Autocomplete completers[] = { prefs_ac, disco_ac, room_ac, autoping_ac, winpos_ac, winpos_ac, winpos_ac };
gchar *cmds[] = { "/prefs", "/disco", "/room", "/autoping", "/mainwin", "/inputwin" };
Autocomplete completers[] = { prefs_ac, disco_ac, room_ac, autoping_ac, winpos_ac, winpos_ac };
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE, previous);
@ -1535,6 +1550,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
g_hash_table_insert(ac_funcs, "/receipts", _receipts_autocomplete);
g_hash_table_insert(ac_funcs, "/wins", _wins_autocomplete);
g_hash_table_insert(ac_funcs, "/tls", _tls_autocomplete);
g_hash_table_insert(ac_funcs, "/titlebar", _titlebar_autocomplete);
g_hash_table_insert(ac_funcs, "/script", _script_autocomplete);
g_hash_table_insert(ac_funcs, "/subject", _subject_autocomplete);
g_hash_table_insert(ac_funcs, "/console", _console_autocomplete);
@ -2869,12 +2885,30 @@ _tls_autocomplete(ProfWin *window, const char *const input, gboolean previous)
return result;
}
result = autocomplete_param_with_func(input, "/tls show", prefs_autocomplete_boolean_choice, previous);
result = autocomplete_param_with_ac(input, "/tls", tls_ac, TRUE, previous);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/tls", tls_ac, TRUE, previous);
return result;
}
static char*
_titlebar_autocomplete(ProfWin *window, const char *const input, gboolean previous)
{
char *result = NULL;
result = autocomplete_param_with_ac(input, "/titlebar show", titlebar_show_ac, TRUE, previous);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/titlebar hide", titlebar_show_ac, TRUE, previous);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/titlebar", titlebar_ac, TRUE, previous);
if (result) {
return result;
}

View File

@ -189,7 +189,6 @@ static struct cmd_t command_defs[] =
{ "trust", cmd_tls_trust },
{ "trusted", cmd_tls_trusted },
{ "revoke", cmd_tls_revoke },
{ "show", cmd_tls_show },
{ "cert", cmd_tls_cert })
CMD_NOMAINFUNC
CMD_TAGS(
@ -206,8 +205,7 @@ static struct cmd_t command_defs[] =
"/tls certpath",
"/tls certpath set <path>",
"/tls certpath clear",
"/tls certpath default",
"/tls show on|off")
"/tls certpath default")
CMD_DESC(
"Handle TLS certificates. ")
CMD_ARGS(
@ -222,8 +220,7 @@ static struct cmd_t command_defs[] =
{ "certpath", "Show the trusted certificate path." },
{ "certpath set <path>", "Specify filesystem path containing trusted certificates." },
{ "certpath clear", "Clear the trusted certificate path." },
{ "certpath default", "Use default system certificate path, if it can be found." },
{ "show on|off", "Show or hide the TLS indicator in the titlebar." })
{ "certpath default", "Use default system certificate path, if it can be found." })
CMD_NOEXAMPLES
},
@ -1327,19 +1324,25 @@ static struct cmd_t command_defs[] =
},
{ "/titlebar",
parse_args, 1, 1, &cons_winpos_setting,
CMD_NOSUBFUNCS
parse_args, 1, 2, &cons_winpos_setting,
CMD_SUBFUNCS(
{ "show", cmd_titlebar_tls_show },
{ "hide", cmd_titlebar_tls_show }
)
CMD_MAINFUNC(cmd_titlebar)
CMD_TAGS(
CMD_TAG_UI)
CMD_SYN(
"/titlebar up",
"/titlebar down")
"/titlebar down",
"/titlebar show|hide tls")
CMD_DESC(
"Move the title bar.")
"Titlebar settings.")
CMD_ARGS(
{ "up", "Move the title bar up the screen." },
{ "down", "Move the title bar down the screen." })
{ "down", "Move the title bar down the screen." },
{ "show", "Show or hide the TLS indicator in the titlebar." }
)
CMD_NOEXAMPLES
},

View File

@ -287,13 +287,6 @@ cmd_tls_revoke(ProfWin *window, const char *const command, gchar **args)
#endif
}
gboolean
cmd_tls_show(ProfWin *window, const char *const command, gchar **args)
{
_cmd_set_boolean_preference(args[1], command, "TLS titlebar indicator", PREF_TLS_SHOW);
return TRUE;
}
gboolean
cmd_tls_cert(ProfWin *window, const char *const command, gchar **args)
{
@ -5953,6 +5946,25 @@ cmd_titlebar(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
gboolean
cmd_titlebar_tls_show(ProfWin *window, const char *const command, gchar **args)
{
if (args[1] == NULL || g_strcmp0(args[1], "tls") != 0) {
cons_bad_cmd_usage(command);
} else {
if (g_strcmp0(args[0], "show") == 0) {
cons_show("TLS titlebar indicator enabled.");
prefs_set_boolean(PREF_TLS_SHOW, TRUE);
} else if (g_strcmp0(args[0], "hide") == 0) {
cons_show("TLS titlebar indicator disabled.");
prefs_set_boolean(PREF_TLS_SHOW, FALSE);
} else {
cons_bad_cmd_usage(command);
}
}
return TRUE;
}
gboolean
cmd_mainwin(ProfWin *window, const char *const command, gchar **args)
{

View File

@ -151,6 +151,7 @@ gboolean cmd_time(ProfWin *window, const char *const command, gchar **args);
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_tls_show(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);
@ -190,7 +191,6 @@ gboolean cmd_tls_certpath(ProfWin *window, const char *const command, gchar **ar
gboolean cmd_tls_trust(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_tls_trusted(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_tls_revoke(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_tls_show(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_tls_cert(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_otr_char(ProfWin *window, const char *const command, gchar **args);