mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-13 20:47:46 +02:00
gsettings tool: use schema for listing keys
Use the newly added g_settings_schema_list_keys() API instead of g_settings_list_keys() in order to list keys. Doing this allows the 'list-keys' command to work without creating a GSettings object, which is more efficient. It also means that we don't have to provide a (meaningless and ignored) path when listing keys on relocatable schemas. While we're at it, update the 'range' command not to require creation of a GSettings object, in a similar way. https://bugzilla.gnome.org/show_bug.cgi?id=740308
This commit is contained in:
committed by
Matthias Clasen
parent
82fcfeb3b0
commit
bb8eea6148
@@ -155,7 +155,7 @@ gsettings_list_keys (void)
|
|||||||
{
|
{
|
||||||
gchar **keys;
|
gchar **keys;
|
||||||
|
|
||||||
keys = g_settings_list_keys (global_settings);
|
keys = g_settings_schema_list_keys (global_schema);
|
||||||
output_list (keys);
|
output_list (keys);
|
||||||
g_strfreev (keys);
|
g_strfreev (keys);
|
||||||
}
|
}
|
||||||
@@ -201,12 +201,12 @@ static void
|
|||||||
enumerate (GSettings *settings)
|
enumerate (GSettings *settings)
|
||||||
{
|
{
|
||||||
gchar **keys;
|
gchar **keys;
|
||||||
gchar *schema;
|
GSettingsSchema *schema;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
g_object_get (settings, "schema-id", &schema, NULL);
|
g_object_get (settings, "settings-schema", &schema, NULL);
|
||||||
|
|
||||||
keys = g_settings_list_keys (settings);
|
keys = g_settings_schema_list_keys (schema);
|
||||||
for (i = 0; keys[i]; i++)
|
for (i = 0; keys[i]; i++)
|
||||||
{
|
{
|
||||||
GVariant *value;
|
GVariant *value;
|
||||||
@@ -214,12 +214,12 @@ enumerate (GSettings *settings)
|
|||||||
|
|
||||||
value = g_settings_get_value (settings, keys[i]);
|
value = g_settings_get_value (settings, keys[i]);
|
||||||
printed = g_variant_print (value, TRUE);
|
printed = g_variant_print (value, TRUE);
|
||||||
g_print ("%s %s %s\n", schema, keys[i], printed);
|
g_print ("%s %s %s\n", g_settings_schema_get_id (schema), keys[i], printed);
|
||||||
g_variant_unref (value);
|
g_variant_unref (value);
|
||||||
g_free (printed);
|
g_free (printed);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (schema);
|
g_settings_schema_unref (schema);
|
||||||
g_strfreev (keys);
|
g_strfreev (keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,15 +344,19 @@ gsettings_reset (void)
|
|||||||
static void
|
static void
|
||||||
reset_all_keys (GSettings *settings)
|
reset_all_keys (GSettings *settings)
|
||||||
{
|
{
|
||||||
|
GSettingsSchema *schema;
|
||||||
gchar **keys;
|
gchar **keys;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
keys = g_settings_list_keys (settings);
|
g_object_get (settings, "settings-schema", &schema, NULL);
|
||||||
|
|
||||||
|
keys = g_settings_schema_list_keys (schema);
|
||||||
for (i = 0; keys[i]; i++)
|
for (i = 0; keys[i]; i++)
|
||||||
{
|
{
|
||||||
g_settings_reset (settings, keys[i]);
|
g_settings_reset (settings, keys[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_settings_schema_unref (schema);
|
||||||
g_strfreev (keys);
|
g_strfreev (keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -682,6 +686,7 @@ int
|
|||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
void (* function) (void);
|
void (* function) (void);
|
||||||
|
gboolean need_settings;
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
gchar *tmp;
|
gchar *tmp;
|
||||||
@@ -728,6 +733,8 @@ main (int argc, char **argv)
|
|||||||
argc -= 2;
|
argc -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
need_settings = TRUE;
|
||||||
|
|
||||||
if (strcmp (argv[1], "help") == 0)
|
if (strcmp (argv[1], "help") == 0)
|
||||||
return gsettings_help (TRUE, argv[2]);
|
return gsettings_help (TRUE, argv[2]);
|
||||||
|
|
||||||
@@ -741,7 +748,10 @@ main (int argc, char **argv)
|
|||||||
function = gsettings_list_relocatable_schemas;
|
function = gsettings_list_relocatable_schemas;
|
||||||
|
|
||||||
else if (argc == 3 && strcmp (argv[1], "list-keys") == 0)
|
else if (argc == 3 && strcmp (argv[1], "list-keys") == 0)
|
||||||
|
{
|
||||||
|
need_settings = FALSE;
|
||||||
function = gsettings_list_keys;
|
function = gsettings_list_keys;
|
||||||
|
}
|
||||||
|
|
||||||
else if (argc == 3 && strcmp (argv[1], "list-children") == 0)
|
else if (argc == 3 && strcmp (argv[1], "list-children") == 0)
|
||||||
function = gsettings_list_children;
|
function = gsettings_list_children;
|
||||||
@@ -750,7 +760,10 @@ main (int argc, char **argv)
|
|||||||
function = gsettings_list_recursively;
|
function = gsettings_list_recursively;
|
||||||
|
|
||||||
else if (argc == 4 && strcmp (argv[1], "range") == 0)
|
else if (argc == 4 && strcmp (argv[1], "range") == 0)
|
||||||
|
{
|
||||||
|
need_settings = FALSE;
|
||||||
function = gsettings_range;
|
function = gsettings_range;
|
||||||
|
}
|
||||||
|
|
||||||
else if (argc == 4 && strcmp (argv[1], "get") == 0)
|
else if (argc == 4 && strcmp (argv[1], "get") == 0)
|
||||||
function = gsettings_get;
|
function = gsettings_get;
|
||||||
@@ -786,6 +799,9 @@ main (int argc, char **argv)
|
|||||||
parts = g_strsplit (argv[2], ":", 2);
|
parts = g_strsplit (argv[2], ":", 2);
|
||||||
|
|
||||||
global_schema = g_settings_schema_source_lookup (global_schema_source, parts[0], TRUE);
|
global_schema = g_settings_schema_source_lookup (global_schema_source, parts[0], TRUE);
|
||||||
|
|
||||||
|
if (need_settings)
|
||||||
|
{
|
||||||
if (parts[1])
|
if (parts[1])
|
||||||
{
|
{
|
||||||
if (!check_relocatable_schema (global_schema, parts[0]) || !check_path (parts[1]))
|
if (!check_relocatable_schema (global_schema, parts[0]) || !check_path (parts[1]))
|
||||||
@@ -800,6 +816,29 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
global_settings = g_settings_new_full (global_schema, NULL, NULL);
|
global_settings = g_settings_new_full (global_schema, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* If the user has given a path then we enforce that we have a
|
||||||
|
* relocatable schema, but if they didn't give a path then it
|
||||||
|
* doesn't matter what type of schema we have (since it's
|
||||||
|
* reasonable to ask for introspection information on a
|
||||||
|
* relocatable schema without having to give the path).
|
||||||
|
*/
|
||||||
|
if (parts[1])
|
||||||
|
{
|
||||||
|
if (!check_relocatable_schema (global_schema, parts[0]) || !check_path (parts[1]))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (global_schema == NULL)
|
||||||
|
{
|
||||||
|
g_printerr (_("No such schema '%s'\n"), parts[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_strfreev (parts);
|
g_strfreev (parts);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user