gsettings-tool: Add 'range' subcommand

Provides access to the g_settings_get_range() functionality, converting
its return value to something that's reasonable for printing at the
console and potentially parseable.  The format may change.

Bug #631264.
This commit is contained in:
Ryan Lortie
2010-10-04 03:41:03 -04:00
parent 59bdba3cbb
commit c4037230d4
2 changed files with 67 additions and 4 deletions

View File

@@ -9,19 +9,19 @@ __gsettings() {
case "${COMP_CWORD}" in case "${COMP_CWORD}" in
1) 1)
choices=$'help \nlist-schemas\nlist-relocatable-schemas\nlist-keys \nlist-children \nget \nset \nreset \nwritable \nmonitor' choices=$'help \nlist-schemas\nlist-relocatable-schemas\nlist-keys \nlist-children \nget \nrange \nset \nreset \nwritable \nmonitor'
;; ;;
2) 2)
case "${COMP_WORDS[1]}" in case "${COMP_WORDS[1]}" in
help) help)
choices=$'list-schemas\nlist-relocatable-schemas\nlist-keys\nlist-children\nget\nset\nreset\nwritable\nmonitor' choices=$'list-schemas\nlist-relocatable-schemas\nlist-keys\nlist-children\nget\nrange\nset\nreset\nwritable\nmonitor'
;; ;;
list-keys|list-children) list-keys|list-children)
choices="$(gsettings list-schemas)"$'\n'"$(gsettings list-relocatable-schemas | sed -e 's.$.:/.')" choices="$(gsettings list-schemas)"$'\n'"$(gsettings list-relocatable-schemas | sed -e 's.$.:/.')"
;; ;;
get|set|reset|writable|monitor) get|range|set|reset|writable|monitor)
choices="$(gsettings list-schemas | sed -e 's.$. .')"$'\n'"$(gsettings list-relocatable-schemas | sed -e 's.$.:/.')" choices="$(gsettings list-schemas | sed -e 's.$. .')"$'\n'"$(gsettings list-relocatable-schemas | sed -e 's.$.:/.')"
;; ;;
esac esac
@@ -33,7 +33,7 @@ __gsettings() {
choices="$(gsettings list-keys ${COMP_WORDS[2]} 2> /dev/null | sed -e 's.$. .')" choices="$(gsettings list-keys ${COMP_WORDS[2]} 2> /dev/null | sed -e 's.$. .')"
;; ;;
get|reset|writable|monitor) get|range|reset|writable|monitor)
choices="$(gsettings list-keys ${COMP_WORDS[2]} 2> /dev/null)" choices="$(gsettings list-keys ${COMP_WORDS[2]} 2> /dev/null)"
;; ;;
esac esac

View File

@@ -205,6 +205,59 @@ gsettings_list_children (GSettings *settings,
g_strfreev (children); g_strfreev (children);
} }
static void
gsettings_range (GSettings *settings,
const gchar *key,
const gchar *value)
{
GVariant *range, *detail;
const gchar *type;
range = g_settings_get_range (settings, key);
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);
}
static void static void
gsettings_get (GSettings *settings, gsettings_get (GSettings *settings,
const gchar *key, const gchar *key,
@@ -350,6 +403,12 @@ gsettings_help (gboolean requested,
synopsis = "SCHEMA[:PATH] KEY"; synopsis = "SCHEMA[:PATH] KEY";
} }
else if (strcmp (command, "range") == 0)
{
description = "Queries the range of valid values for KEY";
synopsis = "SCHEMA[:PATH] KEY";
}
else if (strcmp (command, "set") == 0) else if (strcmp (command, "set") == 0)
{ {
description = "Sets the value of KEY to VALUE"; description = "Sets the value of KEY to VALUE";
@@ -394,6 +453,7 @@ gsettings_help (gboolean requested,
" list-relocatable-schemas List relocatable schemas\n" " list-relocatable-schemas List relocatable schemas\n"
" list-keys List keys in a schema\n" " list-keys List keys in a schema\n"
" list-children List children of a schema\n" " list-children List children of a schema\n"
" range Queries the range of a key\n"
" get Get the value of a key\n" " get Get the value of a key\n"
" set Set the value of a key\n" " set Set the value of a key\n"
" reset Reset the value of a key\n" " reset Reset the value of a key\n"
@@ -468,6 +528,9 @@ main (int argc, char **argv)
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;
else if (argc == 4 && strcmp (argv[1], "range") == 0)
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;