From 7982b8e41334983c222f3e400d62a7d358e908d9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 3 Feb 2013 02:51:15 +0000 Subject: Refactored setting boolean preferences --- src/config/preferences.c | 282 ++++++++++++++++------------------------------- src/config/preferences.h | 16 +-- 2 files changed, 96 insertions(+), 202 deletions(-) (limited to 'src/config') diff --git a/src/config/preferences.c b/src/config/preferences.c index bbedb334..174e825e 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -52,6 +52,9 @@ static Autocomplete boolean_choice_ac; static void _save_prefs(void); static gchar * _get_preferences_file(void); +static const char * _get_group(preference_t pref); +static const char * _get_key(preference_t pref); +static gboolean _get_default_boolean(preference_t pref); void prefs_load(void) @@ -96,93 +99,6 @@ prefs_reset_boolean_choice(void) autocomplete_reset(boolean_choice_ac); } -static const char * -_get_group(preference_t pref) -{ - switch (pref) - { - case PREF_SPLASH: - case PREF_BEEP: - case PREF_THEME: - case PREF_VERCHECK: - case PREF_TITLEBARVERSION: - case PREF_FLASH: - case PREF_INTYPE: - case PREF_HISTORY: - case PREF_MOUSE: - case PREF_STATUSES: - return "ui"; - case PREF_STATES: - case PREF_OUTTYPE: - return "chatstates"; - case PREF_NOTIFY_TYPING: - case PREF_NOTIFY_MESSAGE: - return "notifications"; - case PREF_CHLOG: - return "logging"; - case PREF_AUTOAWAY_CHECK: - return "presence"; - default: - return NULL; - } -} - -static const char * -_get_key(preference_t pref) -{ - switch (pref) - { - case PREF_SPLASH: - return "splash"; - case PREF_BEEP: - return "beep"; - case PREF_THEME: - return "theme"; - case PREF_VERCHECK: - return "vercheck"; - case PREF_TITLEBARVERSION: - return "titlebar.version"; - case PREF_FLASH: - return "flash"; - case PREF_INTYPE: - return "intype"; - case PREF_HISTORY: - return "history"; - case PREF_MOUSE: - return "mouse"; - case PREF_STATUSES: - return "statuses"; - case PREF_STATES: - return "enabled"; - case PREF_OUTTYPE: - return "outtype"; - case PREF_NOTIFY_TYPING: - return "typing"; - case PREF_NOTIFY_MESSAGE: - return "message"; - case PREF_CHLOG: - return "chlog"; - case PREF_AUTOAWAY_CHECK: - return "autoaway.check"; - default: - return NULL; - } -} - -static gboolean -_get_default_boolean(preference_t pref) -{ - switch (pref) - { - case PREF_MOUSE: - case PREF_STATUSES: - case PREF_AUTOAWAY_CHECK: - return TRUE; - default: - return FALSE; - } -} - gboolean prefs_get_boolean(preference_t pref) { @@ -198,9 +114,11 @@ prefs_get_boolean(preference_t pref) } void -prefs_set_beep(gboolean value) +prefs_set_boolean(preference_t pref, gboolean value) { - g_key_file_set_boolean(prefs, PREF_GROUP_UI, "beep", value); + const char *group = _get_group(pref); + const char *key = _get_key(pref); + g_key_file_set_boolean(prefs, group, key, value); _save_prefs(); } @@ -217,20 +135,6 @@ prefs_set_theme(gchar *value) _save_prefs(); } -void -prefs_set_states(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_CHATSTATES, "enabled", value); - _save_prefs(); -} - -void -prefs_set_outtype(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_CHATSTATES, "outtype", value); - _save_prefs(); -} - gint prefs_get_gone(void) { @@ -244,20 +148,6 @@ prefs_set_gone(gint value) _save_prefs(); } -void -prefs_set_notify_typing(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "typing", value); - _save_prefs(); -} - -void -prefs_set_notify_message(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "message", value); - _save_prefs(); -} - gint prefs_get_notify_remind(void) { @@ -327,48 +217,6 @@ prefs_set_autoping(gint value) _save_prefs(); } -void -prefs_set_vercheck(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_UI, "vercheck", value); - _save_prefs(); -} - -void -prefs_set_titlebarversion(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_UI, "titlebar.version", value); - _save_prefs(); -} - -void -prefs_set_flash(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_UI, "flash", value); - _save_prefs(); -} - -void -prefs_set_intype(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_UI, "intype", value); - _save_prefs(); -} - -void -prefs_set_chlog(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_LOGGING, "chlog", value); - _save_prefs(); -} - -void -prefs_set_history(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_UI, "history", value); - _save_prefs(); -} - gchar * prefs_get_autoaway_mode(void) { @@ -423,34 +271,6 @@ prefs_set_autoaway_message(gchar *value) _save_prefs(); } -void -prefs_set_autoaway_check(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_PRESENCE, "autoaway.check", value); - _save_prefs(); -} - -void -prefs_set_splash(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_UI, "splash", value); - _save_prefs(); -} - -void -prefs_set_mouse(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_UI, "mouse", value); - _save_prefs(); -} - -void -prefs_set_statuses(gboolean value) -{ - g_key_file_set_boolean(prefs, PREF_GROUP_UI, "statuses", value); - _save_prefs(); -} - static void _save_prefs(void) { @@ -471,3 +291,91 @@ _get_preferences_file(void) return result; } + +static const char * +_get_group(preference_t pref) +{ + switch (pref) + { + case PREF_SPLASH: + case PREF_BEEP: + case PREF_THEME: + case PREF_VERCHECK: + case PREF_TITLEBARVERSION: + case PREF_FLASH: + case PREF_INTYPE: + case PREF_HISTORY: + case PREF_MOUSE: + case PREF_STATUSES: + return "ui"; + case PREF_STATES: + case PREF_OUTTYPE: + return "chatstates"; + case PREF_NOTIFY_TYPING: + case PREF_NOTIFY_MESSAGE: + return "notifications"; + case PREF_CHLOG: + return "logging"; + case PREF_AUTOAWAY_CHECK: + return "presence"; + default: + return NULL; + } +} + +static const char * +_get_key(preference_t pref) +{ + switch (pref) + { + case PREF_SPLASH: + return "splash"; + case PREF_BEEP: + return "beep"; + case PREF_THEME: + return "theme"; + case PREF_VERCHECK: + return "vercheck"; + case PREF_TITLEBARVERSION: + return "titlebar.version"; + case PREF_FLASH: + return "flash"; + case PREF_INTYPE: + return "intype"; + case PREF_HISTORY: + return "history"; + case PREF_MOUSE: + return "mouse"; + case PREF_STATUSES: + return "statuses"; + case PREF_STATES: + return "enabled"; + case PREF_OUTTYPE: + return "outtype"; + case PREF_NOTIFY_TYPING: + return "typing"; + case PREF_NOTIFY_MESSAGE: + return "message"; + case PREF_CHLOG: + return "chlog"; + case PREF_AUTOAWAY_CHECK: + return "autoaway.check"; + default: + return NULL; + } +} + +static gboolean +_get_default_boolean(preference_t pref) +{ + switch (pref) + { + case PREF_MOUSE: + case PREF_STATUSES: + case PREF_AUTOAWAY_CHECK: + return TRUE; + default: + return FALSE; + } +} + diff --git a/src/config/preferences.h b/src/config/preferences.h index 8a900d57..57b065b2 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -63,25 +63,11 @@ void prefs_reset_login_search(void); char * prefs_autocomplete_boolean_choice(char *prefix); void prefs_reset_boolean_choice(void); -void prefs_set_beep(gboolean value); -void prefs_set_flash(gboolean value); -void prefs_set_chlog(gboolean value); -void prefs_set_history(gboolean value); -void prefs_set_splash(gboolean value); -void prefs_set_vercheck(gboolean value); -void prefs_set_titlebarversion(gboolean value); -void prefs_set_intype(gboolean value); -void prefs_set_states(gboolean value); -void prefs_set_outtype(gboolean value); gint prefs_get_gone(void); void prefs_set_gone(gint value); gchar * prefs_get_theme(void); void prefs_set_theme(gchar *value); -void prefs_set_mouse(gboolean value); -void prefs_set_statuses(gboolean value); -void prefs_set_notify_message(gboolean value); -void prefs_set_notify_typing(gboolean value); void prefs_set_notify_remind(gint period); gint prefs_get_notify_remind(void); void prefs_set_max_log_size(gint value); @@ -99,10 +85,10 @@ gint prefs_get_autoaway_time(void); void prefs_set_autoaway_time(gint value); gchar* prefs_get_autoaway_message(void); void prefs_set_autoaway_message(gchar *value); -void prefs_set_autoaway_check(gboolean value); void prefs_add_login(const char *jid); gboolean prefs_get_boolean(preference_t pref); +void prefs_set_boolean(preference_t pref, gboolean value); #endif -- cgit 1.4.1-2-gfad0