diff options
author | Michael Vetter <jubalh@iodoru.org> | 2019-05-03 11:11:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-03 11:11:40 +0200 |
commit | 4a165b81e6938186fbad59801051b972f77b6e0d (patch) | |
tree | e46d877f75e000f3fdbdc978d2d6466b01706137 | |
parent | 45ea73125ff9a05f239152215072fc9910ecb338 (diff) | |
parent | f082563bf2687465f0ca924985ec4d38277459ba (diff) | |
download | profani-tty-4a165b81e6938186fbad59801051b972f77b6e0d.tar.gz |
Merge pull request #1084 from jubalh/occupants-char
Add occupants char
-rw-r--r-- | src/command/cmd_ac.c | 18 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 3 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 17 | ||||
-rw-r--r-- | src/config/preferences.c | 34 | ||||
-rw-r--r-- | src/config/preferences.h | 3 | ||||
-rw-r--r-- | src/config/theme.c | 10 | ||||
-rw-r--r-- | src/ui/console.c | 6 | ||||
-rw-r--r-- | src/ui/occupantswin.c | 5 | ||||
-rw-r--r-- | theme_template | 1 |
9 files changed, 94 insertions, 3 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 306f789e..5d1dff12 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -184,6 +184,7 @@ static Autocomplete occupants_ac; static Autocomplete occupants_default_ac; static Autocomplete occupants_show_ac; static Autocomplete occupants_header_ac; +static Autocomplete occupants_header_char_ac; static Autocomplete occupants_char_ac; static Autocomplete time_ac; static Autocomplete time_format_ac; @@ -688,6 +689,7 @@ cmd_ac_init(void) autocomplete_add(occupants_ac, "indent"); autocomplete_add(occupants_ac, "header"); autocomplete_add(occupants_ac, "wrap"); + autocomplete_add(occupants_ac, "char"); occupants_default_ac = autocomplete_new(); autocomplete_add(occupants_default_ac, "show"); @@ -696,11 +698,14 @@ cmd_ac_init(void) occupants_show_ac = autocomplete_new(); autocomplete_add(occupants_show_ac, "jid"); + occupants_char_ac = autocomplete_new(); + autocomplete_add(occupants_char_ac, "none"); + occupants_header_ac = autocomplete_new(); autocomplete_add(occupants_header_ac, "char"); - occupants_char_ac = autocomplete_new(); - autocomplete_add(occupants_char_ac, "none"); + occupants_header_char_ac = autocomplete_new(); + autocomplete_add(occupants_header_char_ac, "none"); time_ac = autocomplete_new(); autocomplete_add(time_ac, "console"); @@ -1115,10 +1120,11 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(form_ac); autocomplete_reset(form_field_multi_ac); autocomplete_reset(occupants_ac); + autocomplete_reset(occupants_char_ac); autocomplete_reset(occupants_default_ac); autocomplete_reset(occupants_show_ac); autocomplete_reset(occupants_header_ac); - autocomplete_reset(occupants_char_ac); + autocomplete_reset(occupants_header_char_ac); autocomplete_reset(time_ac); autocomplete_reset(time_format_ac); autocomplete_reset(resource_ac); @@ -1247,6 +1253,7 @@ cmd_ac_uninit(void) autocomplete_free(form_ac); autocomplete_free(form_field_multi_ac); autocomplete_free(occupants_ac); + autocomplete_free(occupants_char_ac); autocomplete_free(occupants_default_ac); autocomplete_free(occupants_show_ac); autocomplete_free(occupants_header_ac); @@ -2563,6 +2570,11 @@ _occupants_autocomplete(ProfWin *window, const char *const input, gboolean previ return found; } + found = autocomplete_param_with_ac(input, "/occupants char", occupants_char_ac, TRUE, previous); + if (found) { + return found; + } + found = autocomplete_param_with_ac(input, "/occupants default hide", occupants_show_ac, TRUE, previous); if (found) { return found; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index d9b26259..c6561949 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -752,6 +752,7 @@ static struct cmd_t command_defs[] = CMD_TAG_UI) CMD_SYN( "/occupants show|hide [jid]", + "/occupants char <char>|none", "/occupants default show|hide [jid]", "/occupants size [<percent>]", "/occupants indent <indent>", @@ -761,6 +762,8 @@ static struct cmd_t command_defs[] = "Show or hide room occupants, and occupants panel display settings.") CMD_ARGS( { "show", "Show the occupants panel in current room." }, + { "char <char>", "Prefix occupants with specified character." }, + { "char none", "Remove occupants character prefix." }, { "hide", "Hide the occupants panel in current room." }, { "show jid", "Show jid in the occupants panel in current room." }, { "hide jid", "Hide jid in the occupants panel in current room." }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index e87f5bb5..12a099e2 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -4402,6 +4402,23 @@ cmd_occupants(ProfWin *window, const char *const command, gchar **args) } } + if (g_strcmp0(args[0], "char") == 0) { + if (!args[1]) { + cons_bad_cmd_usage(command); + } else if (g_strcmp0(args[1], "none") == 0) { + prefs_clear_occupants_char(); + cons_show("Occupants char removed."); + + occupantswin_occupants_all(); + } else { + prefs_set_occupants_char(args[1][0]); + cons_show("Occupants char set to %c.", args[1][0]); + + occupantswin_occupants_all(); + } + return TRUE; + } + if (g_strcmp0(args[0], "default") == 0) { if (g_strcmp0(args[1], "show") == 0) { if (g_strcmp0(args[2], "jid") == 0) { diff --git a/src/config/preferences.c b/src/config/preferences.c index 4fd96381..d93854cc 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -750,6 +750,40 @@ prefs_get_occupants_size(void) } } +char +prefs_get_occupants_char(void) +{ + char result = 0; + + char *resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "occupants.char", NULL); + if (!resultstr) { + result = 0; + } else { + result = resultstr[0]; + } + free(resultstr); + + return result; +} + +void +prefs_set_occupants_char(char ch) +{ + char str[2]; + str[0] = ch; + str[1] = '\0'; + + g_key_file_set_string(prefs, PREF_GROUP_UI, "occupants.char", str); + _save_prefs(); +} + +void +prefs_clear_occupants_char(void) +{ + g_key_file_remove_key(prefs, PREF_GROUP_UI, "occupants.char", NULL); + _save_prefs(); +} + gint prefs_get_occupants_indent(void) { diff --git a/src/config/preferences.h b/src/config/preferences.h index 5bc82dc9..108111c8 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -240,6 +240,9 @@ void prefs_clear_roster_room_char(void); char prefs_get_roster_room_private_char(void); void prefs_set_roster_room_private_char(char ch); void prefs_clear_roster_room_private_char(void); +char prefs_get_occupants_char(void); +void prefs_set_occupants_char(char ch); +void prefs_clear_occupants_char(void); char prefs_get_occupants_header_char(void); void prefs_set_occupants_header_char(char ch); void prefs_clear_occupants_header_char(void); diff --git a/src/config/theme.c b/src/config/theme.c index 8d8061e9..a0ca8356 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -453,6 +453,16 @@ _load_preferences(void) prefs_set_occupants_size(occupants_size); } + if (g_key_file_has_key(theme, "ui", "occupants.char", NULL)) { + gchar *ch = g_key_file_get_string(theme, "ui", "occupants.char", NULL); + if (ch && strlen(ch) > 0) { + prefs_set_occupants_char(ch[0]); + g_free(ch); + } + } else { + prefs_clear_occupants_char(); + } + if (g_key_file_has_key(theme, "ui", "occupants.indent", NULL)) { gint occupants_indent = g_key_file_get_integer(theme, "ui", "occupants.indent", NULL); prefs_set_occupants_indent(occupants_indent); diff --git a/src/ui/console.c b/src/ui/console.c index d16aef6c..c03a8bb7 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1237,6 +1237,12 @@ cons_occupants_setting(void) else cons_show("Occupants wrap (/occupants) : OFF"); + char occupants_ch = prefs_get_occupants_char(); + if (occupants_ch) + cons_show("Occupants char (/occupants) : %c", occupants_ch); + else + cons_show("Occupants char (/occupants) : none"); + gint occupant_indent = prefs_get_occupants_indent(); cons_show("Occupant indent (/occupants) : %d", occupant_indent); diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index 807970a5..68674023 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -60,6 +60,11 @@ _occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant, gboolean sh GString *msg = g_string_new(spaces->str); + char ch = prefs_get_occupants_char(); + if (ch) { + g_string_append_printf(msg, "%c", ch); + } + gboolean wrap = prefs_get_boolean(PREF_OCCUPANTS_WRAP); g_string_append(msg, occupant->nick); diff --git a/theme_template b/theme_template index 04dbdca0..feab8bfc 100644 --- a/theme_template +++ b/theme_template @@ -131,6 +131,7 @@ roster.private= roster.private.char= occupants= occupants.size= +occupants.char= occupants.jid= occupants.wrap= occupants.indent= |