about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-11-30 00:17:44 +0000
committerJames Booth <boothj5@gmail.com>2015-11-30 00:17:44 +0000
commit0920b65ddf8162d850190ccbbb6bcaa7eee63300 (patch)
tree76163c43e836cd7c722e554660f23b010999a2ab /src
parentd9435d3b659c4bd6728b9157bd8c67023050257e (diff)
downloadprofani-tty-0920b65ddf8162d850190ccbbb6bcaa7eee63300.tar.gz
Added /wins unread
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c4
-rw-r--r--src/command/commands.c4
-rw-r--r--src/ui/console.c15
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/window_list.c30
-rw-r--r--src/window_list.h2
6 files changed, 38 insertions, 19 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 6ca09b82..331a9bad 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -799,6 +799,8 @@ static struct cmd_t command_defs[] =
         CMD_TAGS(
             CMD_TAG_UI)
         CMD_SYN(
+            "/wins",
+            "/wins unread",
             "/wins tidy",
             "/wins autotidy on|off",
             "/wins prune",
@@ -807,6 +809,7 @@ static struct cmd_t command_defs[] =
             "Manage windows. "
             "Passing no argument will list all currently active windows and information about their usage.")
         CMD_ARGS(
+            { "unread",                 "List windows with unread messages." },
             { "tidy",                   "Move windows so there are no gaps." },
             { "autotidy on|off",        "Automatically remove gaps when closing windows." },
             { "prune",                  "Close all windows with no unread messages, and then tidy so there are no gaps." },
@@ -2079,6 +2082,7 @@ cmd_init(void)
     autocomplete_add(close_ac, "all");
 
     wins_ac = autocomplete_new();
+    autocomplete_add(wins_ac, "unread");
     autocomplete_add(wins_ac, "prune");
     autocomplete_add(wins_ac, "tidy");
     autocomplete_add(wins_ac, "autotidy");
diff --git a/src/command/commands.c b/src/command/commands.c
index 042fbb1c..6db8f5d3 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1013,7 +1013,9 @@ gboolean
 cmd_wins(ProfWin *window, const char *const command, gchar **args)
 {
     if (args[0] == NULL) {
-        cons_show_wins();
+        cons_show_wins(FALSE);
+    } else if (strcmp(args[0], "unread") == 0) {
+        cons_show_wins(TRUE);
     } else if (strcmp(args[0], "tidy") == 0) {
         if (wins_tidy()) {
             cons_show("Windows tidied.");
diff --git a/src/ui/console.c b/src/ui/console.c
index 28fba4cd..b4083ea3 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -403,12 +403,20 @@ cons_show_login_success(ProfAccount *account, int secured)
 }
 
 void
-cons_show_wins(void)
+cons_show_wins(gboolean unread)
 {
     ProfWin *console = wins_get_console();
     cons_show("");
-    cons_show("Active windows:");
-    GSList *window_strings = wins_create_summary();
+    GSList *window_strings = wins_create_summary(unread);
+
+    if (unread && window_strings == NULL) {
+        cons_show("No windows with unread messages.");
+        return;
+    } else if (unread) {
+        cons_show("Unread:");
+    } else {
+        cons_show("Active windows:");
+    }
 
     GSList *curr = window_strings;
     while (curr) {
@@ -417,7 +425,6 @@ cons_show_wins(void)
     }
     g_slist_free_full(window_strings, free);
 
-    cons_show("");
     cons_alert();
 }
 
diff --git a/src/ui/ui.h b/src/ui/ui.h
index c445452d..e21f2ea8 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -237,7 +237,7 @@ void cons_show_error(const char *const cmd, ...);
 void cons_show_contacts(GSList *list);
 void cons_show_roster(GSList *list);
 void cons_show_roster_group(const char *const group, GSList *list);
-void cons_show_wins(void);
+void cons_show_wins(gboolean unread);
 char* cons_get_string(ProfConsoleWin *conswin);
 void cons_show_status(const char *const barejid);
 void cons_show_info(PContact pcontact);
diff --git a/src/window_list.c b/src/window_list.c
index 806ac736..87d20178 100644
--- a/src/window_list.c
+++ b/src/window_list.c
@@ -647,8 +647,12 @@ wins_tidy(void)
 }
 
 GSList*
-wins_create_summary(void)
+wins_create_summary(gboolean unread)
 {
+    if (unread && wins_get_total_unread() == 0) {
+        return NULL;
+    }
+
     GSList *result = NULL;
 
     GList *keys = g_hash_table_get_keys(windows);
@@ -657,21 +661,23 @@ wins_create_summary(void)
 
     while (curr) {
         ProfWin *window = g_hash_table_lookup(windows, curr->data);
-        GString *line = g_string_new("");
+        if (!unread || (unread && win_unread(window) > 0)) {
+            GString *line = g_string_new("");
+
+            int ui_index = GPOINTER_TO_INT(curr->data);
+            char *winstring = win_get_string(window);
+            if (!winstring) {
+                g_string_free(line, TRUE);
+                continue;
+            }
 
-        int ui_index = GPOINTER_TO_INT(curr->data);
-        char *winstring = win_get_string(window);
-        if (!winstring) {
+            g_string_append_printf(line, "%d: %s", ui_index, winstring);
+            free(winstring);
+
+            result = g_slist_append(result, strdup(line->str));
             g_string_free(line, TRUE);
-            continue;
         }
 
-        g_string_append_printf(line, "%d: %s", ui_index, winstring);
-        free(winstring);
-
-        result = g_slist_append(result, strdup(line->str));
-        g_string_free(line, TRUE);
-
         curr = g_list_next(curr);
     }
 
diff --git a/src/window_list.h b/src/window_list.h
index 4cf4e5f8..6710c539 100644
--- a/src/window_list.h
+++ b/src/window_list.h
@@ -74,7 +74,7 @@ GSList* wins_get_chat_recipients(void);
 GSList* wins_get_prune_wins(void);
 void wins_lost_connection(void);
 gboolean wins_tidy(void);
-GSList* wins_create_summary(void);
+GSList* wins_create_summary(gboolean unread);
 void wins_destroy(void);
 GList* wins_get_nums(void);
 gboolean wins_swap(int source_win, int target_win);