about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-01-02 01:22:19 +0000
committerJames Booth <boothj5@gmail.com>2016-01-02 01:22:19 +0000
commit22a14e1240ee3fcefd251f8acb08afc926043d58 (patch)
tree3b8b59593bd506c61ee76b20c73a7efd948542b1 /src/ui
parentf27cae68c507c6def2591ec43c130f92f485fbec (diff)
downloadprofani-tty-22a14e1240ee3fcefd251f8acb08afc926043d58.tar.gz
Show rooms in roster panel
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/core.c1
-rw-r--r--src/ui/rosterwin.c70
2 files changed, 71 insertions, 0 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index 83c8ed00..362a1ac8 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -644,6 +644,7 @@ ui_focus_win(ProfWin *window)
 
     if (i == 1) {
         title_bar_console();
+        rosterwin_roster();
     } else {
         title_bar_switch();
     }
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 4dd1178b..e9261073 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -370,6 +370,74 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout, gboolean newline)
 }
 
 void
+_rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin)
+{
+    GString *msg = g_string_new(" ");
+    theme_item_t presence_colour = theme_main_presence_attrs("online");
+    wattron(layout->subwin, theme_attrs(presence_colour));
+    int indent = prefs_get_roster_contact_indent();
+    int current_indent = 0;
+    if (indent > 0) {
+        current_indent += indent;
+        while (indent > 0) {
+            g_string_append(msg, " ");
+            indent--;
+        }
+    }
+    char ch = prefs_get_roster_contact_char();
+    if (ch) {
+        g_string_append_printf(msg, "%c", ch);
+    }
+
+    g_string_append(msg, mucwin->roomjid);
+    if (mucwin->unread > 0) {
+        g_string_append_printf(msg, " (%d)", mucwin->unread);
+    }
+
+    win_sub_newline_lazy(layout->subwin);
+    gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
+    win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
+    g_string_free(msg, TRUE);
+    wattroff(layout->subwin, theme_attrs(presence_colour));
+}
+
+void
+_rosterwin_rooms(ProfLayoutSplit *layout, gboolean newline)
+{
+    GList *rooms = muc_rooms();
+
+    // if this group has contacts, or if we want to show empty groups
+    if (rooms || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
+        if (newline) {
+            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, "rooms");
+        if (prefs_get_boolean(PREF_ROSTER_COUNT)) {
+            g_string_append_printf(title_str, " (%d)", g_list_length(rooms));
+        }
+        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_room = rooms;
+        while (curr_room) {
+            ProfMucWin *mucwin = wins_get_muc(curr_room->data);
+            _rosterwin_room(layout, mucwin);
+            curr_room = g_list_next(curr_room);
+        }
+    }
+
+    g_list_free(rooms);
+}
+
+void
 rosterwin_roster(void)
 {
     ProfWin *console = wins_get_console();
@@ -443,4 +511,6 @@ rosterwin_roster(void)
         g_slist_free(contacts);
     }
     prefs_free_string(by);
+
+    _rosterwin_rooms(layout, TRUE);
 }