about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-11-18 02:02:49 +0000
committerJames Booth <boothj5@gmail.com>2015-11-18 02:02:49 +0000
commit4505102fa83e00c70d1ee15967b977957dcf3aa5 (patch)
tree9f8556fc7e9bd8c0abec75a6cca3f00c283c32de
parentedbd2d5843fe7cefd730899aace631416715bb8f (diff)
downloadprofani-tty-4505102fa83e00c70d1ee15967b977957dcf3aa5.tar.gz
Added roster count option
-rw-r--r--src/command/command.c7
-rw-r--r--src/command/commands.c14
-rw-r--r--src/config/preferences.c4
-rw-r--r--src/config/preferences.h1
-rw-r--r--src/ui/console.c5
-rw-r--r--src/ui/rosterwin.c24
6 files changed, 50 insertions, 5 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 2a98ba75..1057084c 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -274,8 +274,8 @@ static struct cmd_t command_defs[] =
         CMD_SYN(
             "/roster",
             "/roster online",
-            "/roster show [offline|resource|presence|status|empty]",
-            "/roster hide [offline|resource|presence|status|empty]",
+            "/roster show [offline|resource|presence|status|empty|count]",
+            "/roster hide [offline|resource|presence|status|empty|count]",
             "/roster by group|presence|none",
             "/roster order name|presence"
             "/roster size <percent>",
@@ -295,12 +295,14 @@ static struct cmd_t command_defs[] =
             { "show presence",       "Show contact's presence in the roster panel." },
             { "show status",         "Show contact's status message in the roster panel." },
             { "show empty",          "When grouping by presence, show empty presence groups." },
+            { "show count",          "Show number of contacts in group/presence." },
             { "hide",                "Hide the roster panel." },
             { "hide offline",        "Hide offline contacts in the roster panel." },
             { "hide resource",       "Hide contact's connected resources in the roster panel." },
             { "hide presence",       "Hide contact's presence in the roster panel." },
             { "hide status",         "Hide contact's status message in the roster panel." },
             { "hide empty",          "When grouping by presence, hide empty presence groups." },
+            { "hide count",          "Hide number of contacts in group/presence." },
             { "by group",            "Group contacts in the roster panel by roster group." },
             { "by presence",         "Group contacts in the roster panel by presence." },
             { "by none",             "No grouping in the roster panel." },
@@ -2027,6 +2029,7 @@ cmd_init(void)
     autocomplete_add(roster_option_ac, "presence");
     autocomplete_add(roster_option_ac, "status");
     autocomplete_add(roster_option_ac, "empty");
+    autocomplete_add(roster_option_ac, "count");
 
     roster_by_ac = autocomplete_new();
     autocomplete_add(roster_by_ac, "group");
diff --git a/src/command/commands.c b/src/command/commands.c
index 10143565..4d8933bd 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1794,6 +1794,13 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
                 rosterwin_roster();
             }
             return TRUE;
+        } else if (g_strcmp0(args[1], "count") == 0) {
+            cons_show("Roster count enabled");
+            prefs_set_boolean(PREF_ROSTER_COUNT, TRUE);
+            if (conn_status == JABBER_CONNECTED) {
+                rosterwin_roster();
+            }
+            return TRUE;
         } else {
             cons_bad_cmd_usage(command);
             return TRUE;
@@ -1841,6 +1848,13 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
                 rosterwin_roster();
             }
             return TRUE;
+        } else if (g_strcmp0(args[1], "count") == 0) {
+            cons_show("Roster count disabled");
+            prefs_set_boolean(PREF_ROSTER_COUNT, FALSE);
+            if (conn_status == JABBER_CONNECTED) {
+                rosterwin_roster();
+            }
+            return TRUE;
         } else {
             cons_bad_cmd_usage(command);
             return TRUE;
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 163df444..46cd3169 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -602,6 +602,7 @@ _get_group(preference_t pref)
         case PREF_ROSTER_EMPTY:
         case PREF_ROSTER_BY:
         case PREF_ROSTER_ORDER:
+        case PREF_ROSTER_COUNT:
         case PREF_RESOURCE_TITLE:
         case PREF_RESOURCE_MESSAGE:
         case PREF_ENC_WARN:
@@ -781,6 +782,8 @@ _get_key(preference_t pref)
             return "roster.by";
         case PREF_ROSTER_ORDER:
             return "roster.order";
+        case PREF_ROSTER_COUNT:
+            return "roster.count";
         case PREF_RESOURCE_TITLE:
             return "resource.title";
         case PREF_RESOURCE_MESSAGE:
@@ -835,6 +838,7 @@ _get_default_boolean(preference_t pref)
         case PREF_ROSTER_PRESENCE:
         case PREF_ROSTER_STATUS:
         case PREF_ROSTER_EMPTY:
+        case PREF_ROSTER_COUNT:
         case PREF_TLS_SHOW:
         case PREF_LASTACTIVITY:
             return TRUE;
diff --git a/src/config/preferences.h b/src/config/preferences.h
index 55b46b07..dcc0f441 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -69,6 +69,7 @@ typedef enum {
     PREF_ROSTER_EMPTY,
     PREF_ROSTER_BY,
     PREF_ROSTER_ORDER,
+    PREF_ROSTER_COUNT,
     PREF_MUC_PRIVILEGES,
     PREF_PRESENCE,
     PREF_WRAP,
diff --git a/src/ui/console.c b/src/ui/console.c
index 03e944d0..b145aa6d 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1222,6 +1222,11 @@ cons_roster_setting(void)
     else
         cons_show("Roster empty (/roster)        : hide");
 
+    if (prefs_get_boolean(PREF_ROSTER_COUNT))
+        cons_show("Roster count (/roster)        : show");
+    else
+        cons_show("Roster count (/roster)        : hide");
+
     char *by = prefs_get_string(PREF_ROSTER_BY);
     cons_show("Roster by (/roster)           : %s", by);
     prefs_free_string(by);
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index a8f24e0e..28ac25ce 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -140,7 +140,12 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese
     // if this group has contacts, or if we want to show empty groups
     if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
         wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-        win_printline_nowrap(layout->subwin, title);
+        GString *title_str = g_string_new(title);
+        if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
+            g_string_append_printf(title_str, " (%d)", g_slist_length(contacts));
+        }
+        win_printline_nowrap(layout->subwin, title_str->str);
+        g_string_free(title_str, TRUE);
         wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
     }
 
@@ -172,6 +177,9 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
         wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
         GString *title = g_string_new(" -");
         g_string_append(title, group);
+        if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
+            g_string_append_printf(title, " (%d)", g_slist_length(contacts));
+        }
         win_printline_nowrap(layout->subwin, title->str);
         g_string_free(title, TRUE);
         wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
@@ -201,7 +209,12 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout)
 
     if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
         wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-        win_printline_nowrap(layout->subwin, " -no group");
+        GString *title = g_string_new(" -no group");
+        if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
+            g_string_append_printf(title, " (%d)", g_slist_length(contacts));
+        }
+        win_printline_nowrap(layout->subwin, title->str);
+        g_string_free(title, TRUE);
         wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
 
         GSList *curr_contact = contacts;
@@ -257,7 +270,12 @@ rosterwin_roster(void)
             werase(layout->subwin);
 
             wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-            win_printline_nowrap(layout->subwin, " -Roster");
+            GString *title = g_string_new(" -Roster");
+            if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
+                g_string_append_printf(title, " (%d)", g_slist_length(contacts));
+            }
+            win_printline_nowrap(layout->subwin, title->str);
+            g_string_free(title, TRUE);
             wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
 
             if (contacts) {