[glib] Cleanup the GSettingsBackend API



commit d5bd531d96a48ba2dac84e0ac7bffa4cf5481738
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jul 22 18:39:50 2010 -0400

    Cleanup the GSettingsBackend API
    
    This is a substantial ABI break.  Rebuild dconf.

 gio/gdelayedsettingsbackend.c  |   15 +-----
 gio/gkeyfilesettingsbackend.c  |   18 +------
 gio/gmemorysettingsbackend.c   |    4 +-
 gio/gnullsettingsbackend.c     |   12 +----
 gio/gsettings-tool.c           |  102 +++++++++++++++++++++++++++++++++++++++-
 gio/gsettingsbackend.c         |   22 +--------
 gio/gsettingsbackend.h         |   19 +++-----
 gio/gsettingsbackendinternal.h |    2 +-
 gio/tests/gsettings.c          |    5 ++
 9 files changed, 125 insertions(+), 74 deletions(-)
---
diff --git a/gio/gdelayedsettingsbackend.c b/gio/gdelayedsettingsbackend.c
index fd166a1..8af7c0e 100644
--- a/gio/gdelayedsettingsbackend.c
+++ b/gio/gdelayedsettingsbackend.c
@@ -151,7 +151,7 @@ add_to_tree (gpointer key,
 }
 
 static gboolean
-g_delayed_settings_backend_write_keys (GSettingsBackend *backend,
+g_delayed_settings_backend_write_tree (GSettingsBackend *backend,
                                        GTree            *tree,
                                        gpointer          origin_tag)
 {
@@ -199,14 +199,6 @@ g_delayed_settings_backend_reset (GSettingsBackend *backend,
 }
 
 static void
-g_delayed_settings_backend_reset_path (GSettingsBackend *backend,
-                                       const gchar      *path,
-                                       gpointer          origin_tag)
-{
-  /* deal with this... */
-}
-
-static void
 g_delayed_settings_backend_subscribe (GSettingsBackend *backend,
                                       const char       *name)
 {
@@ -254,7 +246,7 @@ g_delayed_settings_backend_apply (GDelayedSettingsBackend *delayed)
       g_static_mutex_lock (&delayed->priv->lock);
       tmp = delayed->priv->delayed;
       delayed->priv->delayed = g_settings_backend_create_tree ();
-      success = g_settings_backend_write_keys (delayed->priv->backend,
+      success = g_settings_backend_write_tree (delayed->priv->backend,
                                                tmp, delayed->priv);
       g_static_mutex_unlock (&delayed->priv->lock);
 
@@ -446,9 +438,8 @@ g_delayed_settings_backend_class_init (GDelayedSettingsBackendClass *class)
 
   backend_class->read = g_delayed_settings_backend_read;
   backend_class->write = g_delayed_settings_backend_write;
-  backend_class->write_keys = g_delayed_settings_backend_write_keys;
+  backend_class->write_tree = g_delayed_settings_backend_write_tree;
   backend_class->reset = g_delayed_settings_backend_reset;
-  backend_class->reset_path = g_delayed_settings_backend_reset_path;
   backend_class->get_writable = g_delayed_settings_backend_get_writable;
   backend_class->subscribe = g_delayed_settings_backend_subscribe;
   backend_class->unsubscribe = g_delayed_settings_backend_unsubscribe;
diff --git a/gio/gkeyfilesettingsbackend.c b/gio/gkeyfilesettingsbackend.c
index 0741e16..f681ba9 100644
--- a/gio/gkeyfilesettingsbackend.c
+++ b/gio/gkeyfilesettingsbackend.c
@@ -293,7 +293,7 @@ g_keyfile_settings_backend_check_one (gpointer key,
 }
 
 static gboolean
-g_keyfile_settings_backend_write_many (GSettingsBackend *backend,
+g_keyfile_settings_backend_write_tree (GSettingsBackend *backend,
                                        GTree            *tree,
                                        gpointer          origin_tag)
 {
@@ -339,19 +339,6 @@ g_keyfile_settings_backend_write (GSettingsBackend *backend,
 }
 
 static void
-g_keyfile_settings_backend_reset_path (GSettingsBackend *backend,
-                                       const gchar      *path,
-                                       gpointer          origin_tag)
-{
-  GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
-
-  if (set_to_keyfile (kfsb, path, NULL))
-    g_keyfile_settings_backend_keyfile_write (kfsb);
-
-  g_settings_backend_path_changed (backend, path, origin_tag);
-}
-
-static void
 g_keyfile_settings_backend_reset (GSettingsBackend *backend,
                                   const gchar      *key,
                                   gpointer          origin_tag)
@@ -545,9 +532,8 @@ g_keyfile_settings_backend_class_init (GKeyfileSettingsBackendClass *class)
 
   class->read = g_keyfile_settings_backend_read;
   class->write = g_keyfile_settings_backend_write;
-  class->write_keys = g_keyfile_settings_backend_write_many;
+  class->write_tree = g_keyfile_settings_backend_write_tree;
   class->reset = g_keyfile_settings_backend_reset;
-  class->reset_path = g_keyfile_settings_backend_reset_path;
   class->get_writable = g_keyfile_settings_backend_get_writable;
   class->get_permission = g_keyfile_settings_backend_get_permission;
   /* No need to implement subscribed/unsubscribe: the only point would be to
diff --git a/gio/gmemorysettingsbackend.c b/gio/gmemorysettingsbackend.c
index a573027..6b60058 100644
--- a/gio/gmemorysettingsbackend.c
+++ b/gio/gmemorysettingsbackend.c
@@ -104,7 +104,7 @@ g_memory_settings_backend_write_one (gpointer key,
 }
 
 static gboolean
-g_memory_settings_backend_write_keys (GSettingsBackend *backend,
+g_memory_settings_backend_write_tree (GSettingsBackend *backend,
                                       GTree            *tree,
                                       gpointer          origin_tag)
 {
@@ -168,7 +168,7 @@ g_memory_settings_backend_class_init (GMemorySettingsBackendClass *class)
 
   backend_class->read = g_memory_settings_backend_read;
   backend_class->write = g_memory_settings_backend_write;
-  backend_class->write_keys = g_memory_settings_backend_write_keys;
+  backend_class->write_tree = g_memory_settings_backend_write_tree;
   backend_class->reset = g_memory_settings_backend_reset;
   backend_class->get_writable = g_memory_settings_backend_get_writable;
   backend_class->get_permission = g_memory_settings_backend_get_permission;
diff --git a/gio/gnullsettingsbackend.c b/gio/gnullsettingsbackend.c
index 961b881..a2bead0 100644
--- a/gio/gnullsettingsbackend.c
+++ b/gio/gnullsettingsbackend.c
@@ -58,7 +58,7 @@ g_null_settings_backend_write (GSettingsBackend *backend,
 }
 
 static gboolean
-g_null_settings_backend_write_keys (GSettingsBackend *backend,
+g_null_settings_backend_write_tree (GSettingsBackend *backend,
                                     GTree            *tree,
                                     gpointer          origin_tag)
 {
@@ -72,13 +72,6 @@ g_null_settings_backend_reset (GSettingsBackend *backend,
 {
 }
 
-static void
-g_null_settings_backend_reset_path (GSettingsBackend *backend,
-                                    const gchar      *path,
-                                    gpointer          origin_tag)
-{
-}
-
 static gboolean
 g_null_settings_backend_get_writable (GSettingsBackend *backend,
                                       const gchar      *name)
@@ -105,9 +98,8 @@ g_null_settings_backend_class_init (GNullSettingsBackendClass *class)
 
   backend_class->read = g_null_settings_backend_read;
   backend_class->write = g_null_settings_backend_write;
-  backend_class->write_keys = g_null_settings_backend_write_keys;
+  backend_class->write_tree = g_null_settings_backend_write_tree;
   backend_class->reset = g_null_settings_backend_reset;
-  backend_class->reset_path = g_null_settings_backend_reset_path;
   backend_class->get_writable = g_null_settings_backend_get_writable;
   backend_class->get_permission = g_null_settings_backend_get_permission;
 }
diff --git a/gio/gsettings-tool.c b/gio/gsettings-tool.c
index fd3e4b5..bd7d404 100644
--- a/gio/gsettings-tool.c
+++ b/gio/gsettings-tool.c
@@ -80,6 +80,7 @@ usage (gint      *argc,
       "  help        Show this information\n"
       "  get         Get the value of a key\n"
       "  set         Set the value of a key\n"
+      "  reset       Reset the value of a key\n"
       "  monitor     Monitor a key for changes\n"
       "  writable    Check if a key is writable\n"
       "\n"
@@ -420,6 +421,102 @@ handle_set (gint      *argc,
   return ret;
 }
 
+
+static gint
+handle_reset (gint      *argc,
+              gchar    **argv[],
+              gboolean   request_completion,
+              gchar     *completion_cur,
+              gchar     *completion_prev)
+{
+  gchar *schema;
+  gchar *path;
+  gchar *key;
+  GSettings *settings;
+  GOptionContext *context;
+  GOptionEntry entries[] = {
+    { "path", 'p', 0, G_OPTION_ARG_STRING, &path, N_("Specify the path for the schema"), N_("PATH") },
+    { NULL }
+  };
+  GError *error;
+  gint ret = 1;
+
+  modify_argv0_for_command (argc, argv, "reset");
+
+  context = g_option_context_new (_("SCHEMA KEY VALUE"));
+  g_option_context_set_help_enabled (context, FALSE);
+  g_option_context_set_summary (context, _("Sets KEY to its default value"));
+  g_option_context_set_description (context,
+    _("Arguments:\n"
+      "  SCHEMA      The id of the schema\n"
+      "  KEY         The name of the key\n"));
+  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+
+  settings = NULL;
+  path = NULL;
+  schema = NULL;
+  key = NULL;
+
+  error = NULL;
+  if (!g_option_context_parse (context, argc, argv, NULL))
+    {
+      if (!request_completion)
+        {
+          gchar *s;
+          s = g_option_context_get_help (context, FALSE, NULL);
+          g_printerr ("%s", s);
+          g_free (s);
+          goto out;
+        }
+    }
+
+  if (*argc > 1)
+    schema = (*argv)[1];
+  if (*argc > 2)
+    key = (*argv)[2];
+
+  if (request_completion && completion_cur[0] == '-')
+    {
+      list_options (context, completion_cur);
+      ret = 0;
+      goto out;
+    }
+
+  if (request_completion && !schema_exists (schema))
+    {
+      list_schemas (schema);
+      ret = 0;
+      goto out;
+    }
+
+  if (path)
+    settings = g_settings_new_with_path (schema, path);
+  else
+    settings = g_settings_new (schema);
+
+  if (request_completion && !key_exists (settings, key))
+    {
+      list_keys (settings, key);
+      ret = 0;
+      goto out;
+    }
+
+  if (!request_completion)
+    {
+      g_settings_reset (settings, key);
+      g_settings_sync ();
+      ret = 0;
+    }
+
+ out:
+  if (settings)
+    g_object_unref (settings);
+
+  g_option_context_free (context);
+
+  return ret;
+}
+
 static gint
 handle_writable (gint   *argc,
                  gchar **argv[],
@@ -635,6 +732,7 @@ handle_monitor (gint      *argc,
 
   return ret;
 }
+
 int
 main (int argc, char *argv[])
 {
@@ -671,6 +769,8 @@ main (int argc, char *argv[])
     ret = handle_get (&argc, &argv, request_completion, completion_cur, completion_prev);
   else if (g_strcmp0 (command, "set") == 0)
     ret = handle_set (&argc, &argv, request_completion, completion_cur, completion_prev);
+  else if (g_strcmp0 (command, "reset") == 0)
+    ret = handle_reset (&argc, &argv, request_completion, completion_cur, completion_prev);
   else if (g_strcmp0 (command, "monitor") == 0)
     ret = handle_monitor (&argc, &argv, request_completion, completion_cur, completion_prev);
   else if (g_strcmp0 (command, "writable") == 0)
@@ -725,7 +825,7 @@ main (int argc, char *argv[])
     {
       if (request_completion)
         {
-          g_print ("help \nget \nmonitor \nwritable \nset \n");
+          g_print ("help \nget \nmonitor \nwritable \nset \nreset \n");
           ret = 0;
         }
       else
diff --git a/gio/gsettingsbackend.c b/gio/gsettingsbackend.c
index 0e4c2ab..b1e6cff 100644
--- a/gio/gsettingsbackend.c
+++ b/gio/gsettingsbackend.c
@@ -827,12 +827,12 @@ g_settings_backend_write (GSettingsBackend *backend,
  * old values.
  */
 gboolean
-g_settings_backend_write_keys (GSettingsBackend *backend,
+g_settings_backend_write_tree (GSettingsBackend *backend,
                                GTree            *tree,
                                gpointer          origin_tag)
 {
   return G_SETTINGS_BACKEND_GET_CLASS (backend)
-    ->write_keys (backend, tree, origin_tag);
+    ->write_tree (backend, tree, origin_tag);
 }
 
 /*< private >
@@ -855,24 +855,6 @@ g_settings_backend_reset (GSettingsBackend *backend,
 }
 
 /*< private >
- * g_settings_backend_reset_path:
- * @backend: a #GSettingsBackend implementation
- * @name: the name of a key or path
- * @origin_tag: the origin tag
- *
- * "Resets" the named path.  This means that every key under the path is
- * reset.
- */
-void
-g_settings_backend_reset_path (GSettingsBackend *backend,
-                               const gchar      *path,
-                               gpointer          origin_tag)
-{
-  G_SETTINGS_BACKEND_GET_CLASS (backend)
-    ->reset_path (backend, path, origin_tag);
-}
-
-/*< private >
  * g_settings_backend_get_writable:
  * @backend: a #GSettingsBackend implementation
  * @key: the name of a key
diff --git a/gio/gsettingsbackend.h b/gio/gsettingsbackend.h
index da2690c..3705ee5 100644
--- a/gio/gsettingsbackend.h
+++ b/gio/gsettingsbackend.h
@@ -69,26 +69,21 @@ struct _GSettingsBackendClass
                                      const gchar         *key,
                                      const GVariantType  *expected_type,
                                      gboolean             default_value);
-  gchar **      (*list)             (GSettingsBackend    *backend,
-                                     const gchar         *path,
-                                     gchar              **resets,
-                                     gsize                n_resets,
-                                     gsize               *length);
+
+  gboolean      (*get_writable)     (GSettingsBackend    *backend,
+                                     const gchar         *key);
+
   gboolean      (*write)            (GSettingsBackend    *backend,
                                      const gchar         *key,
                                      GVariant            *value,
                                      gpointer             origin_tag);
-  gboolean      (*write_keys)       (GSettingsBackend    *backend,
+  gboolean      (*write_tree)       (GSettingsBackend    *backend,
                                      GTree               *tree,
                                      gpointer             origin_tag);
   void          (*reset)            (GSettingsBackend    *backend,
                                      const gchar         *key,
                                      gpointer             origin_tag);
-  void          (*reset_path)       (GSettingsBackend    *backend,
-                                     const gchar         *path,
-                                     gpointer             origin_tag);
-  gboolean      (*get_writable)     (GSettingsBackend    *backend,
-                                     const gchar         *key);
+
   void          (*subscribe)        (GSettingsBackend    *backend,
                                      const gchar         *name);
   void          (*unsubscribe)      (GSettingsBackend    *backend,
@@ -98,7 +93,7 @@ struct _GSettingsBackendClass
   GPermission * (*get_permission)   (GSettingsBackend    *backend,
                                      const gchar         *path);
 
-  gpointer padding[7];
+  gpointer padding[24];
 };
 
 struct _GSettingsBackend
diff --git a/gio/gsettingsbackendinternal.h b/gio/gsettingsbackendinternal.h
index 42338ce..aa8ac0c 100644
--- a/gio/gsettingsbackendinternal.h
+++ b/gio/gsettingsbackendinternal.h
@@ -72,7 +72,7 @@ gboolean                g_settings_backend_write                        (GSettin
                                                                          GVariant                             *value,
                                                                          gpointer                              origin_tag);
 G_GNUC_INTERNAL
-gboolean                g_settings_backend_write_keys                   (GSettingsBackend                     *backend,
+gboolean                g_settings_backend_write_tree                   (GSettingsBackend                     *backend,
                                                                          GTree                                *tree,
                                                                          gpointer                              origin_tag);
 G_GNUC_INTERNAL
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index 85dd30f..02319b9 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -55,6 +55,11 @@ test_basic (void)
   g_free (str);
   str = NULL;
 
+  g_settings_reset (settings, "greeting");
+  str = g_settings_get_string (settings, "greeting");
+  g_assert_cmpstr (str, ==, "Hello, earthlings");
+  g_free (str);
+
   g_settings_set (settings, "greeting", "s", "this is the end");
   g_object_unref (settings);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]