[Xfce4-commits] r26793 - in xfconf/trunk: xfconf-query xfsettingsd

Stephan Arts stephan at xfce.org
Tue Apr 8 19:40:04 CEST 2008


Author: stephan
Date: 2008-04-08 17:40:04 +0000 (Tue, 08 Apr 2008)
New Revision: 26793

Modified:
   xfconf/trunk/xfconf-query/main.c
   xfconf/trunk/xfsettingsd/main.c
Log:
Code-cleanup inside xfconf-query
Update --version string of xfconf-query and xfsettingsd



Modified: xfconf/trunk/xfconf-query/main.c
===================================================================
--- xfconf/trunk/xfconf-query/main.c	2008-04-08 07:52:32 UTC (rev 26792)
+++ xfconf/trunk/xfconf-query/main.c	2008-04-08 17:40:04 UTC (rev 26793)
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #endif
 
+#include <stdlib.h>
 #include <glib.h>
 
 #if defined(GETTEXT_PACKAGE)
@@ -42,7 +43,7 @@
 static gboolean verbose = FALSE;
 static gchar *channel_name = NULL;
 static gchar *property_name = NULL;
-static gchar **value = NULL;
+static gchar **set_value = NULL;
 
 static GOptionEntry entries[] =
 {
@@ -62,7 +63,7 @@
         N_("pick the property"),
         NULL
     },
-    {    "set", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING_ARRAY, &value,
+    {    "set", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING_ARRAY, &set_value,
         N_("set (change the value)"),
         NULL
     },
@@ -88,6 +89,12 @@
         return 1;
     }
 
+    if(version)
+    {
+        g_print("xfconf-query  %s\n", PACKAGE_VERSION);
+        return 0;
+    }
+
     /** Check if the channel is specified */
     if(!channel_name)
     {
@@ -104,117 +111,116 @@
 
     channel = xfconf_channel_new(channel_name);
 
-    /** Check if the value is specified */
-    if(!value)
+    if (xfconf_channel_has_property(channel, property_name))
     {
-        /**
-         * Read the property value
-         */
-        if (xfconf_channel_has_property(channel, property_name))
+        GValue value = {0, };
+        xfconf_channel_get_property(channel, property_name, &value);
+
+        GType prop_type = G_VALUE_TYPE(&value);
+        /** Read value */
+        if(set_value == NULL)
         {
-            GValue tmp_value = {0, };
-            xfconf_channel_get_property(channel, property_name, &tmp_value);
-
-            GType prop_type = G_VALUE_TYPE(&tmp_value);
             switch(prop_type)
             {
                 case G_TYPE_INT:
                     {
-                        gint val = g_value_get_int(&tmp_value);
-                        g_print("%d\n", val);
+                        gint i_val = g_value_get_int(&value);
+                        g_print("%d\n", i_val);
                     }
                     break;
                 case G_TYPE_STRING:
                     {
-                        const gchar *val = g_value_get_string(&tmp_value);
-                        g_print("%s\n", val);
+                        const gchar *str_val = g_value_get_string(&value);
+                        g_print("%s\n", str_val);
                     }
                     break;
                 case G_TYPE_BOOLEAN:
                     {
-                        gboolean val = g_value_get_boolean(&tmp_value);
-                        g_print("%d\n", val);
+                        gboolean b_val = g_value_get_boolean(&value);
+                        g_print("%d\n", b_val);
                     }
                     break;
             }
-            g_value_unset(&tmp_value);
+
         }
+
+        /* Write value */
         else
         {
-            g_print("[ERROR] Property doesn't exist\n");
-            return 1;
-        }
-    }
-    else
-    {
-        if (value[0] != NULL)
-        {
-            if (xfconf_channel_has_property(channel, property_name))
+            if (set_value[0] != NULL)
             {
-                GValue tmp_value = {0, };
-                xfconf_channel_get_property(channel, property_name, &tmp_value);
-
-                GType prop_type = G_VALUE_TYPE(&tmp_value);
-                if (value[1] != NULL)
+                gint i = 0;
+                if (set_value[1] != NULL)
                 {
-                    if(!g_strcasecmp(value[0], "int") && (prop_type == G_TYPE_INT))
+                    i++;
+                    /** Check if the type is the same as specified */
+                    switch(prop_type)
                     {
-                        gint i_val = atoi(value[1]);
-                        xfconf_channel_set_int(channel, property_name, i_val);
-                        return 0;
+                        case G_TYPE_INT:
+                            if (g_strcasecmp(set_value[0], "int"))
+                            {
+                                /** ERROR */
+                                g_critical("Property '%s' is not of type '%s'", set_value[1], set_value[0]);
+                                return 1;
+                            }
+                            break;
+                        case G_TYPE_STRING:
+                            if (g_strcasecmp(set_value[0], "string"))
+                            {
+                                /** ERROR */
+                                g_critical("Property '%s' is not of type '%s'", set_value[1], set_value[0]);
+                                return 1;
+                            }
+                            break;
+                        case G_TYPE_BOOLEAN:
+                            if (g_strcasecmp(set_value[0], "boolean"))
+                            {
+                                /** ERROR */
+                                g_critical("Property '%s' is not of type '%s'", set_value[1], set_value[0]);
+                                return 1;
+                            }
+                            break;
                     }
-                    if(!g_strcasecmp(value[0], "string") && (prop_type == G_TYPE_STRING))
-                    {
-                        xfconf_channel_set_string(channel, property_name, value[1]);
-                        return 0;
+                }
 
-                    }
-                    if(!g_strcasecmp(value[0], "bool") && (prop_type == G_TYPE_BOOLEAN))
-                    {
-                        if(!g_strcasecmp(value[1], "True") || !g_strcasecmp(value[1], "1"))
+                /** Set the value */
+                switch(prop_type)
+                {
+                    case G_TYPE_INT:
+                    case G_TYPE_UINT:
                         {
+                        gint i_val = atoi(set_value[i]);
+                        xfconf_channel_set_int(channel, property_name, i_val);
+                        }
+                        break;
+                    case G_TYPE_STRING:
+                        xfconf_channel_set_string(channel, property_name, set_value[i]);
+                        break;
+                    case G_TYPE_BOOLEAN:
+                        if(!g_strcasecmp(set_value[i], "True") || !g_strcasecmp(set_value[i], "1"))
+                        {
                             xfconf_channel_set_bool(channel, property_name, TRUE);
                             return 0;
                         }
-                        if(!g_strcasecmp(value[1], "False") || !g_strcasecmp(value[1], "0"))
+                        if(!g_strcasecmp(set_value[i], "False") || !g_strcasecmp(set_value[i], "0"))
                         {
                             xfconf_channel_set_bool(channel, property_name, FALSE);
                             return 0;
                         }
-                        return 1;
-
-                    }
-                }
-                else
-                {
-                    switch (prop_type)
-                    {
-                        case G_TYPE_INT:
-                            {
-                            gint i_val = atoi(value[0]);
-                            xfconf_channel_set_int(channel, property_name, i_val);
-                            }
                         break;
-                        case G_TYPE_STRING:
-                            xfconf_channel_set_string(channel, property_name, value[0]);
+                    case G_TYPE_DOUBLE:
                         break;
-                        default:
+                    case G_TYPE_INT64:
+                    case G_TYPE_UINT64:
                         break;
-                    }
-
                 }
-                g_value_unset(&tmp_value);
-                    
             }
             else
             {
-                g_print("value not found");
+                /** Error */
             }
         }
-        else
-        {
-            return 1;
-        }
+        g_value_unset(&value);
     }
 
     return 0;

Modified: xfconf/trunk/xfsettingsd/main.c
===================================================================
--- xfconf/trunk/xfsettingsd/main.c	2008-04-08 07:52:32 UTC (rev 26792)
+++ xfconf/trunk/xfsettingsd/main.c	2008-04-08 17:40:04 UTC (rev 26793)
@@ -124,7 +124,7 @@
 
     if(version)
     {
-        g_print("%s\n", PACKAGE_STRING);
+        g_print("xfsettingsd %s\n", PACKAGE_VERSION);
         return 0;
     }
 



More information about the Xfce4-commits mailing list