[Xfce4-commits] r26835 - xfconf/trunk/xfconf-query
Brian Tarricone
kelnos at xfce.org
Mon Apr 14 08:40:40 CEST 2008
Author: kelnos
Date: 2008-04-14 06:40:40 +0000 (Mon, 14 Apr 2008)
New Revision: 26835
Modified:
xfconf/trunk/xfconf-query/main.c
Log:
allow xfconf-query to create new channels/properties
Modified: xfconf/trunk/xfconf-query/main.c
===================================================================
--- xfconf/trunk/xfconf-query/main.c 2008-04-14 06:00:10 UTC (rev 26834)
+++ xfconf/trunk/xfconf-query/main.c 2008-04-14 06:40:40 UTC (rev 26835)
@@ -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 @@
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 @@
{
GError *cli_error = NULL;
XfconfChannel *channel = NULL;
+ gboolean prop_exists;
g_type_init();
xfconf_init(NULL);
@@ -157,11 +168,14 @@
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 @@
/* 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);
More information about the Xfce4-commits
mailing list