about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-08-30 00:33:46 +0100
committerJames Booth <boothj5@gmail.com>2013-08-30 00:33:46 +0100
commit7f476b3e2cb4739adb6b5ea02a9b86f19637b819 (patch)
tree437382b072ef11b37279068da1070ad42c7b2423 /src
parent48794e324c19f2492593a440e26f8b29f4a4515e (diff)
downloadprofani-tty-7f476b3e2cb4739adb6b5ea02a9b86f19637b819.tar.gz
Fixed /close all and /close read to close extra windows
Diffstat (limited to 'src')
-rw-r--r--src/ui/core.c36
-rw-r--r--src/ui/windows.c6
-rw-r--r--src/ui/windows.h1
3 files changed, 33 insertions, 10 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index c97ce67e..d6e17854 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -528,38 +528,54 @@ ui_close_connected_win(int index)
 int
 ui_close_all_wins(void)
 {
-    int curr = 0, count = 0;
+    int count = 0;
     jabber_conn_status_t conn_status = jabber_get_connection_status();
 
-    for (curr = 2; curr <= 10; curr++) {
-        if (ui_win_exists(curr)) {
+    GList *win_nums = wins_get_nums();
+    GList *curr = win_nums;
+
+    while (curr != NULL) {
+        int num = GPOINTER_TO_INT(curr->data);
+        if (num != 1) {
             if (conn_status == JABBER_CONNECTED) {
-                ui_close_connected_win(curr);
+                ui_close_connected_win(num);
             }
-            ui_close_win(curr);
+            ui_close_win(num);
             count++;
         }
+        curr = g_list_next(curr);
     }
 
+    g_list_free(curr);
+    g_list_free(win_nums);
+
     return count;
 }
 
 int
 ui_close_read_wins(void)
 {
-    int curr = 0, count = 0;
+    int count = 0;
     jabber_conn_status_t conn_status = jabber_get_connection_status();
 
-    for (curr = 2; curr <= 10; curr++) {
-        if (ui_win_exists(curr) && (ui_win_unread(curr) == 0)) {
+    GList *win_nums = wins_get_nums();
+    GList *curr = win_nums;
+
+    while (curr != NULL) {
+        int num = GPOINTER_TO_INT(curr->data);
+        if ((num != 1) && (ui_win_unread(num) == 0)) {
             if (conn_status == JABBER_CONNECTED) {
-                ui_close_connected_win(curr);
+                ui_close_connected_win(num);
             }
-            ui_close_win(curr);
+            ui_close_win(num);
             count++;
         }
+        curr = g_list_next(curr);
     }
 
+    g_list_free(curr);
+    g_list_free(win_nums);
+
     return count;
 }
 
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 58e1ec59..81a6d3e6 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -70,6 +70,12 @@ wins_get_current(void)
     return g_hash_table_lookup(windows, GINT_TO_POINTER(current));
 }
 
+GList *
+wins_get_nums(void)
+{
+    return g_hash_table_get_keys(windows);
+}
+
 void
 wins_set_current_by_num(int i)
 {
diff --git a/src/ui/windows.h b/src/ui/windows.h
index f0476896..6d93c434 100644
--- a/src/ui/windows.h
+++ b/src/ui/windows.h
@@ -47,5 +47,6 @@ void wins_lost_connection(void);
 gboolean wins_tidy(void);
 GSList * wins_create_summary(void);
 void wins_destroy(void);
+GList * wins_get_nums(void);
 
 #endif