about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-12 23:19:07 +0000
committerJames Booth <boothj5@gmail.com>2014-11-12 23:19:07 +0000
commit15d0f679f6a2b56fe58837a4257ea90df92d14e4 (patch)
treed8854489f9693788111e489c8937c778c1249585 /src/ui
parent7e360dc35a30bd20ba34239949e461159417182a (diff)
downloadprofani-tty-15d0f679f6a2b56fe58837a4257ea90df92d14e4.tar.gz
Implemented roster grouped by presence
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/core.c143
1 files changed, 91 insertions, 52 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index c5e3711f..f8062b1f 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -84,6 +84,7 @@ static void _win_handle_page(const wint_t * const ch, const int result);
 static void _win_show_history(WINDOW *win, int win_index,
     const char * const contact);
 static void _ui_draw_term_title(void);
+static void _ui_roster_contact(PContact contact);
 
 static void
 _ui_init(void)
@@ -2805,72 +2806,110 @@ _ui_show_lines(ProfWin *window, const gchar** lines)
 }
 
 static void
-_ui_roster(void)
+_ui_roster_contact(PContact contact)
 {
-    ProfWin *window = wins_get_console();
-    if (window) {
-        GSList *contacts = roster_get_contacts();
-        if (contacts) {
-            werase(window->subwin);
-            wattron(window->subwin, COLOUR_ROOMINFO);
-            win_printline_nowrap(window->subwin, " -Roster");
-            wattroff(window->subwin, COLOUR_ROOMINFO);
-            GSList *curr_contact = contacts;
-            while (curr_contact) {
-                PContact contact = curr_contact->data;
-                if (p_contact_subscribed(contact)) {
-                    const char *name = p_contact_name_or_jid(contact);
-                    const char *presence = p_contact_presence(contact);
-
-                    if ((g_strcmp0(presence, "offline") != 0) || ((g_strcmp0(presence, "offline") == 0) &&
-                            (prefs_get_boolean(PREF_ROSTER_OFFLINE)))) {
-                        int presence_colour = win_presence_colour(presence);
+    if (p_contact_subscribed(contact)) {
+        ProfWin *window = wins_get_console();
+        const char *name = p_contact_name_or_jid(contact);
+        const char *presence = p_contact_presence(contact);
 
-                        wattron(window->subwin, presence_colour);
+        if ((g_strcmp0(presence, "offline") != 0) || ((g_strcmp0(presence, "offline") == 0) &&
+                (prefs_get_boolean(PREF_ROSTER_OFFLINE)))) {
+            int presence_colour = win_presence_colour(presence);
 
-                        GString *msg = g_string_new("   ");
-                        g_string_append(msg, name);
-                        win_printline_nowrap(window->subwin, msg->str);
-                        g_string_free(msg, TRUE);
+            wattron(window->subwin, presence_colour);
 
-                        wattroff(window->subwin, presence_colour);
+            GString *msg = g_string_new("   ");
+            g_string_append(msg, name);
+            win_printline_nowrap(window->subwin, msg->str);
+            g_string_free(msg, TRUE);
 
-                        if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
-                            GList *resources = p_contact_get_available_resources(contact);
-                            GList *ordered_resources = NULL;
+            wattroff(window->subwin, presence_colour);
 
-                            // sort in order of availabiltiy
-                            while (resources != NULL) {
-                                Resource *resource = resources->data;
-                                ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability);
-                                resources = g_list_next(resources);
-                            }
+            if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
+                GList *resources = p_contact_get_available_resources(contact);
+                GList *ordered_resources = NULL;
 
-                            g_list_free(resources);
+                // sort in order of availabiltiy
+                while (resources != NULL) {
+                    Resource *resource = resources->data;
+                    ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability);
+                    resources = g_list_next(resources);
+                }
 
-                            while (ordered_resources) {
-                                Resource *resource = ordered_resources->data;
-                                const char *resource_presence = string_from_resource_presence(resource->presence);
-                                int resource_presence_colour = win_presence_colour(resource_presence);
-                                wattron(window->subwin, resource_presence_colour);
+                g_list_free(resources);
 
-                                GString *msg = g_string_new("     ");
-                                g_string_append(msg, resource->name);
-                                win_printline_nowrap(window->subwin, msg->str);
-                                g_string_free(msg, TRUE);
+                while (ordered_resources) {
+                    Resource *resource = ordered_resources->data;
+                    const char *resource_presence = string_from_resource_presence(resource->presence);
+                    int resource_presence_colour = win_presence_colour(resource_presence);
+                    wattron(window->subwin, resource_presence_colour);
 
-                                wattroff(window->subwin, resource_presence_colour);
+                    GString *msg = g_string_new("     ");
+                    g_string_append(msg, resource->name);
+                    win_printline_nowrap(window->subwin, msg->str);
+                    g_string_free(msg, TRUE);
 
-                                ordered_resources = g_list_next(ordered_resources);
-                            }
-                            g_list_free(ordered_resources);
-                        }
-                    }
+                    wattroff(window->subwin, resource_presence_colour);
+
+                    ordered_resources = g_list_next(ordered_resources);
+                }
+                g_list_free(ordered_resources);
+            }
+        }
+    }
+}
+
+static void
+_ui_roster_contacts_by_presence(const char * const presence, char *title)
+{
+    ProfWin *window = wins_get_console();
+    GSList *contacts = roster_get_contacts_by_presence(presence);
+    wattron(window->subwin, COLOUR_ROOMINFO);
+    win_printline_nowrap(window->subwin, title);
+    wattroff(window->subwin, COLOUR_ROOMINFO);
+    if (contacts) {
+        GSList *curr_contact = contacts;
+        while (curr_contact) {
+            PContact contact = curr_contact->data;
+            _ui_roster_contact(contact);
+            curr_contact = g_slist_next(curr_contact);
+        }
+    }
+    g_slist_free(contacts);
+}
+
+static void
+_ui_roster(void)
+{
+    ProfWin *window = wins_get_console();
+    if (window) {
+        if (g_strcmp0(prefs_get_string(PREF_ROSTER_BY), "presence") == 0) {
+            werase(window->subwin);
+            _ui_roster_contacts_by_presence("chat", " -Available for chat");
+            _ui_roster_contacts_by_presence("online", " -Online");
+            _ui_roster_contacts_by_presence("away", " -Away");
+            _ui_roster_contacts_by_presence("xa", " -Extended Away");
+            _ui_roster_contacts_by_presence("dnd", " -Do not disturb");
+            if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) {
+                _ui_roster_contacts_by_presence("offline", " -Offline");
+            }
+        } else {
+            GSList *contacts = roster_get_contacts();
+            if (contacts) {
+                werase(window->subwin);
+                wattron(window->subwin, COLOUR_ROOMINFO);
+                win_printline_nowrap(window->subwin, " -Roster");
+                wattroff(window->subwin, COLOUR_ROOMINFO);
+                GSList *curr_contact = contacts;
+                while (curr_contact) {
+                    PContact contact = curr_contact->data;
+                    _ui_roster_contact(contact);
+                    curr_contact = g_slist_next(curr_contact);
                 }
-                curr_contact = g_slist_next(curr_contact);
             }
+            g_slist_free(contacts);
         }
-        g_slist_free(contacts);
     }
 }