mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
Rename gsettings-tool to gsettings
And make it verb-based.
This commit is contained in:
parent
bf0f8ad8ee
commit
f3e04973e7
@ -117,16 +117,12 @@ content_files = \
|
||||
migrating.xml \
|
||||
gio-querymodules.xml \
|
||||
gschema-compile.xml \
|
||||
gsettings-tool.xml \
|
||||
gsettings.xml \
|
||||
gsettings-schema-convert.xml
|
||||
|
||||
expand_content_files = \
|
||||
overview.xml \
|
||||
migrating.xml \
|
||||
gio-querymodules.xml \
|
||||
gschema-compile.xml \
|
||||
gsettings-tool.xml \
|
||||
gsettings-schema-convert.xml
|
||||
migrating.xml
|
||||
|
||||
extra_files = \
|
||||
version.xml.in \
|
||||
@ -147,7 +143,7 @@ man_MANS = \
|
||||
|
||||
$(man_MANS) : sgml-build.stamp
|
||||
|
||||
%.1 : xml/%.xml
|
||||
%.1 : %.xml
|
||||
@XSLTPROC@ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
|
||||
|
||||
endif
|
||||
|
@ -141,10 +141,10 @@
|
||||
</chapter>
|
||||
<chapter id="tools">
|
||||
<title>GIO Tools</title>
|
||||
<xi:include href="xml/gio-querymodules.xml"/>
|
||||
<xi:include href="xml/gsettings-tool.xml"/>
|
||||
<xi:include href="xml/gschema-compile.xml"/>
|
||||
<xi:include href="xml/gsettings-schema-convert.xml"/>
|
||||
<xi:include href="gio-querymodules.xml"/>
|
||||
<xi:include href="gsettings.xml"/>
|
||||
<xi:include href="gschema-compile.xml"/>
|
||||
<xi:include href="gsettings-schema-convert.xml"/>
|
||||
</chapter>
|
||||
</part>
|
||||
|
||||
|
@ -23,9 +23,10 @@
|
||||
<para><command>gschema-compile</command> compiles all the GSettings XML
|
||||
schema files in <replaceable>directory</replaceable> into a binary file
|
||||
with the name <filename>gschemas.compiled</filename> that can be used
|
||||
by #GSettings. The XML schema files must have the filename extension
|
||||
<filename>.gschema.xml</filename>. For a detailed description of the XML
|
||||
file format, see the #GSettings documentation.
|
||||
by <link linkend="GSettings"><type>GSettings</type></link>. The XML schema
|
||||
files must have the filename extension <filename>.gschema.xml</filename>.
|
||||
For a detailed description of the XML file format, see the
|
||||
<link linkend="GSettings"><type>GSettings</type></link> documentation.
|
||||
</para>
|
||||
<para>
|
||||
At runtime, GSettings looks for schemas in the
|
||||
|
@ -1,93 +0,0 @@
|
||||
<refentry id="gsettings-tool" lang="en">
|
||||
|
||||
<refmeta>
|
||||
<refentrytitle>gsettings-tool</refentrytitle>
|
||||
<manvolnum>1</manvolnum>
|
||||
<refmiscinfo class="manual">User Commands</refmiscinfo>
|
||||
</refmeta>
|
||||
|
||||
<refnamediv>
|
||||
<refname>gsettings-tool</refname>
|
||||
<refpurpose>GSettings configuration tool</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<cmdsynopsis>
|
||||
<command>gsettings-tool</command>
|
||||
<arg choice="opt" rep="repeat">option</arg>
|
||||
<arg choice="req"><replaceable>schema</replaceable></arg>
|
||||
<arg choice="req"><replaceable>key</replaceable></arg>
|
||||
<arg choice="opt"><replaceable>value</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1><title>Description</title>
|
||||
<para><command>gsettings-tool</command> offers a simple commandline
|
||||
interface to #GSettings. It lets you get, set or monitor an individual
|
||||
key for changes.
|
||||
</para>
|
||||
<para>
|
||||
The <replaceable>schema</replaceable> and <replaceable>key</replaceable>
|
||||
arguments are required to specify the schema id and the name of the key
|
||||
to operate on.
|
||||
</para>
|
||||
<para>
|
||||
When setting a key, you also need specify a <replaceable>value</replaceable>
|
||||
The format for the value is that of a serialized #GVariant, so e.g. a string
|
||||
must include explicit quotes: "'foo'". This format is also used when printing
|
||||
out values.
|
||||
</para>
|
||||
|
||||
<refsect2><title>Options</title>
|
||||
<variablelist>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-h</option>, <option>--help</option></term>
|
||||
<listitem><para>
|
||||
Print help and exit
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-g</option>, <option>--get</option></term>
|
||||
<listitem><para>
|
||||
Get the value of <replaceable>key</replaceable>
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-s</option>, <option>--set</option></term>
|
||||
<listitem><para>
|
||||
Set the value of <replaceable>key</replaceable>
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-w</option>, <option>--writable</option></term>
|
||||
<listitem><para>
|
||||
Find out whether <replaceable>key</replaceable> is writable
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-m</option>, <option>--monitor</option></term>
|
||||
<listitem><para>
|
||||
Monitor <replaceable>key</replaceable> for changes and print the
|
||||
changed values. Monitoring will continue until the process is
|
||||
terminated.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-p</option>, <option>--path=<replaceable>path</replaceable></option></term>
|
||||
<listitem><para>
|
||||
The path for the schema. This option is only needed if the schema
|
||||
does not have a fixed path.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
137
docs/reference/gio/gsettings.xml
Normal file
137
docs/reference/gio/gsettings.xml
Normal file
@ -0,0 +1,137 @@
|
||||
<refentry id="gsettings" lang="en">
|
||||
|
||||
<refmeta>
|
||||
<refentrytitle>gsettings</refentrytitle>
|
||||
<manvolnum>1</manvolnum>
|
||||
<refmiscinfo class="manual">User Commands</refmiscinfo>
|
||||
</refmeta>
|
||||
|
||||
<refnamediv>
|
||||
<refname>gsettings</refname>
|
||||
<refpurpose>GSettings configuration tool</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<cmdsynopsis>
|
||||
<command>gsettings</command>
|
||||
<arg choice="plain">get</arg>
|
||||
<arg choice="opt" rep="repeat">option</arg>
|
||||
<arg choice="req"><replaceable>schema</replaceable></arg>
|
||||
<arg choice="req"><replaceable>key</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
<cmdsynopsis>
|
||||
<command>gsettings</command>
|
||||
<arg choice="plain">monitor</arg>
|
||||
<arg choice="opt" rep="repeat">option</arg>
|
||||
<arg choice="req"><replaceable>schema</replaceable></arg>
|
||||
<arg choice="req"><replaceable>key</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
<cmdsynopsis>
|
||||
<command>gsettings</command>
|
||||
<arg choice="plain">writable</arg>
|
||||
<arg choice="opt" rep="repeat">option</arg>
|
||||
<arg choice="req"><replaceable>schema</replaceable></arg>
|
||||
<arg choice="req"><replaceable>key</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
<cmdsynopsis>
|
||||
<command>gsettings</command>
|
||||
<arg choice="plain">set</arg>
|
||||
<arg choice="opt" rep="repeat">option</arg>
|
||||
<arg choice="req"><replaceable>schema</replaceable></arg>
|
||||
<arg choice="req"><replaceable>key</replaceable></arg>
|
||||
<arg choice="req"><replaceable>value</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
<cmdsynopsis>
|
||||
<command>gsettings</command>
|
||||
<arg choice="plain">help</arg>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1><title>Description</title>
|
||||
<para><command>gsettings</command> offers a simple commandline
|
||||
interface to <link linkend="GSettings"><type>GSettings</type></link>.
|
||||
It lets you get, set or monitor an individual key for changes.
|
||||
</para>
|
||||
<para>
|
||||
The <replaceable>schema</replaceable> and <replaceable>key</replaceable>
|
||||
arguments are required to specify the schema id and the name of the key
|
||||
to operate on.
|
||||
</para>
|
||||
<para>
|
||||
When setting a key, you also need specify a <replaceable>value</replaceable>
|
||||
The format for the value is that of a serialized
|
||||
<link linkend="GVariant"><type>GVariant</type></link>,
|
||||
so e.g. a string
|
||||
must include explicit quotes: "'foo'". This format is also used when printing
|
||||
out values.
|
||||
</para>
|
||||
|
||||
<refsect2><title>Commands</title>
|
||||
<variablelist>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>get</option></term>
|
||||
<listitem><para>
|
||||
Get the value of <replaceable>key</replaceable>. The value is printed out
|
||||
as a serialised
|
||||
<link linkend="GVariant"><type>GVariant</type></link>.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>monitor</option></term>
|
||||
<listitem><para>
|
||||
Monitor <replaceable>key</replaceable> for changes and print the changed
|
||||
values. Monitoring will continue until the process is terminated.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>writable</option></term>
|
||||
<listitem><para>
|
||||
Find out whether <replaceable>key</replaceable> is writable.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>set</option></term>
|
||||
<listitem><para>
|
||||
Set the value of <replaceable>key</replaceable> to <replaceable>value</replaceable>.
|
||||
The value is specified as a serialised
|
||||
<link linkend="GVariant"><type>GVariant</type></link>.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>help</option></term>
|
||||
<listitem><para>
|
||||
Print help and exit
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</refsect2>
|
||||
|
||||
|
||||
<refsect2><title>Options</title>
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><option>-h</option>, <option>--help</option></term>
|
||||
<listitem><para>
|
||||
Print help for the command and exit
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-p <replaceable>path</replaceable></option>, <option>--path=<replaceable>path</replaceable></option></term>
|
||||
<listitem><para>
|
||||
The path for the schema. This option is only needed if the schema
|
||||
does not have a fixed path.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect2>
|
||||
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
@ -497,7 +497,7 @@ gio-2.0.lib: libgio-2.0.la gio.def
|
||||
lib -machine:@LIB_EXE_MACHINE_FLAG@ -name:libgio-2.0-$(LT_CURRENT_MINUS_AGE).dll -def:gio.def -out:$@
|
||||
|
||||
dist_bin_SCRIPTS = gsettings-schema-convert
|
||||
bin_PROGRAMS = gio-querymodules gschema-compile gsettings-tool
|
||||
bin_PROGRAMS = gio-querymodules gschema-compile gsettings
|
||||
|
||||
gio_querymodules_SOURCES = gio-querymodules.c
|
||||
gio_querymodules_LDADD = \
|
||||
@ -514,10 +514,10 @@ gschema_compile_SOURCES = \
|
||||
gvdb/gvdb-builder.c \
|
||||
gschema-compile.c
|
||||
|
||||
gsettings_tool_LDADD = \
|
||||
gsettings_LDADD = \
|
||||
$(top_builddir)/glib/libglib-2.0.la \
|
||||
libgio-2.0.la
|
||||
gsettings_tool_SOURCES = gsettings-tool.c
|
||||
gsettings_SOURCES = gsettings-tool.c
|
||||
|
||||
|
||||
schemadir = $(datadir)/glib-2.0/schemas
|
||||
|
@ -19,11 +19,265 @@
|
||||
* Author: Matthias Clasen
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <locale.h>
|
||||
#include <gi18n.h>
|
||||
#include <gio.h>
|
||||
|
||||
static gint
|
||||
usage (gint *argc,
|
||||
gchar **argv[],
|
||||
gboolean use_stdout)
|
||||
{
|
||||
GOptionContext *context;
|
||||
gchar *s;
|
||||
|
||||
g_set_prgname (g_path_get_basename ((*argv)[0]));
|
||||
|
||||
context = g_option_context_new (_("COMMAND"));
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
s = g_strdup_printf (
|
||||
_("Commands:\n"
|
||||
" help Show this information\n"
|
||||
" get Get the value of a key\n"
|
||||
" set Set the value of a key\n"
|
||||
" monitor Monitor a key for changes\n"
|
||||
" writable Check if a key is writable\n"
|
||||
"\n"
|
||||
"Use '%s COMMAND --help' to get help for individual commands.\n"),
|
||||
g_get_prgname ());
|
||||
g_option_context_set_description (context, s);
|
||||
g_free (s);
|
||||
s = g_option_context_get_help (context, FALSE, NULL);
|
||||
if (use_stdout)
|
||||
g_print ("%s", s);
|
||||
else
|
||||
g_printerr ("%s", s);
|
||||
g_free (s);
|
||||
g_option_context_free (context);
|
||||
|
||||
return use_stdout ? 0 : 1;
|
||||
}
|
||||
|
||||
static void
|
||||
remove_arg (gint num, gint *argc, gchar **argv[])
|
||||
{
|
||||
gint n;
|
||||
|
||||
g_assert (num <= (*argc));
|
||||
|
||||
for (n = num; (*argv)[n] != NULL; n++)
|
||||
(*argv)[n] = (*argv)[n+1];
|
||||
(*argv)[n] = NULL;
|
||||
(*argc) = (*argc) - 1;
|
||||
}
|
||||
|
||||
static void
|
||||
modify_argv0_for_command (gint *argc,
|
||||
gchar **argv[],
|
||||
const gchar *command)
|
||||
{
|
||||
gchar *s;
|
||||
|
||||
g_assert (g_strcmp0 ((*argv)[1], command) == 0);
|
||||
remove_arg (1, argc, argv);
|
||||
|
||||
s = g_strdup_printf ("%s %s", (*argv)[0], command);
|
||||
(*argv)[0] = s;
|
||||
}
|
||||
|
||||
|
||||
static gint
|
||||
handle_get (gint *argc,
|
||||
gchar **argv[])
|
||||
{
|
||||
gchar *schema;
|
||||
gchar *path;
|
||||
gchar *key;
|
||||
GSettings *settings;
|
||||
GVariant *v;
|
||||
GOptionContext *context;
|
||||
GOptionEntry entries[] = {
|
||||
{ "path", 'p', 0, G_OPTION_ARG_STRING, &path, N_("Specify the path for the schema"), N_("PATH") },
|
||||
{ NULL }
|
||||
};
|
||||
GError *error;
|
||||
gint ret = 1;
|
||||
|
||||
modify_argv0_for_command (argc, argv, "get");
|
||||
|
||||
context = g_option_context_new (_("SCHEMA KEY"));
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Get the value of KEY"));
|
||||
g_option_context_set_description (context,
|
||||
_("Arguments:\n"
|
||||
" SCHEMA The id of the schema\n"
|
||||
" KEY The name of the key\n"));
|
||||
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
||||
|
||||
path = NULL;
|
||||
|
||||
error = NULL;
|
||||
if (!g_option_context_parse (context, argc, argv, NULL) || *argc != 3)
|
||||
{
|
||||
gchar *s;
|
||||
s = g_option_context_get_help (context, FALSE, NULL);
|
||||
g_printerr ("%s", s);
|
||||
g_free (s);
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
schema = (*argv)[1];
|
||||
key = (*argv)[2];
|
||||
|
||||
settings = g_settings_new_with_path (schema, path);
|
||||
|
||||
v = g_settings_get_value (settings, key);
|
||||
g_print ("%s\n", g_variant_print (v, FALSE));
|
||||
g_variant_unref (v);
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
g_option_context_free (context);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gint
|
||||
handle_set (gint *argc,
|
||||
gchar **argv[])
|
||||
{
|
||||
gchar *schema;
|
||||
gchar *path;
|
||||
gchar *key;
|
||||
gchar *value;
|
||||
GSettings *settings;
|
||||
GVariant *v;
|
||||
const GVariantType *type;
|
||||
GOptionContext *context;
|
||||
GOptionEntry entries[] = {
|
||||
{ "path", 'p', 0, G_OPTION_ARG_STRING, &path, N_("Specify the path for the schema"), N_("PATH") },
|
||||
{ NULL }
|
||||
};
|
||||
GError *error;
|
||||
gint ret = 1;
|
||||
|
||||
modify_argv0_for_command (argc, argv, "set");
|
||||
|
||||
context = g_option_context_new (_("SCHEMA KEY VALUE"));
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Set the value of KEY"));
|
||||
g_option_context_set_description (context,
|
||||
_("Arguments:\n"
|
||||
" SCHEMA The id of the schema\n"
|
||||
" KEY The name of the key\n"
|
||||
" VALUE The value to set key to, as a serialized GVariant\n"));
|
||||
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
||||
|
||||
path = NULL;
|
||||
|
||||
error = NULL;
|
||||
if (!g_option_context_parse (context, argc, argv, NULL) || *argc != 4)
|
||||
{
|
||||
gchar *s;
|
||||
s = g_option_context_get_help (context, FALSE, NULL);
|
||||
g_printerr ("%s", s);
|
||||
g_free (s);
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
schema = (*argv)[1];
|
||||
key = (*argv)[2];
|
||||
value = (*argv)[3];
|
||||
|
||||
settings = g_settings_new_with_path (schema, path);
|
||||
|
||||
v = g_settings_get_value (settings, key);
|
||||
type = g_variant_get_type (v);
|
||||
g_variant_unref (v);
|
||||
|
||||
error = NULL;
|
||||
v = g_variant_parse (type, value, NULL, NULL, &error);
|
||||
if (v == NULL)
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!g_settings_set_value (settings, key, v))
|
||||
{
|
||||
g_printerr (_("Key %s is not writable\n"), key);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
g_option_context_free (context);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gint
|
||||
handle_writable (gint *argc,
|
||||
gchar **argv[])
|
||||
{
|
||||
gchar *schema;
|
||||
gchar *path;
|
||||
gchar *key;
|
||||
GSettings *settings;
|
||||
GOptionContext *context;
|
||||
GOptionEntry entries[] = {
|
||||
{ "path", 'p', 0, G_OPTION_ARG_STRING, &path, N_("Specify the path for the schema"), N_("PATH") },
|
||||
{ NULL }
|
||||
};
|
||||
GError *error;
|
||||
gint ret = 1;
|
||||
|
||||
modify_argv0_for_command (argc, argv, "writable");
|
||||
|
||||
context = g_option_context_new (_("SCHEMA KEY"));
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context, _("Find out whether KEY is writable"));
|
||||
g_option_context_set_description (context,
|
||||
_("Arguments:\n"
|
||||
" SCHEMA The id of the schema\n"
|
||||
" KEY The name of the key\n"));
|
||||
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
||||
|
||||
path = NULL;
|
||||
|
||||
error = NULL;
|
||||
if (!g_option_context_parse (context, argc, argv, NULL) || *argc != 3)
|
||||
{
|
||||
gchar *s;
|
||||
s = g_option_context_get_help (context, FALSE, NULL);
|
||||
g_printerr ("%s", s);
|
||||
g_free (s);
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
schema = (*argv)[1];
|
||||
key = (*argv)[2];
|
||||
|
||||
settings = g_settings_new_with_path (schema, path);
|
||||
|
||||
if (g_settings_is_writable (settings, key))
|
||||
g_print ("true\n");
|
||||
else
|
||||
g_print ("false\n");
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
g_option_context_free (context);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
key_changed (GSettings *settings,
|
||||
const gchar *key)
|
||||
@ -38,133 +292,95 @@ key_changed (GSettings *settings,
|
||||
g_variant_unref (v);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
static gint
|
||||
handle_monitor (gint *argc,
|
||||
gchar **argv[])
|
||||
{
|
||||
gboolean do_get = FALSE;
|
||||
gboolean do_set = FALSE;
|
||||
gboolean do_writable = FALSE;
|
||||
gboolean do_monitor = FALSE;
|
||||
|
||||
gchar *path = NULL;
|
||||
gchar *schema;
|
||||
gchar *path;
|
||||
gchar *key;
|
||||
gchar *value;
|
||||
|
||||
GSettings *settings;
|
||||
GVariant *v;
|
||||
|
||||
gchar *detailed_signal;
|
||||
GMainLoop *loop;
|
||||
GOptionContext *context;
|
||||
GOptionEntry entries[] = {
|
||||
{ "get", 'g', 0, G_OPTION_ARG_NONE, &do_get, N_("Get the value of KEY"), NULL },
|
||||
{ "set", 's', 0, G_OPTION_ARG_NONE, &do_set, N_("Set the value of KEY"), NULL },
|
||||
{ "writable", 'w', 0, G_OPTION_ARG_NONE, &do_writable, N_("Check if KEY is writable"), NULL },
|
||||
{ "monitor", 'm', 0, G_OPTION_ARG_NONE, &do_monitor, N_("Monitor KEY for changes"), NULL },
|
||||
{ "path", 'p', 0, G_OPTION_ARG_STRING, &path, N_("Specify the path for the schema"), N_("PATH") },
|
||||
{ NULL }
|
||||
};
|
||||
GError *error;
|
||||
gint ret = 1;
|
||||
|
||||
modify_argv0_for_command (argc, argv, "monitor");
|
||||
|
||||
context = g_option_context_new (_("SCHEMA KEY"));
|
||||
g_option_context_set_help_enabled (context, FALSE);
|
||||
g_option_context_set_summary (context,
|
||||
_("Monitor KEY for changes and print the changed values.\n"
|
||||
"Monitoring will continue until the process is terminated."));
|
||||
|
||||
g_option_context_set_description (context,
|
||||
_("Arguments:\n"
|
||||
" SCHEMA The id of the schema\n"
|
||||
" KEY The name of the key\n"));
|
||||
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
||||
|
||||
path = NULL;
|
||||
|
||||
error = NULL;
|
||||
if (!g_option_context_parse (context, argc, argv, NULL) || *argc != 3)
|
||||
{
|
||||
gchar *s;
|
||||
s = g_option_context_get_help (context, FALSE, NULL);
|
||||
g_printerr ("%s", s);
|
||||
g_free (s);
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
schema = (*argv)[1];
|
||||
key = (*argv)[2];
|
||||
|
||||
settings = g_settings_new_with_path (schema, path);
|
||||
|
||||
detailed_signal = g_strdup_printf ("changed::%s", key);
|
||||
g_signal_connect (settings, detailed_signal,
|
||||
G_CALLBACK (key_changed), NULL);
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
g_main_loop_run (loop);
|
||||
g_main_loop_unref (loop);
|
||||
|
||||
out:
|
||||
g_option_context_free (context);
|
||||
|
||||
return ret;
|
||||
}
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gboolean ret = 1;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
g_type_init ();
|
||||
|
||||
context = g_option_context_new (N_("SCHEMA KEY [VALUE]"));
|
||||
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
|
||||
g_option_context_set_summary (context, N_("Manipulate GSettings configuration"));
|
||||
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
||||
|
||||
error = NULL;
|
||||
if (!g_option_context_parse (context, &argc, &argv, &error))
|
||||
if (argc < 2)
|
||||
ret = usage (&argc, &argv, FALSE);
|
||||
else if (g_strcmp0 (argv[1], "help") == 0)
|
||||
ret = usage (&argc, &argv, TRUE);
|
||||
else if (g_strcmp0 (argv[1], "get") == 0)
|
||||
ret = handle_get (&argc, &argv);
|
||||
else if (g_strcmp0 (argv[1], "set") == 0)
|
||||
ret = handle_set (&argc, &argv);
|
||||
else if (g_strcmp0 (argv[1], "monitor") == 0)
|
||||
ret = handle_monitor (&argc, &argv);
|
||||
else if (g_strcmp0 (argv[1], "writable") == 0)
|
||||
ret = handle_writable (&argc, &argv);
|
||||
else
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
return 1;
|
||||
g_printerr (_("Unknown command '%s'\n"), argv[1]);
|
||||
ret = usage (&argc, &argv, FALSE);
|
||||
}
|
||||
|
||||
if (do_get + do_set + do_writable + do_monitor != 1)
|
||||
{
|
||||
g_printerr (_("You must specify exactly one of --get, --set, --writable or --monitor\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (do_get || do_writable || do_monitor)
|
||||
{
|
||||
if (argc != 3)
|
||||
{
|
||||
g_printerr (_("You must specify a schema and a key\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
schema = argv[1];
|
||||
key = argv[2];
|
||||
}
|
||||
else if (do_set)
|
||||
{
|
||||
if (argc != 4)
|
||||
{
|
||||
g_printerr (_("You must specify a schema, a key and a value\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
schema = argv[1];
|
||||
key = argv[2];
|
||||
value = argv[3];
|
||||
}
|
||||
|
||||
settings = g_settings_new_with_path (schema, path);
|
||||
|
||||
if (do_get)
|
||||
{
|
||||
v = g_settings_get_value (settings, key);
|
||||
|
||||
g_print ("%s\n", g_variant_print (v, FALSE));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (do_writable)
|
||||
{
|
||||
if (g_settings_is_writable (settings, key))
|
||||
g_print ("true\n");
|
||||
else
|
||||
g_print ("false\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (do_set)
|
||||
{
|
||||
const GVariantType *type;
|
||||
GError *error;
|
||||
|
||||
v = g_settings_get_value (settings, key);
|
||||
type = g_variant_get_type (v);
|
||||
g_variant_unref (v);
|
||||
|
||||
error = NULL;
|
||||
v = g_variant_parse (type, value, NULL, NULL, &error);
|
||||
if (v == NULL)
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!g_settings_set_value (settings, key, v))
|
||||
{
|
||||
g_printerr (_("Key %s is not writable\n"), key);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (do_monitor)
|
||||
{
|
||||
gchar *detailed_signal;
|
||||
GMainLoop *loop;
|
||||
|
||||
detailed_signal = g_strdup_printf ("changed::%s", key);
|
||||
g_signal_connect (settings, detailed_signal,
|
||||
G_CALLBACK (key_changed), NULL);
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
g_main_loop_run (loop);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user