[Xfce4-commits] [apps/mousepad] 32/45: Refactor GSettings path/schema code into separate class

noreply at xfce.org noreply at xfce.org
Fri Jul 11 13:03:37 CEST 2014


This is an automated email from the git hooks/post-receive script.

mbrush pushed a commit to branch master
in repository apps/mousepad.

commit 431baa2598ae6b833833159c636bc913a254bc48
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Wed Jul 9 21:54:50 2014 -0700

    Refactor GSettings path/schema code into separate class
    
    It looks through the main GSettings to find all the keys and recurses
    into child schemas to find their keys and it makes up a lookup hash
    table that maps key paths to their key name and GSettings instance.
    
    The new code is no longer hardcoded to specific schemas/paths except
    for the macros that save typing mistakes for the paths.
---
 mousepad/Makefile.am               |    2 +
 mousepad/mousepad-settings-store.c |  279 ++++++++++++++++++++++++++
 mousepad/mousepad-settings-store.h |   38 ++++
 mousepad/mousepad-settings.c       |  382 +++++-------------------------------
 4 files changed, 371 insertions(+), 330 deletions(-)

diff --git a/mousepad/Makefile.am b/mousepad/Makefile.am
index b5e7a7f..fc97c2b 100644
--- a/mousepad/Makefile.am
+++ b/mousepad/Makefile.am
@@ -45,6 +45,8 @@ mousepad_SOURCES = \
 	mousepad-search-bar.h \
 	mousepad-settings.c \
 	mousepad-settings.h \
+	mousepad-settings-store.c \
+	mousepad-settings-store.h \
 	mousepad-statusbar.c \
 	mousepad-statusbar.h \
 	mousepad-view.c \
diff --git a/mousepad/mousepad-settings-store.c b/mousepad/mousepad-settings-store.c
new file mode 100644
index 0000000..16c13ae
--- /dev/null
+++ b/mousepad/mousepad-settings-store.c
@@ -0,0 +1,279 @@
+#include "mousepad-settings-store.h"
+
+
+
+#ifdef MOUSEPAD_SETTINGS_KEYFILE_BACKEND
+/* Needed to use keyfile GSettings backend */
+# define G_SETTINGS_ENABLE_BACKEND
+# include <gio/gsettingsbackend.h>
+#endif
+
+
+
+struct MousepadSettingsStore_
+{
+  GObject     parent;
+  GSettings  *root;
+  GHashTable *keys;
+};
+
+
+
+struct MousepadSettingsStoreClass_
+{
+  GObjectClass parent_class;
+};
+
+
+
+typedef struct
+{
+  const gchar *name;
+  GSettings   *settings;
+}
+MousepadSettingKey;
+
+
+
+static void mousepad_settings_store_finalize (GObject *object);
+
+
+
+G_DEFINE_TYPE (MousepadSettingsStore, mousepad_settings_store, G_TYPE_OBJECT)
+
+
+
+static MousepadSettingKey *
+mousepad_setting_key_new (const gchar *key_name,
+                          GSettings   *settings)
+{
+  MousepadSettingKey *key;
+
+  key = g_slice_new0 (MousepadSettingKey);
+  key->name = g_intern_string (key_name);
+  key->settings = g_object_ref (settings);
+
+  return key;
+}
+
+
+
+static void
+mousepad_setting_key_free (MousepadSettingKey *key)
+{
+  if (G_LIKELY (key != NULL))
+    {
+      g_object_unref (key->settings);
+      g_slice_free (MousepadSettingKey, key);
+    }
+}
+
+
+
+static void
+mousepad_settings_store_update_env (void)
+{
+  const gchar *old_value = g_getenv ("GSETTINGS_SCHEMA_DIR");
+  gchar       *new_value = NULL;
+
+  /* append to path */
+  if (old_value != NULL)
+    {
+      gchar **paths = g_strsplit (old_value, G_SEARCHPATH_SEPARATOR_S, 0);
+      gchar **paths2;
+      gsize   len = g_strv_length (paths);
+
+      paths2 = g_realloc (paths, len + 2);
+      if (paths2 != NULL)
+        {
+          paths = paths2;
+          paths[len++] = g_strdup (MOUSEPAD_GSETTINGS_SCHEMA_DIR);
+          paths[len] = NULL;
+          new_value = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
+        }
+      g_strfreev (paths);
+    }
+
+  /* set new path */
+  if (new_value == NULL)
+    new_value = g_strdup (MOUSEPAD_GSETTINGS_SCHEMA_DIR);
+
+  g_setenv ("GSETTINGS_SCHEMA_DIR", new_value, TRUE);
+  g_free(new_value);
+}
+
+
+
+static void
+mousepad_settings_store_class_init (MousepadSettingsStoreClass *klass)
+{
+  GObjectClass *g_object_class;
+
+  g_object_class = G_OBJECT_CLASS (klass);
+
+  g_object_class->finalize = mousepad_settings_store_finalize;
+
+  mousepad_settings_store_update_env ();
+}
+
+
+
+static void
+mousepad_settings_store_finalize (GObject *object)
+{
+  MousepadSettingsStore *self;
+
+  g_return_if_fail (MOUSEPAD_IS_SETTINGS_STORE (object));
+
+  self = MOUSEPAD_SETTINGS_STORE (object);
+
+  g_hash_table_destroy (self->keys);
+
+  g_object_unref (self->root);
+
+  G_OBJECT_CLASS (mousepad_settings_store_parent_class)->finalize (object);
+}
+
+
+
+static void
+mousepad_settings_store_add_key (MousepadSettingsStore *self,
+                                 const gchar           *path,
+                                 const gchar           *key_name,
+                                 GSettings             *settings)
+{
+  MousepadSettingKey *key;
+
+  key = mousepad_setting_key_new (key_name, settings);
+
+  g_hash_table_insert (self->keys, (gpointer) g_intern_string (path), key);
+}
+
+
+
+static void
+mousepad_settings_store_add_settings(MousepadSettingsStore *self,
+                                     const gchar           *path,
+                                     GSettings             *settings)
+{
+  gchar **keys, **keyp;
+  gchar **children, **childp;
+
+  /* loop through keys in schema and store mapping of their path to GSettings */
+  keys = g_settings_list_keys (settings);
+  for (keyp = keys; keyp && *keyp; keyp++)
+    {
+      const gchar *key_name = *keyp;
+      gchar *key_path       = g_strdup_printf ("%s/%s", path, key_name);
+      mousepad_settings_store_add_key (self, key_path, key_name, settings);
+      g_free (key_path);
+    }
+  g_strfreev (keys);
+
+  /* loop through child schemas and add them too */
+  children = g_settings_list_children (settings);
+  for (childp = children; childp && *childp; childp++)
+    {
+      const gchar *child_name = *childp;
+      GSettings   *child_settings = g_settings_get_child (settings, child_name);
+      gchar       *child_path = g_strdup_printf ("%s/%s", path, child_name);
+      mousepad_settings_store_add_settings (self, child_path, child_settings);
+      g_object_unref (child_settings);
+      g_free (child_path);
+    }
+  g_strfreev (children);
+}
+
+
+
+static void
+mousepad_settings_store_init (MousepadSettingsStore *self)
+{
+#ifdef MOUSEPAD_SETTINGS_KEYFILE_BACKEND
+  GSettingsBackend *backend;
+  gchar            *conf_file;
+  conf_file = g_build_filename (g_get_user_config_dir (),
+                                "Mousepad",
+                                "settings.conf",
+                                NULL);
+  backend = g_keyfile_settings_backend_new (conf_file, "/", NULL);
+  g_free (conf_file);
+  self->root = g_settings_new_with_backend ("org.xfce.mousepad", backend);
+  g_object_unref (backend);
+#else
+  self->root = g_settings_new ("org.xfce.mousepad");
+#endif
+
+  self->keys = g_hash_table_new_full (g_str_hash,
+                                      g_str_equal,
+                                      NULL,
+                                      (GDestroyNotify) mousepad_setting_key_free);
+
+  mousepad_settings_store_add_settings (self, "", self->root);
+}
+
+
+
+MousepadSettingsStore *
+mousepad_settings_store_new (void)
+{
+  return g_object_new (MOUSEPAD_TYPE_SETTINGS_STORE, NULL);
+}
+
+
+
+const gchar *
+mousepad_settings_store_lookup_key_name (MousepadSettingsStore *self,
+                                         const gchar           *path)
+{
+  const gchar *key_name = NULL;
+
+  if (! mousepad_settings_store_lookup (self, path, &key_name, NULL))
+    return NULL;
+
+  return key_name;
+}
+
+
+
+GSettings *
+mousepad_settings_store_lookup_settings (MousepadSettingsStore *self,
+                                         const gchar           *path)
+{
+  GSettings *settings = NULL;
+
+  if (! mousepad_settings_store_lookup (self, path, NULL, &settings))
+    return NULL;
+
+  return settings;
+}
+
+
+
+gboolean
+mousepad_settings_store_lookup (MousepadSettingsStore *self,
+                                const gchar           *path,
+                                const gchar          **key_name,
+                                GSettings            **settings)
+{
+  MousepadSettingKey *key;
+
+  g_return_val_if_fail (MOUSEPAD_IS_SETTINGS_STORE (self), NULL);
+  g_return_val_if_fail (path != NULL, NULL);
+
+  if (key_name == NULL && settings == NULL)
+    return g_hash_table_contains (self->keys, path);
+
+  key = g_hash_table_lookup (self->keys, path);
+
+  if (G_UNLIKELY (key == NULL))
+    return FALSE;
+
+  if (key_name != NULL)
+    *key_name = key->name;
+
+  if (settings != NULL)
+    *settings = key->settings;
+
+  return TRUE;
+}
diff --git a/mousepad/mousepad-settings-store.h b/mousepad/mousepad-settings-store.h
new file mode 100644
index 0000000..451ed77
--- /dev/null
+++ b/mousepad/mousepad-settings-store.h
@@ -0,0 +1,38 @@
+#ifndef MOUSEPAD_SETTINGS_STORE_H_
+#define MOUSEPAD_SETTINGS_STORE_H_ 1
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+
+#define MOUSEPAD_TYPE_SETTINGS_STORE            (mousepad_settings_store_get_type ())
+#define MOUSEPAD_SETTINGS_STORE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOUSEPAD_TYPE_SETTINGS_STORE, MousepadSettingsStore))
+#define MOUSEPAD_SETTINGS_STORE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), MOUSEPAD_TYPE_SETTINGS_STORE, MousepadSettingsStoreClass))
+#define MOUSEPAD_IS_SETTINGS_STORE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOUSEPAD_TYPE_SETTINGS_STORE))
+#define MOUSEPAD_IS_SETTINGS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOUSEPAD_TYPE_SETTINGS_STORE))
+#define MOUSEPAD_SETTINGS_STORE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), MOUSEPAD_TYPE_SETTINGS_STORE, MousepadSettingsStoreClass))
+
+
+typedef struct MousepadSettingsStore_      MousepadSettingsStore;
+typedef struct MousepadSettingsStoreClass_ MousepadSettingsStoreClass;
+
+
+GType                  mousepad_settings_store_get_type        (void);
+
+MousepadSettingsStore *mousepad_settings_store_new             (void);
+
+const gchar           *mousepad_settings_store_lookup_key_name (MousepadSettingsStore *store,
+                                                                const gchar           *path);
+
+GSettings             *mousepad_settings_store_lookup_settings (MousepadSettingsStore *store,
+                                                                const gchar           *path);
+
+gboolean               mousepad_settings_store_lookup          (MousepadSettingsStore *store,
+                                                                const gchar           *path,
+                                                                const gchar          **key_name,
+                                                                GSettings            **settings);
+
+G_END_DECLS
+
+#endif /* MOUSEPAD_SETTINGS_STORE_H_ */
diff --git a/mousepad/mousepad-settings.c b/mousepad/mousepad-settings.c
index f1c462a..38d1034 100644
--- a/mousepad/mousepad-settings.c
+++ b/mousepad/mousepad-settings.c
@@ -1,46 +1,9 @@
 #include <mousepad/mousepad-private.h>
 #include <mousepad/mousepad-settings.h>
+#include <mousepad/mousepad-settings-store.h>
 #include <stdlib.h>
 #include <ctype.h>
 
-#ifdef MOUSEPAD_SETTINGS_KEYFILE_BACKEND
-/* Needed to use keyfile GSettings backend */
-# define G_SETTINGS_ENABLE_BACKEND
-# include <gio/gsettingsbackend.h>
-#endif
-
-
-
-#define MOUSEPAD_SETTINGS_MAX_KEY_LEN 512
-
-
-
-typedef enum
-{
-  MOUSEPAD_SCHEMA_VIEW_SETTINGS,
-  MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
-  MOUSEPAD_SCHEMA_SEARCH_STATE,
-  MOUSEPAD_SCHEMA_WINDOW_STATE,
-  MOUSEPAD_NUM_SCHEMAS
-}
-MousepadSchema;
-
-
-
-static const gchar *
-mousepad_schema_ids[MOUSEPAD_NUM_SCHEMAS] =
-{
-  "org.xfce.mousepad.preferences.view",
-  "org.xfce.mousepad.preferences.window",
-  "org.xfce.mousepad.state.search",
-  "org.xfce.mousepad.state.window"
-};
-
-
-
-static GSettings *mousepad_settings[MOUSEPAD_NUM_SCHEMAS] = { NULL };
-static gint       mousepad_settings_init_count            = 0;
-
 
 
 G_LOCK_DEFINE (settings_lock);
@@ -49,59 +12,31 @@ G_LOCK_DEFINE (settings_lock);
 
 
 
+static MousepadSettingsStore *settings_store = NULL;
+static gint settings_init_count = 0;
+
+
+
 void
 mousepad_settings_finalize (void)
 {
-  gint i;
-
   MOUSEPAD_SETTINGS_LOCK ();
 
   g_settings_sync ();
 
-  mousepad_settings_init_count--;
-  if (mousepad_settings_init_count > 0)
+  settings_init_count--;
+  if (settings_init_count > 0)
     {
       MOUSEPAD_SETTINGS_UNLOCK ();
       return;
     }
-  MOUSEPAD_SETTINGS_UNLOCK ();
-
-  for (i = 0; i < MOUSEPAD_NUM_SCHEMAS; i++)
-    {
-      if (G_IS_SETTINGS (mousepad_settings[i]))
-        {
-          g_object_unref (mousepad_settings[i]);
-          mousepad_settings[i] = NULL;
-        }
-    }
-}
-
 
+  MOUSEPAD_SETTINGS_UNLOCK ();
 
-static void
-mousepad_settings_update_gsettings_schema_dir (void)
-{
-  const gchar *old_value;
-
-  old_value = g_getenv ("GSETTINGS_SCHEMA_DIR");
-  /* Append to existing env. var. if not in there yet */
-  if (old_value != NULL &&
-      strstr (old_value, MOUSEPAD_GSETTINGS_SCHEMA_DIR) != NULL)
+  if (MOUSEPAD_IS_SETTINGS_STORE (settings_store))
     {
-      gchar       *new_value;
-#ifndef G_OS_WIN32
-      const gchar *pathsep = ":";
-#else
-      const gchar *pathsep = ";";
-#endif
-      new_value = g_strconcat (old_value, pathsep, MOUSEPAD_GSETTINGS_SCHEMA_DIR, NULL);
-      g_setenv ("GSETTINGS_SCHEMA_DIR", new_value, TRUE);
-      g_free (new_value);
-    }
-  /* Create a new env. var. */
-  else
-    {
-      g_setenv ("GSETTINGS_SCHEMA_DIR", MOUSEPAD_GSETTINGS_SCHEMA_DIR, FALSE);
+      g_object_unref (settings_store);
+      settings_store = NULL;
     }
 }
 
@@ -113,208 +48,15 @@ mousepad_settings_init (void)
 
   MOUSEPAD_SETTINGS_LOCK ();
 
-  if (mousepad_settings_init_count == 0)
+  if (settings_init_count == 0)
     {
-      gint i;
-
-      /* If we're installed in an unusual location, we still want to load
-       * the schema so enforce this with the relevant environment variable. */
-      mousepad_settings_update_gsettings_schema_dir ();
-
-#ifdef MOUSEPAD_SETTINGS_KEYFILE_BACKEND
-{
-      GSettingsBackend *backend;
-      gchar            *conf_file;
-
-      /* Path inside user's config directory */
-      conf_file = g_build_filename (g_get_user_config_dir (),
-                                    "Mousepad",
-                                    "settings.conf",
-                                    NULL);
-
-      /* Create a keyfile backend */
-      backend = g_keyfile_settings_backend_new (conf_file, "/", NULL);
-      g_free (conf_file);
-
-      for (i = 0; i < MOUSEPAD_NUM_SCHEMAS; i++)
-        {
-          mousepad_settings[i] = g_object_new (G_TYPE_SETTINGS,
-                                               "backend", backend,
-                                               "schema-id", mousepad_schema_ids[i],
-                                               NULL);
-        }
-
-      g_object_unref (backend);
-}
-#else
-      for (i = 0; i < MOUSEPAD_NUM_SCHEMAS; i++)
-        mousepad_settings[i] = g_settings_new (mousepad_schema_ids[i]);
-#endif
+      if (! MOUSEPAD_IS_SETTINGS_STORE (settings_store))
+        settings_store = mousepad_settings_store_new ();
     }
 
-    mousepad_settings_init_count++;
-
-    MOUSEPAD_SETTINGS_UNLOCK ();
-}
-
-
-
-/* checks that string starts and ends with alnum character and contains only
- * alnum, underscore or dash/hyphen characters */
-static gboolean
-mousepad_settings_check_path_part (const gchar *s,
-                                   gint         len)
-{
-  gint i;
-
-  if (! isalnum (s[0]) || ! isalnum (s[len-1]))
-    return FALSE;
-
-  for (i = 0; i < len ; i++)
-    {
-      if (! isalnum (s[i]) && s[i] != '-' && s[i] != '_')
-        return FALSE;
-    }
+  settings_init_count++;
 
-  return TRUE;
-}
-
-
-
-static gboolean
-mousepad_settings_parse_path_names (const gchar  *path,
-                                    const gchar **type,
-                                    gint         *type_length,
-                                    const gchar **schema,
-                                    gint         *schema_length,
-                                    const gchar **key,
-                                    gint         *key_length,
-                                    gboolean      validate_parts)
-{
-  const gchar *t=NULL, *s=NULL, *k=NULL, *p;
-  gint         tl=0, sl=0, kl=0;
-
-  if (G_UNLIKELY (! path || ! path[0]))
-    return FALSE;
-
-  p = path;
-  while (*p)
-    {
-      if (*p == '/' || p == path /* first char but not a slash */)
-        {
-          if (t == NULL)
-            {
-              /* skip leading slash if exists */
-              t = (*p == '/') ? ++p : p++;
-              continue;
-            }
-          else if (s == NULL)
-            {
-              tl = p - t;
-              s = ++p;
-              continue;
-            }
-          else if (k == NULL)
-            {
-              sl = p - s;
-              k = ++p;
-              continue;
-            }
-        }
-      ++p;
-    }
-
-  kl = p - k;
-  /* remove trailing slash if it exists */
-  if (k[kl - 1] == '/')
-    kl--;
-
-  /* sanity checking on what was actually parsed (or not) */
-  if (!t || !s || !k || !tl || !sl || !kl ||
-      (validate_parts &&
-       (! mousepad_settings_check_path_part (t, tl) ||
-        ! mousepad_settings_check_path_part (s, sl) ||
-        ! mousepad_settings_check_path_part (k, kl))))
-    {
-        return FALSE;
-    }
-
-  /* return desired values to caller */
-  if (type)          *type          = t;
-  if (type_length)   *type_length   = tl;
-  if (schema)        *schema        = s;
-  if (schema_length) *schema_length = sl;
-  if (key)           *key           = k;
-  if (key_length)    *key_length    = kl;
-
-  return TRUE;
-}
-
-
-
-static MousepadSchema
-mousepad_settings_schema_from_names (const gchar *type,
-                                     gint         type_len,
-                                     const gchar *name,
-                                     gint         name_len)
-{
-  if (type_len == 11 && strncmp ("preferences", type, type_len) == 0)
-    {
-      if (name_len == 4 && strncmp ("view", name, name_len) == 0)
-        return MOUSEPAD_SCHEMA_VIEW_SETTINGS;
-      else if (name_len == 6 && strncmp ("window", name, name_len) == 0)
-        return MOUSEPAD_SCHEMA_WINDOW_SETTINGS;
-    }
-  else if (type_len == 5 && strncmp ("state", type, type_len) == 0)
-    {
-      if (name_len == 6 && strncmp ("search", name, name_len) == 0)
-        return MOUSEPAD_SCHEMA_SEARCH_STATE;
-      else if (name_len == 6 && strncmp ("window", name, name_len) == 0)
-        return MOUSEPAD_SCHEMA_WINDOW_STATE;
-    }
-  return MOUSEPAD_NUM_SCHEMAS; /* not found */
-}
-
-
-
-static MousepadSchema
-mousepad_settings_parse_path (const gchar  *path,
-                              gchar        *out_key_name, /* out */
-                              gsize        *out_key_len)  /* in/out */
-{
-  const gchar *type_name, *schema_name, *key_name;
-  gint         type_len, schema_len, key_len;
-
-  if (mousepad_settings_parse_path_names (path,
-                                          &type_name,
-                                          &type_len,
-                                          &schema_name,
-                                          &schema_len,
-                                          &key_name,
-                                          &key_len,
-                                          TRUE))
-    {
-      MousepadSchema  schema;
-      gboolean        have_key_len = (out_key_len != NULL);
-      gsize           max_key_len = have_key_len ? MIN (key_len, *out_key_len) : key_len;
-
-      schema = mousepad_settings_schema_from_names (type_name,
-                                                    type_len,
-                                                    schema_name,
-                                                    schema_len);
-
-      /* copy into the caller's string */
-      if (schema != MOUSEPAD_NUM_SCHEMAS && out_key_name != NULL)
-        strncpy (out_key_name, key_name, max_key_len);
-
-      /* tell caller how much was copied */
-      if (have_key_len)
-        *out_key_len = max_key_len;
-
-      return schema;
-    }
-
-  return MOUSEPAD_NUM_SCHEMAS;
+  MOUSEPAD_SETTINGS_UNLOCK ();
 }
 
 
@@ -325,24 +67,20 @@ mousepad_setting_bind (const gchar       *path,
                        const gchar       *prop,
                        GSettingsBindFlags flags)
 {
-  gboolean       result = FALSE;
-  MousepadSchema schema;
-  gchar          key_name[MOUSEPAD_SETTINGS_MAX_KEY_LEN] = {0};
-  gsize          key_len = MOUSEPAD_SETTINGS_MAX_KEY_LEN - 1;
+  gboolean     result = FALSE;
+  const gchar *key_name = NULL;
+  GSettings   *settings = NULL;
 
   g_return_val_if_fail (path != NULL, FALSE);
-  g_return_val_if_fail (object != NULL, FALSE);
+  g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
   g_return_val_if_fail (prop != NULL, FALSE);
 
-
-  schema = mousepad_settings_parse_path (path, key_name, &key_len);
-
-  if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+  if (mousepad_settings_store_lookup (settings_store, path, &key_name, &settings))
     {
       MOUSEPAD_SETTINGS_LOCK ();
-      g_settings_bind (mousepad_settings[schema], key_name, object, prop, flags);
+      g_settings_bind (settings, key_name, object, prop, flags);
       MOUSEPAD_SETTINGS_UNLOCK ();
-      result = TRUE;
+      return TRUE;
     }
 
   return result;
@@ -356,24 +94,21 @@ mousepad_setting_connect (const gchar  *path,
                            gpointer     user_data,
                            GSignalFlags connect_flags)
 {
-  gulong         signal_id = 0;
-  MousepadSchema schema;
-  gchar          key_name[MOUSEPAD_SETTINGS_MAX_KEY_LEN] = {0};
-  gsize          key_len = MOUSEPAD_SETTINGS_MAX_KEY_LEN - 1;
+  gulong       signal_id = 0;
+  const gchar *key_name = NULL;
+  GSettings   *settings = NULL;
 
   g_return_val_if_fail (path != NULL, 0);
   g_return_val_if_fail (callback != NULL, 0);
 
-  schema = mousepad_settings_parse_path (path, key_name, &key_len);
-
-  if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+  if (mousepad_settings_store_lookup (settings_store, path, &key_name, &settings))
     {
       gchar *signal_name;
 
       signal_name = g_strdup_printf ("changed::%s", key_name);
 
       MOUSEPAD_SETTINGS_LOCK ();
-      signal_id = g_signal_connect_data (mousepad_settings[schema],
+      signal_id = g_signal_connect_data (settings,
                                          signal_name,
                                          callback,
                                          user_data,
@@ -393,15 +128,15 @@ void
 mousepad_setting_disconnect (const gchar *path,
                              gulong       handler_id)
 {
-  MousepadSchema schema;
+  GSettings *settings;
 
   g_return_if_fail (path != NULL);
   g_return_if_fail (handler_id > 0);
 
-  schema = mousepad_settings_parse_path (path, NULL, NULL);
+  settings = mousepad_settings_store_lookup_settings (settings_store, path);
 
-  if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
-    g_signal_handler_disconnect (mousepad_settings[schema], handler_id);
+  if (G_IS_SETTINGS (settings))
+    g_signal_handler_disconnect (settings, handler_id);
   else
     g_warn_if_reached ();
 }
@@ -413,24 +148,20 @@ mousepad_setting_get (const gchar *path,
                       const gchar *format_string,
                       ...)
 {
-  gboolean       result = FALSE;
-  MousepadSchema schema;
-  gchar          key_name[MOUSEPAD_SETTINGS_MAX_KEY_LEN] = {0};
-  gsize          key_len = MOUSEPAD_SETTINGS_MAX_KEY_LEN - 1;
+  gboolean     result = FALSE;
+  const gchar *key_name = NULL;
+  GSettings   *settings = NULL;
 
   g_return_val_if_fail (path != NULL, FALSE);
   g_return_val_if_fail (format_string != NULL, FALSE);
 
-  schema = mousepad_settings_parse_path (path, key_name, &key_len);
-
-  if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+  if (mousepad_settings_store_lookup (settings_store, path, &key_name, &settings))
     {
-
       GVariant *variant;
       va_list   ap;
 
       MOUSEPAD_SETTINGS_LOCK ();
-      variant = g_settings_get_value (mousepad_settings[schema], key_name);
+      variant = g_settings_get_value (settings, key_name);
       MOUSEPAD_SETTINGS_UNLOCK ();
 
       g_variant_ref_sink (variant);
@@ -454,17 +185,14 @@ mousepad_setting_set (const gchar *path,
                       const gchar *format_string,
                       ...)
 {
-  gboolean       result = FALSE;
-  MousepadSchema schema;
-  gchar          key_name[MOUSEPAD_SETTINGS_MAX_KEY_LEN] = {0};
-  gsize          key_len = MOUSEPAD_SETTINGS_MAX_KEY_LEN - 1;
+  gboolean     result = FALSE;
+  const gchar *key_name = NULL;
+  GSettings   *settings = NULL;
 
   g_return_val_if_fail (path != NULL, FALSE);
   g_return_val_if_fail (format_string != NULL, FALSE);
 
-  schema = mousepad_settings_parse_path (path, key_name, &key_len);
-
-  if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+  if (mousepad_settings_store_lookup (settings_store, path, &key_name, &settings))
     {
       GVariant *variant;
       va_list   ap;
@@ -476,7 +204,7 @@ mousepad_setting_set (const gchar *path,
       g_variant_ref_sink (variant);
 
       MOUSEPAD_SETTINGS_LOCK ();
-      g_settings_set_value (mousepad_settings[schema], key_name, variant);
+      g_settings_set_value (settings, key_name, variant);
       MOUSEPAD_SETTINGS_UNLOCK ();
 
       g_variant_unref (variant);
@@ -553,19 +281,16 @@ mousepad_setting_set_string (const gchar *path,
 gint
 mousepad_setting_get_enum (const gchar *path)
 {
-  gint           result = 0;
-  MousepadSchema schema;
-  gchar          key_name[MOUSEPAD_SETTINGS_MAX_KEY_LEN] = {0};
-  gsize          key_len = MOUSEPAD_SETTINGS_MAX_KEY_LEN - 1;
+  gint         result = 0;
+  const gchar *key_name = NULL;
+  GSettings   *settings = NULL;
 
   g_return_val_if_fail (path != NULL, FALSE);
 
-  schema = mousepad_settings_parse_path (path, key_name, &key_len);
-
-  if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+  if (mousepad_settings_store_lookup (settings_store, path, &key_name, &settings))
     {
       MOUSEPAD_SETTINGS_LOCK ();
-      result = g_settings_get_enum (mousepad_settings[schema], key_name);
+      result = g_settings_get_enum (settings, key_name);
       MOUSEPAD_SETTINGS_UNLOCK ();
     }
   else
@@ -580,18 +305,15 @@ void
 mousepad_setting_set_enum (const gchar *path,
                            gint         value)
 {
-  MousepadSchema schema;
-  gchar          key_name[MOUSEPAD_SETTINGS_MAX_KEY_LEN] = {0};
-  gsize          key_len = MOUSEPAD_SETTINGS_MAX_KEY_LEN - 1;
+  const gchar *key_name = NULL;
+  GSettings   *settings = NULL;
 
   g_return_val_if_fail (path != NULL, FALSE);
 
-  schema = mousepad_settings_parse_path (path, key_name, &key_len);
-
-  if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+  if (mousepad_settings_store_lookup (settings_store, path, &key_name, &settings))
     {
       MOUSEPAD_SETTINGS_LOCK ();
-      g_settings_set_enum (mousepad_settings[schema], key_name, value);
+      g_settings_set_enum (settings, key_name, value);
       MOUSEPAD_SETTINGS_UNLOCK ();
     }
   else

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list