about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-10-18 20:22:34 +0100
committerJames Booth <boothj5@gmail.com>2014-10-18 20:22:34 +0100
commitfc049c9eefd740fdc2a9a271150cbcca5d7b2022 (patch)
tree4a559b577322f819ae626aeea966fd778400dbd2 /src/ui
parent0cc25e1b763cbf396a0bb397183761fc7399b4fe (diff)
downloadprofani-tty-fc049c9eefd740fdc2a9a271150cbcca5d7b2022.tar.gz
Added /privileges command to set UI option for showing roles/affiliations in rooms
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/console.c11
-rw-r--r--src/ui/core.c147
-rw-r--r--src/ui/ui.h2
3 files changed, 108 insertions, 52 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index d12edae8..73aa9710 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -822,6 +822,15 @@ _cons_theme_setting(void)
 }
 
 static void
+_cons_privileges_setting(void)
+{
+    if (prefs_get_boolean(PREF_MUC_PRIVILEGES))
+        cons_show("MUC privileges (/privileges)  : ON");
+    else
+        cons_show("MUC privileges (/privileges)  : OFF");
+}
+
+static void
 _cons_beep_setting(void)
 {
     if (prefs_get_boolean(PREF_BEEP))
@@ -926,6 +935,7 @@ _cons_show_ui_prefs(void)
     cons_mouse_setting();
     cons_statuses_setting();
     cons_occupants_setting();
+    cons_privileges_setting();
     cons_titlebar_setting();
 
     cons_alert();
@@ -1518,6 +1528,7 @@ console_init_module(void)
     cons_show_account_list = _cons_show_account_list;
     cons_show_account = _cons_show_account;
     cons_theme_setting = _cons_theme_setting;
+    cons_privileges_setting = _cons_privileges_setting;
     cons_beep_setting = _cons_beep_setting;
     cons_flash_setting = _cons_flash_setting;
     cons_splash_setting = _cons_splash_setting;
diff --git a/src/ui/core.c b/src/ui/core.c
index 5868f5e6..12cc2055 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -670,6 +670,26 @@ _ui_close_read_wins(void)
     return count;
 }
 
+static void
+_ui_redraw_all_room_rosters(void)
+{
+    GList *win_nums = wins_get_nums();
+    GList *curr = win_nums;
+
+    while (curr != NULL) {
+        int num = GPOINTER_TO_INT(curr->data);
+        ProfWin *window = wins_get_by_num(num);
+        if (window->type == WIN_MUC && window->subwin) {
+            char *room = window->from;
+            ui_muc_roster(room);
+        }
+        curr = g_list_next(curr);
+    }
+
+    g_list_free(curr);
+    g_list_free(win_nums);
+}
+
 static gboolean
 _ui_win_has_unsaved_form(int num)
 {
@@ -1305,14 +1325,16 @@ _ui_room_join(const char * const room, gboolean focus)
     }
 
     char *nick = muc_nick(room);
-    char *role = muc_role_str(room);
-    char *affiliation = muc_affiliation_str(room);
     win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "-> You have joined the room as %s", nick);
-    if (role) {
-        win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", role: %s", role);
-    }
-    if (affiliation) {
-        win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", affiliation: %s", affiliation);
+    if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
+        char *role = muc_role_str(room);
+        char *affiliation = muc_affiliation_str(room);
+        if (role) {
+            win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", role: %s", role);
+        }
+        if (affiliation) {
+            win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ROOMINFO, "", ", affiliation: %s", affiliation);
+        }
     }
     win_save_print(window, '!', NULL, NO_DATE, COLOUR_ROOMINFO, "", "");
 
@@ -1593,11 +1615,13 @@ _ui_room_member_online(const char * const room, const char * const nick, const c
         log_error("Received online presence for room participant %s, but no window open for %s.", nick, room);
     } else {
         win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ONLINE, "", "-> %s has joined the room", nick);
-        if (role) {
-            win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", role: %s", role);
-        }
-        if (affiliation) {
-            win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", affiliation: %s", affiliation);
+        if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
+            if (role) {
+                win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", role: %s", role);
+            }
+            if (affiliation) {
+                win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, COLOUR_ONLINE, "", ", affiliation: %s", affiliation);
+            }
         }
         win_save_print(window, '!', NULL, NO_DATE, COLOUR_ROOMINFO, "", "");
     }
@@ -2763,49 +2787,67 @@ _ui_muc_roster(const char * const 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");
+            if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
+                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);
                 }
-                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");
+                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);
                 }
-                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) {
+                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);
+                }
+            } else {
+                wattron(window->subwin, COLOUR_ROOMINFO);
+                wprintw(window->subwin, " -Occupants\n");
+                wattroff(window->subwin, COLOUR_ROOMINFO);
+                GList *roster_curr = roster;
+                while (roster_curr) {
+                    Occupant *occupant = roster_curr->data;
                     wprintw(window->subwin, "   ");
                     const char *presence_str = string_from_resource_presence(occupant->presence);
                     int presence_colour = win_presence_colour(presence_str);
@@ -2813,8 +2855,8 @@ _ui_muc_roster(const char * const room)
                     wprintw(window->subwin, occupant->nick);
                     wattroff(window->subwin, presence_colour);
                     wprintw(window->subwin, "\n");
+                    roster_curr = g_list_next(roster_curr);
                 }
-                roster_curr = g_list_next(roster_curr);
             }
         }
     }
@@ -3137,5 +3179,6 @@ ui_init_module(void)
     ui_room_occupant_role_change = _ui_room_occupant_role_change;
     ui_room_occupant_affiliation_change = _ui_room_occupant_affiliation_change;
     ui_room_occupant_role_and_affiliation_change = _ui_room_occupant_role_and_affiliation_change;
+    ui_redraw_all_room_rosters = _ui_redraw_all_room_rosters;
 }
 
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 4048b3a5..eb610801 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -209,6 +209,7 @@ void (*ui_show_form_field)(ProfWin *window, DataForm *form, char *tag);
 void (*ui_show_form_help)(ProfWin *window, DataForm *form);
 void (*ui_show_form_field_help)(ProfWin *window, DataForm *form, char *tag);
 void (*ui_show_lines)(ProfWin *window, const gchar** lines);
+void (*ui_redraw_all_room_rosters)(void);
 
 // contact status functions
 void (*ui_status_room)(const char * const contact);
@@ -292,6 +293,7 @@ void (*cons_show_received_subs)(void);
 void (*cons_show_sent_subs)(void);
 void (*cons_alert)(void);
 void (*cons_theme_setting)(void);
+void (*cons_privileges_setting)(void);
 void (*cons_beep_setting)(void);
 void (*cons_flash_setting)(void);
 void (*cons_splash_setting)(void);