about summary refs log tree commit diff stats
path: root/src/config/preferences.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-02-03 02:51:15 +0000
committerJames Booth <boothj5@gmail.com>2013-02-03 02:51:15 +0000
commit7982b8e41334983c222f3e400d62a7d358e908d9 (patch)
treeb07bd2d29a9a5931f37cdd510d9d6e799119022a /src/config/preferences.c
parentca26452af60b15bcecc61c02644e24e1cf352654 (diff)
downloadprofani-tty-7982b8e41334983c222f3e400d62a7d358e908d9.tar.gz
Refactored setting boolean preferences
Diffstat (limited to 'src/config/preferences.c')
-rw-r--r--src/config/preferences.c282
1 files changed, 95 insertions, 187 deletions
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;
+    }
+}
+