about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c10
-rw-r--r--src/config/theme.c56
-rw-r--r--src/ui/core.c43
-rw-r--r--src/ui/ui.h2
4 files changed, 111 insertions, 0 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index ecb3b30c..ad1ef1a9 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -715,6 +715,16 @@ cmd_theme(gchar **args, struct cmd_help_t help)
         } else if (theme_load(args[1])) {
             ui_load_colours();
             prefs_set_string(PREF_THEME, args[1]);
+            if (prefs_get_boolean(PREF_ROSTER)) {
+                ui_show_roster();
+            } else {
+                ui_hide_roster();
+            }
+            if (prefs_get_boolean(PREF_OCCUPANTS)) {
+                ui_show_all_room_rosters();
+            } else {
+                ui_hide_all_room_rosters();
+            }
             ui_redraw();
             cons_show("Loaded theme: %s", args[1]);
         } else {
diff --git a/src/config/theme.c b/src/config/theme.c
index 756ab7d1..714560dd 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -47,6 +47,7 @@
 #include "common.h"
 #include "log.h"
 #include "theme.h"
+#include "preferences.h"
 
 static GString *theme_loc;
 static GKeyFile *theme;
@@ -125,6 +126,7 @@ static struct colours_t {
 static NCURSES_COLOR_T _lookup_colour(const char * const colour);
 static void _set_colour(gchar *val, NCURSES_COLOR_T *pref, NCURSES_COLOR_T def, theme_item_t theme_item);
 static void _load_colours(void);
+static void _load_preferences(void);
 static gchar * _get_themes_dir(void);
 void _theme_list_dir(const gchar * const dir, GSList **result);
 static GString * _theme_find(const char * const theme_name);
@@ -169,6 +171,7 @@ theme_load(const char * const theme_name)
     }
 
     _load_colours();
+    _load_preferences();
     return TRUE;
 }
 
@@ -381,6 +384,59 @@ _load_colours(void)
     _set_colour("occupants.header",         &colour_prefs.occupantsheader,      COLOR_YELLOW,   THEME_OCCUPANTS_HEADER);
 }
 
+static void
+_set_string_preference(char *prefstr, preference_t pref)
+{
+    if (g_key_file_has_key(theme, "ui", prefstr, NULL)) {
+        gchar *val = g_key_file_get_string(theme, "ui", prefstr, NULL);
+        prefs_set_string(pref, val);
+    }
+}
+
+static void
+_set_boolean_preference(char *prefstr, preference_t pref)
+{
+    if (g_key_file_has_key(theme, "ui", prefstr, NULL)) {
+        gboolean val = g_key_file_get_boolean(theme, "ui", prefstr, NULL);
+        prefs_set_boolean(pref, val);
+    }
+}
+
+static void
+_load_preferences(void)
+{
+    _set_boolean_preference("intype", PREF_INTYPE);
+    _set_boolean_preference("beep", PREF_BEEP);
+    _set_boolean_preference("flash", PREF_FLASH);
+    _set_boolean_preference("privileges", PREF_MUC_PRIVILEGES);
+    _set_boolean_preference("presence", PREF_PRESENCE);
+    _set_boolean_preference("wrap", PREF_WRAP);
+
+    _set_string_preference("time", PREF_TIME);
+    _set_string_preference("statuses.muc", PREF_STATUSES_MUC);
+    _set_string_preference("statuses.console", PREF_STATUSES_CONSOLE);
+    _set_string_preference("statuses.chat", PREF_STATUSES_CHAT);
+
+    _set_boolean_preference("occupants", PREF_OCCUPANTS);
+
+    if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) {
+        gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL);
+        prefs_set_occupants_size(occupants_size);
+    }
+
+    _set_boolean_preference("roster", PREF_ROSTER);
+    _set_boolean_preference("roster.offline", PREF_ROSTER_OFFLINE);
+    _set_boolean_preference("roster.resource", PREF_ROSTER_RESOURCE);
+    _set_string_preference("roster.by", PREF_ROSTER_BY);
+
+    if (g_key_file_has_key(theme, "ui", "roster.size", NULL)) {
+        gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL);
+        prefs_set_roster_size(roster_size);
+    }
+
+    _set_boolean_preference("otr.warn", PREF_OTR_WARN);
+}
+
 static gchar *
 _get_themes_dir(void)
 {
diff --git a/src/ui/core.c b/src/ui/core.c
index 1bf4081b..95275e64 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -706,6 +706,46 @@ _ui_redraw_all_room_rosters(void)
     g_list_free(win_nums);
 }
 
+static void
+_ui_hide_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_room_hide_occupants(room);
+        }
+        curr = g_list_next(curr);
+    }
+
+    g_list_free(curr);
+    g_list_free(win_nums);
+}
+
+static void
+_ui_show_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 == NULL) {
+            char *room = window->from;
+            ui_room_show_occupants(room);
+        }
+        curr = g_list_next(curr);
+    }
+
+    g_list_free(curr);
+    g_list_free(win_nums);
+}
+
 static gboolean
 _ui_win_has_unsaved_form(int num)
 {
@@ -3424,4 +3464,7 @@ ui_init_module(void)
     ui_room_occupant_role_and_affiliation_change = _ui_room_occupant_role_and_affiliation_change;
     ui_redraw_all_room_rosters = _ui_redraw_all_room_rosters;
     ui_redraw = _ui_redraw;
+    ui_show_all_room_rosters = _ui_show_all_room_rosters;
+    ui_hide_all_room_rosters = _ui_hide_all_room_rosters;
 }
+
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 7eebac24..265806a7 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -209,6 +209,8 @@ 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);
+void (*ui_show_all_room_rosters)(void);
+void (*ui_hide_all_room_rosters)(void);
 
 // contact status functions
 void (*ui_status_room)(const char * const contact);