Add IBusConfigService#unset().
authorDaiki Ueno <ueno@unixuser.org>
Thu, 7 Jan 2010 09:06:48 +0000 (18:06 +0900)
committerPeng Huang <shawn.p.huang@gmail.com>
Sat, 9 Jan 2010 10:00:38 +0000 (18:00 +0800)
Add a new method unset() to IBusConfigService, which removes existing entry to
a configuration option.  This also adds ibus.Config.unset() to the Python API
and ibus_config_unset() to the C API.

gconf/config.c
ibus/config.py
src/ibusconfig.c
src/ibusconfig.h
src/ibusconfigservice.c
src/ibusconfigservice.h

index a7fa394a00bc5121f9b4dc7339389b97d094c07d..f03d368a201be2399a3f8be7fe568a63dfb72847 100644 (file)
@@ -20,6 +20,10 @@ static gboolean     ibus_config_gconf_get_value     (IBusConfigService      *con
                                                      const gchar            *name,
                                                      GValue                 *value,
                                                      IBusError             **error);
+static gboolean     ibus_config_gconf_unset     (IBusConfigService      *config,
+                                                 const gchar            *section,
+                                                 const gchar            *name,
+                                                 IBusError             **error);
 
 static GConfValue   *_to_gconf_value                (const GValue           *value);
 static void          _from_gconf_value              (GValue                 *value,
@@ -64,6 +68,7 @@ ibus_config_gconf_class_init (IBusConfigGConfClass *klass)
        IBUS_OBJECT_CLASS (object_class)->destroy = (IBusObjectDestroyFunc) ibus_config_gconf_destroy;
     IBUS_CONFIG_SERVICE_CLASS (object_class)->set_value = ibus_config_gconf_set_value;
     IBUS_CONFIG_SERVICE_CLASS (object_class)->get_value = ibus_config_gconf_get_value;
+    IBUS_CONFIG_SERVICE_CLASS (object_class)->unset = ibus_config_gconf_unset;
 }
 
 static void
@@ -298,6 +303,30 @@ ibus_config_gconf_get_value (IBusConfigService      *config,
     gconf_value_free (gv);
     return TRUE;
 }
+static gboolean
+ibus_config_gconf_unset (IBusConfigService      *config,
+                         const gchar            *section,
+                         const gchar            *name,
+                         IBusError             **error)
+{
+    gchar *key;
+    GError *gerror = NULL;
+
+    key = g_strdup_printf (GCONF_PREFIX"/%s/%s", section, name);
+
+    gconf_client_unset (((IBusConfigGConf *)config)->client, key, &gerror);
+    g_free (key);
+
+    if (gerror != NULL) {
+        if (error) {
+            *error = ibus_error_new_from_text (DBUS_ERROR_FAILED, gerror->message);
+            g_error_free (gerror);
+        }
+        return FALSE;
+    }
+
+    return TRUE;
+}
 
 IBusConfigGConf *
 ibus_config_gconf_new (IBusConnection *connection)
index f3410b86654c104c0657c90d491139efe491a81a..29632dd776448da876439ba7c73286568e9f06e3 100644 (file)
@@ -46,6 +46,9 @@ class ConfigBase(object.Object):
     def set_value(self, section, name, value):
         pass
 
+    def unset(self, section, name):
+        pass
+
     def value_changed(self, section, name, value):
         self.__proxy.ValueChanged(section, name, value)
 
@@ -62,6 +65,9 @@ class ConfigProxy(interface.IConfig):
     def SetValue(self, section, name, value):
         return self.__config.set_value(section, name, value)
 
+    def Unset(self, section, name):
+        return self.__config.unset(section, name)
+
     def Destroy(self):
         self.__config.destroy()
 
@@ -141,3 +147,8 @@ class Config(object.Object):
     def set_list(self, section, name, value, signature):
         return self.set_value(section, name, dbus.Array(value, signature=signature))
 
+    def unset(self, section, name):
+        try:
+            return self.__config.Unset(section, name)
+        except:
+            return
index 99db5b540f7ea45b0f11f33a9f41c741b3068018..a3c30133b8ba938fa3b9a14c4cfe9659206d1271 100644 (file)
@@ -281,3 +281,23 @@ ibus_config_set_value (IBusConfig   *config,
     g_assert (retval);
     return TRUE;
 }
+
+gboolean
+ibus_config_unset (IBusConfig   *config,
+                   const gchar  *section,
+                   const gchar  *name)
+{
+    g_assert (IBUS_IS_CONFIG (config));
+    g_assert (section != NULL);
+    g_assert (name != NULL);
+
+    gboolean retval;
+
+    retval = ibus_proxy_call ((IBusProxy *) config,
+                              "Unset",
+                              G_TYPE_STRING, &section,
+                              G_TYPE_STRING, &name,
+                              G_TYPE_INVALID);
+    g_assert (retval);
+    return TRUE;
+}
index 6ed9f8edba0caad8a29c122556b1735492f67894..5981b2334892e8cbc8dca64b70ed8b9863315a0f 100644 (file)
@@ -120,6 +120,20 @@ gboolean         ibus_config_set_value      (IBusConfig         *config,
                                              const gchar        *section,
                                              const gchar        *name,
                                              const GValue       *value);
+
+/**
+ * ibus_config_unset:
+ * @config: An IBusConfig
+ * @section: Section name of the configuration option.
+ * @name: Name of the configure option its self.
+ * @returns: TRUE if succeed; FALSE otherwise.
+ *
+ * Remove an entry of a configuration option.
+ * @see_also: ibus_config_get_value.
+ */
+gboolean         ibus_config_unset      (IBusConfig         *config,
+                                         const gchar        *section,
+                                         const gchar        *name);
 G_END_DECLS
 #endif
 
index 9eb6bfc3c2f7408da6b420b62b1002d805ba011b..a8f704185d12fc81a540dc7136179dd2fd9ea00b 100644 (file)
@@ -58,6 +58,10 @@ static gboolean ibus_config_service_get_value       (IBusConfigService      *con
                                                      const gchar            *name,
                                                      GValue                 *value,
                                                      IBusError             **error);
+static gboolean ibus_config_service_unset       (IBusConfigService      *config,
+                                                 const gchar            *section,
+                                                 const gchar            *name,
+                                                 IBusError             **error);
 
 static IBusServiceClass  *parent_class = NULL;
 
@@ -118,6 +122,7 @@ ibus_config_service_class_init (IBusConfigServiceClass *klass)
 
     klass->set_value = ibus_config_service_set_value;
     klass->get_value = ibus_config_service_get_value;
+    klass->unset = ibus_config_service_unset;
 
     /* install properties */
     /**
@@ -260,6 +265,33 @@ ibus_config_service_ibus_message (IBusConfigService     *config,
             g_value_unset (&value);
         }
     }
+    else if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "Unset")) {
+        gchar *section;
+        gchar *name;
+        IBusError *error = NULL;
+        gboolean retval;
+
+        retval = ibus_message_get_args (message,
+                                        &error,
+                                        G_TYPE_STRING, &section,
+                                        G_TYPE_STRING, &name,
+                                        G_TYPE_INVALID);
+        if (!retval) {
+            reply = ibus_message_new_error_printf (message,
+                                                   DBUS_ERROR_INVALID_ARGS,
+                                                   "Can not parse arguments 1 of Unset");
+            ibus_error_free (error);
+        }
+        else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->unset (config, section, name, &error)) {
+            reply = ibus_message_new_error (message,
+                                            error->name,
+                                            error->message);
+            ibus_error_free (error);
+        }
+        else {
+            reply = ibus_message_new_method_return (message);
+        }
+    }
 
     if (reply) {
         ibus_connection_send (connection, reply);
@@ -300,6 +332,20 @@ ibus_config_service_get_value (IBusConfigService *config,
     return FALSE;
 }
 
+static gboolean
+ibus_config_service_unset (IBusConfigService *config,
+                           const gchar       *section,
+                           const gchar       *name,
+                           IBusError        **error)
+{
+    if (error) {
+        *error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
+                                             "Can not unset [%s, %s]",
+                                             section, name);
+    }
+    return FALSE;
+}
+
 void
 ibus_config_service_value_changed (IBusConfigService  *config,
                                    const gchar        *section,
index 9ef17db6b878784af9e77b2167168ef7b0c71f02..c37939020d2b7acca5f43f731663d1a858a34357 100644 (file)
  *        <para>Get value of a configuration option.
  *        </para>
  *     </listitem>
+ *     <listitem>
+ *         <para>gboolean unset(IBusConfigService *config, const gchar *section, const gchar *name,
+ *             IBusError **error)
+ *         </para>
+ *         <variablelist>
+ *             <varlistentry>
+ *                 <term>config:</term>
+ *                 <listitem>A configure service</listitem>
+ *             </varlistentry>
+ *             <varlistentry>
+ *                 <term>section:</term>
+ *                 <listitem>Section name of the configuration option.</listitem>
+ *             </varlistentry>
+ *             <varlistentry>
+ *                 <term>name:</term>
+ *                 <listitem>Name of the configuration option.</listitem>
+ *             </varlistentry>
+ *             <varlistentry>
+ *                 <term>error:</term>
+ *                 <listitem>Error outputs here.</listitem>
+ *             </varlistentry>
+ *             <varlistentry>
+ *                 <term>Returns:</term>
+ *                 <listitem>TRUE if succeed; FALSE otherwise.</listitem>
+ *             </varlistentry>
+ *         </variablelist>
+ *         <para>Remove an entry to a configuration option.
+ *         </para>
+ *     </listitem>
  * </itemizedlist>
  */
 #ifndef __IBUS_CONFIG_SERVICE_H_
@@ -149,6 +178,10 @@ struct _IBusConfigServiceClass {
                                const gchar          *name,
                                GValue               *value,
                                IBusError           **error);
+    gboolean    (* unset) (IBusConfigService    *config,
+                           const gchar          *section,
+                           const gchar          *name,
+                           IBusError           **error);
 
     /*< private >*/
     /* padding */