Load colours from preferences

This commit is contained in:
James Booth
2012-06-18 22:16:57 +01:00
parent 32205af079
commit 028a2da3f6
3 changed files with 94 additions and 11 deletions

View File

@@ -23,6 +23,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ncurses.h>
#include <glib.h> #include <glib.h>
#include "preferences.h" #include "preferences.h"
@@ -34,6 +35,33 @@ static GKeyFile *prefs;
// search logins list // search logins list
static PAutocomplete ac; static PAutocomplete ac;
struct colour_string_t {
char *str;
NCURSES_COLOR_T colour;
};
/*
static struct colour_string_t colours[] = {
{ "bkgnd", -1 },
{ "white", COLOR_WHITE },
{ "green", COLOR_GREEN },
{ "red", COLOR_RED },
{ "yellow", COLOR_YELLOW },
{ "blue", COLOR_BLUE },
{ "cyan", COLOR_CYAN },
};
*/
// colour preferences
static struct colours_t {
NCURSES_COLOR_T bkgnd;
NCURSES_COLOR_T text;
NCURSES_COLOR_T online;
NCURSES_COLOR_T err;
NCURSES_COLOR_T inc;
NCURSES_COLOR_T bar;
NCURSES_COLOR_T bar_text;
} colour_prefs;
static void _load_colours(void);
static void _save_prefs(void); static void _save_prefs(void);
void prefs_load(void) void prefs_load(void)
@@ -54,6 +82,19 @@ void prefs_load(void)
for (i = 0; i < njids; i++) { for (i = 0; i < njids; i++) {
p_autocomplete_add(ac, jids[i]); p_autocomplete_add(ac, jids[i]);
} }
_load_colours();
}
static void _load_colours(void)
{
colour_prefs.bkgnd = -1;
colour_prefs.text = COLOR_WHITE;
colour_prefs.online = COLOR_GREEN;
colour_prefs.err = COLOR_RED;
colour_prefs.inc = COLOR_YELLOW;
colour_prefs.bar = COLOR_BLUE;
colour_prefs.bar_text = COLOR_CYAN;
} }
char * find_login(char *prefix) char * find_login(char *prefix)
@@ -146,3 +187,38 @@ static void _save_prefs(void)
char *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL); char *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
g_file_set_contents(prefs_loc->str, g_prefs_data, g_data_size, NULL); g_file_set_contents(prefs_loc->str, g_prefs_data, g_data_size, NULL);
} }
NCURSES_COLOR_T prefs_get_bkgnd()
{
return colour_prefs.bkgnd;
}
NCURSES_COLOR_T prefs_get_text()
{
return colour_prefs.text;
}
NCURSES_COLOR_T prefs_get_online()
{
return colour_prefs.online;
}
NCURSES_COLOR_T prefs_get_err()
{
return colour_prefs.err;
}
NCURSES_COLOR_T prefs_get_inc()
{
return colour_prefs.inc;
}
NCURSES_COLOR_T prefs_get_bar()
{
return colour_prefs.bar;
}
NCURSES_COLOR_T prefs_get_bar_text()
{
return colour_prefs.bar_text;
}

View File

@@ -38,4 +38,12 @@ void prefs_add_login(const char *jid);
gboolean prefs_get_showsplash(void); gboolean prefs_get_showsplash(void);
void prefs_set_showsplash(gboolean value); void prefs_set_showsplash(gboolean value);
NCURSES_COLOR_T prefs_get_bkgnd();
NCURSES_COLOR_T prefs_get_text();
NCURSES_COLOR_T prefs_get_online();
NCURSES_COLOR_T prefs_get_err();
NCURSES_COLOR_T prefs_get_inc();
NCURSES_COLOR_T prefs_get_bar();
NCURSES_COLOR_T prefs_get_bar_text();
#endif #endif

View File

@@ -78,14 +78,13 @@ void gui_init(void)
use_default_colors(); use_default_colors();
start_color(); start_color();
init_pair(1, COLOR_WHITE, -1); init_pair(1, prefs_get_text(), prefs_get_bkgnd());
init_pair(2, COLOR_GREEN, -1); init_pair(2, prefs_get_online(), prefs_get_bkgnd());
init_pair(3, COLOR_WHITE, COLOR_BLUE); init_pair(3, prefs_get_text(), prefs_get_bar());
init_pair(4, COLOR_CYAN, COLOR_BLUE); init_pair(4, prefs_get_bar_text(), prefs_get_bar());
init_pair(5, COLOR_CYAN, -1); init_pair(5, prefs_get_bar_text(), prefs_get_bkgnd());
init_pair(6, COLOR_RED, -1); init_pair(6, prefs_get_err(), prefs_get_bkgnd());
init_pair(7, COLOR_MAGENTA, -1); init_pair(7, prefs_get_inc(), prefs_get_bkgnd());
init_pair(8, COLOR_YELLOW, -1);
} }
refresh(); refresh();
@@ -564,9 +563,9 @@ static void _show_status_string(WINDOW *win, const char * const from,
static void _cons_show_incoming_message(const char * const short_from, const int win_index) static void _cons_show_incoming_message(const char * const short_from, const int win_index)
{ {
_win_show_time(_cons_win); _win_show_time(_cons_win);
wattron(_cons_win, COLOR_PAIR(8)); wattron(_cons_win, COLOR_PAIR(7));
wprintw(_cons_win, "<< incoming from %s (%d)\n", short_from, win_index + 1); wprintw(_cons_win, "<< incoming from %s (%d)\n", short_from, win_index + 1);
wattroff(_cons_win, COLOR_PAIR(8)); wattroff(_cons_win, COLOR_PAIR(7));
} }
static void _win_handle_switch(const int * const ch) static void _win_handle_switch(const int * const ch)