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

titlebar: allow displaying MUC name and MUC jid

`/titlebar use name|jid` -> `/titlebar show|hide name|jid`

Fix https://github.com/profanity-im/profanity/issues/1284
This commit is contained in:
Michael Vetter 2020-03-24 22:13:14 +01:00
parent fd090d384d
commit f131680055
9 changed files with 65 additions and 63 deletions

View File

@ -210,7 +210,6 @@ static Autocomplete pgp_sendfile_ac;
static Autocomplete tls_ac; static Autocomplete tls_ac;
static Autocomplete titlebar_ac; static Autocomplete titlebar_ac;
static Autocomplete titlebar_show_ac; static Autocomplete titlebar_show_ac;
static Autocomplete titlebar_use_ac;
static Autocomplete tls_certpath_ac; static Autocomplete tls_certpath_ac;
static Autocomplete script_ac; static Autocomplete script_ac;
static Autocomplete script_show_ac; static Autocomplete script_show_ac;
@ -825,10 +824,8 @@ cmd_ac_init(void)
autocomplete_add(titlebar_show_ac, "encwarn"); autocomplete_add(titlebar_show_ac, "encwarn");
autocomplete_add(titlebar_show_ac, "resource"); autocomplete_add(titlebar_show_ac, "resource");
autocomplete_add(titlebar_show_ac, "presence"); autocomplete_add(titlebar_show_ac, "presence");
autocomplete_add(titlebar_show_ac, "jid");
titlebar_use_ac = autocomplete_new(); autocomplete_add(titlebar_show_ac, "name");
autocomplete_add(titlebar_use_ac, "name");
autocomplete_add(titlebar_use_ac, "jid");
tls_certpath_ac = autocomplete_new(); tls_certpath_ac = autocomplete_new();
autocomplete_add(tls_certpath_ac, "set"); autocomplete_add(tls_certpath_ac, "set");
@ -1256,7 +1253,6 @@ cmd_ac_reset(ProfWin *window)
autocomplete_reset(tls_ac); autocomplete_reset(tls_ac);
autocomplete_reset(titlebar_ac); autocomplete_reset(titlebar_ac);
autocomplete_reset(titlebar_show_ac); autocomplete_reset(titlebar_show_ac);
autocomplete_reset(titlebar_use_ac);
autocomplete_reset(tls_certpath_ac); autocomplete_reset(tls_certpath_ac);
autocomplete_reset(console_ac); autocomplete_reset(console_ac);
autocomplete_reset(console_msg_ac); autocomplete_reset(console_msg_ac);
@ -1405,7 +1401,6 @@ cmd_ac_uninit(void)
autocomplete_free(tls_ac); autocomplete_free(tls_ac);
autocomplete_free(titlebar_ac); autocomplete_free(titlebar_ac);
autocomplete_free(titlebar_show_ac); autocomplete_free(titlebar_show_ac);
autocomplete_free(titlebar_use_ac);
autocomplete_free(tls_certpath_ac); autocomplete_free(tls_certpath_ac);
autocomplete_free(script_ac); autocomplete_free(script_ac);
autocomplete_free(script_show_ac); autocomplete_free(script_show_ac);
@ -3085,11 +3080,6 @@ _titlebar_autocomplete(ProfWin *window, const char *const input, gboolean previo
return result; 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); result = autocomplete_param_with_ac(input, "/titlebar", titlebar_ac, TRUE, previous);
if (result) { if (result) {
return result; return result;

View File

@ -1292,8 +1292,7 @@ static struct cmd_t command_defs[] =
parse_args, 1, 2, &cons_titlebar_setting, parse_args, 1, 2, &cons_titlebar_setting,
CMD_SUBFUNCS( CMD_SUBFUNCS(
{ "show", cmd_titlebar_show_hide }, { "show", cmd_titlebar_show_hide },
{ "hide", cmd_titlebar_show_hide }, { "hide", cmd_titlebar_show_hide }
{ "use", cmd_titlebar_use }
) )
CMD_MAINFUNC(cmd_titlebar) CMD_MAINFUNC(cmd_titlebar)
CMD_TAGS( CMD_TAGS(
@ -1301,8 +1300,7 @@ static struct cmd_t command_defs[] =
CMD_SYN( CMD_SYN(
"/titlebar up", "/titlebar up",
"/titlebar down", "/titlebar down",
"/titlebar show|hide [encwarn|resource|tls]", "/titlebar show|hide [encwarn|resource|tls]"
"/titlebar use name|jid"
) )
CMD_DESC( CMD_DESC(
"Titlebar settings.") "Titlebar settings.")
@ -1312,14 +1310,13 @@ static struct cmd_t command_defs[] =
{ "show tls", "Show or hide TLS indicator in the titlebar." }, { "show tls", "Show or hide TLS indicator in the titlebar." },
{ "show encwarn", "Enable or disable the unencrypted warning message 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." }, { "show name", "In case of a MUC. Show the MUC name in the titlebar." },
{ "use jid", "In case of a MUC. Use the JID as title." } { "show jid", "In case of a MUC. Show the JID in the titlebar." }
) )
CMD_EXAMPLES( CMD_EXAMPLES(
"/titlebar up", "/titlebar up",
"/titlebar show tls", "/titlebar show tls",
"/titlebar hide encwarn", "/titlebar hide encwarn")
"/titlebar use name")
}, },
{ "/mainwin", { "/mainwin",

View File

@ -5958,6 +5958,12 @@ cmd_titlebar_show_hide(ProfWin *window, const char *const command, gchar **args)
} else if (g_strcmp0(args[1], "presence") == 0) { } else if (g_strcmp0(args[1], "presence") == 0) {
cons_show("Showing contact presence in titlebar enabled."); cons_show("Showing contact presence in titlebar enabled.");
prefs_set_boolean(PREF_PRESENCE , TRUE); prefs_set_boolean(PREF_PRESENCE , TRUE);
} else if (g_strcmp0(args[1], "jid") == 0) {
cons_show("Showing MUC JID in titlebar as title enabled.");
prefs_set_boolean(PREF_TITLEBAR_MUC_TITLE_JID, TRUE);
} else if (g_strcmp0(args[1], "name") == 0) {
cons_show("Showing MUC name in titlebar as title enabled.");
prefs_set_boolean(PREF_TITLEBAR_MUC_TITLE_NAME, TRUE);
} else { } else {
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);
} }
@ -5975,6 +5981,12 @@ cmd_titlebar_show_hide(ProfWin *window, const char *const command, gchar **args)
} else if (g_strcmp0(args[1], "presence") == 0) { } else if (g_strcmp0(args[1], "presence") == 0) {
cons_show("Showing contact presence in titlebar enabled."); cons_show("Showing contact presence in titlebar enabled.");
prefs_set_boolean(PREF_PRESENCE , FALSE); prefs_set_boolean(PREF_PRESENCE , FALSE);
} else if (g_strcmp0(args[1], "jid") == 0) {
cons_show("Showing MUC JID in titlebar as title disabled.");
prefs_set_boolean(PREF_TITLEBAR_MUC_TITLE_JID, FALSE);
} else if (g_strcmp0(args[1], "name") == 0) {
cons_show("Showing MUC name in titlebar as title disabled.");
prefs_set_boolean(PREF_TITLEBAR_MUC_TITLE_NAME, FALSE);
} else { } else {
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);
} }
@ -5986,31 +5998,6 @@ cmd_titlebar_show_hide(ProfWin *window, const char *const command, gchar **args)
return TRUE; 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 gboolean
cmd_mainwin(ProfWin *window, const char *const command, gchar **args) cmd_mainwin(ProfWin *window, const char *const command, gchar **args)
{ {

View File

@ -146,7 +146,6 @@ gboolean cmd_resource(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_inpblock(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(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_titlebar_show_hide(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_mainwin(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_statusbar(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); gboolean cmd_inputwin(ProfWin *window, const char *const command, gchar **args);

View File

@ -149,6 +149,16 @@ static void _prefs_load(void)
g_key_file_remove_key(prefs, PREF_GROUP_UI, "titlebar.goodbye", NULL); g_key_file_remove_key(prefs, PREF_GROUP_UI, "titlebar.goodbye", NULL);
} }
// after 0.8.1: titlebar use jid|name -> titlebar show|hide jid|name
if (g_key_file_has_key(prefs, PREF_GROUP_UI, "titlebar.muc.title", NULL)) {
char *value = g_key_file_get_string(prefs, PREF_GROUP_UI, "titlebar.muc.title", NULL);
if (g_strcmp0(value, "name") == 0) {
g_key_file_set_boolean(prefs, PREF_GROUP_UI, "titlebar.muc.title.name", TRUE);
} else if (g_strcmp0(value, "jid") == 0) {
g_key_file_set_boolean(prefs, PREF_GROUP_UI, "titlebar.muc.title.jid", TRUE);
}
}
_save_prefs(); _save_prefs();
boolean_choice_ac = autocomplete_new(); boolean_choice_ac = autocomplete_new();
@ -1742,7 +1752,8 @@ _get_group(preference_t pref)
case PREF_STATUSBAR_SELF: case PREF_STATUSBAR_SELF:
case PREF_STATUSBAR_CHAT: case PREF_STATUSBAR_CHAT:
case PREF_STATUSBAR_ROOM: case PREF_STATUSBAR_ROOM:
case PREF_TITLEBAR_MUC_TITLE: case PREF_TITLEBAR_MUC_TITLE_JID:
case PREF_TITLEBAR_MUC_TITLE_NAME:
case PREF_HISTORY_COLOR_MUC: case PREF_HISTORY_COLOR_MUC:
case PREF_SLASH_GUARD: case PREF_SLASH_GUARD:
return PREF_GROUP_UI; return PREF_GROUP_UI;
@ -2000,8 +2011,10 @@ _get_key(preference_t pref)
return "inpblock.dynamic"; return "inpblock.dynamic";
case PREF_ENC_WARN: case PREF_ENC_WARN:
return "enc.warn"; return "enc.warn";
case PREF_TITLEBAR_MUC_TITLE: case PREF_TITLEBAR_MUC_TITLE_JID:
return "titlebar.muc.title"; return "titlebar.muc.title.jid";
case PREF_TITLEBAR_MUC_TITLE_NAME:
return "titlebar.muc.title.name";
case PREF_PGP_LOG: case PREF_PGP_LOG:
return "log"; return "log";
case PREF_PGP_SENDFILE: case PREF_PGP_SENDFILE:
@ -2109,6 +2122,7 @@ _get_default_boolean(preference_t pref)
case PREF_CARBONS: case PREF_CARBONS:
case PREF_STATES: case PREF_STATES:
case PREF_OUTTYPE: case PREF_OUTTYPE:
case PREF_TITLEBAR_MUC_TITLE_NAME:
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;
@ -2146,8 +2160,6 @@ _get_default_string(preference_t pref)
return "none"; return "none";
case PREF_ROSTER_ROOMS_USE_AS_NAME: case PREF_ROSTER_ROOMS_USE_AS_NAME:
return "name"; return "name";
case PREF_TITLEBAR_MUC_TITLE:
return "name";
case PREF_ROSTER_ROOMS_ORDER: case PREF_ROSTER_ROOMS_ORDER:
return "name"; return "name";
case PREF_ROSTER_ROOMS_UNREAD: case PREF_ROSTER_ROOMS_UNREAD:

View File

@ -140,7 +140,8 @@ typedef enum {
PREF_RESOURCE_MESSAGE, PREF_RESOURCE_MESSAGE,
PREF_INPBLOCK_DYNAMIC, PREF_INPBLOCK_DYNAMIC,
PREF_ENC_WARN, PREF_ENC_WARN,
PREF_TITLEBAR_MUC_TITLE, PREF_TITLEBAR_MUC_TITLE_JID,
PREF_TITLEBAR_MUC_TITLE_NAME,
PREF_PGP_LOG, PREF_PGP_LOG,
PREF_PGP_SENDFILE, PREF_PGP_SENDFILE,
PREF_TLS_CERTPATH, PREF_TLS_CERTPATH,

View File

@ -315,7 +315,8 @@ _load_preferences(void)
_set_boolean_preference("presence", PREF_PRESENCE); _set_boolean_preference("presence", PREF_PRESENCE);
_set_boolean_preference("intype", PREF_INTYPE); _set_boolean_preference("intype", PREF_INTYPE);
_set_boolean_preference("enc.warn", PREF_ENC_WARN); _set_boolean_preference("enc.warn", PREF_ENC_WARN);
_set_boolean_preference("titlebar.muc.title", PREF_TITLEBAR_MUC_TITLE); _set_boolean_preference("titlebar.muc.title.name", PREF_TITLEBAR_MUC_TITLE_NAME);
_set_boolean_preference("titlebar.muc.title.jid", PREF_TITLEBAR_MUC_TITLE_JID);
_set_boolean_preference("tls.show", PREF_TLS_SHOW); _set_boolean_preference("tls.show", PREF_TLS_SHOW);
_set_boolean_preference("statusbar.show.name", PREF_STATUSBAR_SHOW_NAME); _set_boolean_preference("statusbar.show.name", PREF_STATUSBAR_SHOW_NAME);
_set_boolean_preference("statusbar.show.number", PREF_STATUSBAR_SHOW_NUMBER); _set_boolean_preference("statusbar.show.number", PREF_STATUSBAR_SHOW_NUMBER);

View File

@ -1159,9 +1159,17 @@ cons_titlebar_setting(void)
cons_show("Titlebar presence (/titlebar) : OFF"); cons_show("Titlebar presence (/titlebar) : OFF");
} }
char *muctitle = prefs_get_string(PREF_TITLEBAR_MUC_TITLE); if (prefs_get_boolean(PREF_TITLEBAR_MUC_TITLE_NAME)) {
cons_show("MUC window title (/titlebar) : %s", muctitle); cons_show("Titlebar show MUC name (/titlebar) : ON");
prefs_free_string(muctitle); } else {
cons_show("Titlebar show MUC name (/titlebar) : OFF");
}
if (prefs_get_boolean(PREF_TITLEBAR_MUC_TITLE_JID)) {
cons_show("Titlebar show MUC JID (/titlebar) : ON");
} else {
cons_show("Titlebar show MUC JID (/titlebar) : OFF");
}
} }
void void

View File

@ -300,14 +300,21 @@ win_get_title(ProfWin *window)
ProfMucWin *mucwin = (ProfMucWin*) window; ProfMucWin *mucwin = (ProfMucWin*) window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
char *use_as_name = prefs_get_string(PREF_TITLEBAR_MUC_TITLE); gboolean show_titlebar_jid = prefs_get_boolean(PREF_TITLEBAR_MUC_TITLE_JID);
if ((g_strcmp0(use_as_name, "name") == 0) && mucwin->room_name) { gboolean show_titlebar_name = prefs_get_boolean(PREF_TITLEBAR_MUC_TITLE_NAME);
prefs_free_string(use_as_name); GString *title = g_string_new("");
return strdup(mucwin->room_name);
} else { if (show_titlebar_name) {
prefs_free_string(use_as_name); g_string_append(title, mucwin->room_name);
return strdup(mucwin->roomjid); g_string_append(title, " ");
} }
if (show_titlebar_jid) {
g_string_append(title, mucwin->roomjid);
}
char *title_str = title->str;
g_string_free(title, FALSE);
return title_str;
} }
if (window->type == WIN_CONFIG) { if (window->type == WIN_CONFIG) {
ProfConfWin *confwin = (ProfConfWin*) window; ProfConfWin *confwin = (ProfConfWin*) window;