From c7929285479cb5fa9cf0b65bb5b8b7f920d76434 Mon Sep 17 00:00:00 2001 From: Brian Tarricone Date: Mon, 14 Apr 2008 06:40:40 +0000 Subject: allow xfconf-query to create new channels/properties (Old svn revision: 26835) --- xfconf-query/main.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'xfconf-query') diff --git a/xfconf-query/main.c b/xfconf-query/main.c index 0376366..ff6ee40 100644 --- a/xfconf-query/main.c +++ b/xfconf-query/main.c @@ -44,9 +44,11 @@ static gboolean version = FALSE; static gboolean list = FALSE; static gboolean verbose = FALSE; +static gboolean create = FALSE; static gchar *channel_name = NULL; static gchar *property_name = NULL; static gchar **set_value = NULL; +static gchar *type = NULL; static void xfconf_query_get_propname_size (gpointer key, gpointer value, gpointer user_data) @@ -111,6 +113,14 @@ static GOptionEntry entries[] = N_("Verbose output"), NULL }, + { "create", 'n', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &create, + N_("Create if missing"), + NULL + }, + { "type", 't', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &type, + N_("Specify the property value type"), + NULL + }, { NULL } }; @@ -119,6 +129,7 @@ main(int argc, char **argv) { GError *cli_error = NULL; XfconfChannel *channel = NULL; + gboolean prop_exists; g_type_init(); xfconf_init(NULL); @@ -157,10 +168,13 @@ main(int argc, char **argv) if (property_name) { - if (xfconf_channel_has_property(channel, property_name)) + prop_exists = xfconf_channel_has_property(channel, property_name); + if (prop_exists || (create && type)) { GValue value = {0, }; - xfconf_channel_get_property(channel, property_name, &value); + + if(prop_exists) + xfconf_channel_get_property(channel, property_name, &value); /** Read value */ if(set_value == NULL) @@ -171,6 +185,20 @@ main(int argc, char **argv) /* Write value */ else { + if(!prop_exists) + { + GType gtype = _xfconf_gtype_from_string(type); + + if(G_TYPE_NONE == gtype || G_TYPE_INVALID == gtype) + { + g_printerr(_("Unable to convert \"%s\" to type\n"), + type); + return 1; + } + + g_value_init(&value, gtype); + } + if(_xfconf_gvalue_from_string(&value, set_value[0])) { xfconf_channel_set_property(channel, property_name, &value); -- cgit v1.2.1