about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-01-24 01:30:02 +0000
committerJames Booth <boothj5@gmail.com>2016-01-24 01:30:02 +0000
commit7cacee87817f523a8cb60de27cd0745882fe6eb9 (patch)
treef4bc3ba80bb3df3103d182b659c0ff86b45b313c
parent6d8a3e2020067a9a322b27a311e83a892f79962e (diff)
downloadprofani-tty-7cacee87817f523a8cb60de27cd0745882fe6eb9.tar.gz
Added private chat roster group
-rw-r--r--src/ui/rosterwin.c79
-rw-r--r--src/window_list.c2
2 files changed, 79 insertions, 2 deletions
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 30ebba0b..e6337c0d 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -576,7 +576,7 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin)
 
             win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent);
 
-            if (mucwin->unread > 0) {
+            if (privwin->unread > 0) {
                 wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
             } else {
                 wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
@@ -611,6 +611,77 @@ _compare_rooms_unread(ProfMucWin *a, ProfMucWin *b)
 }
 
 void
+_rosterwin_private_chats(ProfLayoutSplit *layout)
+{
+    GList *privs = wins_get_private_chats(NULL);
+    if (privs || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
+        win_sub_newline_lazy(layout->subwin);
+        wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+        GString *title_str = g_string_new(" ");
+        char ch = prefs_get_roster_header_char();
+        if (ch) {
+            g_string_append_printf(title_str, "%c", ch);
+        }
+        g_string_append(title_str, "Private chats");
+        if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
+            g_string_append_printf(title_str, " (%d)", g_list_length(privs));
+        }
+        gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
+        win_sub_print(layout->subwin, title_str->str, FALSE, wrap, 1);
+        g_string_free(title_str, TRUE);
+        wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+
+        GList *curr = privs;
+        while (curr) {
+            ProfPrivateWin *privwin = curr->data;
+            win_sub_newline_lazy(layout->subwin);
+
+            GString *privmsg = g_string_new(" ");
+            int indent = prefs_get_roster_contact_indent();
+            int current_indent = 0;
+            if (indent > 0) {
+                current_indent += indent;
+                while (indent > 0) {
+                    g_string_append(privmsg, " ");
+                    indent--;
+                }
+            }
+
+            char *unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
+            if ((g_strcmp0(unreadpos, "before") == 0) && privwin->unread > 0) {
+                g_string_append_printf(privmsg, "(%d) ", privwin->unread);
+            }
+
+            g_string_append(privmsg, privwin->fulljid);
+
+            if ((g_strcmp0(unreadpos, "after") == 0) && privwin->unread > 0) {
+                g_string_append_printf(privmsg, " (%d)", privwin->unread);
+            }
+            prefs_free_string(unreadpos);
+
+            if (privwin->unread > 0) {
+                wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
+            } else {
+                wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
+            }
+
+            win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent);
+
+            if (privwin->unread > 0) {
+                wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
+            } else {
+                wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
+            }
+
+            g_string_free(privmsg, TRUE);
+            curr = g_list_next(curr);
+        }
+
+        g_list_free(privs);
+    }
+}
+
+void
 _rosterwin_rooms(ProfLayoutSplit *layout, gboolean newline)
 {
     GList *rooms = muc_rooms();
@@ -659,6 +730,12 @@ _rosterwin_rooms(ProfLayoutSplit *layout, gboolean newline)
     }
 
     g_list_free(rooms_sorted);
+
+    char *privpref = prefs_get_string(PREF_ROSTER_PRIVATE);
+    if (g_strcmp0(privpref, "group") == 0) {
+        _rosterwin_private_chats(layout);
+    }
+    prefs_free_string(privpref);
 }
 
 void
diff --git a/src/window_list.c b/src/window_list.c
index cd6724ac..efb6e331 100644
--- a/src/window_list.c
+++ b/src/window_list.c
@@ -185,7 +185,7 @@ wins_get_private_chats(const char *const roomjid)
         ProfWin *window = curr->data;
         if (window->type == WIN_PRIVATE) {
             ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
-            if (g_str_has_prefix(privatewin->fulljid, prefix->str)) {
+            if (roomjid == NULL || g_str_has_prefix(privatewin->fulljid, prefix->str)) {
                 result = g_list_append(result, privatewin);
             }
         }