about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/command.c44
-rw-r--r--src/config/preferences.c282
-rw-r--r--src/config/preferences.h16
3 files changed, 117 insertions, 225 deletions
diff --git a/src/command/command.c b/src/command/command.c
index a95d064a..24c1b8fa 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -71,8 +71,7 @@ static struct cmd_t * _cmd_get_command(const char * const command);
 static void _update_presence(const jabber_presence_t presence,
     const char * const show, gchar **args);
 static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
-    const char * const display,
-    void (*set_func)(gboolean));
+    const char * const display, preference_t pref);
 
 static void _cmd_complete_parameters(char *input, int *size);
 static void _notify_autocomplete(char *input, int *size);
@@ -2006,14 +2005,14 @@ _cmd_close(gchar **args, struct cmd_help_t help)
 static gboolean
 _cmd_set_beep(gchar **args, struct cmd_help_t help)
 {
-    return _cmd_set_boolean_preference(args[0], help, "Sound", prefs_set_beep);
+    return _cmd_set_boolean_preference(args[0], help, "Sound", PREF_BEEP);
 }
 
 static gboolean
 _cmd_set_states(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help, "Sending chat states",
-        prefs_set_states);
+        PREF_STATES);
 }
 
 static gboolean
@@ -2024,7 +2023,7 @@ _cmd_set_titlebar(gchar **args, struct cmd_help_t help)
         return TRUE;
     } else {
         return _cmd_set_boolean_preference(args[1], help,
-        "Show version in window title", prefs_set_titlebarversion);
+        "Show version in window title", PREF_TITLEBARVERSION);
     }
 }
 
@@ -2032,7 +2031,7 @@ static gboolean
 _cmd_set_outtype(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,
-        "Sending typing notifications", prefs_set_outtype);
+        "Sending typing notifications", PREF_OUTTYPE);
 }
 
 static gboolean
@@ -2069,10 +2068,10 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help)
     } else if (strcmp(kind, "message") == 0) {
         if (strcmp(value, "on") == 0) {
             cons_show("Message notifications enabled.");
-            prefs_set_notify_message(TRUE);
+            prefs_set_boolean(PREF_NOTIFY_MESSAGE, TRUE);
         } else if (strcmp(value, "off") == 0) {
             cons_show("Message notifications disabled.");
-            prefs_set_notify_message(FALSE);
+            prefs_set_boolean(PREF_NOTIFY_MESSAGE, FALSE);
         } else {
             cons_show("Usage: /notify message on|off");
         }
@@ -2081,10 +2080,10 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help)
     } else if (strcmp(kind, "typing") == 0) {
         if (strcmp(value, "on") == 0) {
             cons_show("Typing notifications enabled.");
-            prefs_set_notify_typing(TRUE);
+            prefs_set_boolean(PREF_NOTIFY_TYPING, TRUE);
         } else if (strcmp(value, "off") == 0) {
             cons_show("Typing notifications disabled.");
-            prefs_set_notify_typing(FALSE);
+            prefs_set_boolean(PREF_NOTIFY_TYPING, FALSE);
         } else {
             cons_show("Usage: /notify typing on|off");
         }
@@ -2218,7 +2217,7 @@ _cmd_set_autoaway(gchar **args, struct cmd_help_t help)
 
     if (strcmp(setting, "check") == 0) {
         return _cmd_set_boolean_preference(value, help, "Online check",
-            prefs_set_autoaway_check);
+            PREF_AUTOAWAY_CHECK);
     }
 
     return TRUE;
@@ -2252,7 +2251,7 @@ static gboolean
 _cmd_set_statuses(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,
-        "Status notifications", prefs_set_statuses);
+        "Status notifications", PREF_STATUSES);
 }
 
 static gboolean
@@ -2265,7 +2264,7 @@ _cmd_vercheck(gchar **args, struct cmd_help_t help)
         return TRUE;
     } else {
         return _cmd_set_boolean_preference(args[0], help,
-            "Version checking", prefs_set_vercheck);
+            "Version checking", PREF_VERCHECK);
     }
 }
 
@@ -2273,42 +2272,42 @@ static gboolean
 _cmd_set_flash(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,
-        "Screen flash", prefs_set_flash);
+        "Screen flash", PREF_FLASH);
 }
 
 static gboolean
 _cmd_set_intype(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,
-        "Show contact typing", prefs_set_intype);
+        "Show contact typing", PREF_INTYPE);
 }
 
 static gboolean
 _cmd_set_splash(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,
-        "Splash screen", prefs_set_splash);
+        "Splash screen", PREF_SPLASH);
 }
 
 static gboolean
 _cmd_set_chlog(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,
-        "Chat logging", prefs_set_chlog);
+        "Chat logging", PREF_CHLOG);
 }
 
 static gboolean
 _cmd_set_mouse(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,
-        "Mouse handling", prefs_set_mouse);
+        "Mouse handling", PREF_MOUSE);
 }
 
 static gboolean
 _cmd_set_history(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,
-        "Chat history", prefs_set_history);
+        "Chat history", PREF_HISTORY);
 }
 
 static gboolean
@@ -2379,8 +2378,7 @@ _update_presence(const jabber_presence_t presence,
 
 static gboolean
 _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
-    const char * const display,
-    void (*set_func)(gboolean))
+    const char * const display, preference_t pref)
 {
     GString *enabled = g_string_new(display);
     g_string_append(enabled, " enabled.");
@@ -2390,10 +2388,10 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
 
     if (strcmp(arg, "on") == 0) {
         cons_show(enabled->str);
-        set_func(TRUE);
+        prefs_set_boolean(pref, TRUE);
     } else if (strcmp(arg, "off") == 0) {
         cons_show(disabled->str);
-        set_func(FALSE);
+        prefs_set_boolean(pref, FALSE);
     } else {
         char usage[strlen(help.usage) + 8];
         sprintf(usage, "Usage: %s", help.usage);
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