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
26 key_changed (GSettings *settings,
32 v = g_settings_get_value (settings, key);
33 value = g_variant_print (v, FALSE);
34 g_print ("%s\n", value);
40 main (int argc, char *argv[])
42 gboolean do_get = FALSE;
43 gboolean do_set = FALSE;
44 gboolean do_writable = FALSE;
45 gboolean do_monitor = FALSE;
55 GOptionContext *context;
56 GOptionEntry entries[] = {
57 { "get", 'g', 0, G_OPTION_ARG_NONE, &do_get, "get a key", NULL },
58 { "set", 's', 0, G_OPTION_ARG_NONE, &do_set, "set a key", NULL },
59 { "writable", 'w', 0, G_OPTION_ARG_NONE, &do_writable, "check if key is writable", NULL },
60 { "monitor", 'm', 0, G_OPTION_ARG_NONE, &do_monitor, "monitor key for changes", NULL },
61 { "path", 'p', 0, G_OPTION_ARG_STRING, &path, "path for the schema" },
68 context = g_option_context_new ("SCHEMA KEY [VALUE]");
70 g_option_context_set_summary (context, "Manipulate GSettings configuration");
72 g_option_context_add_main_entries (context, entries, NULL);
75 if (!g_option_context_parse (context, &argc, &argv, &error))
77 g_printerr ("%s\n", error->message);
81 if (do_get + do_set + do_writable + do_monitor != 1)
83 g_printerr ("You must specify exactly one of --get, --set, --writable or --monitor\n");
87 if (do_get || do_writable || do_monitor)
91 g_printerr ("You must specify a schema and a key\n");
102 g_printerr ("You must specify a schema, a key and a value\n");
111 settings = g_settings_new_with_path (schema, path);
115 v = g_settings_get_value (settings, key);
117 g_print ("%s\n", g_variant_print (v, FALSE));
121 else if (do_writable)
125 if (g_settings_is_writable (settings, key))
134 const GVariantType *type;
137 v = g_settings_get_value (settings, key);
138 type = g_variant_get_type (v);
142 v = g_variant_parse (type, value, NULL, NULL, &error);
145 g_printerr ("%s\n", error->message);
149 if (!g_settings_set_value (settings, key, v))
151 g_printerr ("Key %s is not writable\n", key);
157 gchar *detailed_signal;
160 detailed_signal = g_strdup_printf ("changed::%s", key);
161 g_signal_connect (settings, detailed_signal,
162 G_CALLBACK (key_changed), NULL);
164 loop = g_main_loop_new (NULL, FALSE);
165 g_main_loop_run (loop);