about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c10
-rw-r--r--src/roster_list.c82
-rw-r--r--src/roster_list.h14
-rw-r--r--src/ui/console.c2
-rw-r--r--src/ui/rosterwin.c12
5 files changed, 41 insertions, 79 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 67f8ae98..c1edfdb2 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1320,13 +1320,13 @@ _who_roster(ProfWin *window, const char *const command, gchar **args)
     cons_show("");
     GSList *list = NULL;
     if (group) {
-        list = roster_get_group(group);
+        list = roster_get_group(group, ROSTER_ORD_NAME);
         if (list == NULL) {
             cons_show("No such group: %s.", group);
             return;
         }
     } else {
-        list = roster_get_contacts();
+        list = roster_get_contacts(ROSTER_ORD_NAME);
         if (list == NULL) {
             cons_show("No contacts in roster.");
             return;
@@ -1628,7 +1628,7 @@ cmd_group(ProfWin *window, const char *const command, gchar **args)
             return TRUE;
         }
 
-        GSList *list = roster_get_group(group);
+        GSList *list = roster_get_group(group, ROSTER_ORD_NAME);
         cons_show_roster_group(group, list);
         return TRUE;
     }
@@ -1711,7 +1711,7 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
             return TRUE;
         }
 
-        GSList *list = roster_get_contacts();
+        GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
         cons_show_roster(list);
         g_slist_free(list);
         return TRUE;
@@ -1931,7 +1931,7 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
             return TRUE;
         }
 
-        GSList *all = roster_get_contacts();
+        GSList *all = roster_get_contacts(ROSTER_ORD_NAME);
         GSList *curr = all;
         while (curr) {
             PContact contact = curr->data;
diff --git a/src/roster_list.c b/src/roster_list.c
index fe3063dd..2f1a0b55 100644
--- a/src/roster_list.c
+++ b/src/roster_list.c
@@ -383,33 +383,23 @@ roster_get_contacts_by_presence(const char *const presence)
 }
 
 GSList*
-roster_get_contacts_ord_presence(void)
+roster_get_contacts(roster_ord_t order)
 {
     GSList *result = NULL;
     GHashTableIter iter;
     gpointer key;
     gpointer value;
 
-    g_hash_table_iter_init(&iter, contacts);
-    while (g_hash_table_iter_next(&iter, &key, &value)) {
-        result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_presence);
+    GCompareFunc cmp_func;
+    if (order == ROSTER_ORD_PRESENCE) {
+        cmp_func = (GCompareFunc) _compare_presence;
+    } else {
+        cmp_func = (GCompareFunc) _compare_name;
     }
 
-    // return all contact structs
-    return result;
-}
-
-GSList*
-roster_get_contacts(void)
-{
-    GSList *result = NULL;
-    GHashTableIter iter;
-    gpointer key;
-    gpointer value;
-
     g_hash_table_iter_init(&iter, contacts);
     while (g_hash_table_iter_next(&iter, &key, &value)) {
-        result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name);
+        result = g_slist_insert_sorted(result, value, cmp_func);
     }
 
     // return all contact structs
@@ -465,38 +455,25 @@ roster_fulljid_autocomplete(const char *const search_str)
 }
 
 GSList*
-roster_get_nogroup_ord_presence(void)
+roster_get_nogroup(roster_ord_t order)
 {
     GSList *result = NULL;
     GHashTableIter iter;
     gpointer key;
     gpointer value;
 
-    g_hash_table_iter_init(&iter, contacts);
-    while (g_hash_table_iter_next(&iter, &key, &value)) {
-        GSList *groups = p_contact_groups(value);
-        if (groups == NULL) {
-            result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_presence);
-        }
+    GCompareFunc cmp_func;
+    if (order == ROSTER_ORD_PRESENCE) {
+        cmp_func = (GCompareFunc) _compare_presence;
+    } else {
+        cmp_func = (GCompareFunc) _compare_name;
     }
 
-    // return all contact structs
-    return result;
-}
-
-GSList*
-roster_get_nogroup(void)
-{
-    GSList *result = NULL;
-    GHashTableIter iter;
-    gpointer key;
-    gpointer value;
-
     g_hash_table_iter_init(&iter, contacts);
     while (g_hash_table_iter_next(&iter, &key, &value)) {
         GSList *groups = p_contact_groups(value);
         if (groups == NULL) {
-            result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name);
+            result = g_slist_insert_sorted(result, value, cmp_func);
         }
     }
 
@@ -505,43 +482,26 @@ roster_get_nogroup(void)
 }
 
 GSList*
-roster_get_group_ord_presence(const char *const group)
+roster_get_group(const char *const group, roster_ord_t order)
 {
     GSList *result = NULL;
     GHashTableIter iter;
     gpointer key;
     gpointer value;
 
-    g_hash_table_iter_init(&iter, contacts);
-    while (g_hash_table_iter_next(&iter, &key, &value)) {
-        GSList *groups = p_contact_groups(value);
-        while (groups) {
-            if (strcmp(groups->data, group) == 0) {
-                result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_presence);
-                break;
-            }
-            groups = g_slist_next(groups);
-        }
+    GCompareFunc cmp_func;
+    if (order == ROSTER_ORD_PRESENCE) {
+        cmp_func = (GCompareFunc) _compare_presence;
+    } else {
+        cmp_func = (GCompareFunc) _compare_name;
     }
 
-    // return all contact structs
-    return result;
-}
-
-GSList*
-roster_get_group(const char *const group)
-{
-    GSList *result = NULL;
-    GHashTableIter iter;
-    gpointer key;
-    gpointer value;
-
     g_hash_table_iter_init(&iter, contacts);
     while (g_hash_table_iter_next(&iter, &key, &value)) {
         GSList *groups = p_contact_groups(value);
         while (groups) {
             if (strcmp(groups->data, group) == 0) {
-                result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name);
+                result = g_slist_insert_sorted(result, value, cmp_func);
                 break;
             }
             groups = g_slist_next(groups);
diff --git a/src/roster_list.h b/src/roster_list.h
index da4bbbcd..15cdacef 100644
--- a/src/roster_list.h
+++ b/src/roster_list.h
@@ -40,6 +40,11 @@
 #include "resource.h"
 #include "contact.h"
 
+typedef enum {
+    ROSTER_ORD_NAME,
+    ROSTER_ORD_PRESENCE
+} roster_ord_t;
+
 void roster_clear(void);
 gboolean roster_update_presence(const char *const barejid, Resource *resource, GDateTime *last_activity);
 PContact roster_get_contact(const char *const barejid);
@@ -54,20 +59,17 @@ void roster_update(const char *const barejid, const char *const name, GSList *gr
 gboolean roster_add(const char *const barejid, const char *const name, GSList *groups, const char *const subscription,
     gboolean pending_out);
 char* roster_barejid_from_name(const char *const name);
-GSList* roster_get_contacts(void);
-GSList* roster_get_contacts_ord_presence(void);
+GSList* roster_get_contacts(roster_ord_t order);
 GSList* roster_get_contacts_online(void);
 gboolean roster_has_pending_subscriptions(void);
 char* roster_contact_autocomplete(const char *const search_str);
 char* roster_fulljid_autocomplete(const char *const search_str);
-GSList* roster_get_group(const char *const group);
-GSList* roster_get_group_ord_presence(const char *const group);
+GSList* roster_get_group(const char *const group, roster_ord_t order);
 GSList* roster_get_groups(void);
 char* roster_group_autocomplete(const char *const search_str);
 char* roster_barejid_autocomplete(const char *const search_str);
 GSList* roster_get_contacts_by_presence(const char *const presence);
-GSList* roster_get_nogroup(void);
-GSList* roster_get_nogroup_ord_presence(void);
+GSList* roster_get_nogroup(roster_ord_t order);
 char* roster_get_msg_display_name(const char *const barejid, const char *const resource);
 
 #endif
diff --git a/src/ui/console.c b/src/ui/console.c
index 882a9b54..0c6733c4 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -527,7 +527,7 @@ void
 cons_show_sent_subs(void)
 {
    if (roster_has_pending_subscriptions()) {
-        GSList *contacts = roster_get_contacts();
+        GSList *contacts = roster_get_contacts(ROSTER_ORD_NAME);
         PContact contact = NULL;
         cons_show("Awaiting subscription responses from:");
         GSList *curr = contacts;
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 95d374bd..a689f033 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -171,9 +171,9 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
 
     char *order = prefs_get_string(PREF_ROSTER_ORDER);
     if (g_strcmp0(order, "presence") == 0) {
-        contacts = roster_get_group_ord_presence(group);
+        contacts = roster_get_group(group, ROSTER_ORD_PRESENCE);
     } else {
-        contacts = roster_get_group(group);
+        contacts = roster_get_group(group, ROSTER_ORD_NAME);
     }
 
     if (contacts) {
@@ -194,9 +194,9 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout)
 
     char *order = prefs_get_string(PREF_ROSTER_ORDER);
     if (g_strcmp0(order, "presence") == 0) {
-        contacts = roster_get_nogroup_ord_presence();
+        contacts = roster_get_nogroup(ROSTER_ORD_PRESENCE);
     } else {
-        contacts = roster_get_nogroup();
+        contacts = roster_get_nogroup(ROSTER_ORD_NAME);
     }
 
     if (contacts) {
@@ -248,9 +248,9 @@ rosterwin_roster(void)
 
             char *order = prefs_get_string(PREF_ROSTER_ORDER);
             if (g_strcmp0(order, "presence") == 0) {
-                contacts = roster_get_contacts_ord_presence();
+                contacts = roster_get_contacts(ROSTER_ORD_PRESENCE);
             } else {
-                contacts = roster_get_contacts();
+                contacts = roster_get_contacts(ROSTER_ORD_NAME);
             }
 
             if (contacts) {