summaryrefslogtreecommitdiff
path: root/eel
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2012-09-05 17:26:04 +0200
committerStefano Karapetsas <[email protected]>2012-09-05 17:26:04 +0200
commitd66d6c4b4f07b9a18a81b0ac369a779c74af6e39 (patch)
tree8c2f4eb0b94a298bfdf3c929677e1346d421b59e /eel
parent16be9e9816c2201c049c411572343b0c4c408552 (diff)
downloadcaja-d66d6c4b4f07b9a18a81b0ac369a779c74af6e39.tar.bz2
caja-d66d6c4b4f07b9a18a81b0ac369a779c74af6e39.tar.xz
add some more g_settings auto helpers to eel-glib-extensions
Diffstat (limited to 'eel')
-rw-r--r--eel/eel-glib-extensions.c85
-rw-r--r--eel/eel-glib-extensions.h9
2 files changed, 94 insertions, 0 deletions
diff --git a/eel/eel-glib-extensions.c b/eel/eel-glib-extensions.c
index 1014c2b0..e0aa93cb 100644
--- a/eel/eel-glib-extensions.c
+++ b/eel/eel-glib-extensions.c
@@ -1025,6 +1025,54 @@ eel_get_filename_charset (const gchar **filename_charset)
}
static void
+update_auto_boolean (GSettings *settings,
+ const gchar *key,
+ gpointer user_data)
+{
+ int *storage = user_data;
+
+ *storage = g_settings_get_boolean (settings, key);
+}
+
+void
+eel_g_settings_add_auto_boolean (GSettings *settings,
+ const char *key,
+ gboolean *storage)
+{
+ char *signal;
+
+ *storage = g_settings_get_boolean (settings, key);
+ signal = g_strconcat ("changed::", key, NULL);
+ g_signal_connect (settings, signal,
+ G_CALLBACK(update_auto_boolean),
+ storage);
+}
+
+static void
+update_auto_int (GSettings *settings,
+ const gchar *key,
+ gpointer user_data)
+{
+ int *storage = user_data;
+
+ *storage = g_settings_get_int (settings, key);
+}
+
+void
+eel_g_settings_add_auto_int (GSettings *settings,
+ const char *key,
+ int *storage)
+{
+ char *signal;
+
+ *storage = g_settings_get_int (settings, key);
+ signal = g_strconcat ("changed::", key, NULL);
+ g_signal_connect (settings, signal,
+ G_CALLBACK(update_auto_int),
+ storage);
+}
+
+static void
update_auto_enum (GSettings *settings,
const gchar *key,
gpointer user_data)
@@ -1048,6 +1096,43 @@ eel_g_settings_add_auto_enum (GSettings *settings,
storage);
}
+static void
+update_auto_strv_as_quarks (GSettings *settings,
+ const gchar *key,
+ gpointer user_data)
+{
+ GQuark **storage = user_data;
+ int i = 0;
+ char **value;
+
+ value = g_settings_get_strv (settings, key);
+
+ g_free (*storage);
+ *storage = g_new (GQuark, g_strv_length (value) + 1);
+
+ for (i = 0; value[i] != NULL; ++i) {
+ (*storage)[i] = g_quark_from_string (value[i]);
+ }
+ (*storage)[i] = 0;
+
+ g_strfreev (value);
+}
+
+void
+eel_g_settings_add_auto_strv_as_quarks (GSettings *settings,
+ const char *key,
+ GQuark **storage)
+{
+ char *signal;
+
+ *storage = NULL;
+ update_auto_strv_as_quarks (settings, key, storage);
+ signal = g_strconcat ("changed::", key, NULL);
+ g_signal_connect (settings, signal,
+ G_CALLBACK(update_auto_strv_as_quarks),
+ storage);
+}
+
#if !defined (EEL_OMIT_SELF_CHECK)
static void
diff --git a/eel/eel-glib-extensions.h b/eel/eel-glib-extensions.h
index a71c5b4c..fee8a573 100644
--- a/eel/eel-glib-extensions.h
+++ b/eel/eel-glib-extensions.h
@@ -128,5 +128,14 @@ gboolean eel_get_filename_charset (const gchar **filename_
void eel_g_settings_add_auto_enum (GSettings *settings,
const char *key,
int *storage);
+void eel_g_settings_add_auto_int (GSettings *settings,
+ const char *key,
+ int *storage);
+void eel_g_settings_add_auto_boolean (GSettings *settings,
+ const char *key,
+ gboolean *storage);
+void eel_g_settings_add_auto_strv_as_quarks (GSettings *settings,
+ const char *key,
+ GQuark **storage);
#endif /* EEL_GLIB_EXTENSIONS_H */