1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 2010 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Author: Matthias Clasen
28 key_changed (GSettings *settings,
34 v = g_settings_get_value (settings, key);
35 value = g_variant_print (v, FALSE);
36 g_print ("%s\n", value);
42 main (int argc, char *argv[])
44 gboolean do_get = FALSE;
45 gboolean do_set = FALSE;
46 gboolean do_writable = FALSE;
47 gboolean do_monitor = FALSE;
57 GOptionContext *context;
58 GOptionEntry entries[] = {
59 { "get", 'g', 0, G_OPTION_ARG_NONE, &do_get, N_("Get the value of KEY"), NULL },
60 { "set", 's', 0, G_OPTION_ARG_NONE, &do_set, N_("Set the value of KEY"), NULL },
61 { "writable", 'w', 0, G_OPTION_ARG_NONE, &do_writable, N_("Check if KEY is writable"), NULL },
62 { "monitor", 'm', 0, G_OPTION_ARG_NONE, &do_monitor, N_("Monitor KEY for changes"), NULL },
63 { "path", 'p', 0, G_OPTION_ARG_STRING, &path, N_("Specify the path for the schema"), N_("PATH") },
68 setlocale (LC_ALL, "");
72 context = g_option_context_new (N_("SCHEMA KEY [VALUE]"));
73 g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
74 g_option_context_set_summary (context, N_("Manipulate GSettings configuration"));
75 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
78 if (!g_option_context_parse (context, &argc, &argv, &error))
80 g_printerr ("%s\n", error->message);
84 if (do_get + do_set + do_writable + do_monitor != 1)
86 g_printerr (_("You must specify exactly one of --get, --set, --writable or --monitor\n"));
90 if (do_get || do_writable || do_monitor)
94 g_printerr (_("You must specify a schema and a key\n"));
105 g_printerr (_("You must specify a schema, a key and a value\n"));
114 settings = g_settings_new_with_path (schema, path);
118 v = g_settings_get_value (settings, key);
120 g_print ("%s\n", g_variant_print (v, FALSE));
124 else if (do_writable)
126 if (g_settings_is_writable (settings, key))
135 const GVariantType *type;
138 v = g_settings_get_value (settings, key);
139 type = g_variant_get_type (v);
143 v = g_variant_parse (type, value, NULL, NULL, &error);
146 g_printerr ("%s\n", error->message);
150 if (!g_settings_set_value (settings, key, v))
152 g_printerr (_("Key %s is not writable\n"), key);
158 gchar *detailed_signal;
161 detailed_signal = g_strdup_printf ("changed::%s", key);
162 g_signal_connect (settings, detailed_signal,
163 G_CALLBACK (key_changed), NULL);
165 loop = g_main_loop_new (NULL, FALSE);
166 g_main_loop_run (loop);