From 20fa96325d9b0618646d5fb94f98d2ffde66a0d8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 19 Nov 2014 23:58:55 +0000 Subject: [PATCH] Added [ui] preferences to themes --- src/command/commands.c | 10 ++++++ src/config/theme.c | 56 ++++++++++++++++++++++++++++++++++ src/ui/core.c | 43 ++++++++++++++++++++++++++ src/ui/ui.h | 2 ++ themes/advanced | 69 ++++++++++++++++++++++++++++++++++++++++++ themes/boothj5 | 26 ++++++++++++++-- themes/minimal | 62 +++++++++++++++++++++++++++++++++++++ themes/mono | 47 ++++++++++++++++++++++++++++ themes/simple | 67 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 380 insertions(+), 2 deletions(-) create mode 100644 themes/advanced create mode 100644 themes/minimal create mode 100644 themes/mono create mode 100644 themes/simple 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); diff --git a/themes/advanced b/themes/advanced new file mode 100644 index 00000000..a3e3313b --- /dev/null +++ b/themes/advanced @@ -0,0 +1,69 @@ +[colours] +bkgnd=default +titlebar=blue +statusbar=blue +titlebar.text=bold_white +titlebar.brackets=white +statusbar.text=bold_white +statusbar.brackets=white +statusbar.active=bold_cyan +statusbar.new=bold_green +main.text=white +main.text.me=cyan +main.text.them=bold_white +input.text=bold_green +main.time=yellow +main.splash=bold_red +online=bold_green +away=bold_cyan +chat=bold_white +dnd=magenta +xa=bold_blue +offline=red +typing=yellow +gone=red +error=red +incoming=bold_yellow +roominfo=yellow +roommention=bold_red +me=blue +them=bold_green +titlebar.unencrypted=bold_red +titlebar.encrypted=bold_white +titlebar.untrusted=bold_yellow +titlebar.trusted=bold_white +titlebar.online=bold_green +titlebar.offline=bold_red +titlebar.away=bold_cyan +titlebar.xa=bold_cyan +titlebar.dnd=bold_red +titlebar.chat=bold_green +otr.started.trusted=green +otr.started.untrusted=yellow +otr.ended=red +otr.trusted=green +otr.untrusted=yellow +roster.header=bold_yellow +occupants.header=bold_yellow + +[ui] +intype=true +beep=false +flash=flase +privileges=true +presence=true +wrap=true +time=minutes +statuses.muc=off +statuses.chat=online +statuses.console=off +occupants=true +occupants.size=15 +roster=true +roster.size=25 +roster.offline=true +roster.resource=true +roster.by=presence +otr.warn=true + + diff --git a/themes/boothj5 b/themes/boothj5 index 61b3cf9c..fc856c0f 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -17,9 +17,9 @@ main.splash=bold_red online=bold_green away=bold_cyan chat=bold_white -dnd=bold_red +dnd=magenta xa=bold_blue -offline=bold_black +offline=red typing=yellow gone=red error=red @@ -45,3 +45,25 @@ otr.trusted=green otr.untrusted=yellow roster.header=bold_yellow occupants.header=bold_yellow + +[ui] +intype=true +beep=false +flash=flase +privileges=true +presence=true +wrap=true +time=minutes +statuses.muc=off +statuses.chat=online +statuses.console=all +occupants=true +occupants.size=15 +roster=true +roster.size=25 +roster.offline=true +roster.resource=true +roster.by=presence +otr.warn=true + + diff --git a/themes/minimal b/themes/minimal new file mode 100644 index 00000000..cabf1887 --- /dev/null +++ b/themes/minimal @@ -0,0 +1,62 @@ +[colours] +bkgnd=default +titlebar=blue +statusbar=blue +titlebar.text=bold_white +titlebar.brackets=white +statusbar.text=bold_white +statusbar.brackets=white +statusbar.active=bold_cyan +statusbar.new=bold_green +main.text=white +main.text.me=cyan +main.text.them=bold_white +input.text=bold_green +main.time=yellow +main.splash=bold_red +online=bold_green +away=bold_cyan +chat=bold_white +dnd=magenta +xa=bold_blue +offline=red +typing=yellow +gone=red +error=red +incoming=bold_yellow +roominfo=yellow +roommention=bold_red +me=blue +them=bold_green +titlebar.unencrypted=bold_red +titlebar.encrypted=bold_white +titlebar.untrusted=bold_yellow +titlebar.trusted=bold_white +titlebar.online=bold_green +titlebar.offline=bold_red +titlebar.away=bold_cyan +titlebar.xa=bold_cyan +titlebar.dnd=bold_red +titlebar.chat=bold_green +otr.started.trusted=green +otr.started.untrusted=yellow +otr.ended=red +otr.trusted=green +otr.untrusted=yellow +roster.header=bold_yellow +occupants.header=bold_yellow + +[ui] +intype=true +beep=false +flash=false +privileges=false +presence=false +wrap=false +time=off +statuses.muc=all +statuses.chat=all +statuses.console=all +occupants=false +roster=false +otr.warn=false diff --git a/themes/mono b/themes/mono new file mode 100644 index 00000000..42beb174 --- /dev/null +++ b/themes/mono @@ -0,0 +1,47 @@ +[colours] +bkgnd=default +titlebar=white +statusbar=white +titlebar.text=black +titlebar.brackets=black +statusbar.text=black +statusbar.brackets=black +statusbar.active=black +statusbar.new=black +main.text=white +main.text.me=white +main.text.them=white +input.text=white +main.time=white +main.splash=white +online=white +away=white +chat=white +dnd=white +xa=white +offline=white +typing=white +gone=white +error=white +incoming=white +roominfo=white +roommention=white +me=white +them=white +titlebar.unencrypted=black +titlebar.encrypted=black +titlebar.untrusted=black +titlebar.trusted=black +titlebar.online=black +titlebar.offline=black +titlebar.away=black +titlebar.xa=black +titlebar.dnd=black +titlebar.chat=black +otr.started.trusted=white +otr.started.untrusted=white +otr.ended=white +otr.trusted=white +otr.untrusted=white +roster.header=white +occupants.header=white diff --git a/themes/simple b/themes/simple new file mode 100644 index 00000000..44c6977b --- /dev/null +++ b/themes/simple @@ -0,0 +1,67 @@ +[colours] +bkgnd=default +titlebar=blue +statusbar=blue +titlebar.text=bold_white +titlebar.brackets=white +statusbar.text=bold_white +statusbar.brackets=white +statusbar.active=bold_cyan +statusbar.new=bold_green +main.text=white +main.text.me=cyan +main.text.them=bold_white +input.text=bold_green +main.time=yellow +main.splash=bold_red +online=bold_green +away=bold_cyan +chat=bold_white +dnd=magenta +xa=bold_blue +offline=red +typing=yellow +gone=red +error=red +incoming=bold_yellow +roominfo=yellow +roommention=bold_red +me=blue +them=bold_green +titlebar.unencrypted=bold_red +titlebar.encrypted=bold_white +titlebar.untrusted=bold_yellow +titlebar.trusted=bold_white +titlebar.online=bold_green +titlebar.offline=bold_red +titlebar.away=bold_cyan +titlebar.xa=bold_cyan +titlebar.dnd=bold_red +titlebar.chat=bold_green +otr.started.trusted=green +otr.started.untrusted=yellow +otr.ended=red +otr.trusted=green +otr.untrusted=yellow +roster.header=bold_yellow +occupants.header=bold_yellow + +[ui] +intype=false +beep=false +flash=false +privileges=false +presence=false +wrap=true +time=minutes +statuses.muc=off +statuses.chat=online +statuses.console=off +occupants=true +occupants.size=15 +roster=true +roster.size=25 +roster.offline=false +roster.resource=false +roster.by=presence +otr.warn=false