about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-07-22 23:27:36 +0100
committerJames Booth <boothj5@gmail.com>2014-07-22 23:27:36 +0100
commitfd1d54088955c181a662f68506a01d79c1770e32 (patch)
tree80c26cef162c1e0570579e97ef6f24afa063a685
parent6a1975f65bdbd59575bca75c09d4a14430284b69 (diff)
downloadprofani-tty-fd1d54088955c181a662f68506a01d79c1770e32.tar.gz
Added _who_roster function
-rw-r--r--src/command/commands.c339
1 files changed, 173 insertions, 166 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index b6f168b1..49d0557f 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -62,6 +62,7 @@ static int _strtoi(char *str, int *saveptr, int min, int max);
 static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size);
 static gint _compare_commands(Command *a, Command *b);
 static void _who_room(const char * const presence);
+static void _who_roster(const char * const group, const char * const presence);
 
 extern GHashTable *commands;
 
@@ -794,6 +795,177 @@ _who_room(const char * const presence)
     }
 }
 
+static void
+_who_roster(const char * const group, const char * const presence)
+{
+    cons_show("");
+    GSList *list = NULL;
+    if (group != NULL) {
+        list = roster_get_group(group);
+    } else {
+        list = roster_get_contacts();
+    }
+
+    // no arg, show all contacts
+    if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
+        if (group != NULL) {
+            if (list == NULL) {
+                cons_show("No contacts in group %s.", group);
+            } else {
+                cons_show("%s:", group);
+                cons_show_contacts(list);
+            }
+        } else {
+            if (list == NULL) {
+                cons_show("You have no contacts.");
+            } else {
+                cons_show("All contacts:");
+                cons_show_contacts(list);
+            }
+        }
+
+    // available
+    } else if (strcmp("available", presence) == 0) {
+        GSList *filtered = NULL;
+
+        while (list != NULL) {
+            PContact contact = list->data;
+            if (p_contact_is_available(contact)) {
+                filtered = g_slist_append(filtered, contact);
+            }
+            list = g_slist_next(list);
+        }
+
+        if (group != NULL) {
+            if (filtered == NULL) {
+                cons_show("No contacts in group %s are %s.", group, presence);
+            } else {
+                cons_show("%s (%s):", group, presence);
+                cons_show_contacts(filtered);
+            }
+        } else {
+            if (filtered == NULL) {
+                cons_show("No contacts are %s.", presence);
+            } else {
+                cons_show("Contacts (%s):", presence);
+                cons_show_contacts(filtered);
+            }
+        }
+
+    // unavailable
+    } else if (strcmp("unavailable", presence) == 0) {
+        GSList *filtered = NULL;
+
+        while (list != NULL) {
+            PContact contact = list->data;
+            if (!p_contact_is_available(contact)) {
+                filtered = g_slist_append(filtered, contact);
+            }
+            list = g_slist_next(list);
+        }
+
+        if (group != NULL) {
+            if (filtered == NULL) {
+                cons_show("No contacts in group %s are %s.", group, presence);
+            } else {
+                cons_show("%s (%s):", group, presence);
+                cons_show_contacts(filtered);
+            }
+        } else {
+            if (filtered == NULL) {
+                cons_show("No contacts are %s.", presence);
+            } else {
+                cons_show("Contacts (%s):", presence);
+                cons_show_contacts(filtered);
+            }
+        }
+
+    // online, available resources
+    } else if (strcmp("online", presence) == 0) {
+        GSList *filtered = NULL;
+
+        while (list != NULL) {
+            PContact contact = list->data;
+            if (p_contact_has_available_resource(contact)) {
+                filtered = g_slist_append(filtered, contact);
+            }
+            list = g_slist_next(list);
+        }
+
+        if (group != NULL) {
+            if (filtered == NULL) {
+                cons_show("No contacts in group %s are %s.", group, presence);
+            } else {
+                cons_show("%s (%s):", group, presence);
+                cons_show_contacts(filtered);
+            }
+        } else {
+            if (filtered == NULL) {
+                cons_show("No contacts are %s.", presence);
+            } else {
+                cons_show("Contacts (%s):", presence);
+                cons_show_contacts(filtered);
+            }
+        }
+
+    // offline, no available resources
+    } else if (strcmp("offline", presence) == 0) {
+        GSList *filtered = NULL;
+
+        while (list != NULL) {
+            PContact contact = list->data;
+            if (!p_contact_has_available_resource(contact)) {
+                filtered = g_slist_append(filtered, contact);
+            }
+            list = g_slist_next(list);
+        }
+
+        if (group != NULL) {
+            if (filtered == NULL) {
+                cons_show("No contacts in group %s are %s.", group, presence);
+            } else {
+                cons_show("%s (%s):", group, presence);
+                cons_show_contacts(filtered);
+            }
+        } else {
+            if (filtered == NULL) {
+                cons_show("No contacts are %s.", presence);
+            } else {
+                cons_show("Contacts (%s):", presence);
+                cons_show_contacts(filtered);
+            }
+        }
+
+    // show specific status
+    } else {
+        GSList *filtered = NULL;
+
+        while (list != NULL) {
+            PContact contact = list->data;
+            if (strcmp(p_contact_presence(contact), presence) == 0) {
+                filtered = g_slist_append(filtered, contact);
+            }
+            list = g_slist_next(list);
+        }
+
+        if (group != NULL) {
+            if (filtered == NULL) {
+                cons_show("No contacts in group %s are %s.", group, presence);
+            } else {
+                cons_show("%s (%s):", group, presence);
+                cons_show_contacts(filtered);
+            }
+        } else {
+            if (filtered == NULL) {
+                cons_show("No contacts are %s.", presence);
+            } else {
+                cons_show("Contacts (%s):", presence);
+                cons_show_contacts(filtered);
+            }
+        }
+    }
+}
+
 gboolean
 cmd_who(gchar **args, struct cmd_help_t help)
 {
@@ -831,172 +1003,7 @@ cmd_who(gchar **args, struct cmd_help_t help)
                 }
 
             } else {
-                cons_show("");
-                GSList *list = NULL;
-                if (group != NULL) {
-                    list = roster_get_group(group);
-                } else {
-                    list = roster_get_contacts();
-                }
-
-                // no arg, show all contacts
-                if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
-                    if (group != NULL) {
-                        if (list == NULL) {
-                            cons_show("No contacts in group %s.", group);
-                        } else {
-                            cons_show("%s:", group);
-                            cons_show_contacts(list);
-                        }
-                    } else {
-                        if (list == NULL) {
-                            cons_show("You have no contacts.");
-                        } else {
-                            cons_show("All contacts:");
-                            cons_show_contacts(list);
-                        }
-                    }
-
-                // available
-                } else if (strcmp("available", presence) == 0) {
-                    GSList *filtered = NULL;
-
-                    while (list != NULL) {
-                        PContact contact = list->data;
-                        if (p_contact_is_available(contact)) {
-                            filtered = g_slist_append(filtered, contact);
-                        }
-                        list = g_slist_next(list);
-                    }
-
-                    if (group != NULL) {
-                        if (filtered == NULL) {
-                            cons_show("No contacts in group %s are %s.", group, presence);
-                        } else {
-                            cons_show("%s (%s):", group, presence);
-                            cons_show_contacts(filtered);
-                        }
-                    } else {
-                        if (filtered == NULL) {
-                            cons_show("No contacts are %s.", presence);
-                        } else {
-                            cons_show("Contacts (%s):", presence);
-                            cons_show_contacts(filtered);
-                        }
-                    }
-
-                // unavailable
-                } else if (strcmp("unavailable", presence) == 0) {
-                    GSList *filtered = NULL;
-
-                    while (list != NULL) {
-                        PContact contact = list->data;
-                        if (!p_contact_is_available(contact)) {
-                            filtered = g_slist_append(filtered, contact);
-                        }
-                        list = g_slist_next(list);
-                    }
-
-                    if (group != NULL) {
-                        if (filtered == NULL) {
-                            cons_show("No contacts in group %s are %s.", group, presence);
-                        } else {
-                            cons_show("%s (%s):", group, presence);
-                            cons_show_contacts(filtered);
-                        }
-                    } else {
-                        if (filtered == NULL) {
-                            cons_show("No contacts are %s.", presence);
-                        } else {
-                            cons_show("Contacts (%s):", presence);
-                            cons_show_contacts(filtered);
-                        }
-                    }
-
-                // online, available resources
-                } else if (strcmp("online", presence) == 0) {
-                    GSList *filtered = NULL;
-
-                    while (list != NULL) {
-                        PContact contact = list->data;
-                        if (p_contact_has_available_resource(contact)) {
-                            filtered = g_slist_append(filtered, contact);
-                        }
-                        list = g_slist_next(list);
-                    }
-
-                    if (group != NULL) {
-                        if (filtered == NULL) {
-                            cons_show("No contacts in group %s are %s.", group, presence);
-                        } else {
-                            cons_show("%s (%s):", group, presence);
-                            cons_show_contacts(filtered);
-                        }
-                    } else {
-                        if (filtered == NULL) {
-                            cons_show("No contacts are %s.", presence);
-                        } else {
-                            cons_show("Contacts (%s):", presence);
-                            cons_show_contacts(filtered);
-                        }
-                    }
-
-                // offline, no available resources
-                } else if (strcmp("offline", presence) == 0) {
-                    GSList *filtered = NULL;
-
-                    while (list != NULL) {
-                        PContact contact = list->data;
-                        if (!p_contact_has_available_resource(contact)) {
-                            filtered = g_slist_append(filtered, contact);
-                        }
-                        list = g_slist_next(list);
-                    }
-
-                    if (group != NULL) {
-                        if (filtered == NULL) {
-                            cons_show("No contacts in group %s are %s.", group, presence);
-                        } else {
-                            cons_show("%s (%s):", group, presence);
-                            cons_show_contacts(filtered);
-                        }
-                    } else {
-                        if (filtered == NULL) {
-                            cons_show("No contacts are %s.", presence);
-                        } else {
-                            cons_show("Contacts (%s):", presence);
-                            cons_show_contacts(filtered);
-                        }
-                    }
-
-                // show specific status
-                } else {
-                    GSList *filtered = NULL;
-
-                    while (list != NULL) {
-                        PContact contact = list->data;
-                        if (strcmp(p_contact_presence(contact), presence) == 0) {
-                            filtered = g_slist_append(filtered, contact);
-                        }
-                        list = g_slist_next(list);
-                    }
-
-                    if (group != NULL) {
-                        if (filtered == NULL) {
-                            cons_show("No contacts in group %s are %s.", group, presence);
-                        } else {
-                            cons_show("%s (%s):", group, presence);
-                            cons_show_contacts(filtered);
-                        }
-                    } else {
-                        if (filtered == NULL) {
-                            cons_show("No contacts are %s.", presence);
-                        } else {
-                            cons_show("Contacts (%s):", presence);
-                            cons_show_contacts(filtered);
-                        }
-                    }
-                }
+                _who_roster(group, presence);
             }
         }
     }