Added basic colour preferences loading

This commit is contained in:
James Booth
2012-06-18 23:06:17 +01:00
parent 028a2da3f6
commit e39494dcc9
5 changed files with 64 additions and 7 deletions

View File

@@ -30,7 +30,7 @@ history.o: history.h prof_history.h
contact_list.o: contact_list.h contact.h prof_autocomplete.h contact_list.o: contact_list.h contact.h prof_autocomplete.h
prof_history.o: prof_history.h prof_history.o: prof_history.h
contact.o: contact.h contact.o: contact.h
preferences.o: preferences.h preferences.o: preferences.h log.h
prof_autocomplete.o: prof_autocomplete.h common.h prof_autocomplete.o: prof_autocomplete.h common.h
main.o: profanity.h main.o: profanity.h

View File

@@ -59,6 +59,7 @@ void create_input_window(void)
getmaxyx(stdscr, rows, cols); getmaxyx(stdscr, rows, cols);
inp_win = newwin(1, cols, rows-1, 0); inp_win = newwin(1, cols, rows-1, 0);
wbkgd(inp_win, COLOR_PAIR(1));
keypad(inp_win, TRUE); keypad(inp_win, TRUE);
wattrset(inp_win, A_BOLD); wattrset(inp_win, A_BOLD);
wmove(inp_win, 0, 1); wmove(inp_win, 0, 1);

View File

@@ -26,6 +26,7 @@
#include <ncurses.h> #include <ncurses.h>
#include <glib.h> #include <glib.h>
#include "log.h"
#include "preferences.h" #include "preferences.h"
#include "prof_autocomplete.h" #include "prof_autocomplete.h"
@@ -39,9 +40,10 @@ struct colour_string_t {
char *str; char *str;
NCURSES_COLOR_T colour; NCURSES_COLOR_T colour;
}; };
/*
static int num_colours = 7;
static struct colour_string_t colours[] = { static struct colour_string_t colours[] = {
{ "bkgnd", -1 }, { "default", -1 },
{ "white", COLOR_WHITE }, { "white", COLOR_WHITE },
{ "green", COLOR_GREEN }, { "green", COLOR_GREEN },
{ "red", COLOR_RED }, { "red", COLOR_RED },
@@ -49,7 +51,7 @@ static struct colour_string_t colours[] = {
{ "blue", COLOR_BLUE }, { "blue", COLOR_BLUE },
{ "cyan", COLOR_CYAN }, { "cyan", COLOR_CYAN },
}; };
*/
// colour preferences // colour preferences
static struct colours_t { static struct colours_t {
NCURSES_COLOR_T bkgnd; NCURSES_COLOR_T bkgnd;
@@ -61,6 +63,7 @@ static struct colours_t {
NCURSES_COLOR_T bar_text; NCURSES_COLOR_T bar_text;
} colour_prefs; } colour_prefs;
static NCURSES_COLOR_T _lookup_colour(const char * const colour);
static void _load_colours(void); static void _load_colours(void);
static void _save_prefs(void); static void _save_prefs(void);
@@ -86,10 +89,61 @@ void prefs_load(void)
_load_colours(); _load_colours();
} }
static NCURSES_COLOR_T _lookup_colour(const char * const colour)
{
int i;
for (i = 0; i < num_colours; i++) {
if (strcmp(colours[i].str, colour) == 0) {
return colours[i].colour;
}
}
return -99;
}
/*
static void _set_colour(gchar *val, NCURSES_COLOR_T *pref,
NCURSES_COLOR_T def)
{
if(!val) {
*pref = def;
} else {
NCURSES_COLOR_T col = _lookup_colour(val);
if (col == -99) {
*pref = def;
} else {
*pref = col;
}
}
}
*/
static void _load_colours(void) static void _load_colours(void)
{ {
colour_prefs.bkgnd = -1; gchar *bkgnd_val = g_key_file_get_string(prefs, "colours", "bkgnd", NULL);
colour_prefs.text = COLOR_WHITE;
if(!bkgnd_val) {
colour_prefs.bkgnd = -1;
} else {
NCURSES_COLOR_T col = _lookup_colour(bkgnd_val);
if (col == -99) {
colour_prefs.bkgnd = -1;
} else {
colour_prefs.bkgnd = col;
}
}
gchar *text_val = g_key_file_get_string(prefs, "colours", "text", NULL);
if(!text_val) {
colour_prefs.text = COLOR_WHITE;
} else {
NCURSES_COLOR_T col = _lookup_colour(text_val);
if (col == -99) {
colour_prefs.text = COLOR_WHITE;
} else {
colour_prefs.text = col;
}
}
colour_prefs.online = COLOR_GREEN; colour_prefs.online = COLOR_GREEN;
colour_prefs.err = COLOR_RED; colour_prefs.err = COLOR_RED;
colour_prefs.inc = COLOR_YELLOW; colour_prefs.inc = COLOR_YELLOW;

View File

@@ -65,8 +65,8 @@ void profanity_run(void)
void profanity_init(const int disable_tls) void profanity_init(const int disable_tls)
{ {
prefs_load();
log_init(); log_init();
prefs_load();
gui_init(); gui_init();
jabber_init(disable_tls); jabber_init(disable_tls);
command_init(); command_init();

View File

@@ -387,6 +387,7 @@ static void _create_windows(void)
struct prof_win cons; struct prof_win cons;
strcpy(cons.from, CONS_WIN_TITLE); strcpy(cons.from, CONS_WIN_TITLE);
cons.win = newpad(PAD_SIZE, cols); cons.win = newpad(PAD_SIZE, cols);
wbkgd(cons.win, COLOR_PAIR(1));
cons.y_pos = 0; cons.y_pos = 0;
cons.paged = 0; cons.paged = 0;
scrollok(cons.win, TRUE); scrollok(cons.win, TRUE);
@@ -411,6 +412,7 @@ static void _create_windows(void)
struct prof_win chat; struct prof_win chat;
strcpy(chat.from, ""); strcpy(chat.from, "");
chat.win = newpad(PAD_SIZE, cols); chat.win = newpad(PAD_SIZE, cols);
wbkgd(chat.win, COLOR_PAIR(1));
chat.y_pos = 0; chat.y_pos = 0;
chat.paged = 0; chat.paged = 0;
wattrset(chat.win, A_BOLD); wattrset(chat.win, A_BOLD);