2010-10-03 08:40:48 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Codethink Limited
|
2010-04-21 02:54:53 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2010-10-03 08:40:48 +02:00
|
|
|
* version 2 of the licence, or (at your option) any later version.
|
2010-04-21 02:54:53 +02:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2014-01-23 12:58:29 +01:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2010-04-21 02:54:53 +02:00
|
|
|
*
|
2010-10-03 08:40:48 +02:00
|
|
|
* Author: Ryan Lortie <desrt@desrt.ca>
|
2010-04-21 02:54:53 +02:00
|
|
|
*/
|
|
|
|
|
2010-10-30 05:12:07 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
#include <gio/gio.h>
|
2010-10-30 05:12:07 +02:00
|
|
|
#include <gi18n.h>
|
|
|
|
#include <locale.h>
|
2010-10-03 08:40:48 +02:00
|
|
|
#include <string.h>
|
2010-06-27 22:00:20 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-11-10 16:51:18 +01:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include "glib/glib-private.h"
|
|
|
|
#endif
|
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
static GSettingsSchemaSource *global_schema_source;
|
2013-10-28 18:23:29 +01:00
|
|
|
static GSettings *global_settings;
|
2013-10-28 18:54:08 +01:00
|
|
|
static GSettingsSchema *global_schema;
|
|
|
|
static GSettingsSchemaKey *global_schema_key;
|
2013-10-28 18:23:29 +01:00
|
|
|
const gchar *global_key;
|
|
|
|
const gchar *global_value;
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static gboolean
|
2011-12-17 20:08:50 +01:00
|
|
|
is_relocatable_schema (GSettingsSchema *schema)
|
2010-10-03 08:40:48 +02:00
|
|
|
{
|
2011-12-17 20:08:50 +01:00
|
|
|
return g_settings_schema_get_path (schema) == NULL;
|
2010-10-03 08:40:48 +02:00
|
|
|
}
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static gboolean
|
2011-12-17 20:08:50 +01:00
|
|
|
check_relocatable_schema (GSettingsSchema *schema,
|
|
|
|
const gchar *schema_id)
|
2010-10-03 08:40:48 +02:00
|
|
|
{
|
2011-12-17 20:08:50 +01:00
|
|
|
if (schema == NULL)
|
|
|
|
{
|
|
|
|
g_printerr (_("No such schema '%s'\n"), schema_id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
if (!is_relocatable_schema (schema))
|
|
|
|
{
|
|
|
|
g_printerr (_("Schema '%s' is not relocatable "
|
|
|
|
"(path must not be specified)\n"),
|
|
|
|
schema_id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
return TRUE;
|
2010-04-22 07:15:54 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static gboolean
|
2011-12-17 20:08:50 +01:00
|
|
|
check_schema (GSettingsSchema *schema,
|
|
|
|
const gchar *schema_id)
|
2010-04-22 07:15:54 +02:00
|
|
|
{
|
2011-12-17 20:08:50 +01:00
|
|
|
if (schema == NULL)
|
|
|
|
{
|
|
|
|
g_printerr (_("No such schema '%s'\n"), schema_id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
if (is_relocatable_schema (schema))
|
2011-12-17 20:08:50 +01:00
|
|
|
{
|
|
|
|
g_printerr (_("Schema '%s' is relocatable "
|
|
|
|
"(path must be specified)\n"),
|
|
|
|
schema_id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
return TRUE;
|
2010-10-03 08:40:48 +02:00
|
|
|
}
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static gboolean
|
|
|
|
check_path (const gchar *path)
|
2010-04-22 07:15:54 +02:00
|
|
|
{
|
2010-10-03 08:40:48 +02:00
|
|
|
if (path[0] == '\0')
|
|
|
|
{
|
2010-10-30 05:12:07 +02:00
|
|
|
g_printerr (_("Empty path given.\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
if (path[0] != '/')
|
|
|
|
{
|
2010-10-30 05:12:07 +02:00
|
|
|
g_printerr (_("Path must begin with a slash (/)\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_str_has_suffix (path, "/"))
|
|
|
|
{
|
2010-10-30 05:12:07 +02:00
|
|
|
g_printerr (_("Path must end with a slash (/)\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
if (strstr (path, "//"))
|
|
|
|
{
|
2010-10-30 05:12:07 +02:00
|
|
|
g_printerr (_("Path must not contain two adjacent slashes (//)\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2010-04-22 07:15:54 +02:00
|
|
|
}
|
|
|
|
|
2010-06-27 22:00:20 +02:00
|
|
|
static void
|
2013-10-28 18:54:08 +01:00
|
|
|
output_list (gchar **list)
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
for (i = 0; list[i]; i++)
|
|
|
|
g_print ("%s\n", list[i]);
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
2013-04-03 21:15:49 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_print_version (void)
|
2013-04-03 21:15:49 +02:00
|
|
|
{
|
|
|
|
g_print ("%d.%d.%d\n", glib_major_version, glib_minor_version,
|
|
|
|
glib_micro_version);
|
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_list_schemas (void)
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2013-10-28 18:54:08 +01:00
|
|
|
gchar **schemas;
|
|
|
|
|
|
|
|
g_settings_schema_source_list_schemas (global_schema_source, TRUE, &schemas, NULL);
|
|
|
|
output_list (schemas);
|
|
|
|
g_strfreev (schemas);
|
2010-10-03 08:40:48 +02:00
|
|
|
}
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_list_relocatable_schemas (void)
|
2010-10-03 08:40:48 +02:00
|
|
|
{
|
2013-10-28 18:54:08 +01:00
|
|
|
gchar **schemas;
|
|
|
|
|
|
|
|
g_settings_schema_source_list_schemas (global_schema_source, TRUE, NULL, &schemas);
|
|
|
|
output_list (schemas);
|
|
|
|
g_strfreev (schemas);
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_list_keys (void)
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2010-09-06 18:47:37 +02:00
|
|
|
gchar **keys;
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2014-11-19 18:42:10 +01:00
|
|
|
keys = g_settings_schema_list_keys (global_schema);
|
2013-10-28 18:54:08 +01:00
|
|
|
output_list (keys);
|
2010-09-06 18:47:37 +02:00
|
|
|
g_strfreev (keys);
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_list_children (void)
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2010-10-03 08:40:48 +02:00
|
|
|
gchar **children;
|
|
|
|
gint max = 0;
|
2010-06-27 22:00:20 +02:00
|
|
|
gint i;
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
children = g_settings_list_children (global_settings);
|
2010-10-03 08:40:48 +02:00
|
|
|
for (i = 0; children[i]; i++)
|
|
|
|
if (strlen (children[i]) > max)
|
|
|
|
max = strlen (children[i]);
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
for (i = 0; children[i]; i++)
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2010-10-03 08:40:48 +02:00
|
|
|
GSettings *child;
|
2011-12-17 20:08:50 +01:00
|
|
|
GSettingsSchema *schema;
|
2010-10-03 08:40:48 +02:00
|
|
|
gchar *path;
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
child = g_settings_get_child (global_settings, children[i]);
|
2010-10-03 08:40:48 +02:00
|
|
|
g_object_get (child,
|
2011-12-17 20:08:50 +01:00
|
|
|
"settings-schema", &schema,
|
2010-10-03 08:40:48 +02:00
|
|
|
"path", &path,
|
|
|
|
NULL);
|
2010-04-21 02:54:53 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
if (g_settings_schema_get_path (schema) != NULL)
|
|
|
|
g_print ("%-*s %s\n", max, children[i], g_settings_schema_get_id (schema));
|
2010-10-03 08:40:48 +02:00
|
|
|
else
|
2011-12-17 20:08:50 +01:00
|
|
|
g_print ("%-*s %s:%s\n", max, children[i], g_settings_schema_get_id (schema), path);
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
g_object_unref (child);
|
2011-12-17 20:08:50 +01:00
|
|
|
g_settings_schema_unref (schema);
|
2010-10-03 08:40:48 +02:00
|
|
|
g_free (path);
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
g_strfreev (children);
|
|
|
|
}
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-30 06:00:06 +02:00
|
|
|
static void
|
|
|
|
enumerate (GSettings *settings)
|
|
|
|
{
|
|
|
|
gchar **keys;
|
2014-11-19 18:42:10 +01:00
|
|
|
GSettingsSchema *schema;
|
2010-10-30 06:00:06 +02:00
|
|
|
gint i;
|
|
|
|
|
2014-11-19 18:42:10 +01:00
|
|
|
g_object_get (settings, "settings-schema", &schema, NULL);
|
2010-10-30 06:00:06 +02:00
|
|
|
|
2014-11-19 18:42:10 +01:00
|
|
|
keys = g_settings_schema_list_keys (schema);
|
2010-10-30 06:00:06 +02:00
|
|
|
for (i = 0; keys[i]; i++)
|
|
|
|
{
|
|
|
|
GVariant *value;
|
|
|
|
gchar *printed;
|
|
|
|
|
|
|
|
value = g_settings_get_value (settings, keys[i]);
|
|
|
|
printed = g_variant_print (value, TRUE);
|
2014-11-19 18:42:10 +01:00
|
|
|
g_print ("%s %s %s\n", g_settings_schema_get_id (schema), keys[i], printed);
|
2010-10-30 06:00:06 +02:00
|
|
|
g_variant_unref (value);
|
|
|
|
g_free (printed);
|
|
|
|
}
|
|
|
|
|
2014-11-19 18:42:10 +01:00
|
|
|
g_settings_schema_unref (schema);
|
2010-10-30 06:00:06 +02:00
|
|
|
g_strfreev (keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
list_recursively (GSettings *settings)
|
2010-10-30 06:00:06 +02:00
|
|
|
{
|
2013-10-28 18:23:29 +01:00
|
|
|
gchar **children;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
enumerate (settings);
|
|
|
|
children = g_settings_list_children (settings);
|
|
|
|
for (i = 0; children[i]; i++)
|
2011-02-23 06:13:39 +01:00
|
|
|
{
|
2013-10-28 18:23:29 +01:00
|
|
|
GSettings *child;
|
2010-10-30 06:00:06 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
child = g_settings_get_child (settings, children[i]);
|
|
|
|
list_recursively (child);
|
|
|
|
g_object_unref (child);
|
|
|
|
}
|
2010-10-30 06:00:06 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
g_strfreev (children);
|
|
|
|
}
|
2010-10-30 06:00:06 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
static void
|
|
|
|
gsettings_list_recursively (void)
|
|
|
|
{
|
|
|
|
if (global_settings)
|
|
|
|
{
|
|
|
|
list_recursively (global_settings);
|
2010-10-30 06:00:06 +02:00
|
|
|
}
|
2011-02-23 06:13:39 +01:00
|
|
|
else
|
|
|
|
{
|
2013-10-28 18:54:08 +01:00
|
|
|
gchar **schemas;
|
2011-02-23 06:13:39 +01:00
|
|
|
gint i;
|
2010-10-30 06:00:06 +02:00
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
g_settings_schema_source_list_schemas (global_schema_source, TRUE, &schemas, NULL);
|
2011-02-23 06:13:39 +01:00
|
|
|
|
|
|
|
for (i = 0; schemas[i]; i++)
|
|
|
|
{
|
2013-10-28 18:23:29 +01:00
|
|
|
GSettings *settings;
|
|
|
|
|
2011-02-23 06:13:39 +01:00
|
|
|
settings = g_settings_new (schemas[i]);
|
2013-10-28 18:23:29 +01:00
|
|
|
list_recursively (settings);
|
2011-02-23 06:13:39 +01:00
|
|
|
g_object_unref (settings);
|
|
|
|
}
|
2013-10-28 18:54:08 +01:00
|
|
|
|
|
|
|
g_strfreev (schemas);
|
2011-02-23 06:13:39 +01:00
|
|
|
}
|
2010-10-30 06:00:06 +02:00
|
|
|
}
|
|
|
|
|
2010-10-04 09:41:03 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_range (void)
|
2010-10-04 09:41:03 +02:00
|
|
|
{
|
|
|
|
GVariant *range, *detail;
|
|
|
|
const gchar *type;
|
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
range = g_settings_schema_key_get_range (global_schema_key);
|
2010-10-04 09:41:03 +02:00
|
|
|
g_variant_get (range, "(&sv)", &type, &detail);
|
|
|
|
|
|
|
|
if (strcmp (type, "type") == 0)
|
|
|
|
g_print ("type %s\n", g_variant_get_type_string (detail) + 1);
|
|
|
|
|
|
|
|
else if (strcmp (type, "range") == 0)
|
|
|
|
{
|
|
|
|
GVariant *min, *max;
|
|
|
|
gchar *smin, *smax;
|
|
|
|
|
|
|
|
g_variant_get (detail, "(**)", &min, &max);
|
|
|
|
smin = g_variant_print (min, FALSE);
|
|
|
|
smax = g_variant_print (max, FALSE);
|
|
|
|
|
|
|
|
g_print ("range %s %s %s\n",
|
|
|
|
g_variant_get_type_string (min), smin, smax);
|
|
|
|
g_variant_unref (min);
|
|
|
|
g_variant_unref (max);
|
|
|
|
g_free (smin);
|
|
|
|
g_free (smax);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (strcmp (type, "enum") == 0 || strcmp (type, "flags") == 0)
|
|
|
|
{
|
|
|
|
GVariantIter iter;
|
|
|
|
GVariant *item;
|
|
|
|
|
|
|
|
g_print ("%s\n", type);
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, detail);
|
|
|
|
while (g_variant_iter_loop (&iter, "*", &item))
|
|
|
|
{
|
|
|
|
gchar *printed;
|
|
|
|
|
|
|
|
printed = g_variant_print (item, FALSE);
|
|
|
|
g_print ("%s\n", printed);
|
|
|
|
g_free (printed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_unref (detail);
|
|
|
|
g_variant_unref (range);
|
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_get (void)
|
2010-10-03 08:40:48 +02:00
|
|
|
{
|
|
|
|
GVariant *value;
|
|
|
|
gchar *printed;
|
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
value = g_settings_get_value (global_settings, global_key);
|
2010-10-03 08:40:48 +02:00
|
|
|
printed = g_variant_print (value, TRUE);
|
|
|
|
g_print ("%s\n", printed);
|
|
|
|
g_variant_unref (value);
|
|
|
|
g_free (printed);
|
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_reset (void)
|
2010-10-03 08:40:48 +02:00
|
|
|
{
|
2013-10-28 18:23:29 +01:00
|
|
|
g_settings_reset (global_settings, global_key);
|
2010-10-03 08:40:48 +02:00
|
|
|
g_settings_sync ();
|
2010-04-21 02:54:53 +02:00
|
|
|
}
|
|
|
|
|
2011-04-12 17:00:54 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
reset_all_keys (GSettings *settings)
|
2011-04-12 17:00:54 +02:00
|
|
|
{
|
2014-11-19 18:42:10 +01:00
|
|
|
GSettingsSchema *schema;
|
2011-04-12 17:00:54 +02:00
|
|
|
gchar **keys;
|
|
|
|
gint i;
|
|
|
|
|
2014-11-19 18:42:10 +01:00
|
|
|
g_object_get (settings, "settings-schema", &schema, NULL);
|
|
|
|
|
|
|
|
keys = g_settings_schema_list_keys (schema);
|
2011-04-12 17:00:54 +02:00
|
|
|
for (i = 0; keys[i]; i++)
|
|
|
|
{
|
|
|
|
g_settings_reset (settings, keys[i]);
|
|
|
|
}
|
|
|
|
|
2014-11-19 18:42:10 +01:00
|
|
|
g_settings_schema_unref (schema);
|
2011-04-12 17:00:54 +02:00
|
|
|
g_strfreev (keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_reset_recursively (void)
|
2011-04-12 17:00:54 +02:00
|
|
|
{
|
|
|
|
gchar **children;
|
|
|
|
gint i;
|
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
g_settings_delay (global_settings);
|
2011-05-18 23:56:50 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
reset_all_keys (global_settings);
|
|
|
|
children = g_settings_list_children (global_settings);
|
2011-04-12 17:00:54 +02:00
|
|
|
for (i = 0; children[i]; i++)
|
|
|
|
{
|
|
|
|
GSettings *child;
|
2013-10-28 18:23:29 +01:00
|
|
|
child = g_settings_get_child (global_settings, children[i]);
|
2011-05-18 23:56:50 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
reset_all_keys (child);
|
2011-05-18 23:56:50 +02:00
|
|
|
|
2011-04-12 17:00:54 +02:00
|
|
|
g_object_unref (child);
|
|
|
|
}
|
2011-05-18 23:56:50 +02:00
|
|
|
|
2011-04-12 17:00:54 +02:00
|
|
|
g_strfreev (children);
|
2011-05-18 23:56:50 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
g_settings_apply (global_settings);
|
2011-04-12 17:00:54 +02:00
|
|
|
g_settings_sync ();
|
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_writable (void)
|
2010-04-21 02:54:53 +02:00
|
|
|
{
|
2010-10-03 08:40:48 +02:00
|
|
|
g_print ("%s\n",
|
2013-10-28 18:23:29 +01:00
|
|
|
g_settings_is_writable (global_settings, global_key) ?
|
2010-10-03 08:40:48 +02:00
|
|
|
"true" : "false");
|
|
|
|
}
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static void
|
2013-11-27 18:40:27 +01:00
|
|
|
value_changed (GSettings *settings,
|
|
|
|
const gchar *key,
|
|
|
|
gpointer user_data)
|
2010-10-03 08:40:48 +02:00
|
|
|
{
|
|
|
|
GVariant *value;
|
|
|
|
gchar *printed;
|
|
|
|
|
2013-11-27 18:40:27 +01:00
|
|
|
value = g_settings_get_value (settings, key);
|
2010-10-03 08:40:48 +02:00
|
|
|
printed = g_variant_print (value, TRUE);
|
2013-11-27 18:40:27 +01:00
|
|
|
g_print ("%s: %s\n", key, printed);
|
2010-10-03 08:40:48 +02:00
|
|
|
g_variant_unref (value);
|
|
|
|
g_free (printed);
|
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_monitor (void)
|
2010-10-03 08:40:48 +02:00
|
|
|
{
|
2013-10-28 18:23:29 +01:00
|
|
|
if (global_key)
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2010-10-03 08:40:48 +02:00
|
|
|
gchar *name;
|
2010-04-21 02:54:53 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
name = g_strdup_printf ("changed::%s", global_key);
|
|
|
|
g_signal_connect (global_settings, name, G_CALLBACK (value_changed), NULL);
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
2010-06-19 18:33:26 +02:00
|
|
|
else
|
2013-10-28 18:23:29 +01:00
|
|
|
g_signal_connect (global_settings, "changed", G_CALLBACK (value_changed), NULL);
|
GSettings: delay backend subscription
GSettings objects begin watching for changes as soon as they are created
in order that they can emit the "changed" signal.
In the case of dconf, if we want to be able to emit the changed signal,
we need to go on the bus and add some match rules. This requires
creating the dconf helper thread and also requires initialising GDBus
(which creates another thread).
Some users of GSettings are never interested in the "changed" signal.
One of these users is the glib-networking code that gets run every time
a new network connection is created.
Some users are reporting that they are annoyed that simply establishing
a network connection would spawn two extra threads and create a D-Bus
connection.
In order to avoid doing unnecessary work for these simple uses, delay
the subscription until we know that we will actually need to do it.
We do this in a simple way, using a simple argument: in order for the
user to care that a value changed then they must have:
1) watched for a change signal; and then
2) actually read a value
If the user didn't actually read a value then they cannot possibly be
interested in if the value changed or not (since they never knew the old
value to begin with and therefore would be unable to observe that it
ever changed, since they have nothing to compare the new value with).
This really is a behaviour change, however, and it does impact at least
one user: the 'monitor' functionality of the GSettings commandline tool,
which is interested in reporting changes without ever having known the
original values. We add a workaround to the commandline tool in order
to ensure that it continues to function properly.
It's also possible to argue that it is completely valid to have read a
value and _then_ established a change signal connection under the
(correct) assumption that it would not have been possible to miss a
change signal by virtue of not having returned to the mainloop.
Although this argument is true, this pattern is extremely non-idiomatic,
and the problem is easily avoided by doing things in the usual order.
We never really talked about change notification in the overview
documentation for GSettings, so it seems like now is a good time to add
some discussion, including the new rules for when one can expect change
signals to be emitted.
https://bugzilla.gnome.org/show_bug.cgi?id=733791
2014-07-26 17:16:37 +02:00
|
|
|
|
2013-11-27 18:41:33 +01:00
|
|
|
for (;;)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2010-10-03 08:40:48 +02:00
|
|
|
}
|
2010-04-21 02:54:53 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static void
|
2013-10-28 18:23:29 +01:00
|
|
|
gsettings_set (void)
|
2010-10-03 08:40:48 +02:00
|
|
|
{
|
|
|
|
const GVariantType *type;
|
|
|
|
GError *error = NULL;
|
|
|
|
GVariant *new;
|
2010-10-30 07:13:42 +02:00
|
|
|
gchar *freeme = NULL;
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
type = g_settings_schema_key_get_value_type (global_schema_key);
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
new = g_variant_parse (type, global_value, NULL, NULL, &error);
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2011-05-17 17:58:46 +02:00
|
|
|
/* 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().
|
2010-10-30 07:13:42 +02:00
|
|
|
*/
|
2010-11-09 22:56:28 +01:00
|
|
|
if (new == NULL &&
|
2011-05-17 17:58:46 +02:00
|
|
|
g_variant_type_equal (type, G_VARIANT_TYPE_STRING) &&
|
2013-10-28 18:23:29 +01:00
|
|
|
global_value[0] != '\'' && global_value[0] != '"')
|
2010-10-30 07:13:42 +02:00
|
|
|
{
|
2011-05-17 17:58:46 +02:00
|
|
|
g_clear_error (&error);
|
2013-10-28 18:23:29 +01:00
|
|
|
new = g_variant_new_string (global_value);
|
2010-10-30 07:13:42 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
if (new == NULL)
|
|
|
|
{
|
2013-11-22 18:55:10 +01:00
|
|
|
gchar *context;
|
|
|
|
|
|
|
|
context = g_variant_parse_error_print_context (error, global_value);
|
|
|
|
g_printerr ("%s", context);
|
2010-10-03 08:40:48 +02:00
|
|
|
exit (1);
|
2010-04-21 02:54:53 +02:00
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
if (!g_settings_schema_key_range_check (global_schema_key, new))
|
2010-10-04 09:40:22 +02:00
|
|
|
{
|
2010-10-30 05:12:07 +02:00
|
|
|
g_printerr (_("The provided value is outside of the valid range\n"));
|
2011-05-23 19:39:09 +02:00
|
|
|
g_variant_unref (new);
|
2010-10-04 09:40:22 +02:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
if (!g_settings_set_value (global_settings, global_key, new))
|
2013-07-20 01:41:24 +02:00
|
|
|
{
|
|
|
|
g_printerr (_("The key is not writable\n"));
|
|
|
|
exit (1);
|
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2011-05-23 19:39:09 +02:00
|
|
|
g_settings_sync ();
|
|
|
|
|
2010-10-30 07:13:42 +02:00
|
|
|
g_free (freeme);
|
2010-04-22 07:15:54 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
static int
|
|
|
|
gsettings_help (gboolean requested,
|
|
|
|
const gchar *command)
|
2010-07-23 00:39:50 +02:00
|
|
|
{
|
2010-10-03 08:40:48 +02:00
|
|
|
const gchar *description;
|
|
|
|
const gchar *synopsis;
|
|
|
|
GString *string;
|
2010-07-23 00:39:50 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
string = g_string_new (NULL);
|
2010-07-23 00:39:50 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
if (command == NULL)
|
|
|
|
;
|
|
|
|
|
2011-01-22 00:02:05 +01:00
|
|
|
else if (strcmp (command, "help") == 0)
|
|
|
|
{
|
|
|
|
description = _("Print help");
|
|
|
|
synopsis = "[COMMAND]";
|
|
|
|
}
|
|
|
|
|
2013-04-03 21:15:49 +02:00
|
|
|
else if (strcmp (command, "--version") == 0)
|
|
|
|
{
|
|
|
|
description = _("Print version information and exit");
|
|
|
|
synopsis = "";
|
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (strcmp (command, "list-schemas") == 0)
|
2010-07-23 00:39:50 +02:00
|
|
|
{
|
2010-10-30 05:12:07 +02:00
|
|
|
description = _("List the installed (non-relocatable) schemas");
|
2010-10-03 08:40:48 +02:00
|
|
|
synopsis = "";
|
2010-07-23 00:39:50 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (strcmp (command, "list-relocatable-schemas") == 0)
|
2010-07-23 00:39:50 +02:00
|
|
|
{
|
2010-10-30 05:12:07 +02:00
|
|
|
description = _("List the installed relocatable schemas");
|
2010-10-03 08:40:48 +02:00
|
|
|
synopsis = "";
|
2010-07-23 00:39:50 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (strcmp (command, "list-keys") == 0)
|
2010-07-23 00:39:50 +02:00
|
|
|
{
|
2011-01-22 00:02:05 +01:00
|
|
|
description = _("List the keys in SCHEMA");
|
2010-10-30 05:12:07 +02:00
|
|
|
synopsis = N_("SCHEMA[:PATH]");
|
2010-07-23 00:39:50 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (strcmp (command, "list-children") == 0)
|
2010-07-23 00:39:50 +02:00
|
|
|
{
|
2011-01-22 00:02:05 +01:00
|
|
|
description = _("List the children of SCHEMA");
|
2010-10-30 05:12:07 +02:00
|
|
|
synopsis = N_("SCHEMA[:PATH]");
|
2010-07-23 00:39:50 +02:00
|
|
|
}
|
|
|
|
|
2010-10-30 06:00:06 +02:00
|
|
|
else if (strcmp (command, "list-recursively") == 0)
|
|
|
|
{
|
2011-02-23 06:13:39 +01:00
|
|
|
description = _("List keys and values, recursively\n"
|
|
|
|
"If no SCHEMA is given, list all keys\n");
|
|
|
|
synopsis = N_("[SCHEMA[:PATH]]");
|
2010-10-30 06:00:06 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (strcmp (command, "get") == 0)
|
2010-04-21 02:54:53 +02:00
|
|
|
{
|
2011-01-22 00:02:05 +01:00
|
|
|
description = _("Get the value of KEY");
|
2010-10-30 05:12:07 +02:00
|
|
|
synopsis = N_("SCHEMA[:PATH] KEY");
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
2010-10-04 09:41:03 +02:00
|
|
|
else if (strcmp (command, "range") == 0)
|
|
|
|
{
|
2011-01-22 00:02:05 +01:00
|
|
|
description = _("Query the range of valid values for KEY");
|
2010-10-30 05:12:07 +02:00
|
|
|
synopsis = N_("SCHEMA[:PATH] KEY");
|
2010-10-04 09:41:03 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (strcmp (command, "set") == 0)
|
|
|
|
{
|
2011-01-22 00:02:05 +01:00
|
|
|
description = _("Set the value of KEY to VALUE");
|
2010-10-30 05:12:07 +02:00
|
|
|
synopsis = N_("SCHEMA[:PATH] KEY VALUE");
|
2010-10-03 08:40:48 +02:00
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (strcmp (command, "reset") == 0)
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2011-01-22 00:02:05 +01:00
|
|
|
description = _("Reset KEY to its default value");
|
2010-10-30 05:12:07 +02:00
|
|
|
synopsis = N_("SCHEMA[:PATH] KEY");
|
2010-04-21 02:54:53 +02:00
|
|
|
}
|
|
|
|
|
2011-04-12 17:00:54 +02:00
|
|
|
else if (strcmp (command, "reset-recursively") == 0)
|
|
|
|
{
|
|
|
|
description = _("Reset all keys in SCHEMA to their defaults");
|
|
|
|
synopsis = N_("SCHEMA[:PATH]");
|
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (strcmp (command, "writable") == 0)
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2011-01-22 00:02:05 +01:00
|
|
|
description = _("Check if KEY is writable");
|
2010-10-30 05:12:07 +02:00
|
|
|
synopsis = N_("SCHEMA[:PATH] KEY");
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (strcmp (command, "monitor") == 0)
|
|
|
|
{
|
2011-01-22 00:02:05 +01:00
|
|
|
description = _("Monitor KEY for changes.\n"
|
2010-10-03 08:40:48 +02:00
|
|
|
"If no KEY is specified, monitor all keys in SCHEMA.\n"
|
2010-10-30 05:12:07 +02:00
|
|
|
"Use ^C to stop monitoring.\n");
|
|
|
|
synopsis = N_("SCHEMA[:PATH] [KEY]");
|
2010-10-03 08:40:48 +02:00
|
|
|
}
|
2010-06-19 19:00:13 +02:00
|
|
|
else
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2010-10-30 05:12:07 +02:00
|
|
|
g_string_printf (string, _("Unknown command %s\n\n"), command);
|
2010-10-03 08:40:48 +02:00
|
|
|
requested = FALSE;
|
|
|
|
command = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command == NULL)
|
|
|
|
{
|
|
|
|
g_string_append (string,
|
2010-10-30 05:12:07 +02:00
|
|
|
_("Usage:\n"
|
2013-08-28 18:05:29 +02:00
|
|
|
" gsettings --version\n"
|
2011-12-17 20:08:50 +01:00
|
|
|
" gsettings [--schemadir SCHEMADIR] COMMAND [ARGS...]\n"
|
2010-10-03 08:40:48 +02:00
|
|
|
"\n"
|
|
|
|
"Commands:\n"
|
|
|
|
" help Show this information\n"
|
|
|
|
" list-schemas List installed schemas\n"
|
|
|
|
" list-relocatable-schemas List relocatable schemas\n"
|
|
|
|
" list-keys List keys in a schema\n"
|
|
|
|
" list-children List children of a schema\n"
|
2010-10-30 06:00:06 +02:00
|
|
|
" list-recursively List keys and values, recursively\n"
|
2010-10-04 09:41:03 +02:00
|
|
|
" range Queries the range of a key\n"
|
2010-10-03 08:40:48 +02:00
|
|
|
" get Get the value of a key\n"
|
|
|
|
" set Set the value of a key\n"
|
|
|
|
" reset Reset the value of a key\n"
|
2011-04-12 17:00:54 +02:00
|
|
|
" reset-recursively Reset all values in a given schema\n"
|
2010-10-03 08:40:48 +02:00
|
|
|
" writable Check if a key is writable\n"
|
|
|
|
" monitor Watch for changes\n"
|
|
|
|
"\n"
|
2010-10-30 05:12:07 +02:00
|
|
|
"Use 'gsettings help COMMAND' to get detailed help.\n\n"));
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
2010-10-03 08:40:48 +02:00
|
|
|
else
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2011-12-17 20:08:50 +01:00
|
|
|
g_string_append_printf (string, _("Usage:\n gsettings [--schemadir SCHEMADIR] %s %s\n\n%s\n\n"),
|
2011-02-12 18:42:18 +01:00
|
|
|
command, synopsis[0] ? _(synopsis) : "", description);
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
g_string_append (string, _("Arguments:\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
g_string_append (string,
|
|
|
|
_(" SCHEMADIR A directory to search for additional schemas\n"));
|
2011-01-22 00:02:05 +01:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
if (strstr (synopsis, "[COMMAND]"))
|
|
|
|
g_string_append (string,
|
|
|
|
_(" COMMAND The (optional) command to explain\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
else if (strstr (synopsis, "SCHEMA"))
|
|
|
|
g_string_append (string,
|
|
|
|
_(" SCHEMA The name of the schema\n"
|
|
|
|
" PATH The path, for relocatable schemas\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
if (strstr (synopsis, "[KEY]"))
|
|
|
|
g_string_append (string,
|
|
|
|
_(" KEY The (optional) key within the schema\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
else if (strstr (synopsis, "KEY"))
|
|
|
|
g_string_append (string,
|
|
|
|
_(" KEY The key within the schema\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
if (strstr (synopsis, "VALUE"))
|
|
|
|
g_string_append (string,
|
|
|
|
_(" VALUE The value to set\n"));
|
|
|
|
|
|
|
|
g_string_append (string, "\n");
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
2010-04-21 02:54:53 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
if (requested)
|
|
|
|
g_print ("%s", string->str);
|
|
|
|
else
|
2011-02-12 18:42:18 +01:00
|
|
|
g_printerr ("%s\n", string->str);
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
g_string_free (string, TRUE);
|
2010-04-21 02:54:53 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
return requested ? 0 : 1;
|
2010-04-22 07:15:54 +02:00
|
|
|
}
|
2010-04-21 02:54:53 +02:00
|
|
|
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
2010-04-22 07:15:54 +02:00
|
|
|
{
|
2013-10-28 18:23:29 +01:00
|
|
|
void (* function) (void);
|
2014-11-19 18:42:10 +01:00
|
|
|
gboolean need_settings;
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2011-06-07 04:49:29 +02:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
gchar *tmp;
|
|
|
|
#endif
|
|
|
|
|
2010-10-30 05:12:07 +02:00
|
|
|
setlocale (LC_ALL, "");
|
2011-02-12 18:42:18 +01:00
|
|
|
textdomain (GETTEXT_PACKAGE);
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
2011-06-07 04:49:29 +02:00
|
|
|
tmp = _glib_get_locale_dir ();
|
2011-02-12 18:42:18 +01:00
|
|
|
bindtextdomain (GETTEXT_PACKAGE, tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
#else
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
#endif
|
2010-10-30 05:12:07 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
if (argc < 2)
|
|
|
|
return gsettings_help (FALSE, NULL);
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
global_schema_source = g_settings_schema_source_ref (g_settings_schema_source_get_default ());
|
2011-12-17 20:08:50 +01:00
|
|
|
|
|
|
|
if (argc > 3 && g_str_equal (argv[1], "--schemadir"))
|
|
|
|
{
|
2013-10-28 18:54:08 +01:00
|
|
|
GSettingsSchemaSource *parent = global_schema_source;
|
2011-12-17 20:08:50 +01:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
global_schema_source = g_settings_schema_source_new_from_directory (argv[2], parent, FALSE, &error);
|
2011-12-17 20:08:50 +01:00
|
|
|
g_settings_schema_source_unref (parent);
|
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
if (global_schema_source == NULL)
|
2011-12-17 20:08:50 +01:00
|
|
|
{
|
2013-03-09 15:56:02 +01:00
|
|
|
g_printerr (_("Could not load schemas from %s: %s\n"), argv[2], error->message);
|
2011-12-17 20:08:50 +01:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shift remaining arguments (not correct wrt argv[0], but doesn't matter) */
|
|
|
|
argv = argv + 2;
|
|
|
|
argc -= 2;
|
|
|
|
}
|
|
|
|
|
2014-11-19 18:42:10 +01:00
|
|
|
need_settings = TRUE;
|
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
if (strcmp (argv[1], "help") == 0)
|
2010-10-03 08:40:48 +02:00
|
|
|
return gsettings_help (TRUE, argv[2]);
|
2010-04-21 02:54:53 +02:00
|
|
|
|
2013-04-03 21:15:49 +02:00
|
|
|
else if (argc == 2 && strcmp (argv[1], "--version") == 0)
|
|
|
|
function = gsettings_print_version;
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (argc == 2 && strcmp (argv[1], "list-schemas") == 0)
|
|
|
|
function = gsettings_list_schemas;
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (argc == 2 && strcmp (argv[1], "list-relocatable-schemas") == 0)
|
|
|
|
function = gsettings_list_relocatable_schemas;
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (argc == 3 && strcmp (argv[1], "list-keys") == 0)
|
2014-11-19 18:42:10 +01:00
|
|
|
{
|
|
|
|
need_settings = FALSE;
|
|
|
|
function = gsettings_list_keys;
|
|
|
|
}
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (argc == 3 && strcmp (argv[1], "list-children") == 0)
|
|
|
|
function = gsettings_list_children;
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2011-02-23 06:13:39 +01:00
|
|
|
else if ((argc == 2 || argc == 3) && strcmp (argv[1], "list-recursively") == 0)
|
2010-10-30 06:00:06 +02:00
|
|
|
function = gsettings_list_recursively;
|
|
|
|
|
2010-10-04 09:41:03 +02:00
|
|
|
else if (argc == 4 && strcmp (argv[1], "range") == 0)
|
2014-11-19 18:42:10 +01:00
|
|
|
{
|
|
|
|
need_settings = FALSE;
|
|
|
|
function = gsettings_range;
|
|
|
|
}
|
2010-10-04 09:41:03 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (argc == 4 && strcmp (argv[1], "get") == 0)
|
|
|
|
function = gsettings_get;
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (argc == 5 && strcmp (argv[1], "set") == 0)
|
|
|
|
function = gsettings_set;
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (argc == 4 && strcmp (argv[1], "reset") == 0)
|
|
|
|
function = gsettings_reset;
|
2010-07-23 00:39:50 +02:00
|
|
|
|
2011-04-12 17:00:54 +02:00
|
|
|
else if (argc == 3 && strcmp (argv[1], "reset-recursively") == 0)
|
|
|
|
function = gsettings_reset_recursively;
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if (argc == 4 && strcmp (argv[1], "writable") == 0)
|
|
|
|
function = gsettings_writable;
|
2010-04-21 02:54:53 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else if ((argc == 3 || argc == 4) && strcmp (argv[1], "monitor") == 0)
|
|
|
|
function = gsettings_monitor;
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
else
|
|
|
|
return gsettings_help (FALSE, argv[1]);
|
2010-04-22 07:15:54 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
if (argc > 2)
|
2010-04-22 07:15:54 +02:00
|
|
|
{
|
2010-10-03 08:40:48 +02:00
|
|
|
gchar **parts;
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
if (argv[2][0] == '\0')
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2011-02-12 18:42:18 +01:00
|
|
|
g_printerr (_("Empty schema name given\n"));
|
2010-10-03 08:40:48 +02:00
|
|
|
return 1;
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
parts = g_strsplit (argv[2], ":", 2);
|
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
global_schema = g_settings_schema_source_lookup (global_schema_source, parts[0], TRUE);
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2014-11-19 18:42:10 +01:00
|
|
|
if (need_settings)
|
|
|
|
{
|
|
|
|
if (parts[1])
|
|
|
|
{
|
|
|
|
if (!check_relocatable_schema (global_schema, parts[0]) || !check_path (parts[1]))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
global_settings = g_settings_new_full (global_schema, NULL, parts[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!check_schema (global_schema, parts[0]))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
global_settings = g_settings_new_full (global_schema, NULL, NULL);
|
|
|
|
}
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
2010-10-03 08:40:48 +02:00
|
|
|
else
|
|
|
|
{
|
2014-11-19 18:42:10 +01:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
2010-10-03 08:40:48 +02:00
|
|
|
}
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
g_strfreev (parts);
|
2010-06-27 22:00:20 +02:00
|
|
|
}
|
2010-10-03 08:40:48 +02:00
|
|
|
|
|
|
|
if (argc > 3)
|
2010-06-27 22:00:20 +02:00
|
|
|
{
|
2013-10-28 18:54:08 +01:00
|
|
|
if (!g_settings_schema_has_key (global_schema, argv[3]))
|
|
|
|
{
|
|
|
|
g_printerr (_("No such key '%s'\n"), argv[3]);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
global_key = argv[3];
|
2013-10-28 18:54:08 +01:00
|
|
|
global_schema_key = g_settings_schema_get_key (global_schema, global_key);
|
2010-04-21 02:54:53 +02:00
|
|
|
}
|
2010-10-03 08:40:48 +02:00
|
|
|
|
2013-10-28 18:23:29 +01:00
|
|
|
if (argc > 4)
|
|
|
|
global_value = argv[4];
|
|
|
|
|
|
|
|
(* function) ();
|
2010-04-21 02:54:53 +02:00
|
|
|
|
2011-12-17 20:08:50 +01:00
|
|
|
|
2013-10-28 18:54:08 +01:00
|
|
|
g_clear_pointer (&global_schema_source, g_settings_schema_source_unref);
|
|
|
|
g_clear_pointer (&global_schema_key, g_settings_schema_key_unref);
|
|
|
|
g_clear_pointer (&global_schema, g_settings_schema_unref);
|
|
|
|
g_clear_object (&global_settings);
|
2010-06-27 22:00:20 +02:00
|
|
|
|
2010-10-03 08:40:48 +02:00
|
|
|
return 0;
|
2010-04-21 02:54:53 +02:00
|
|
|
}
|