about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/ui/chatwin.c26
-rw-r--r--src/ui/console.c9
-rw-r--r--src/ui/mucconfwin.c17
-rw-r--r--src/ui/mucwin.c17
-rw-r--r--src/ui/privwin.c18
-rw-r--r--src/ui/ui.h8
-rw-r--r--src/ui/window.c41
-rw-r--r--src/ui/xmlwin.c8
-rw-r--r--src/window_list.c104
9 files changed, 156 insertions, 92 deletions
diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c
index 2875256d..ba66c7ae 100644
--- a/src/ui/chatwin.c
+++ b/src/ui/chatwin.c
@@ -355,6 +355,32 @@ chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status)
     free(display_str);
 }
 
+char*
+chatwin_get_string(ProfChatWin *chatwin)
+{
+    assert(chatwin != NULL);
+
+    GString *res = g_string_new("Chat ");
+
+    PContact contact = roster_get_contact(chatwin->barejid);
+    if (contact == NULL) {
+        g_string_append(res, chatwin->barejid);
+    } else {
+        const char *display_name = p_contact_name_or_jid(contact);
+        g_string_append(res, display_name);
+        g_string_append_printf(res, " - %s", p_contact_presence(contact));
+    }
+
+    if (chatwin->unread > 0) {
+        g_string_append_printf(res, ", %d unread", chatwin->unread);
+    }
+
+    char *resstr = res->str;
+    g_string_free(res, FALSE);
+
+    return resstr;
+}
+
 static void
 _chatwin_history(ProfChatWin *chatwin, const char *const contact)
 {
diff --git a/src/ui/console.c b/src/ui/console.c
index 4d155afb..28fba4cd 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -35,6 +35,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <assert.h>
 
 #ifdef HAVE_NCURSESW_NCURSES_H
 #include <ncursesw/ncurses.h>
@@ -1901,6 +1902,14 @@ cons_alert(void)
     }
 }
 
+char*
+cons_get_string(ProfConsoleWin *conswin)
+{
+    assert(conswin != NULL);
+
+    return strdup("Console");
+}
+
 void
 cons_theme_colours(void)
 {
diff --git a/src/ui/mucconfwin.c b/src/ui/mucconfwin.c
index dd614306..c262ae0e 100644
--- a/src/ui/mucconfwin.c
+++ b/src/ui/mucconfwin.c
@@ -328,3 +328,20 @@ _mucconfwin_form_field(ProfWin *window, char *tag, FormField *field)
         break;
     }
 }
+
+char*
+mucconfwin_get_string(ProfMucConfWin *confwin)
+{
+    assert(confwin != NULL);
+
+    GString *res = g_string_new("");
+
+    char *title = win_get_title((ProfWin*)confwin);
+    g_string_append(res, title);
+    free(title);
+
+    char *resstr = res->str;
+    g_string_free(res, FALSE);
+
+    return resstr;
+}
diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c
index 097e9589..432256de 100644
--- a/src/ui/mucwin.c
+++ b/src/ui/mucwin.c
@@ -773,3 +773,20 @@ mucwin_hide_occupants(ProfMucWin *mucwin)
     }
 }
 
+char*
+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);
+    }
+
+    char *resstr = res->str;
+    g_string_free(res, FALSE);
+
+    return resstr;
+}
diff --git a/src/ui/privwin.c b/src/ui/privwin.c
index 204335bd..77a0a92d 100644
--- a/src/ui/privwin.c
+++ b/src/ui/privwin.c
@@ -107,3 +107,21 @@ privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message)
 
     win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message);
 }
+
+char*
+privwin_get_string(ProfPrivateWin *privwin)
+{
+    assert(privwin != NULL);
+
+    GString *res = g_string_new("Private ");
+    g_string_append(res, privwin->fulljid);
+
+    if (privwin->unread > 0) {
+        g_string_append_printf(res, ", %d unread", privwin->unread);
+    }
+
+    char *resstr = res->str;
+    g_string_free(res, FALSE);
+
+    return resstr;
+}
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 458255f1..c445452d 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -134,6 +134,8 @@ void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char
 void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message);
 void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity);
 void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status);
+char* chatwin_get_string(ProfChatWin *chatwin);
+
 #ifdef HAVE_LIBOTR
 void chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted);
 void chatwin_otr_unsecured(ProfChatWin *chatwin);
@@ -187,10 +189,12 @@ void mucwin_role_set_error(ProfMucWin *mucwin, const char *const nick, const cha
 void mucwin_role_list_error(ProfMucWin *mucwin, const char *const role, const char *const error);
 void mucwin_handle_role_list(ProfMucWin *mucwin, const char *const role, GSList *nicks);
 void mucwin_kick_error(ProfMucWin *mucwin, const char *const nick, const char *const error);
+char* mucwin_get_string(ProfMucWin *mucwin);
 
 // MUC private chat window
 void privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDateTime *timestamp);
 void privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message);
+char* privwin_get_string(ProfPrivateWin *privwin);
 
 // MUC room config window
 void mucconfwin_handle_configuration(ProfMucConfWin *confwin, DataForm *form);
@@ -198,9 +202,11 @@ void mucconfwin_show_form(ProfMucConfWin *confwin);
 void mucconfwin_show_form_field(ProfMucConfWin *confwin, DataForm *form, char *tag);
 void mucconfwin_form_help(ProfMucConfWin *confwin);
 void mucconfwin_field_help(ProfMucConfWin *confwin, char *tag);
+char* mucconfwin_get_string(ProfMucConfWin *confwin);
 
 // xml console
 void xmlwin_show(ProfXMLWin *xmlwin, const char *const msg);
+char* xmlwin_get_string(ProfXMLWin *xmlwin);
 
 // Input window
 char* inp_readline(void);
@@ -232,6 +238,7 @@ void cons_show_contacts(GSList *list);
 void cons_show_roster(GSList *list);
 void cons_show_roster_group(const char *const group, GSList *list);
 void cons_show_wins(void);
+char* cons_get_string(ProfConsoleWin *conswin);
 void cons_show_status(const char *const barejid);
 void cons_show_info(PContact pcontact);
 void cons_show_caps(const char *const fulljid, resource_presence_t presence);
@@ -336,6 +343,7 @@ void win_show_info(ProfWin *window, PContact contact);
 void win_println(ProfWin *window, int pad, const char *const message);
 void win_vprintln_ch(ProfWin *window, char ch, const char *const message, ...);
 void win_clear(ProfWin *window);
+char* win_get_string(ProfWin *window);
 
 // desktop notifications
 void notifier_initialise(void);
diff --git a/src/ui/window.c b/src/ui/window.c
index d6500a67..039d4770 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -285,6 +285,47 @@ win_get_title(ProfWin *window)
     return NULL;
 }
 
+char*
+win_get_string(ProfWin *window)
+{
+    assert(window != NULL);
+
+    switch (window->type) {
+        case WIN_CONSOLE:
+        {
+            ProfConsoleWin *conswin = (ProfConsoleWin*)window;
+            return cons_get_string(conswin);
+        }
+        case WIN_CHAT:
+        {
+            ProfChatWin *chatwin = (ProfChatWin*)window;
+            return chatwin_get_string(chatwin);
+        }
+        case WIN_MUC:
+        {
+            ProfMucWin *mucwin = (ProfMucWin*)window;
+            return mucwin_get_string(mucwin);
+        }
+        case WIN_MUC_CONFIG:
+        {
+            ProfMucConfWin *mucconfwin = (ProfMucConfWin*)window;
+            return mucconfwin_get_string(mucconfwin);
+        }
+        case WIN_PRIVATE:
+        {
+            ProfPrivateWin *privwin = (ProfPrivateWin*)window;
+            return privwin_get_string(privwin);
+        }
+        case WIN_XML:
+        {
+            ProfXMLWin *xmlwin = (ProfXMLWin*)window;
+            return xmlwin_get_string(xmlwin);
+        }
+        default:
+            return NULL;
+    }
+}
+
 void
 win_hide_subwin(ProfWin *window)
 {
diff --git a/src/ui/xmlwin.c b/src/ui/xmlwin.c
index 31921390..b19586bb 100644
--- a/src/ui/xmlwin.c
+++ b/src/ui/xmlwin.c
@@ -53,3 +53,11 @@ xmlwin_show(ProfXMLWin *xmlwin, const char *const msg)
         win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", "");
     }
 }
+
+char*
+xmlwin_get_string(ProfXMLWin *xmlwin)
+{
+    assert(xmlwin != NULL);
+
+    return strdup("XML console");
+}
diff --git a/src/window_list.c b/src/window_list.c
index 14bf6ea5..806ac736 100644
--- a/src/window_list.c
+++ b/src/window_list.c
@@ -657,106 +657,26 @@ wins_create_summary(void)
 
     while (curr) {
         ProfWin *window = g_hash_table_lookup(windows, curr->data);
-        int ui_index = GPOINTER_TO_INT(curr->data);
-
-        GString *chat_string;
-        GString *priv_string;
-        GString *muc_string;
-        GString *muc_config_string;
-        GString *xml_string;
-
-        switch (window->type)
-        {
-            case WIN_CONSOLE:
-                result = g_slist_append(result, strdup("1: Console"));
-                break;
-            case WIN_CHAT:
-                chat_string = g_string_new("");
-
-                ProfChatWin *chatwin = (ProfChatWin*)window;
-                PContact contact = roster_get_contact(chatwin->barejid);
-                if (contact == NULL) {
-                    g_string_printf(chat_string, "%d: Chat %s", ui_index, chatwin->barejid);
-                } else {
-                    const char *display_name = p_contact_name_or_jid(contact);
-                    g_string_printf(chat_string, "%d: Chat %s", ui_index, display_name);
-                    GString *chat_presence = g_string_new("");
-                    g_string_printf(chat_presence, " - %s", p_contact_presence(contact));
-                    g_string_append(chat_string, chat_presence->str);
-                    g_string_free(chat_presence, TRUE);
-                }
-
-                if (chatwin->unread > 0) {
-                    GString *chat_unread = g_string_new("");
-                    g_string_printf(chat_unread, ", %d unread", chatwin->unread);
-                    g_string_append(chat_string, chat_unread->str);
-                    g_string_free(chat_unread, TRUE);
-                }
-
-                result = g_slist_append(result, strdup(chat_string->str));
-                g_string_free(chat_string, TRUE);
-
-                break;
-
-            case WIN_PRIVATE:
-                priv_string = g_string_new("");
-                ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
-                g_string_printf(priv_string, "%d: Private %s", ui_index, privatewin->fulljid);
-
-                if (privatewin->unread > 0) {
-                    GString *priv_unread = g_string_new("");
-                    g_string_printf(priv_unread, ", %d unread", privatewin->unread);
-                    g_string_append(priv_string, priv_unread->str);
-                    g_string_free(priv_unread, TRUE);
-                }
-
-                result = g_slist_append(result, strdup(priv_string->str));
-                g_string_free(priv_string, TRUE);
+        GString *line = g_string_new("");
 
-                break;
-
-            case WIN_MUC:
-                muc_string = g_string_new("");
-                ProfMucWin *mucwin = (ProfMucWin*)window;
-                g_string_printf(muc_string, "%d: Room %s", ui_index, mucwin->roomjid);
-
-                if (mucwin->unread > 0) {
-                    GString *muc_unread = g_string_new("");
-                    g_string_printf(muc_unread, ", %d unread", mucwin->unread);
-                    g_string_append(muc_string, muc_unread->str);
-                    g_string_free(muc_unread, TRUE);
-                }
-
-                result = g_slist_append(result, strdup(muc_string->str));
-                g_string_free(muc_string, TRUE);
-
-                break;
-
-            case WIN_MUC_CONFIG:
-                muc_config_string = g_string_new("");
-                char *title = win_get_title(window);
-                g_string_printf(muc_config_string, "%d: %s", ui_index, title);
-                result = g_slist_append(result, strdup(muc_config_string->str));
-                g_string_free(muc_config_string, TRUE);
-                free(title);
-
-                break;
+        int ui_index = GPOINTER_TO_INT(curr->data);
+        char *winstring = win_get_string(window);
+        if (!winstring) {
+            g_string_free(line, TRUE);
+            continue;
+        }
 
-            case WIN_XML:
-                xml_string = g_string_new("");
-                g_string_printf(xml_string, "%d: XML console", ui_index);
-                result = g_slist_append(result, strdup(xml_string->str));
-                g_string_free(xml_string, TRUE);
+        g_string_append_printf(line, "%d: %s", ui_index, winstring);
+        free(winstring);
 
-                break;
+        result = g_slist_append(result, strdup(line->str));
+        g_string_free(line, TRUE);
 
-            default:
-                break;
-        }
         curr = g_list_next(curr);
     }
 
     g_list_free(keys);
+
     return result;
 }