Added [ui] preferences to themes

This commit is contained in:
James Booth
2014-11-19 23:58:55 +00:00
parent 1a896d7b53
commit 20fa96325d
9 changed files with 380 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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)
{

View File

@@ -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;
}

View File

@@ -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);