about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-12-21 23:14:01 +0000
committerJames Booth <boothj5@gmail.com>2014-12-21 23:14:01 +0000
commitd5dee1632dd6e68a616a748456a880ea05983b3e (patch)
tree3405b4a4f8a4439a0d84b8e145509a70de28b83e
parenteef7f9cfd4f74b03b6e3ecfe5ef496fbb4e238a8 (diff)
downloadprofani-tty-d5dee1632dd6e68a616a748456a880ea05983b3e.tar.gz
Moved unread to window subtypes
-rw-r--r--src/ui/core.c19
-rw-r--r--src/ui/titlebar.c1
-rw-r--r--src/ui/window.c29
-rw-r--r--src/ui/window.h5
-rw-r--r--src/ui/windows.c41
5 files changed, 61 insertions, 34 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index 091ed0eb..f72ec732 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -369,7 +369,7 @@ _ui_incoming_msg(const char * const barejid, const char * const message, GTimeVa
             flash();
         }
 
-        window->unread++;
+        chatwin->unread++;
         if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
             _win_show_history(num, barejid);
         }
@@ -438,7 +438,7 @@ _ui_incoming_private_msg(const char * const fulljid, const char * const message,
             flash();
         }
 
-        window->unread++;
+        privatewin->unread++;
         if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
             _win_show_history(num, fulljid);
         }
@@ -854,8 +854,6 @@ _ui_switch_win(const int i)
 
         wins_set_current_by_num(i);
 
-        new_current->unread = 0;
-
         if (i == 1) {
             title_bar_console();
             status_bar_current(1);
@@ -889,8 +887,6 @@ _ui_previous_win(void)
     int i = wins_get_num(new_current);
     wins_set_current_by_num(i);
 
-    new_current->unread = 0;
-
     if (i == 1) {
         title_bar_console();
         status_bar_current(1);
@@ -920,8 +916,6 @@ _ui_next_win(void)
     int i = wins_get_num(new_current);
     wins_set_current_by_num(i);
 
-    new_current->unread = 0;
-
     if (i == 1) {
         title_bar_console();
         status_bar_current(1);
@@ -1840,10 +1834,11 @@ static void
 _ui_room_message(const char * const roomjid, const char * const nick,
     const char * const message)
 {
-    ProfWin *window = (ProfWin*)wins_get_muc(roomjid);
-    if (window == NULL) {
+    ProfMucWin *mucwin = wins_get_muc(roomjid);
+    if (mucwin == NULL) {
         log_error("Room message received from %s, but no window open for %s", nick, roomjid);
     } else {
+        ProfWin *window = (ProfWin*) mucwin;
         int num = wins_get_num(window);
         char *my_nick = muc_nick(roomjid);
 
@@ -1872,7 +1867,7 @@ _ui_room_message(const char * const roomjid, const char * const nick,
                 }
             }
 
-            window->unread++;
+            mucwin->unread++;
         }
 
         int ui_index = num;
@@ -2228,7 +2223,7 @@ _ui_win_unread(int index)
 {
     ProfWin *window = wins_get_by_num(index);
     if (window != NULL) {
-        return window->unread;
+        return win_unread(window);
     } else {
         return 0;
     }
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c
index a8cb23fa..15f8efca 100644
--- a/src/ui/titlebar.c
+++ b/src/ui/titlebar.c
@@ -121,7 +121,6 @@ title_bar_set_presence(contact_presence_t presence)
     _title_bar_draw();
 }
 
-// TODO remove
 void
 title_bar_switch(void)
 {
diff --git a/src/ui/window.c b/src/ui/window.c
index 76c923af..607dddc1 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -120,7 +120,6 @@ win_create_console(void)
     ProfConsoleWin *new_win = malloc(sizeof(ProfConsoleWin));
     new_win->window.type = WIN_CONSOLE;
     new_win->window.layout = _win_create_split_layout();
-    new_win->window.unread = 0;
 
     return &new_win->window;
 }
@@ -131,13 +130,13 @@ win_create_chat(const char * const barejid)
     ProfChatWin *new_win = malloc(sizeof(ProfChatWin));
     new_win->window.type = WIN_CHAT;
     new_win->window.layout = _win_create_simple_layout();
-    new_win->window.unread = 0;
 
     new_win->barejid = strdup(barejid);
     new_win->resource = NULL;
     new_win->is_otr = FALSE;
     new_win->is_trusted = FALSE;
     new_win->history_shown = FALSE;
+    new_win->unread = 0;
 
     new_win->memcheck = PROFCHATWIN_MEMCHECK;
 
@@ -175,7 +174,7 @@ win_create_muc(const char * const roomjid)
     new_win->window.layout = (ProfLayout*)layout;
 
     new_win->roomjid = strdup(roomjid);
-    new_win->window.unread = 0;
+    new_win->unread = 0;
 
     new_win->memcheck = PROFMUCWIN_MEMCHECK;
 
@@ -188,7 +187,6 @@ win_create_muc_config(const char * const roomjid, DataForm *form)
     ProfMucConfWin *new_win = malloc(sizeof(ProfMucConfWin));
     new_win->window.type = WIN_MUC_CONFIG;
     new_win->window.layout = _win_create_simple_layout();
-    new_win->window.unread = 0;
 
     new_win->roomjid = strdup(roomjid);
     new_win->form = form;
@@ -204,9 +202,9 @@ win_create_private(const char * const fulljid)
     ProfPrivateWin *new_win = malloc(sizeof(ProfPrivateWin));
     new_win->window.type = WIN_PRIVATE;
     new_win->window.layout = _win_create_simple_layout();
-    new_win->window.unread = 0;
 
     new_win->fulljid = strdup(fulljid);
+    new_win->unread = 0;
 
     new_win->memcheck = PROFPRIVATEWIN_MEMCHECK;
 
@@ -219,7 +217,6 @@ win_create_xmlconsole(void)
     ProfXMLWin *new_win = malloc(sizeof(ProfXMLWin));
     new_win->window.type = WIN_XML;
     new_win->window.layout = _win_create_simple_layout();
-    new_win->window.unread = 0;
 
     new_win->memcheck = PROFXMLWIN_MEMCHECK;
 
@@ -957,6 +954,26 @@ win_has_modified_form(ProfWin *window)
     }
 }
 
+int
+win_unread(ProfWin *window)
+{
+    if (window->type == WIN_CHAT) {
+        ProfChatWin *chatwin = (ProfChatWin*) window;
+        assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
+        return chatwin->unread;
+    } else if (window->type == WIN_MUC) {
+        ProfMucWin *mucwin = (ProfMucWin*) window;
+        assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+        return mucwin->unread;
+    } else if (window->type == WIN_PRIVATE) {
+        ProfPrivateWin *privatewin = (ProfPrivateWin*) window;
+        assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
+        return privatewin->unread;
+    } else {
+        return 0;
+    }
+}
+
 void
 win_printline_nowrap(WINDOW *win, char *msg)
 {
diff --git a/src/ui/window.h b/src/ui/window.h
index 5acade5e..ce74c973 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -99,7 +99,6 @@ typedef enum {
 typedef struct prof_win_t {
     win_type_t type;
     ProfLayout *layout;
-    int unread;
 } ProfWin;
 
 typedef struct prof_console_win_t {
@@ -109,6 +108,7 @@ typedef struct prof_console_win_t {
 typedef struct prof_chat_win_t {
     ProfWin window;
     char *barejid;
+    int unread;
     gboolean is_otr;
     gboolean is_trusted;
     char *resource;
@@ -119,6 +119,7 @@ typedef struct prof_chat_win_t {
 typedef struct prof_muc_win_t {
     ProfWin window;
     char *roomjid;
+    int unread;
     unsigned long memcheck;
 } ProfMucWin;
 
@@ -132,6 +133,7 @@ typedef struct prof_mucconf_win_t {
 typedef struct prof_private_win_t {
     ProfWin window;
     char *fulljid;
+    int unread;
     unsigned long memcheck;
 } ProfPrivateWin;
 
@@ -173,6 +175,7 @@ int win_roster_cols(void);
 int win_occpuants_cols(void);
 void win_printline_nowrap(WINDOW *win, char *msg);
 
+int win_unread(ProfWin *window);
 gboolean win_has_active_subwin(ProfWin *window);
 gboolean win_has_modified_form(ProfWin *window);
 gboolean win_chat_history_shown(ProfWin *window);
diff --git a/src/ui/windows.c b/src/ui/windows.c
index bbd8a5f7..d7913d4c 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -250,8 +250,21 @@ wins_get_nums(void)
 void
 wins_set_current_by_num(int i)
 {
-    if (g_hash_table_lookup(windows, GINT_TO_POINTER(i)) != NULL) {
+    ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(i));
+    if (window) {
         current = i;
+        if (window->type == WIN_CHAT) {
+            ProfChatWin *chatwin = (ProfChatWin*) window;
+            assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
+            chatwin->unread = 0;
+        } else if (window->type == WIN_MUC) {
+            ProfMucWin *mucwin = (ProfMucWin*) window;
+            assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+            mucwin->unread = 0;
+        } else if (window->type == WIN_PRIVATE) {
+            ProfPrivateWin *privatewin = (ProfPrivateWin*) window;
+            privatewin->unread = 0;
+        }
     }
 }
 
@@ -480,7 +493,7 @@ wins_get_total_unread(void)
 
     while (curr != NULL) {
         ProfWin *window = curr->data;
-        result += window->unread;
+        result += win_unread(window);
         curr = g_list_next(curr);
     }
     g_list_free(values);
@@ -628,7 +641,7 @@ wins_get_prune_wins(void)
 
     while (curr != NULL) {
         ProfWin *window = curr->data;
-        if (window->unread == 0 &&
+        if (win_unread(window) == 0 &&
                 window->type != WIN_MUC &&
                 window->type != WIN_MUC_CONFIG &&
                 window->type != WIN_XML &&
@@ -675,7 +688,7 @@ wins_swap(int source_win, int target_win)
             g_hash_table_steal(windows, GINT_TO_POINTER(source_win));
             status_bar_inactive(source_win);
             g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source);
-            if (source->unread > 0) {
+            if (win_unread(source) > 0) {
                 status_bar_new(target_win);
             } else {
                 status_bar_active(target_win);
@@ -691,12 +704,12 @@ wins_swap(int source_win, int target_win)
             g_hash_table_steal(windows, GINT_TO_POINTER(target_win));
             g_hash_table_insert(windows, GINT_TO_POINTER(source_win), target);
             g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source);
-            if (source->unread > 0) {
+            if (win_unread(source) > 0) {
                 status_bar_new(target_win);
             } else {
                 status_bar_active(target_win);
             }
-            if (target->unread > 0) {
+            if (win_unread(target) > 0) {
                 status_bar_new(source_win);
             } else {
                 status_bar_active(source_win);
@@ -742,14 +755,14 @@ wins_tidy(void)
             ProfWin *window = g_hash_table_lookup(windows, curr->data);
             if (num == 10) {
                 g_hash_table_insert(new_windows, GINT_TO_POINTER(0), window);
-                if (window->unread > 0) {
+                if (win_unread(window) > 0) {
                     status_bar_new(0);
                 } else {
                     status_bar_active(0);
                 }
             } else {
                 g_hash_table_insert(new_windows, GINT_TO_POINTER(num), window);
-                if (window->unread > 0) {
+                if (win_unread(window) > 0) {
                     status_bar_new(num);
                 } else {
                     status_bar_active(num);
@@ -810,9 +823,9 @@ wins_create_summary(void)
                     g_string_free(chat_presence, TRUE);
                 }
 
-                if (window->unread > 0) {
+                if (chatwin->unread > 0) {
                     GString *chat_unread = g_string_new("");
-                    g_string_printf(chat_unread, ", %d unread", window->unread);
+                    g_string_printf(chat_unread, ", %d unread", chatwin->unread);
                     g_string_append(chat_string, chat_unread->str);
                     g_string_free(chat_unread, TRUE);
                 }
@@ -827,9 +840,9 @@ wins_create_summary(void)
                 ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
                 g_string_printf(priv_string, "%d: Private %s", ui_index, privatewin->fulljid);
 
-                if (window->unread > 0) {
+                if (privatewin->unread > 0) {
                     GString *priv_unread = g_string_new("");
-                    g_string_printf(priv_unread, ", %d unread", window->unread);
+                    g_string_printf(priv_unread, ", %d unread", privatewin->unread);
                     g_string_append(priv_string, priv_unread->str);
                     g_string_free(priv_unread, TRUE);
                 }
@@ -844,9 +857,9 @@ wins_create_summary(void)
                 ProfMucWin *mucwin = (ProfMucWin*)window;
                 g_string_printf(muc_string, "%d: Room %s", ui_index, mucwin->roomjid);
 
-                if (window->unread > 0) {
+                if (mucwin->unread > 0) {
                     GString *muc_unread = g_string_new("");
-                    g_string_printf(muc_unread, ", %d unread", window->unread);
+                    g_string_printf(muc_unread, ", %d unread", mucwin->unread);
                     g_string_append(muc_string, muc_unread->str);
                     g_string_free(muc_unread, TRUE);
                 }