about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2023-03-23 18:47:09 +0100
committerGitHub <noreply@github.com>2023-03-23 18:47:09 +0100
commit2093fe417f6a1d7f8741613a83ed81e18ae272c9 (patch)
tree545177f774356337b8b8a6388f2bd77393d2df55
parentb393363bd513bbea5d7ed5a0fccbef61aff07daa (diff)
parent732cbbfefc3536d4ce4e16f4eca0a5470f5c18b0 (diff)
downloadprofani-tty-2093fe417f6a1d7f8741613a83ed81e18ae272c9.tar.gz
Merge pull request #1800 from profanity-im/switch
Improve some UI functions
-rw-r--r--src/ui/chatwin.c5
-rw-r--r--src/ui/mucwin.c12
-rw-r--r--src/ui/window.c55
3 files changed, 39 insertions, 33 deletions
diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c
index 399d0fe0..ff425c0f 100644
--- a/src/ui/chatwin.c
+++ b/src/ui/chatwin.c
@@ -514,10 +514,7 @@ chatwin_get_string(ProfChatWin* chatwin)
         g_string_append_printf(res, ", %d unread", chatwin->unread);
     }
 
-    char* resstr = res->str;
-    g_string_free(res, FALSE);
-
-    return resstr;
+    return g_string_free(res, FALSE);
 }
 
 void
diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c
index a3d154e0..a4bcc191 100644
--- a/src/ui/mucwin.c
+++ b/src/ui/mucwin.c
@@ -943,17 +943,11 @@ mucwin_get_string(ProfMucWin* mucwin)
 {
     assert(mucwin != NULL);
 
-    GString* res = g_string_new("Room ");
-    g_string_append(res, mucwin->roomjid);
-
     if (mucwin->unread > 0) {
-        g_string_append_printf(res, ", %d unread", mucwin->unread);
+        return g_strdup_printf("Room %s, %d unread", mucwin->roomjid, mucwin->unread);
+    } else {
+        return g_strdup_printf("Room %s", mucwin->roomjid);
     }
-
-    char* resstr = res->str;
-    g_string_free(res, FALSE);
-
-    return resstr;
 }
 
 void
diff --git a/src/ui/window.c b/src/ui/window.c
index 2534dddb..c1d5edf3 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -302,10 +302,14 @@ win_get_title(ProfWin* window)
     if (window == NULL) {
         return strdup(CONS_WIN_TITLE);
     }
-    if (window->type == WIN_CONSOLE) {
+
+    switch (window->type) {
+    case WIN_CONSOLE:
+    {
         return strdup(CONS_WIN_TITLE);
     }
-    if (window->type == WIN_CHAT) {
+    case WIN_CHAT:
+    {
         ProfChatWin* chatwin = (ProfChatWin*)window;
         assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
         jabber_conn_status_t conn_status = connection_get_status();
@@ -321,7 +325,8 @@ win_get_title(ProfWin* window)
             return strdup(chatwin->barejid);
         }
     }
-    if (window->type == WIN_MUC) {
+    case WIN_MUC:
+    {
         ProfMucWin* mucwin = (ProfMucWin*)window;
         assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
 
@@ -339,30 +344,37 @@ win_get_title(ProfWin* window)
 
         return g_string_free(title, FALSE);
     }
-    if (window->type == WIN_CONFIG) {
-        ProfConfWin* confwin = (ProfConfWin*)window;
-        assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
-        GString* title = g_string_new(confwin->roomjid);
-        g_string_append(title, " config");
-        if (confwin->form->modified) {
-            g_string_append(title, " *");
+    case WIN_CONFIG:
+    {
+        if (window->type == WIN_CONFIG) {
+            ProfConfWin* confwin = (ProfConfWin*)window;
+            assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
+            GString* title = g_string_new(confwin->roomjid);
+            g_string_append(title, " config");
+            if (confwin->form->modified) {
+                g_string_append(title, " *");
+            }
+            return g_string_free(title, FALSE);
         }
-        return g_string_free(title, FALSE);
     }
-    if (window->type == WIN_PRIVATE) {
+    case WIN_PRIVATE:
+    {
         ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
         assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
         return strdup(privatewin->fulljid);
     }
-    if (window->type == WIN_XML) {
+    case WIN_XML:
+    {
         return strdup(XML_WIN_TITLE);
     }
-    if (window->type == WIN_PLUGIN) {
+    case WIN_PLUGIN:
+    {
         ProfPluginWin* pluginwin = (ProfPluginWin*)window;
         assert(pluginwin->memcheck == PROFPLUGINWIN_MEMCHECK);
         return strdup(pluginwin->tag);
     }
-    if (window->type == WIN_VCARD) {
+    case WIN_VCARD:
+    {
         ProfVcardWin* vcardwin = (ProfVcardWin*)window;
         assert(vcardwin->memcheck == PROFVCARDWIN_MEMCHECK);
 
@@ -378,7 +390,8 @@ win_get_title(ProfWin* window)
         free(jid);
         return g_string_free(title, FALSE);
     }
-    return NULL;
+    }
+    assert(FALSE);
 }
 
 char*
@@ -420,9 +433,12 @@ win_get_tab_identifier(ProfWin* window)
     {
         return strdup("xmlconsole");
     }
-    default:
-        return strdup("UNKNOWN");
+    case WIN_VCARD:
+    {
+        return strdup("vcard");
     }
+    }
+    assert(FALSE);
 }
 
 char*
@@ -503,9 +519,8 @@ win_to_string(ProfWin* window)
         ProfVcardWin* vcardwin = (ProfVcardWin*)window;
         return vcardwin_get_string(vcardwin);
     }
-    default:
-        return NULL;
     }
+    assert(FALSE);
 }
 
 void