about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-10-07 16:37:14 +0100
committerJames Booth <boothj5@gmail.com>2014-10-07 16:37:14 +0100
commit0c24b53bfac7687f9fd2dc4e03768cd52cf0ac76 (patch)
tree7e452fd38f41e62b50b694ccf650c75b1f510e8c /src
parent0e18b10b8ec1ffed606ca222b642dcc935efc43d (diff)
downloadprofani-tty-0c24b53bfac7687f9fd2dc4e03768cd52cf0ac76.tar.gz
Added room occupants panel
Diffstat (limited to 'src')
-rw-r--r--src/server_events.c7
-rw-r--r--src/ui/core.c67
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/window.c26
-rw-r--r--src/ui/window.h1
5 files changed, 100 insertions, 3 deletions
diff --git a/src/server_events.c b/src/server_events.c
index 8ae1cdfa..7dbf30af 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -591,6 +591,7 @@ handle_room_occupant_offline(const char * const room, const char * const nick,
         ui_room_member_offline(room, nick);
     }
     prefs_free_string(muc_status_pref);
+    ui_muc_roster(room);
 }
 
 void
@@ -599,6 +600,7 @@ handle_room_occupent_kicked(const char * const room, const char * const nick, co
 {
     muc_roster_remove(room, nick);
     ui_room_member_kicked(room, nick, actor, reason);
+    ui_muc_roster(room);
 }
 
 void
@@ -607,6 +609,7 @@ handle_room_occupent_banned(const char * const room, const char * const nick, co
 {
     muc_roster_remove(room, nick);
     ui_room_member_banned(room, nick, actor, reason);
+    ui_muc_roster(room);
 }
 
 void
@@ -716,6 +719,8 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea
 
     muc_set_role(room, role);
     muc_set_affiliation(room, affiliation);
+
+    ui_muc_roster(room);
 }
 
 void
@@ -751,4 +756,6 @@ handle_muc_occupant_online(const char * const room, const char * const nick, con
         }
         prefs_free_string(muc_status_pref);
     }
+
+    ui_muc_roster(room);
 }
\ No newline at end of file
diff --git a/src/ui/core.c b/src/ui/core.c
index 5f55b423..6cac05b9 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -2714,6 +2714,72 @@ _ui_show_lines(ProfWin *window, const gchar** lines)
 }
 
 static void
+_ui_muc_roster(const char * const room)
+{
+    ProfWin *window = wins_get_by_recipient(room);
+    if (room) {
+        GList *roster = muc_roster(room);
+        if (roster) {
+            werase(window->subwin);
+
+            wattron(window->subwin, COLOUR_ROOMINFO);
+            wprintw(window->subwin, " -Moderators\n");
+            wattroff(window->subwin, COLOUR_ROOMINFO);
+            GList *roster_curr = roster;
+            while (roster_curr) {
+                Occupant *occupant = roster_curr->data;
+                if (occupant->role == MUC_ROLE_MODERATOR) {
+                    wprintw(window->subwin, "   ");
+                    const char *presence_str = string_from_resource_presence(occupant->presence);
+                    int presence_colour = win_presence_colour(presence_str);
+                    wattron(window->subwin, presence_colour);
+                    wprintw(window->subwin, occupant->nick);
+                    wattroff(window->subwin, presence_colour);
+                    wprintw(window->subwin, "\n");
+                }
+                roster_curr = g_list_next(roster_curr);
+            }
+
+            wattron(window->subwin, COLOUR_ROOMINFO);
+            wprintw(window->subwin, " -Participants\n");
+            wattroff(window->subwin, COLOUR_ROOMINFO);
+            roster_curr = roster;
+            while (roster_curr) {
+                Occupant *occupant = roster_curr->data;
+                if (occupant->role == MUC_ROLE_PARTICIPANT) {
+                    wprintw(window->subwin, "   ");
+                    const char *presence_str = string_from_resource_presence(occupant->presence);
+                    int presence_colour = win_presence_colour(presence_str);
+                    wattron(window->subwin, presence_colour);
+                    wprintw(window->subwin, occupant->nick);
+                    wattroff(window->subwin, presence_colour);
+                    wprintw(window->subwin, "\n");
+                }
+                roster_curr = g_list_next(roster_curr);
+            }
+
+            wattron(window->subwin, COLOUR_ROOMINFO);
+            wprintw(window->subwin, " -Visitors\n");
+            wattroff(window->subwin, COLOUR_ROOMINFO);
+            roster_curr = roster;
+            while (roster_curr) {
+                Occupant *occupant = roster_curr->data;
+                if (occupant->role == MUC_ROLE_VISITOR) {
+                    wprintw(window->subwin, "   ");
+                    const char *presence_str = string_from_resource_presence(occupant->presence);
+                    int presence_colour = win_presence_colour(presence_str);
+                    wattron(window->subwin, presence_colour);
+                    wprintw(window->subwin, occupant->nick);
+                    wattroff(window->subwin, presence_colour);
+                    wprintw(window->subwin, "\n");
+                }
+                roster_curr = g_list_next(roster_curr);
+            }
+        }
+    }
+}
+
+static void
 _win_handle_switch(const wint_t * const ch)
 {
     if (*ch == KEY_F(1)) {
@@ -2980,5 +3046,6 @@ ui_init_module(void)
     ui_handle_room_role_set = _ui_handle_room_role_set;
     ui_handle_room_role_list_error = _ui_handle_room_role_list_error;
     ui_handle_room_role_list = _ui_handle_room_role_list;
+    ui_muc_roster = _ui_muc_roster;
 }
 
diff --git a/src/ui/ui.h b/src/ui/ui.h
index b7bd7fbd..f168b8be 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -235,6 +235,8 @@ void (*ui_open_xmlconsole_win)(void);
 
 gboolean (*ui_win_has_unsaved_form)(int num);
 
+void (*ui_muc_roster)(const char * const room);
+
 // console window actions
 void (*cons_show)(const char * const msg, ...);
 void (*cons_about)(void);
diff --git a/src/ui/window.c b/src/ui/window.c
index b4da5147..da4deb0f 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -58,8 +58,21 @@ win_create(const char * const title, int cols, win_type_t type)
 {
     ProfWin *new_win = malloc(sizeof(struct prof_win_t));
     new_win->from = strdup(title);
-    new_win->win = newpad(PAD_SIZE, cols);
-    wbkgd(new_win->win, COLOUR_TEXT);
+
+    if (type == WIN_MUC) {
+        new_win->win = newpad(PAD_SIZE, (cols/4) * 3);
+        wbkgd(new_win->win, COLOUR_TEXT);
+
+        new_win->subwin = newpad(PAD_SIZE, cols/4);
+        wvline(new_win->subwin, 0, 0);
+        wbkgd(new_win->subwin, COLOUR_TEXT);
+    } else {
+        new_win->win = newpad(PAD_SIZE, (cols));
+        wbkgd(new_win->win, COLOUR_TEXT);
+
+        new_win->subwin = NULL;
+    }
+
     new_win->buffer = buffer_create();
     new_win->y_pos = 0;
     new_win->paged = 0;
@@ -89,7 +102,14 @@ win_update_virtual(ProfWin *window)
 {
     int rows, cols;
     getmaxyx(stdscr, rows, cols);
-    pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, cols-1);
+
+    if (window->type == WIN_MUC) {
+        pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, ((cols/4) * 3) -1);
+        pnoutrefresh(window->subwin, 0, 0, 1, (cols/4) * 3, rows-3, cols-1);
+    } else {
+        pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, cols-1);
+    }
+
 }
 
 void
diff --git a/src/ui/window.h b/src/ui/window.h
index 804ea300..196578d8 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -69,6 +69,7 @@ typedef enum {
 typedef struct prof_win_t {
     char *from;
     WINDOW *win;
+    WINDOW *subwin;
     ProfBuff buffer;
     win_type_t type;
     gboolean is_otr;