const gchar *key,
const gchar *value)
{
- gchar **children;
- gint i;
-
- enumerate (settings);
+ if (settings)
+ {
+ gchar **children;
+ gint i;
- children = g_settings_list_children (settings);
+ enumerate (settings);
+ children = g_settings_list_children (settings);
+ for (i = 0; children[i]; i++)
+ {
+ GSettings *child;
+ gchar *schema;
- 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);
- child = g_settings_get_child (settings, children[i]);
- g_object_get (child, "schema", &schema, NULL);
+ if (is_schema (schema))
+ enumerate (child);
- if (is_schema (schema))
- enumerate (child);
+ g_object_unref (child);
+ g_free (schema);
+ }
- g_object_unref (child);
- g_free (schema);
+ g_strfreev (children);
}
+ else
+ {
+ const gchar * const *schemas;
+ gint i;
- g_strfreev (children);
+ schemas = g_settings_list_schemas ();
+
+ for (i = 0; schemas[i]; i++)
+ {
+ settings = g_settings_new (schemas[i]);
+ enumerate (settings);
+ g_object_unref (settings);
+ }
+ }
}
static void
}
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_apply (settings);
+ g_settings_sync ();
+}
+
+static void
gsettings_writable (GSettings *settings,
const gchar *key,
const gchar *value)
new = g_variant_parse (type, value, NULL, NULL, &error);
- /* A common error is to specify a string with single quotes
- * (or use completion for that), and forget that the shell
- * will eat one level of quoting, resulting in 'unknown keyword'
- * error from the gvariant parser.
- * To handle this case, try to parse again with an extra level
- * of quotes.
+ /* If that didn't work and the type is string then we should assume
+ * that the user is just trying to set a string directly and forgot
+ * the quotes (or had them consumed by the shell).
+ *
+ * If the user started with a quote then we assume that some deeper
+ * problem is at play and we want the failure in that case.
+ *
+ * Consider:
+ *
+ * gsettings set x.y.z key "'i don't expect this to work'"
+ *
+ * Note that we should not just add quotes and try parsing again, but
+ * rather assume that the user is providing us with a bare string.
+ * Assume we added single quotes, then consider this case:
+ *
+ * gsettings set x.y.z key "i'd expect this to work"
+ *
+ * A similar example could be given for double quotes.
+ *
+ * Avoid that whole mess by just using g_variant_new_string().
*/
if (new == NULL &&
- g_error_matches (error, G_VARIANT_PARSE_ERROR,
- G_VARIANT_PARSE_ERROR_UNKNOWN_KEYWORD))
+ g_variant_type_equal (type, G_VARIANT_TYPE_STRING) &&
+ value[0] != '\'' && value[0] != '"')
{
- value = freeme = g_strdup_printf ("\"%s\"", value);
- new = g_variant_parse (type, value, NULL, NULL, NULL);
- if (new != NULL)
- g_clear_error (&error);
+ g_clear_error (&error);
+ new = g_variant_new_string (value);
}
if (new == NULL)
else if (strcmp (command, "list-recursively") == 0)
{
- description = _("List keys and values, recursively");
- synopsis = N_("SCHEMA[:PATH]");
+ description = _("List keys and values, recursively\n"
+ "If no SCHEMA is given, list all keys\n");
+ synopsis = N_("[SCHEMA[:PATH]]");
}
else if (strcmp (command, "get") == 0)
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");
" 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"
GSettings *settings;
const gchar *key;
+#ifdef G_OS_WIN32
+ extern gchar *_glib_get_locale_dir (void);
+ gchar *tmp;
+#endif
+
setlocale (LC_ALL, "");
textdomain (GETTEXT_PACKAGE);
#ifdef G_OS_WIN32
- gchar *tmp = _glib_get_locale_dir ();
+ tmp = _glib_get_locale_dir ();
bindtextdomain (GETTEXT_PACKAGE, tmp);
g_free (tmp);
#else
else if (argc == 3 && strcmp (argv[1], "list-children") == 0)
function = gsettings_list_children;
- else if (argc == 3 && strcmp (argv[1], "list-recursively") == 0)
+ else if ((argc == 2 || argc == 3) && strcmp (argv[1], "list-recursively") == 0)
function = gsettings_list_recursively;
else if (argc == 4 && strcmp (argv[1], "range") == 0)
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;