diff --git a/Makefile b/Makefile index 24e8d2fa..7bc0e963 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ profanity: $(OBJS) $(CC) -o profanity $(OBJS) $(LIBS) log.o: log.h -windows.o: windows.h util.h contact_list.h +windows.o: windows.h util.h contact_list.h preferences.h title_bar.o: windows.h status_bar.o: windows.h util.h input_win.o: windows.h @@ -27,7 +27,7 @@ history.o: history.h prof_history.h contact_list.o: contact_list.h contact.h prof_history.o: prof_history.h contact.o: contact.h -preferences.o: preferences.h windows.h +preferences.o: preferences.h main.o: profanity.h test_contact_list.o: contact_list.h contact.h diff --git a/command.c b/command.c index ea36aa82..d963b1eb 100644 --- a/command.c +++ b/command.c @@ -31,6 +31,7 @@ #include "jabber.h" #include "windows.h" #include "util.h" +#include "preferences.h" static gboolean _handle_command(const char * const command, const char * const inp); @@ -223,10 +224,10 @@ static gboolean _cmd_set_beep(const char * const inp) { if (strcmp(inp, "/beep on") == 0) { cons_show("Sound enabled."); - win_set_beep(TRUE); + prefs_set_beep(TRUE); } else if (strcmp(inp, "/beep off") == 0) { cons_show("Sound disabled."); - win_set_beep(FALSE); + prefs_set_beep(FALSE); } else { cons_show("Usage: /beep "); } @@ -238,10 +239,10 @@ static gboolean _cmd_set_flash(const char * const inp) { if (strcmp(inp, "/flash on") == 0) { cons_show("Screen flash enabled."); - status_bar_set_flash(TRUE); + prefs_set_flash(TRUE); } else if (strcmp(inp, "/flash off") == 0) { cons_show("Screen flash disabled."); - status_bar_set_flash(FALSE); + prefs_set_flash(FALSE); } else { cons_show("Usage: /flash "); } diff --git a/preferences.c b/preferences.c index f200eab3..7b33b390 100644 --- a/preferences.c +++ b/preferences.c @@ -23,25 +23,38 @@ #include #include -#include "windows.h" +static GKeyFile *prefs; void prefs_load(void) { GString *prefs_loc = g_string_new(getenv("HOME")); g_string_append(prefs_loc, "/.profanity"); - GKeyFile *g_prefs = g_key_file_new(); - g_key_file_load_from_file(g_prefs, prefs_loc->str, - G_KEY_FILE_NONE, NULL); - - gboolean beep = g_key_file_get_boolean(g_prefs, "ui", "beep", NULL); - gboolean flash = g_key_file_get_boolean(g_prefs, "ui", "flash", NULL); - - win_set_beep(beep); - status_bar_set_flash(flash); + prefs = g_key_file_new(); + g_key_file_load_from_file(prefs, prefs_loc->str, G_KEY_FILE_NONE, NULL); // g_key_file_set_string(g_prefs, "settings", "somekey2", "someothervalue"); // gsize g_data_len; // char *g_prefs_data = g_key_file_to_data(g_prefs, &g_data_len, NULL); // g_file_set_contents("/home/james/.profanity", g_prefs_data, g_data_len, NULL); } + +gboolean prefs_get_beep(void) +{ + return g_key_file_get_boolean(prefs, "ui", "beep", NULL); +} + +void prefs_set_beep(gboolean value) +{ + g_key_file_set_boolean(prefs, "ui", "beep", value); +} + +gboolean prefs_get_flash(void) +{ + return g_key_file_get_boolean(prefs, "ui", "flash", NULL); +} + +void prefs_set_flash(gboolean value) +{ + g_key_file_set_boolean(prefs, "ui", "flash", value); +} diff --git a/preferences.h b/preferences.h index a1349592..31754b0e 100644 --- a/preferences.h +++ b/preferences.h @@ -23,6 +23,13 @@ #ifndef PREFERENCES_H #define PREFERENCES_H +#include + void prefs_load(void); +gboolean prefs_get_beep(void); +void prefs_set_beep(gboolean value); +gboolean prefs_get_flash(void); +void prefs_set_flash(gboolean value); + #endif diff --git a/profanity.c b/profanity.c index ad914567..5eacb95a 100644 --- a/profanity.c +++ b/profanity.c @@ -64,11 +64,11 @@ void profanity_run(void) void profanity_init(const int disable_tls) { + prefs_load(); log_init(); gui_init(); jabber_init(disable_tls); command_init(); - prefs_load(); atexit(_profanity_shutdown); } diff --git a/status_bar.c b/status_bar.c index 2101f8b0..84d6b306 100644 --- a/status_bar.c +++ b/status_bar.c @@ -24,8 +24,10 @@ #include #include + #include "windows.h" #include "util.h" +#include "preferences.h" static WINDOW *status_bar; static char *message = NULL; @@ -35,9 +37,6 @@ static int is_new[9]; static int dirty; static char curr_time[80]; -// allow flash? -static int do_flash = FALSE; - static void _status_bar_update_time(void); void create_status_bar(void) @@ -161,17 +160,12 @@ void status_bar_new(const int win) wattroff(status_bar, COLOR_PAIR(3)); wattroff(status_bar, A_BLINK); - if (do_flash == TRUE) + if (prefs_get_flash()) flash(); dirty = TRUE; } -void status_bar_set_flash(int val) -{ - do_flash = val; -} - void status_bar_get_password(void) { status_bar_print_message("Enter password:"); diff --git a/windows.c b/windows.c index 6462a790..2bc8a175 100644 --- a/windows.c +++ b/windows.c @@ -29,6 +29,7 @@ #include "windows.h" #include "util.h" #include "contact.h" +#include "preferences.h" #define CONS_WIN_TITLE "_cons" #define PAD_SIZE 200 @@ -49,9 +50,6 @@ static int dirty; // max columns for main windows, never resize below static int max_cols = 0; -// allow beep? -static int do_beep = FALSE; - static void _create_windows(void); static int _find_prof_win_index(const char * const contact); static int _new_prof_win(const char * const contact); @@ -156,11 +154,6 @@ int win_in_chat(void) (strcmp(_wins[_curr_prof_win].from, "") != 0)); } -void win_set_beep(int val) -{ - do_beep = val; -} - char *win_get_recipient(void) { struct prof_win current = _wins[_curr_prof_win]; @@ -192,7 +185,7 @@ void win_show_incomming_msg(const char * const from, const char * const message) _cons_show_incoming_message(short_from, win_index); } - if (do_beep == TRUE) + if (prefs_get_beep()) beep(); } diff --git a/windows.h b/windows.h index d5a951fa..920142d7 100644 --- a/windows.h +++ b/windows.h @@ -67,7 +67,6 @@ void win_contact_online(const char * const from, const char * const show, void win_contact_offline(const char * const from, const char * const show, const char * const status); void win_disconnected(void); -void win_set_beep(int val); // console window actions void cons_help(void); @@ -87,7 +86,6 @@ void status_bar_inactive(const int win); void status_bar_active(const int win); void status_bar_new(const int win); void status_bar_update_time(void); -void status_bar_set_flash(int val); // input window actions void inp_get_char(int *ch, char *input, int *size);