[glib] gsettings: Implement reset-recursively



commit 3fd9f2e8f98d59c614a04be8b4a052027e025a64
Author: Colin Walters <walters verbum org>
Date:   Tue Apr 12 11:00:54 2011 -0400

    gsettings: Implement reset-recursively
    
    Motivation was the ability to:
    $ gsettings reset-recursively org.gnome.gnome-panel
    
    https://bugzilla.gnome.org/show_bug.cgi?id=647579

 gio/gsettings-tool.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/gio/gsettings-tool.c b/gio/gsettings-tool.c
index a5d43a4..bed72f1 100644
--- a/gio/gsettings-tool.c
+++ b/gio/gsettings-tool.c
@@ -358,6 +358,53 @@ gsettings_reset (GSettings   *settings,
 }
 
 static void
+reset_all_keys (GSettings   *settings)
+{
+  gchar **keys;
+  gint i;
+
+  keys = g_settings_list_keys (settings);
+  for (i = 0; keys[i]; i++)
+    {
+      g_settings_reset (settings, keys[i]);
+    }
+
+  g_strfreev (keys);
+}
+
+static void
+gsettings_reset_recursively (GSettings   *settings,
+			     const gchar *key,
+			     const gchar *value)
+{
+  gchar **children;
+  gint i;
+
+  g_settings_delay (settings);
+  
+  reset_all_keys (settings);
+  children = g_settings_list_children (settings);
+  for (i = 0; children[i]; i++)
+    {
+      GSettings *child;
+      gchar *schema;
+      
+      child = g_settings_get_child (settings, children[i]);
+      g_object_get (child, "schema", &schema, NULL);
+      
+      if (is_schema (schema))
+	reset_all_keys (child);
+      
+      g_object_unref (child);
+      g_free (schema);
+    }
+  
+  g_strfreev (children);
+  
+  g_settings_sync ();
+}
+
+static void
 gsettings_writable (GSettings   *settings,
                     const gchar *key,
                     const gchar *value)
@@ -537,6 +584,12 @@ gsettings_help (gboolean     requested,
       synopsis = N_("SCHEMA[:PATH] KEY");
     }
 
+  else if (strcmp (command, "reset-recursively") == 0)
+    {
+      description = _("Reset all keys in SCHEMA to their defaults");
+      synopsis = N_("SCHEMA[:PATH]");
+    }
+
   else if (strcmp (command, "writable") == 0)
     {
       description = _("Check if KEY is writable");
@@ -574,6 +627,7 @@ gsettings_help (gboolean     requested,
         "  get                       Get the value of a key\n"
         "  set                       Set the value of a key\n"
         "  reset                     Reset the value of a key\n"
+        "  reset-recursively         Reset all values in a given schema\n"
         "  writable                  Check if a key is writable\n"
         "  monitor                   Watch for changes\n"
         "\n"
@@ -679,6 +733,9 @@ main (int argc, char **argv)
   else if (argc == 4 && strcmp (argv[1], "reset") == 0)
     function = gsettings_reset;
 
+  else if (argc == 3 && strcmp (argv[1], "reset-recursively") == 0)
+    function = gsettings_reset_recursively;
+
   else if (argc == 4 && strcmp (argv[1], "writable") == 0)
     function = gsettings_writable;
 



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