about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-10-21 15:30:01 +0200
committerMichael Vetter <jubalh@iodoru.org>2021-10-21 15:30:01 +0200
commit91898597dd15d2d8661ab587a69585b232b7d00e (patch)
treeaf631bfd5e6e18e29f31ece78369a907f7d0c3e0
parent37e1699c84bfb34dafaee4cd061eedad79fc114d (diff)
downloadprofani-tty-91898597dd15d2d8661ab587a69585b232b7d00e.tar.gz
Allow utf8 in roster header char
This and the following commits should make a couple of more configs
allow utf8 chars so people can use their weird icons :-)

We did the same for the otr/omemo/pgp indicators at:
https://github.com/profanity-im/profanity/commit/1f8b1eb740391941e79e1004ad041f8178a2b674
https://github.com/profanity-im/profanity/commit/5cf6ee1bc6d0b99b01891bc455a657bf022a72b0
-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.c5
-rw-r--r--src/ui/rosterwin.c20
6 files changed, 32 insertions, 29 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 6e590598..3f221ff3 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -2388,8 +2388,8 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args)
                 cons_show("Roster header char removed.");
                 rosterwin_roster();
             } else {
-                prefs_set_roster_header_char(args[2][0]);
-                cons_show("Roster header char set to %c.", args[2][0]);
+                prefs_set_roster_header_char(args[2]);
+                cons_show("Roster header char set to %c.", args[2]);
                 rosterwin_roster();
             }
         } else {
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 114455fd..6539fc0c 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -1080,32 +1080,30 @@ prefs_set_omemo_char(char* ch)
     return _prefs_set_encryption_char(ch, PREF_GROUP_OMEMO, "omemo.char");
 }
 
-char
+char*
 prefs_get_roster_header_char(void)
 {
-    char result = 0;
+    char* result = NULL;
 
     char* resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "roster.header.char", NULL);
-    if (!resultstr) {
-        result = 0;
-    } else {
-        result = resultstr[0];
+    if (resultstr) {
+        result = resultstr;
     }
-    free(resultstr);
 
     return result;
 }
 
 void
-prefs_set_roster_header_char(char ch)
+prefs_set_roster_header_char(char* ch)
 {
-    char str[2];
-    str[0] = ch;
-    str[1] = '\0';
-
-    g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.header.char", str);
+    if (g_utf8_strlen(ch, 4) == 1) {
+        g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.header.char", ch);
+    } else {
+        log_error("Could not set roster header char: %s", ch);
+    }
 }
 
+
 void
 prefs_clear_roster_header_char(void)
 {
diff --git a/src/config/preferences.h b/src/config/preferences.h
index 30bd434a..1eddceca 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -254,8 +254,8 @@ gboolean prefs_set_omemo_char(char* ch);
 char* prefs_get_ox_char(void);
 gboolean prefs_set_ox_char(char* ch);
 
-char prefs_get_roster_header_char(void);
-void prefs_set_roster_header_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);
diff --git a/src/config/theme.c b/src/config/theme.c
index dd19dc57..61346167 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -422,8 +422,8 @@ _load_preferences(void)
 
     if (g_key_file_has_key(theme, "ui", "roster.header.char", NULL)) {
         gchar* ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL);
-        if (ch && strlen(ch) > 0) {
-            prefs_set_roster_header_char(ch[0]);
+        if (ch && g_utf8_strlen(ch, 4) == 1) {
+            prefs_set_roster_header_char(ch);
             g_free(ch);
         }
     }
diff --git a/src/ui/console.c b/src/ui/console.c
index bdb8f24d..b2773f2d 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1475,11 +1475,12 @@ cons_roster_setting(void)
     else
         cons_show("Roster offline (/roster)            : hide");
 
-    char header_ch = prefs_get_roster_header_char();
+    char* header_ch = prefs_get_roster_header_char();
     if (header_ch)
-        cons_show("Roster header char (/roster)        : %c", header_ch);
+        cons_show("Roster header char (/roster)        : %s", header_ch);
     else
         cons_show("Roster header char (/roster)        : none");
+    free(header_ch);
 
     char contact_ch = prefs_get_roster_contact_char();
     if (contact_ch)
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 5c41fc82..9a5926a9 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -1028,9 +1028,10 @@ _rosterwin_unsubscribed_header(ProfLayoutSplit* layout, GList* wins)
     win_sub_newline_lazy(layout->subwin);
 
     GString* header = g_string_new(" ");
-    char ch = prefs_get_roster_header_char();
+    char* ch = prefs_get_roster_header_char();
     if (ch) {
-        g_string_append_printf(header, "%c", ch);
+        g_string_append_printf(header, "%s", ch);
+        free(ch);
     }
 
     g_string_append(header, "Unsubscribed");
@@ -1074,9 +1075,10 @@ _rosterwin_contacts_header(ProfLayoutSplit* layout, const char* const title, GSL
     win_sub_newline_lazy(layout->subwin);
 
     GString* header = g_string_new(" ");
-    char ch = prefs_get_roster_header_char();
+    char* ch = prefs_get_roster_header_char();
     if (ch) {
-        g_string_append_printf(header, "%c", ch);
+        g_string_append_printf(header, "%s", ch);
+        free(ch);
     }
 
     g_string_append(header, title);
@@ -1125,9 +1127,10 @@ _rosterwin_rooms_header(ProfLayoutSplit* layout, GList* rooms, char* title)
 {
     win_sub_newline_lazy(layout->subwin);
     GString* header = g_string_new(" ");
-    char ch = prefs_get_roster_header_char();
+    char* ch = prefs_get_roster_header_char();
     if (ch) {
-        g_string_append_printf(header, "%c", ch);
+        g_string_append_printf(header, "%s", ch);
+        free(ch);
     }
     g_string_append(header, title);
 
@@ -1188,9 +1191,10 @@ _rosterwin_private_header(ProfLayoutSplit* layout, GList* privs)
     win_sub_newline_lazy(layout->subwin);
 
     GString* title_str = g_string_new(" ");
-    char ch = prefs_get_roster_header_char();
+    char* ch = prefs_get_roster_header_char();
     if (ch) {
-        g_string_append_printf(title_str, "%c", ch);
+        g_string_append_printf(title_str, "%s", ch);
+        free(ch);
     }
     g_string_append(title_str, "Private chats");