about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-05-02 17:01:55 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-05-02 17:01:55 +0200
commitf082563bf2687465f0ca924985ec4d38277459ba (patch)
tree54fe7df828b967fd29e056d2c04a8933677f2d2a /src
parent722cb5fdc3ced8b76b58992326c8761227240202 (diff)
downloadprofani-tty-f082563bf2687465f0ca924985ec4d38277459ba.tar.gz
Add occupants char
`/occupants char` now sets a character that is displayed before the nick
in MUCs. Similar like `/roster char` is displaying a char for the roster.

Regards #690
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_ac.c18
-rw-r--r--src/command/cmd_defs.c3
-rw-r--r--src/command/cmd_funcs.c17
-rw-r--r--src/config/preferences.c34
-rw-r--r--src/config/preferences.h3
-rw-r--r--src/config/theme.c10
-rw-r--r--src/ui/console.c6
-rw-r--r--src/ui/occupantswin.c5
8 files changed, 93 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 5aaf56ef..6a1cb006 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 f1fa3231..af51465b 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);