about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-10-22 16:23:18 +0200
committerMichael Vetter <jubalh@iodoru.org>2021-10-22 16:23:18 +0200
commita668ca45b78bf9653f93c0380e58101da3c3bced (patch)
tree7aaa5c56212fbe63f3045b622e18df0beaf753dd
parent91898597dd15d2d8661ab587a69585b232b7d00e (diff)
downloadprofani-tty-a668ca45b78bf9653f93c0380e58101da3c3bced.tar.gz
Allow utf8 in roster contact char
-rw-r--r--src/command/cmd_funcs.c4
-rw-r--r--src/config/preferences.c24
-rw-r--r--src/config/preferences.h4
-rw-r--r--src/config/theme.c4
-rw-r--r--src/ui/console.c17
-rw-r--r--src/ui/rosterwin.c8
6 files changed, 28 insertions, 33 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 3f221ff3..575ccaf3 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -2407,8 +2407,8 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args)
                 cons_show("Roster contact char removed.");
                 rosterwin_roster();
             } else {
-                prefs_set_roster_contact_char(args[2][0]);
-                cons_show("Roster contact char set to %c.", args[2][0]);
+                prefs_set_roster_contact_char(args[2]);
+                cons_show("Roster contact char set to %s.", args[2]);
                 rosterwin_roster();
             }
         } else if (g_strcmp0(args[1], "indent") == 0) {
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 6539fc0c..3bc5800f 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -1110,30 +1110,22 @@ prefs_clear_roster_header_char(void)
     g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.header.char", NULL);
 }
 
-char
+char*
 prefs_get_roster_contact_char(void)
 {
-    char result = 0;
-
-    char* resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "roster.contact.char", NULL);
-    if (!resultstr) {
-        result = 0;
-    } else {
-        result = resultstr[0];
-    }
-    free(resultstr);
+    char* result = g_key_file_get_string(prefs, PREF_GROUP_UI, "roster.contact.char", NULL);
 
     return result;
 }
 
 void
-prefs_set_roster_contact_char(char ch)
+prefs_set_roster_contact_char(char* ch)
 {
-    char str[2];
-    str[0] = ch;
-    str[1] = '\0';
-
-    g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.contact.char", str);
+    if (g_utf8_strlen(ch, 4) == 1) {
+        g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.contact.char", ch);
+    } else {
+        log_error("Could not set roster contact char: %s", ch);
+    }
 }
 
 void
diff --git a/src/config/preferences.h b/src/config/preferences.h
index 1eddceca..2fb5b9b1 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -257,8 +257,8 @@ gboolean prefs_set_ox_char(char* ch);
 char* prefs_get_roster_header_char(void);
 void prefs_set_roster_header_char(char* ch);
 void prefs_clear_roster_header_char(void);
-char prefs_get_roster_contact_char(void);
-void prefs_set_roster_contact_char(char ch);
+char* prefs_get_roster_contact_char(void);
+void prefs_set_roster_contact_char(char* ch);
 void prefs_clear_roster_contact_char(void);
 char prefs_get_roster_resource_char(void);
 void prefs_set_roster_resource_char(char ch);
diff --git a/src/config/theme.c b/src/config/theme.c
index 61346167..26c3c669 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -430,8 +430,8 @@ _load_preferences(void)
 
     if (g_key_file_has_key(theme, "ui", "roster.contact.char", NULL)) {
         gchar* ch = g_key_file_get_string(theme, "ui", "roster.contact.char", NULL);
-        if (ch && strlen(ch) > 0) {
-            prefs_set_roster_contact_char(ch[0]);
+        if (ch && g_utf8_strlen(ch, 4) == 1) {
+            prefs_set_roster_contact_char(ch);
             g_free(ch);
         }
     }
diff --git a/src/ui/console.c b/src/ui/console.c
index b2773f2d..d6306dcc 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1476,17 +1476,20 @@ cons_roster_setting(void)
         cons_show("Roster offline (/roster)            : hide");
 
     char* header_ch = prefs_get_roster_header_char();
-    if (header_ch)
+    if (header_ch) {
         cons_show("Roster header char (/roster)        : %s", header_ch);
-    else
+        free(header_ch);
+    } else {
         cons_show("Roster header char (/roster)        : none");
-    free(header_ch);
+    }
 
-    char contact_ch = prefs_get_roster_contact_char();
-    if (contact_ch)
-        cons_show("Roster contact char (/roster)       : %c", contact_ch);
-    else
+    char* contact_ch = prefs_get_roster_contact_char();
+    if (contact_ch) {
+        cons_show("Roster contact char (/roster)       : %s", contact_ch);
+        free(contact_ch);
+    } else {
         cons_show("Roster contact char (/roster)       : none");
+    }
 
     char resource_ch = prefs_get_roster_resource_char();
     if (resource_ch)
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 9a5926a9..a3dfffba 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -314,9 +314,9 @@ _rosterwin_unsubscribed_item(ProfLayoutSplit* layout, ProfChatWin* chatwin)
             indent--;
         }
     }
-    char ch = prefs_get_roster_contact_char();
+    char *ch = prefs_get_roster_contact_char();
     if (ch) {
-        g_string_append_printf(msg, "%c", ch);
+        g_string_append_printf(msg, "%s", ch);
     }
 
     char* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD);
@@ -376,9 +376,9 @@ _rosterwin_contact(ProfLayoutSplit* layout, PContact contact)
             indent--;
         }
     }
-    char ch = prefs_get_roster_contact_char();
+    char *ch = prefs_get_roster_contact_char();
     if (ch) {
-        g_string_append_printf(msg, "%c", ch);
+        g_string_append_printf(msg, "%s", ch);
     }
 
     char* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD);