about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-10 23:51:13 +0000
committerJames Booth <boothj5@gmail.com>2014-11-10 23:51:13 +0000
commitf715c0580c904caababf980e0fef72ae28944424 (patch)
treee90477a22657838c4435422a235c095f922e0933
parent497b07c1c3563efdfc147b22bd8afd094caf619a (diff)
downloadprofani-tty-f715c0580c904caababf980e0fef72ae28944424.tar.gz
Added /roster show|hide offline
-rw-r--r--src/command/command.c34
-rw-r--r--src/command/commands.c37
-rw-r--r--src/ui/core.c60
3 files changed, 85 insertions, 46 deletions
diff --git a/src/command/command.c b/src/command/command.c
index a8b409d7..e441656d 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -169,17 +169,19 @@ static struct cmd_t command_defs[] =
 
     { "/roster",
         cmd_roster, parse_args_with_freetext, 0, 3, NULL,
-        { "/roster [show|hide|add|remove|nick|clearnick] [jid] [nickname]", "Manage your roster.",
-        { "/roster [show|hide|add|remove|nick|clearnick] [jid] [nickname]",
-          "--------------------------------------------------------------",
+        { "/roster [show|hide|add|remove|nick|clearnick] [offline] [jid] [nickname]", "Manage your roster.",
+        { "/roster [show|hide|add|remove|nick|clearnick] [offline] [jid] [nickname]",
+          "------------------------------------------------------------------------",
           "View, add to, and remove from your roster.",
           "Passing no arguments lists all contacts in your roster.",
-          "The 'show' command will show the roster panel in the console window.",
-          "The 'hide' command will hide the roster panel.",
-          "The 'add' command will add a new item, jid is required, nickname is optional.",
-          "The 'remove' command removes a contact, jid is required.",
-          "The 'nick' command changes a contacts nickname, both jid and nickname are required,",
-          "The 'clearnick' command removes the current nickname, jid is required.",
+          "show         - Show the roster panel in the console window.",
+          "hide         - Hide the roster panel.",
+          "show offline - Show offline contacts in the roster panel.",
+          "hide offline - Hide offline contacts in the roster panel.",
+          "add          - Add a new item, jid is required, nickname is optional.",
+          "remove       - Removes a contact, jid is required.",
+          "nick         - Changes a contacts nickname, both jid and nickname are required,",
+          "clearnick    - Removes the current nickname, jid is required.",
           "",
           "Example : /roster (show your roster)",
           "Example : /roster add someone@contacts.org (add the contact)",
@@ -1039,6 +1041,7 @@ static Autocomplete disco_ac;
 static Autocomplete close_ac;
 static Autocomplete wins_ac;
 static Autocomplete roster_ac;
+static Autocomplete roster_option_ac;
 static Autocomplete group_ac;
 static Autocomplete bookmark_ac;
 static Autocomplete bookmark_property_ac;
@@ -1235,6 +1238,9 @@ cmd_init(void)
     autocomplete_add(roster_ac, "show");
     autocomplete_add(roster_ac, "hide");
 
+    roster_option_ac = autocomplete_new();
+    autocomplete_add(roster_option_ac, "offline");
+
     group_ac = autocomplete_new();
     autocomplete_add(group_ac, "show");
     autocomplete_add(group_ac, "add");
@@ -1404,6 +1410,7 @@ cmd_uninit(void)
     autocomplete_free(close_ac);
     autocomplete_free(wins_ac);
     autocomplete_free(roster_ac);
+    autocomplete_free(roster_option_ac);
     autocomplete_free(group_ac);
     autocomplete_free(bookmark_ac);
     autocomplete_free(bookmark_property_ac);
@@ -1572,6 +1579,7 @@ cmd_reset_autocomplete()
     autocomplete_reset(close_ac);
     autocomplete_reset(wins_ac);
     autocomplete_reset(roster_ac);
+    autocomplete_reset(roster_option_ac);
     autocomplete_reset(group_ac);
     autocomplete_reset(bookmark_ac);
     autocomplete_reset(bookmark_property_ac);
@@ -2000,6 +2008,14 @@ _roster_autocomplete(char *input, int *size)
     if (result != NULL) {
         return result;
     }
+    result = autocomplete_param_with_ac(input, size, "/roster show", roster_option_ac, TRUE);
+    if (result != NULL) {
+        return result;
+    }
+    result = autocomplete_param_with_ac(input, size, "/roster hide", roster_option_ac, TRUE);
+    if (result != NULL) {
+        return result;
+    }
     result = autocomplete_param_with_ac(input, size, "/roster", roster_ac, TRUE);
     if (result != NULL) {
         return result;
diff --git a/src/command/commands.c b/src/command/commands.c
index 877b6857..568cd352 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1332,16 +1332,35 @@ cmd_roster(gchar **args, struct cmd_help_t help)
 
     // show/hide roster
     } else if (g_strcmp0(args[0], "show") == 0) {
-        cons_show("Roster enabled.");
-        prefs_set_boolean(PREF_ROSTER, TRUE);
-        ui_show_roster();
-        return TRUE;
+        if (args[1] == NULL) {
+            cons_show("Roster enabled.");
+            prefs_set_boolean(PREF_ROSTER, TRUE);
+            ui_show_roster();
+            return TRUE;
+        } else if (g_strcmp0(args[1], "offline") == 0) {
+            cons_show("Roster offline enabled");
+            prefs_set_boolean(PREF_ROSTER_OFFLINE, TRUE);
+            ui_roster();
+            return TRUE;
+        } else {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        }
     } else if (g_strcmp0(args[0], "hide") == 0) {
-        cons_show("Roster disabled.");
-        prefs_set_boolean(PREF_ROSTER, FALSE);
-        ui_hide_roster();
-        return TRUE;
-
+        if (args[1] == NULL) {
+            cons_show("Roster disabled.");
+            prefs_set_boolean(PREF_ROSTER, FALSE);
+            ui_hide_roster();
+            return TRUE;
+        } else if (g_strcmp0(args[1], "offline") == 0) {
+            cons_show("Roster offline disabled");
+            prefs_set_boolean(PREF_ROSTER_OFFLINE, FALSE);
+            ui_roster();
+            return TRUE;
+        } else {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        }
     // add contact
     } else if (strcmp(args[0], "add") == 0) {
         char *jid = args[1];
diff --git a/src/ui/core.c b/src/ui/core.c
index 66b5fa2b..e2beae04 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -2821,45 +2821,49 @@ _ui_roster(void)
                 if (p_contact_subscribed(contact)) {
                     const char *name = p_contact_name_or_jid(contact);
                     const char *presence = p_contact_presence(contact);
-                    int presence_colour = win_presence_colour(presence);
 
-                    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);
 
-                    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);
-                    }
+                        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);
+
+                            GString *msg = g_string_new("     ");
+                            g_string_append(msg, resource->name);
+                            win_printline_nowrap(window->subwin, msg->str);
+                            g_string_free(msg, TRUE);
 
-                        wattroff(window->subwin, resource_presence_colour);
+                            wattroff(window->subwin, resource_presence_colour);
 
-                        ordered_resources = g_list_next(ordered_resources);
+                            ordered_resources = g_list_next(ordered_resources);
+                        }
+                        g_list_free(ordered_resources);
                     }
-                    g_list_free(ordered_resources);
                 }
                 curr_contact = g_slist_next(curr_contact);
             }