Use va_list in IBusEngineDesc and IBusComponent for back compatibility.
authorPeng Huang <shawn.p.huang@gmail.com>
Tue, 19 Oct 2010 01:26:08 +0000 (10:26 +0900)
committerPeng Huang <shawn.p.huang@gmail.com>
Wed, 3 Nov 2010 01:54:58 +0000 (10:54 +0900)
Provided by fujiwarat <takao.fujiwara1@gmail.com>

Conflicts:

bus/engineproxy.c
bus/factoryproxy.c
bus/ibusimpl.c
src/ibuscomponent.c
src/ibusenginedesc.c
src/test-bus.c
src/tests/ibus-global-engine.c

bus/engineproxy.c
bus/factoryproxy.c
bus/ibusimpl.c
bus/registry.c
ibus/component.py
ibus/enginedesc.py
src/ibuscomponent.c
src/ibuscomponent.h
src/ibusenginedesc.c
src/ibusenginedesc.h
src/tests/ibus-global-engine.c

index 9529c99..cd21a0b 100644 (file)
@@ -491,8 +491,9 @@ bus_engine_proxy_new (const gchar    *path,
 
     engine->desc = desc;
     g_object_ref_sink (desc);
-    if (desc->layout != NULL && desc->layout[0] != '\0') {
-        engine->keymap = ibus_keymap_get (desc->layout);
+    const gchar *layout = ibus_engine_desc_get_layout (desc);
+    if (layout != NULL && layout[0] != '\0') {
+        engine->keymap = ibus_keymap_get (layout);
     }
 
     if (engine->keymap == NULL) {
index 9de44f5..2445399 100644 (file)
@@ -88,7 +88,8 @@ bus_factory_proxy_new (IBusComponent *component,
     GList *p;
 
     if (connection == NULL) {
-        connection = bus_dbus_impl_get_connection_by_name (BUS_DEFAULT_DBUS, component->name);
+        const gchar *name = ibus_component_get_name (component);
+        connection = bus_dbus_impl_get_connection_by_name (BUS_DEFAULT_DBUS, name);
     }
 
     if (connection == NULL) {
@@ -161,7 +162,7 @@ bus_factory_proxy_create_engine (BusFactoryProxy *factory,
     GError *error = NULL;
     GVariant *retval = g_dbus_proxy_call_sync ((GDBusProxy *)factory,
                                                "CreateEngine",
-                                               g_variant_new ("(s)", desc->name),
+                                               g_variant_new ("(s)", ibus_engine_desc_get_name (desc)),
                                                G_DBUS_CALL_FLAGS_NONE,
                                                -1, NULL, &error);
     if (retval == NULL) {
index 5b1646b..da358c7 100644 (file)
@@ -401,7 +401,8 @@ static gint
 _engine_desc_cmp (IBusEngineDesc *desc1,
                   IBusEngineDesc *desc2)
 {
-    return - ((gint) desc1->rank) + ((gint) desc2->rank);
+    return - ((gint) ibus_engine_desc_get_rank (desc1)) +
+              ((gint) ibus_engine_desc_get_rank (desc2));
 }
 
 static void
@@ -448,8 +449,8 @@ bus_ibus_impl_set_default_preload_engines (BusIBusImpl *ibus)
     for (list = engines; list != NULL; list = list->next) {
         IBusEngineDesc *desc = (IBusEngineDesc *)list->data;
         /* ignore engines with rank <== 0 */
-        if (desc->rank > 0)
-            g_variant_builder_add (&builder, "s", desc->name);
+        if (ibus_engine_desc_get_rank (desc) > 0)
+            g_variant_builder_add (&builder, "s", ibus_engine_desc_get_name (desc));
     }
     ibus_config_set_value (ibus->config,
                     "general", "preload_engines", g_variant_builder_end (&builder));
@@ -831,14 +832,14 @@ _find_engine_desc_by_name(BusIBusImpl *ibus,
     /* find engine in registered engine list */
     for (p = ibus->register_engine_list; p != NULL; p = p->next) {
         engine_desc = (IBusEngineDesc *)p->data;
-        if (g_strcmp0 (engine_desc->name, engine_name) == 0)
+        if (g_strcmp0 (ibus_engine_desc_get_name (engine_desc), engine_name) == 0)
             return engine_desc;
     }
 
     /* find engine in preload engine list */
     for (p = ibus->engine_list; p != NULL; p = p->next) {
         engine_desc = (IBusEngineDesc *)p->data;
-        if (g_strcmp0 (engine_desc->name, engine_name) == 0)
+        if (g_strcmp0 (ibus_engine_desc_get_name (engine_desc), engine_name) == 0)
             return engine_desc;
     }
 
@@ -985,7 +986,8 @@ bus_ibus_impl_set_global_engine (BusIBusImpl    *ibus,
     ibus->global_previous_engine_name = NULL;
     if (ibus->global_engine) {
         /* Save the current global engine's name as previous engine. */
-        ibus->global_previous_engine_name = g_strdup (bus_engine_proxy_get_desc (ibus->global_engine)->name);
+        const gchar *name = ibus_engine_desc_get_name (bus_engine_proxy_get_desc (ibus->global_engine));
+        ibus->global_previous_engine_name = g_strdup (name);
 
         ibus_proxy_destroy ((IBusProxy *)ibus->global_engine);
         /* global_engine should be NULL */
@@ -1028,8 +1030,9 @@ bus_ibus_impl_set_context_engine (BusIBusImpl     *ibus,
   if (!ibus->use_global_engine) {
       BusEngineProxy *previous_engine = bus_input_context_get_engine (context);
       if (previous_engine) {
+          const gchar *name = ibus_engine_desc_get_name (bus_engine_proxy_get_desc (previous_engine));
           g_object_set_data_full (G_OBJECT (context), "previous-engine-name",
-                                  g_strdup (bus_engine_proxy_get_desc (previous_engine)->name),
+                                  g_strdup (name),
                                   g_free);
       }
   }
@@ -1458,7 +1461,7 @@ _ibus_set_global_engine (BusIBusImpl           *ibus,
     const gchar *old_engine_name = NULL;
 
     if (ibus->global_engine) {
-        old_engine_name = bus_engine_proxy_get_desc (ibus->global_engine)->name;
+        old_engine_name = ibus_engine_desc_get_name (bus_engine_proxy_get_desc (ibus->global_engine));
     }
 
     if (g_strcmp0 (new_engine_name, old_engine_name) == 0) {
@@ -1769,9 +1772,10 @@ bus_ibus_impl_save_global_engine_name_to_config (BusIBusImpl *ibus)
     g_return_if_fail (IBUS_IS_CONFIG (ibus->config));
 
     if (ibus->use_global_engine && ibus->global_engine) {
+        IBusEngineDesc *desc = bus_engine_proxy_get_desc (ibus->global_engine);
         ibus_config_set_value (ibus->config,
                         "general", "global_engine",
-                        g_variant_new ("s", bus_engine_proxy_get_desc (ibus->global_engine)->name));
+                        g_variant_new ("s", ibus_engine_desc_get_name (desc)));
     }
 }
 
@@ -1806,6 +1810,7 @@ bus_ibus_impl_save_global_previous_engine_name_to_config (BusIBusImpl *ibus)
 static void
 _add_engine_hotkey (IBusEngineDesc *engine, BusIBusImpl *ibus)
 {
+    const gchar *hotkeys;
     gchar **hotkey_list;
     gchar **p;
     gchar *hotkey;
@@ -1815,11 +1820,17 @@ _add_engine_hotkey (IBusEngineDesc *engine, BusIBusImpl *ibus)
     guint keyval;
     guint modifiers;
 
-    if (!engine || !engine->hotkeys || !*engine->hotkeys) {
+    if (!engine) {
+        return;
+    }
+
+    hotkeys = ibus_engine_desc_get_hotkeys (engine);
+
+    if (!hotkeys || !*hotkeys) {
         return;
     }
 
-    hotkey_list = g_strsplit_set (engine->hotkeys, ";,", 0);
+    hotkey_list = g_strsplit_set (hotkeys, ";,", 0);
 
     for (p = hotkey_list; p && *p; ++p) {
         hotkey = g_strstrip (*p);
index 8532c5d..cceaa02 100644 (file)
@@ -117,7 +117,9 @@ bus_registry_init (BusRegistry *registry)
 
         for (p1 = comp->engines; p1 != NULL; p1 = p1->next) {
             IBusEngineDesc *desc = (IBusEngineDesc *)p1->data;
-            g_hash_table_insert (registry->engine_table, desc->name, desc);
+            g_hash_table_insert (registry->engine_table,
+                                 (gpointer) ibus_engine_desc_get_name (desc),
+                                 desc);
             g_object_set_data ((GObject *)desc, "component", comp);
         }
     }
@@ -403,7 +405,7 @@ _component_is_name (IBusComponent *component,
     g_assert (IBUS_IS_COMPONENT (component));
     g_assert (name);
 
-    return g_strcmp0 (component->name, name);
+    return g_strcmp0 (ibus_component_get_name (component), name);
 }
 
 IBusComponent *
@@ -460,7 +462,7 @@ bus_registry_get_engines_by_language (BusRegistry *registry,
 
     for (p2 = p1; p2 != NULL; p2 = p2->next) {
         IBusEngineDesc *desc = (IBusEngineDesc *) p2->data;
-        if (strncmp (desc->language, language, n) == 0) {
+        if (strncmp (ibus_engine_desc_get_language (desc), language, n) == 0) {
             engines = g_list_append (engines, desc);
         }
     }
index a662b70..12f593d 100644 (file)
@@ -106,6 +106,8 @@ class Component(Serializable):
         struct.append (dbus.String(self.__textdomain))
         struct.append (dbus.Array(map(serialize_object,self.__observed_paths), signature="v"))
         struct.append (dbus.Array(map(serialize_object,self.__engines), signature="v"))
+        # New properties of Component will use dict for serialize
+        struct.append(dbus.Array({}, signature=None))
 
     def deserialize(self, struct):
         super(Component, self).deserialize(struct)
@@ -121,6 +123,8 @@ class Component(Serializable):
 
         self.__observed_paths = map(deserialize_object, struct.pop(0))
         self.__engines = map(deserialize_object, struct.pop(0))
+        # New properties of Component will use dict for serialize
+        #value = struct.pop(0)
 
 def test():
     text = Component("Hello", "", "", "", "", "", "", "")
index d8ba28b..e8a8982 100644 (file)
@@ -41,8 +41,8 @@ class EngineDesc(Serializable):
         self.__author = author
         self.__icon = icon
         self.__layout = layout
-        self.__hotkeys = hotkeys
         self.__rank = rank
+        self.__hotkeys = hotkeys
 
     def get_name(self):
         return self.__name
@@ -68,12 +68,12 @@ class EngineDesc(Serializable):
     def get_layout(self):
         return self.__layout
 
-    def get_hotkeys(self):
-        return self.__hotkeys
-
     def get_rank(self):
         return self.__rank
 
+    def get_hotkeys(self):
+        return self.__hotkeys
+
     name        = property(get_name)
     longname    = property(get_longname)
     description = property(get_description)
@@ -82,8 +82,8 @@ class EngineDesc(Serializable):
     author      = property(get_author)
     icon        = property(get_icon)
     layout      = property(get_layout)
-    hotkeys     = property(get_hotkeys)
     rank        = property(get_rank)
+    hotkeys     = property(get_hotkeys)
 
     def serialize(self, struct):
         super(EngineDesc, self).serialize(struct)
@@ -95,8 +95,10 @@ class EngineDesc(Serializable):
         struct.append(dbus.String(self.__author))
         struct.append(dbus.String(self.__icon))
         struct.append(dbus.String(self.__layout))
-        struct.append(dbus.String(self.__hotkeys))
         struct.append(dbus.UInt32(self.__rank))
+        struct.append(dbus.String(self.__hotkeys))
+        # New properties of EngineDesc will use dict for serialize
+        struct.append(dbus.Array({}, signature=None))
 
     def deserialize(self, struct):
         super(EngineDesc, self).deserialize(struct)
@@ -108,8 +110,10 @@ class EngineDesc(Serializable):
         self.__author = struct.pop(0)
         self.__icon = struct.pop(0)
         self.__layout = struct.pop(0)
-        self.__hotkeys = struct.pop(0)
         self.__rank = struct.pop(0)
+        self.__hotkeys = struct.pop(0)
+        # New properties of EngineDesc will use dict for serialize
+        #value = struct.pop(0)
 
 def test():
     engine = EngineDesc("Hello", "", "", "", "", "", "", "", "")
index 47a0276..14ff241 100644 (file)
@@ -26,9 +26,30 @@ enum {
     LAST_SIGNAL,
 };
 
+enum {
+    PROP_0 = 0,
+    PROP_NAME,
+    PROP_DESCRIPTION,
+    PROP_VERSION,
+    PROP_LICENSE,
+    PROP_AUTHOR,
+    PROP_HOMEPAGE,
+    PROP_EXEC,
+    PROP_TEXTDOMAIN,
+};
+
 
 /* IBusComponentPriv */
 struct _IBusComponentPrivate {
+    gchar *name;
+    gchar *description;
+    gchar *version;
+    gchar *license;
+    gchar *author;
+    gchar *homepage;
+    gchar *exec;
+    gchar *textdomain;
+
     // TRUE if the component started in the verbose mode.
     gboolean verbose;
     // TRUE if the component needs to be restarted when it dies.
@@ -41,6 +62,14 @@ struct _IBusComponentPrivate {
 // static guint            _signals[LAST_SIGNAL] = { 0 };
 
 /* functions prototype */
+static void         ibus_component_set_property (IBusComponent          *component,
+                                                 guint                   prop_id,
+                                                 const GValue           *value,
+                                                 GParamSpec             *pspec);
+static void         ibus_component_get_property (IBusComponent          *component,
+                                                 guint                   prop_id,
+                                                 GValue                 *value,
+                                                 GParamSpec             *pspec);
 static void         ibus_component_destroy      (IBusComponent          *component);
 static gboolean     ibus_component_serialize    (IBusComponent          *component,
                                                  GVariantBuilder        *builder);
@@ -65,16 +94,124 @@ G_DEFINE_TYPE (IBusComponent, ibus_component, IBUS_TYPE_SERIALIZABLE)
 static void
 ibus_component_class_init (IBusComponentClass *class)
 {
+    GObjectClass *gobject_class = G_OBJECT_CLASS (class);
     IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class);
     IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class);
 
     g_type_class_add_private (class, sizeof (IBusComponentPrivate));
 
+    gobject_class->set_property = (GObjectSetPropertyFunc) ibus_component_set_property;
+    gobject_class->get_property = (GObjectGetPropertyFunc) ibus_component_get_property;
     object_class->destroy = (IBusObjectDestroyFunc) ibus_component_destroy;
 
     serializable_class->serialize   = (IBusSerializableSerializeFunc) ibus_component_serialize;
     serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_component_deserialize;
     serializable_class->copy        = (IBusSerializableCopyFunc) ibus_component_copy;
+
+    /* install properties */
+    /**
+     * IBusComponent:name:
+     *
+     * The name of component
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_NAME,
+                    g_param_spec_string ("name",
+                        "component name",
+                        "The name of component",
+                        NULL,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusComponent:description:
+     *
+     * The description of component
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_DESCRIPTION,
+                    g_param_spec_string ("description",
+                        "component description",
+                        "The description of component",
+                        NULL,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusComponent:version:
+     *
+     * The version of component
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_VERSION,
+                    g_param_spec_string ("version",
+                        "component version",
+                        "The version of component",
+                        NULL,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusComponent:license:
+     *
+     * The license of component
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_LICENSE,
+                    g_param_spec_string ("license",
+                        "component license",
+                        "The license of component",
+                        NULL,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusComponent:author:
+     *
+     * The author of component
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_AUTHOR,
+                    g_param_spec_string ("author",
+                        "component author",
+                        "The author of component",
+                        NULL,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusComponent:homepage:
+     *
+     * The homepage of component
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_HOMEPAGE,
+                    g_param_spec_string ("homepage",
+                        "component homepage",
+                        "The homepage of component",
+                        NULL,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusComponent:exec:
+     *
+     * The exec path of component
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_EXEC,
+                    g_param_spec_string ("exec",
+                        "component exec",
+                        "The exec path of component",
+                        NULL,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusComponent:textdomain:
+     *
+     * The textdomain of component
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_TEXTDOMAIN,
+                    g_param_spec_string ("textdomain",
+                        "component textdomain",
+                        "The textdomain path of component",
+                        NULL,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 }
 
 
@@ -82,8 +219,23 @@ static void
 ibus_component_init (IBusComponent *component)
 {
     component->priv = IBUS_COMPONENT_GET_PRIVATE (component);
+
+    component->engines = NULL;
+    component->observed_paths = NULL;
+    component->pid = 0;
+    component->child_source_id = 0;
+
+    component->priv->name = NULL;
+    component->priv->description = NULL;
+    component->priv->version = NULL;
+    component->priv->license = NULL;
+    component->priv->author = NULL;
+    component->priv->homepage = NULL;
+    component->priv->exec = NULL;
+    component->priv->textdomain = NULL;
     component->priv->verbose = FALSE;
     component->priv->restart = FALSE;
+
 }
 
 static void
@@ -91,23 +243,23 @@ ibus_component_destroy (IBusComponent *component)
 {
     GList *p;
 
-    g_free (component->name);
-    g_free (component->description);
-    g_free (component->version);
-    g_free (component->license);
-    g_free (component->author);
-    g_free (component->homepage);
-    g_free (component->exec);
-    g_free (component->textdomain);
-
-    component->name = NULL;
-    component->description = NULL;
-    component->version = NULL;
-    component->license = NULL;
-    component->author = NULL;
-    component->homepage = NULL;
-    component->exec = NULL;
-    component->textdomain = NULL;
+    g_free (component->priv->name);
+    g_free (component->priv->description);
+    g_free (component->priv->version);
+    g_free (component->priv->license);
+    g_free (component->priv->author);
+    g_free (component->priv->homepage);
+    g_free (component->priv->exec);
+    g_free (component->priv->textdomain);
+
+    component->priv->name = NULL;
+    component->priv->description = NULL;
+    component->priv->version = NULL;
+    component->priv->license = NULL;
+    component->priv->author = NULL;
+    component->priv->homepage = NULL;
+    component->priv->exec = NULL;
+    component->priv->textdomain = NULL;
 
     g_list_foreach (component->observed_paths, (GFunc)g_object_unref, NULL);
     g_list_free (component->observed_paths);
@@ -135,6 +287,86 @@ ibus_component_destroy (IBusComponent *component)
     IBUS_OBJECT_CLASS (ibus_component_parent_class)->destroy (IBUS_OBJECT (component));
 }
 
+static void
+ibus_component_set_property (IBusComponent *component,
+                             guint          prop_id,
+                             const GValue  *value,
+                             GParamSpec    *pspec)
+{
+    switch (prop_id) {
+    case PROP_NAME:
+        g_assert (component->priv->name == NULL);
+        component->priv->name = g_value_dup_string (value);
+        break;
+    case PROP_DESCRIPTION:
+        g_assert (component->priv->description == NULL);
+        component->priv->description = g_value_dup_string (value);
+        break;
+    case PROP_VERSION:
+        g_assert (component->priv->version == NULL);
+        component->priv->version = g_value_dup_string (value);
+        break;
+    case PROP_LICENSE:
+        g_assert (component->priv->license == NULL);
+        component->priv->license = g_value_dup_string (value);
+        break;
+    case PROP_AUTHOR:
+        g_assert (component->priv->author == NULL);
+        component->priv->author = g_value_dup_string (value);
+        break;
+    case PROP_HOMEPAGE:
+        g_assert (component->priv->homepage == NULL);
+        component->priv->homepage = g_value_dup_string (value);
+        break;
+    case PROP_EXEC:
+        g_assert (component->priv->exec == NULL);
+        component->priv->exec = g_value_dup_string (value);
+        break;
+    case PROP_TEXTDOMAIN:
+        g_assert (component->priv->textdomain == NULL);
+        component->priv->textdomain = g_value_dup_string (value);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (component, prop_id, pspec);
+    }
+}
+
+static void
+ibus_component_get_property (IBusComponent *component,
+                             guint          prop_id,
+                             GValue        *value,
+                             GParamSpec    *pspec)
+{
+    switch (prop_id) {
+    case PROP_NAME:
+        g_value_set_string (value, ibus_component_get_name (component));
+        break;
+    case PROP_DESCRIPTION:
+        g_value_set_string (value, ibus_component_get_description (component));
+        break;
+    case PROP_VERSION:
+        g_value_set_string (value, ibus_component_get_version (component));
+        break;
+    case PROP_LICENSE:
+        g_value_set_string (value, ibus_component_get_license (component));
+        break;
+    case PROP_AUTHOR:
+        g_value_set_string (value, ibus_component_get_author (component));
+        break;
+    case PROP_HOMEPAGE:
+        g_value_set_string (value, ibus_component_get_homepage (component));
+        break;
+    case PROP_EXEC:
+        g_value_set_string (value, ibus_component_get_exec (component));
+        break;
+    case PROP_TEXTDOMAIN:
+        g_value_set_string (value, ibus_component_get_textdomain (component));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (component, prop_id, pspec);
+    }
+}
+
 static gboolean
 ibus_component_serialize (IBusComponent   *component,
                           GVariantBuilder *builder)
@@ -144,14 +376,14 @@ ibus_component_serialize (IBusComponent   *component,
     retval = IBUS_SERIALIZABLE_CLASS (ibus_component_parent_class)->serialize ((IBusSerializable *)component, builder);
     g_return_val_if_fail (retval, FALSE);
 
-    g_variant_builder_add (builder, "s", component->name);
-    g_variant_builder_add (builder, "s", component->description);
-    g_variant_builder_add (builder, "s", component->version);
-    g_variant_builder_add (builder, "s", component->license);
-    g_variant_builder_add (builder, "s", component->author);
-    g_variant_builder_add (builder, "s", component->homepage);
-    g_variant_builder_add (builder, "s", component->exec);
-    g_variant_builder_add (builder, "s", component->textdomain);
+    g_variant_builder_add (builder, "s", component->priv->name);
+    g_variant_builder_add (builder, "s", component->priv->description);
+    g_variant_builder_add (builder, "s", component->priv->version);
+    g_variant_builder_add (builder, "s", component->priv->license);
+    g_variant_builder_add (builder, "s", component->priv->author);
+    g_variant_builder_add (builder, "s", component->priv->homepage);
+    g_variant_builder_add (builder, "s", component->priv->exec);
+    g_variant_builder_add (builder, "s", component->priv->textdomain);
 
     GList *p;
     GVariantBuilder *array;
@@ -162,7 +394,7 @@ ibus_component_serialize (IBusComponent   *component,
     }
     g_variant_builder_add (builder, "av", array);
 
-    /* serialize engine desc */
+    /* serialize engine desc list */
     array = g_variant_builder_new (G_VARIANT_TYPE ("av"));
     for (p = component->engines; p != NULL; p = p->next) {
         g_variant_builder_add (array, "v", ibus_serializable_serialize ((IBusSerializable *)p->data));
@@ -181,14 +413,14 @@ ibus_component_deserialize (IBusComponent   *component,
     retval = IBUS_SERIALIZABLE_CLASS (ibus_component_parent_class)->deserialize ((IBusSerializable *)component, variant);
     g_return_val_if_fail (retval, 0);
 
-    g_variant_get_child (variant, retval++, "s", &component->name);
-    g_variant_get_child (variant, retval++, "s", &component->description);
-    g_variant_get_child (variant, retval++, "s", &component->version);
-    g_variant_get_child (variant, retval++, "s", &component->license);
-    g_variant_get_child (variant, retval++, "s", &component->author);
-    g_variant_get_child (variant, retval++, "s", &component->homepage);
-    g_variant_get_child (variant, retval++, "s", &component->exec);
-    g_variant_get_child (variant, retval++, "s", &component->textdomain);
+    g_variant_get_child (variant, retval++, "s", &component->priv->name);
+    g_variant_get_child (variant, retval++, "s", &component->priv->description);
+    g_variant_get_child (variant, retval++, "s", &component->priv->version);
+    g_variant_get_child (variant, retval++, "s", &component->priv->license);
+    g_variant_get_child (variant, retval++, "s", &component->priv->author);
+    g_variant_get_child (variant, retval++, "s", &component->priv->homepage);
+    g_variant_get_child (variant, retval++, "s", &component->priv->exec);
+    g_variant_get_child (variant, retval++, "s", &component->priv->textdomain);
 
     GVariant *var;
     GVariantIter *iter = NULL;
@@ -219,15 +451,14 @@ ibus_component_copy (IBusComponent       *dest,
                                  (IBusSerializable *)src);
     g_return_val_if_fail (retval, FALSE);
 
-
-    dest->name          = g_strdup (src->name);
-    dest->description   = g_strdup (src->description);
-    dest->version       = g_strdup (src->version);
-    dest->license       = g_strdup (src->license);
-    dest->author        = g_strdup (src->author);
-    dest->homepage      = g_strdup (src->homepage);
-    dest->exec          = g_strdup (src->exec);
-    dest->textdomain    = g_strdup (src->textdomain);
+    dest->priv->name          = g_strdup (src->priv->name);
+    dest->priv->description   = g_strdup (src->priv->description);
+    dest->priv->version       = g_strdup (src->priv->version);
+    dest->priv->license       = g_strdup (src->priv->license);
+    dest->priv->author        = g_strdup (src->priv->author);
+    dest->priv->homepage      = g_strdup (src->priv->homepage);
+    dest->priv->exec          = g_strdup (src->priv->exec);
+    dest->priv->textdomain    = g_strdup (src->priv->textdomain);
 
     dest->observed_paths = g_list_copy (src->observed_paths);
     g_list_foreach (dest->observed_paths, (GFunc) g_object_ref, NULL);
@@ -261,8 +492,8 @@ ibus_component_output (IBusComponent *component,
 #define OUTPUT_ENTRY(field, element)                                        \
     {                                                                       \
         gchar *escape_text =                                                \
-            g_markup_escape_text (component->field ?                        \
-                                    component->field : "", -1);             \
+            g_markup_escape_text (component->priv->field ?                  \
+                                  component->priv->field : "", -1);         \
         g_string_append_indent (output, indent + 1);                        \
         g_string_append_printf (output, "<"element">%s</"element">\n",      \
                                 escape_text);                               \
@@ -326,8 +557,8 @@ ibus_component_output_engines (IBusComponent  *component,
 
 static gboolean
 ibus_component_parse_xml_node (IBusComponent   *component,
-                              XMLNode        *node,
-                              gboolean        access_fs)
+                              XMLNode          *node,
+                              gboolean          access_fs)
 {
     g_assert (component);
     g_assert (node);
@@ -340,13 +571,13 @@ ibus_component_parse_xml_node (IBusComponent   *component,
     for (p = node->sub_nodes; p != NULL; p = p->next) {
         XMLNode *sub_node = (XMLNode *)p->data;
 
-#define PARSE_ENTRY(field_name, element_name)                   \
-        if (g_strcmp0 (sub_node->name, element_name) == 0) {    \
-            if (component->field_name != NULL) {                \
-                g_free (component->field_name);                 \
-            }                                                   \
-            component->field_name = g_strdup (sub_node->text);  \
-            continue;                                           \
+#define PARSE_ENTRY(field_name, element_name)                           \
+        if (g_strcmp0 (sub_node->name, element_name) == 0) {            \
+            if (component->priv->field_name != NULL) {                  \
+                g_free (component->priv->field_name);                   \
+            }                                                           \
+            component->priv->field_name = g_strdup (sub_node->text);    \
+            continue;                                                   \
         }
 #define PARSE_ENTRY_1(name) PARSE_ENTRY (name, #name)
         PARSE_ENTRY_1 (name);
@@ -455,6 +686,23 @@ ibus_component_parse_observed_paths (IBusComponent    *component,
     }
 }
 
+#define IBUS_COMPONENT_GET_PROPERTY(property, return_type)  \
+return_type                                                 \
+ibus_component_get_ ## property (IBusComponent *component)  \
+{                                                           \
+    return component->priv->property;                       \
+}
+
+IBUS_COMPONENT_GET_PROPERTY (name, const gchar *)
+IBUS_COMPONENT_GET_PROPERTY (description, const gchar *)
+IBUS_COMPONENT_GET_PROPERTY (version, const gchar *)
+IBUS_COMPONENT_GET_PROPERTY (license, const gchar *)
+IBUS_COMPONENT_GET_PROPERTY (author, const gchar *)
+IBUS_COMPONENT_GET_PROPERTY (homepage, const gchar *)
+IBUS_COMPONENT_GET_PROPERTY (exec, const gchar *)
+IBUS_COMPONENT_GET_PROPERTY (textdomain, const gchar *)
+#undef IBUS_COMPONENT_GET_PROPERTY
+
 IBusComponent *
 ibus_component_new (const gchar *name,
                     const gchar *description,
@@ -465,18 +713,37 @@ ibus_component_new (const gchar *name,
                     const gchar *exec,
                     const gchar *textdomain)
 {
+    return ibus_component_new2 ("name", name,
+                                "description", description,
+                                "version", version,
+                                "license", license,
+                                "author", author,
+                                "homepage", homepage,
+                                "exec", exec,
+                                "textdomain", textdomain,
+                                NULL);
+}
+
 
+IBusComponent *
+ibus_component_new2 (const gchar *first_property_name, ...)
+{
+    va_list var_args;
     IBusComponent *component;
-    component = (IBusComponent *)g_object_new (IBUS_TYPE_COMPONENT, NULL);
+    IBusComponentPrivate *priv;
+
+    g_assert (first_property_name);
+
+    va_start (var_args, first_property_name);
+    component = (IBusComponent *) g_object_new_valist (IBUS_TYPE_COMPONENT,
+                                                       first_property_name,
+                                                       var_args);
+    va_end (var_args);
+
+    priv = IBUS_COMPONENT_GET_PRIVATE (component);
 
-    component->name         = g_strdup (name);
-    component->description  = g_strdup (description);
-    component->version      = g_strdup (version);
-    component->license      = g_strdup (license);
-    component->author       = g_strdup (author);
-    component->homepage     = g_strdup (homepage);
-    component->exec         = g_strdup (exec);
-    component->textdomain   = g_strdup (textdomain);
+    /* name is required. Other properties are set in class_init by default. */
+    g_assert (priv->name);
 
     return component;
 }
@@ -583,10 +850,9 @@ ibus_component_child_cb (GPid            pid,
     component->pid = 0;
     component->child_source_id = 0;
 
-    IBusComponentPrivate *priv = IBUS_COMPONENT_GET_PRIVATE (component);
-    if (priv->restart) {
-        g_debug ("==== Restarting %s", component->exec);
-        ibus_component_start (component, priv->verbose);
+    if (component->priv->restart) {
+        g_debug ("==== Restarting %s", component->priv->exec);
+        ibus_component_start (component, component->priv->verbose);
     }
 }
 
@@ -598,8 +864,7 @@ ibus_component_start (IBusComponent *component, gboolean verbose)
     if (component->pid != 0)
         return TRUE;
 
-    IBusComponentPrivate *priv = IBUS_COMPONENT_GET_PRIVATE (component);
-    priv->verbose = verbose;
+    component->priv->verbose = verbose;
 
     gint argc;
     gchar **argv;
@@ -608,8 +873,9 @@ ibus_component_start (IBusComponent *component, gboolean verbose)
     GSpawnFlags flags;
 
     error = NULL;
-    if (!g_shell_parse_argv (component->exec, &argc, &argv, &error)) {
-        g_warning ("Can not parse component %s exec: %s", component->name, error->message);
+    if (!g_shell_parse_argv (component->priv->exec, &argc, &argv, &error)) {
+        g_warning ("Can not parse component %s exec: %s",
+                        component->priv->name, error->message);
         g_error_free (error);
         return FALSE;
     }
@@ -625,7 +891,8 @@ ibus_component_start (IBusComponent *component, gboolean verbose)
                             &(component->pid), &error);
     g_strfreev (argv);
     if (!retval) {
-        g_warning ("Can not execute component %s: %s", component->name, error->message);
+        g_warning ("Can not execute component %s: %s",
+                        component->priv->name, error->message);
         g_error_free (error);
         return FALSE;
     }
index 8fb050d..2383de9 100644 (file)
@@ -75,16 +75,17 @@ typedef struct _IBusComponentPrivate IBusComponentPrivate;
 
 /**
  * IBusComponent:
- * @name: Name of the component.
- * @description: Detailed description of component.
- * @version: Component version.
- * @license: Distribution license of this component.
- * @author: Author(s) of the component.
- * @homepage: Homepage of the component.
- * @exec: path to component executable.
- * @textdomain: Domain name for dgettext()
  *
  * An IBusComponent stores component information.
+ * You can get extended values with g_object_get_properties.
+ * name: Name of the component.
+ * description: Detailed description of component.
+ * version: Component version.
+ * license: Distribution license of this component.
+ * author: Author(s) of the component.
+ * homepage: Homepage of the component.
+ * exec: path to component executable.
+ * textdomain: Domain name for dgettext()
  */
 struct _IBusComponent {
     /*< private >*/
@@ -93,16 +94,6 @@ struct _IBusComponent {
     /* instance members */
 
     /*< public >*/
-    gchar *name;
-    gchar *description;
-    gchar *version;
-    gchar *license;
-    gchar *author;
-    gchar *homepage;
-    gchar *exec;
-
-    /* text domain for dgettext */
-    gchar *textdomain;
 
     /*< private >*/
     /* engines */
@@ -150,6 +141,21 @@ IBusComponent   *ibus_component_new             (const gchar    *name,
                                                  const gchar    *textdomain);
 
 /**
+ * ibus_component_new2:
+ * @first_property_name: Name of the first property.
+ * @Varargs: the NULL-terminated arguments of the properties and values.
+ *
+ * New an IBusComponent.
+ * ibus_component_new2() supports the va_list format.
+ * name property is required. e.g.
+ * IBusComponent *component = ibus_component_new2 ("name", "ibus-foo",
+ *                                                 "exec", "/usr/libexec/ibus-engine-foo --ibus",
+ *                                                 NULL)
+ */
+IBusComponent   *ibus_component_new2            (const gchar    *first_property_name,
+                                                 ...);
+
+/**
  * ibus_component_new_from_xml_node:
  * @node: Root node of component XML tree.
  * @returns: A newly allocated IBusComponent.
@@ -172,6 +178,78 @@ IBusComponent   *ibus_component_new_from_xml_node
 IBusComponent   *ibus_component_new_from_file   (const gchar    *filename);
 
 /**
+ * ibus_component_get_name:
+ * @component: An IBusComponent
+ * @returns: name property in IBusComponent
+ *
+ * Return the name property in IBusComponent. It should not be freed.
+ */
+const gchar     *ibus_component_get_name        (IBusComponent  *component);
+
+/**
+ * ibus_component_get_description:
+ * @component: An IBusComponent
+ * @returns: description property in IBusComponent
+ *
+ * Return the description property in IBusComponent. It should not be freed.
+ */
+const gchar     *ibus_component_get_description (IBusComponent  *component);
+
+/**
+ * ibus_component_get_version:
+ * @component: An IBusComponent
+ * @returns: version property in IBusComponent
+ *
+ * Return the version property in IBusComponent. It should not be freed.
+ */
+const gchar     *ibus_component_get_version     (IBusComponent  *component);
+
+/**
+ * ibus_component_get_license:
+ * @component: An IBusComponent
+ * @returns: license property in IBusComponent
+ *
+ * Return the license property in IBusComponent. It should not be freed.
+ */
+const gchar     *ibus_component_get_license     (IBusComponent  *component);
+
+/**
+ * ibus_component_get_author:
+ * @component: An IBusComponent
+ * @returns: author property in IBusComponent
+ *
+ * Return the author property in IBusComponent. It should not be freed.
+ */
+const gchar     *ibus_component_get_author      (IBusComponent  *component);
+
+/**
+ * ibus_component_get_homepage:
+ * @component: An IBusComponent
+ * @returns: homepage property in IBusComponent
+ *
+ * Return the homepage property in IBusComponent. It should not be freed.
+ */
+const gchar     *ibus_component_get_homepage    (IBusComponent  *component);
+
+/**
+ * ibus_component_get_exec:
+ * @component: An IBusComponent
+ * @returns: exec property in IBusComponent
+ *
+ * Return the exec property in IBusComponent. It should not be freed.
+ */
+const gchar     *ibus_component_get_exec        (IBusComponent  *component);
+
+/**
+ * ibus_component_get_textdomain:
+ * @component: An IBusComponent
+ * @returns: textdomain property in IBusComponent
+ *
+ * Return the textdomain property in IBusComponent. It should not be freed.
+ */
+const gchar     *ibus_component_get_textdomain  (IBusComponent  *component);
+
+/**
  * ibus_component_add_observed_path:
  * @component: An IBusComponent
  * @path: Observed path to be added.
index e6550fc..8bcef34 100644 (file)
@@ -27,19 +27,49 @@ enum {
     LAST_SIGNAL,
 };
 
+enum {
+    PROP_0 = 0,
+    PROP_NAME,
+    PROP_LONGNAME,
+    PROP_DESCRIPTION,
+    PROP_LANGUAGE,
+    PROP_LICENSE,
+    PROP_AUTHOR,
+    PROP_ICON,
+    PROP_LAYOUT,
+    PROP_RANK,
+    PROP_HOTKEYS,
+};
+
 
 /* IBusEngineDescPriv */
 struct _IBusEngineDescPrivate {
-    gpointer pad;
+    gchar      *name;
+    gchar      *longname;
+    gchar      *description;
+    gchar      *language;
+    gchar      *license;
+    gchar      *author;
+    gchar      *icon;
+    gchar      *layout;
+    guint       rank;
+    gchar      *hotkeys;
 };
-typedef struct _IBusEngineDescPrivate IBusEngineDescPrivate;
 
 #define IBUS_ENGINE_DESC_GET_PRIVATE(o)  \
-   (G_TYPE_INSTANCE_GET_PRIVATE ((o), BUS_TYPE_ENGINE_INFO, IBusEngineDescPrivate))
+   (G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_ENGINE_DESC, IBusEngineDescPrivate))
 
 // static guint            _signals[LAST_SIGNAL] = { 0 };
 
 /* functions prototype */
+static void         ibus_engine_desc_set_property   (IBusEngineDesc         *desc,
+                                                     guint                   prop_id,
+                                                     const GValue           *value,
+                                                     GParamSpec             *pspec);
+static void         ibus_engine_desc_get_property   (IBusEngineDesc         *desc,
+                                                     guint                   prop_id,
+                                                     GValue                 *value,
+                                                     GParamSpec             *pspec);
 static void         ibus_engine_desc_destroy        (IBusEngineDesc         *desc);
 static gboolean     ibus_engine_desc_serialize      (IBusEngineDesc         *desc,
                                                      GVariantBuilder        *builder);
@@ -56,48 +86,280 @@ G_DEFINE_TYPE (IBusEngineDesc, ibus_engine_desc, IBUS_TYPE_SERIALIZABLE)
 static void
 ibus_engine_desc_class_init (IBusEngineDescClass *class)
 {
+    GObjectClass *gobject_class = G_OBJECT_CLASS (class);
     IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class);
     IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class);
 
+    gobject_class->set_property = (GObjectSetPropertyFunc) ibus_engine_desc_set_property;
+    gobject_class->get_property = (GObjectGetPropertyFunc) ibus_engine_desc_get_property;
     object_class->destroy = (IBusObjectDestroyFunc) ibus_engine_desc_destroy;
 
     serializable_class->serialize   = (IBusSerializableSerializeFunc) ibus_engine_desc_serialize;
     serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_engine_desc_deserialize;
     serializable_class->copy        = (IBusSerializableCopyFunc) ibus_engine_desc_copy;
+
+    g_type_class_add_private (class, sizeof (IBusEngineDescPrivate));
+
+    /* install properties */
+    /**
+     * IBusEngineDesc:name:
+     *
+     * The name of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_NAME,
+                    g_param_spec_string ("name",
+                        "description name",
+                        "The name of engine description",
+                        NULL,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusEngineDesc:longname:
+     *
+     * The longname of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_LONGNAME,
+                    g_param_spec_string ("longname",
+                        "description longname",
+                        "The longname of engine description",
+                        "",
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusEngineDesc:description:
+     *
+     * The description of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_DESCRIPTION,
+                    g_param_spec_string ("description",
+                        "description description",
+                        "The description of engine description",
+                        "",
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusEngineDesc:language:
+     *
+     * The language of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_LANGUAGE,
+                    g_param_spec_string ("language",
+                        "description language",
+                        "The language of engine description",
+                        "",
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusEngineDesc:license:
+     *
+     * The license of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_LICENSE,
+                    g_param_spec_string ("license",
+                        "description license",
+                        "The license of engine description",
+                        "",
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusEngineDesc:author:
+     *
+     * The author of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_AUTHOR,
+                    g_param_spec_string ("author",
+                        "description author",
+                        "The author of engine description",
+                        "",
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusEngineDesc:icon:
+     *
+     * The icon of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_ICON,
+                    g_param_spec_string ("icon",
+                        "description icon",
+                        "The icon of engine description",
+                        "ibus-engine",
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusEngineDesc:layout:
+     *
+     * The layout of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_LAYOUT,
+                    g_param_spec_string ("layout",
+                        "description layout",
+                        "The layout of engine description",
+                        "us",
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusEngineDesc:rank:
+     *
+     * The rank of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_RANK,
+                    g_param_spec_uint ("rank",
+                        "description rank",
+                        "The lank of eingine description",
+                        0,
+                        G_MAXUINT,
+                        0,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * IBusEngineDesc:hotkeys:
+     *
+     * The hotkeys of engine description
+     */
+    g_object_class_install_property (gobject_class,
+                    PROP_HOTKEYS,
+                    g_param_spec_string ("hotkeys",
+                        "description hotkeys",
+                        "The hotkeys of engine description",
+                        "",
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
 ibus_engine_desc_init (IBusEngineDesc *desc)
 {
-
-    desc->name = NULL;
-    desc->longname = NULL;
-    desc->description = NULL;
-    desc->language = NULL;
-    desc->license = NULL;
-    desc->author = NULL;
-    desc->icon = NULL;
-    desc->layout = NULL;
-    desc->hotkeys = NULL;
-    desc->rank = 0;
+    desc->priv = IBUS_ENGINE_DESC_GET_PRIVATE (desc);
+
+    desc->priv->name = NULL;
+    desc->priv->longname = NULL;
+    desc->priv->description = NULL;
+    desc->priv->language = NULL;
+    desc->priv->license = NULL;
+    desc->priv->author = NULL;
+    desc->priv->icon = NULL;
+    desc->priv->layout = NULL;
+    desc->priv->rank = 0;
+    desc->priv->hotkeys = NULL;
 }
 
 static void
 ibus_engine_desc_destroy (IBusEngineDesc *desc)
 {
-    g_free (desc->name);
-    g_free (desc->longname);
-    g_free (desc->description);
-    g_free (desc->language);
-    g_free (desc->license);
-    g_free (desc->author);
-    g_free (desc->icon);
-    g_free (desc->layout);
-    g_free (desc->hotkeys);
+    g_free (desc->priv->name);
+    g_free (desc->priv->longname);
+    g_free (desc->priv->description);
+    g_free (desc->priv->language);
+    g_free (desc->priv->license);
+    g_free (desc->priv->author);
+    g_free (desc->priv->icon);
+    g_free (desc->priv->layout);
+    g_free (desc->priv->hotkeys);
 
     IBUS_OBJECT_CLASS (ibus_engine_desc_parent_class)->destroy (IBUS_OBJECT (desc));
 }
 
+static void
+ibus_engine_desc_set_property (IBusEngineDesc *desc,
+                               guint           prop_id,
+                               const GValue   *value,
+                               GParamSpec     *pspec)
+{
+    switch (prop_id) {
+    case PROP_NAME:
+        g_assert (desc->priv->name == NULL);
+        desc->priv->name = g_value_dup_string (value);
+        break;
+    case PROP_LONGNAME:
+        g_assert (desc->priv->longname == NULL);
+        desc->priv->longname = g_value_dup_string (value);
+        break;
+    case PROP_DESCRIPTION:
+        g_assert (desc->priv->description == NULL);
+        desc->priv->description  = g_value_dup_string (value);
+        break;
+    case PROP_LANGUAGE:
+        g_assert (desc->priv->language == NULL);
+        desc->priv->language = g_value_dup_string (value);
+        break;
+    case PROP_LICENSE:
+        g_assert (desc->priv->license == NULL);
+        desc->priv->license = g_value_dup_string (value);
+        break;
+    case PROP_AUTHOR:
+        g_assert (desc->priv->author == NULL);
+        desc->priv->author = g_value_dup_string (value);
+        break;
+    case PROP_ICON:
+        g_assert (desc->priv->icon == NULL);
+        desc->priv->icon = g_value_dup_string (value);
+        break;
+    case PROP_LAYOUT:
+        g_assert (desc->priv->layout == NULL);
+        desc->priv->layout = g_value_dup_string (value);
+        break;
+    case PROP_RANK:
+        desc->priv->rank = g_value_get_uint (value);
+        break;
+    case PROP_HOTKEYS:
+        g_assert (desc->priv->hotkeys == NULL);
+        desc->priv->hotkeys = g_value_dup_string (value);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (desc, prop_id, pspec);
+    }
+}
+
+static void
+ibus_engine_desc_get_property (IBusEngineDesc *desc,
+                               guint           prop_id,
+                               GValue         *value,
+                               GParamSpec     *pspec)
+{
+    switch (prop_id) {
+    case PROP_NAME:
+        g_value_set_string (value, ibus_engine_desc_get_name (desc));
+        break;
+    case PROP_LONGNAME:
+        g_value_set_string (value, ibus_engine_desc_get_longname (desc));
+        break;
+    case PROP_DESCRIPTION:
+        g_value_set_string (value, ibus_engine_desc_get_description (desc));
+        break;
+    case PROP_LANGUAGE:
+        g_value_set_string (value, ibus_engine_desc_get_language (desc));
+        break;
+    case PROP_LICENSE:
+        g_value_set_string (value, ibus_engine_desc_get_license (desc));
+        break;
+    case PROP_AUTHOR:
+        g_value_set_string (value, ibus_engine_desc_get_author (desc));
+        break;
+    case PROP_ICON:
+        g_value_set_string (value, ibus_engine_desc_get_icon (desc));
+        break;
+    case PROP_LAYOUT:
+        g_value_set_string (value, ibus_engine_desc_get_layout (desc));
+        break;
+    case PROP_RANK:
+        g_value_set_uint (value, ibus_engine_desc_get_rank (desc));
+        break;
+    case PROP_HOTKEYS:
+        g_value_set_string (value, ibus_engine_desc_get_hotkeys (desc));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (desc, prop_id, pspec);
+    }
+}
+
 static gboolean
 ibus_engine_desc_serialize (IBusEngineDesc  *desc,
                             GVariantBuilder *builder)
@@ -106,18 +368,19 @@ ibus_engine_desc_serialize (IBusEngineDesc  *desc,
 
     retval = IBUS_SERIALIZABLE_CLASS (ibus_engine_desc_parent_class)->serialize ((IBusSerializable *)desc, builder);
     g_return_val_if_fail (retval, FALSE);
+    /* End dict iter */
 
 #define NOTNULL(s) ((s) != NULL ? (s) : "")
-    g_variant_builder_add (builder, "s", NOTNULL (desc->name));
-    g_variant_builder_add (builder, "s", NOTNULL (desc->longname));
-    g_variant_builder_add (builder, "s", NOTNULL (desc->description));
-    g_variant_builder_add (builder, "s", NOTNULL (desc->language));
-    g_variant_builder_add (builder, "s", NOTNULL (desc->license));
-    g_variant_builder_add (builder, "s", NOTNULL (desc->author));
-    g_variant_builder_add (builder, "s", NOTNULL (desc->icon));
-    g_variant_builder_add (builder, "s", NOTNULL (desc->layout));
-    g_variant_builder_add (builder, "s", NOTNULL (desc->hotkeys));
-    g_variant_builder_add (builder, "u", desc->rank);
+    g_variant_builder_add (builder, "s", NOTNULL (desc->priv->name));
+    g_variant_builder_add (builder, "s", NOTNULL (desc->priv->longname));
+    g_variant_builder_add (builder, "s", NOTNULL (desc->priv->description));
+    g_variant_builder_add (builder, "s", NOTNULL (desc->priv->language));
+    g_variant_builder_add (builder, "s", NOTNULL (desc->priv->license));
+    g_variant_builder_add (builder, "s", NOTNULL (desc->priv->author));
+    g_variant_builder_add (builder, "s", NOTNULL (desc->priv->icon));
+    g_variant_builder_add (builder, "s", NOTNULL (desc->priv->layout));
+    g_variant_builder_add (builder, "s", NOTNULL (desc->priv->hotkeys));
+    g_variant_builder_add (builder, "u", desc->priv->rank);
 #undef NOTNULL
     return TRUE;
 }
@@ -131,16 +394,16 @@ ibus_engine_desc_deserialize (IBusEngineDesc *desc,
     retval = IBUS_SERIALIZABLE_CLASS (ibus_engine_desc_parent_class)->deserialize ((IBusSerializable *)desc, variant);
     g_return_val_if_fail (retval, 0);
 
-    g_variant_get_child (variant, retval++, "s", &desc->name);
-    g_variant_get_child (variant, retval++, "s", &desc->longname);
-    g_variant_get_child (variant, retval++, "s", &desc->description);
-    g_variant_get_child (variant, retval++, "s", &desc->language);
-    g_variant_get_child (variant, retval++, "s", &desc->license);
-    g_variant_get_child (variant, retval++, "s", &desc->author);
-    g_variant_get_child (variant, retval++, "s", &desc->icon);
-    g_variant_get_child (variant, retval++, "s", &desc->layout);
-    g_variant_get_child (variant, retval++, "s", &desc->hotkeys);
-    g_variant_get_child (variant, retval++, "u", &desc->rank);
+    g_variant_get_child (variant, retval++, "s", &desc->priv->name);
+    g_variant_get_child (variant, retval++, "s", &desc->priv->longname);
+    g_variant_get_child (variant, retval++, "s", &desc->priv->description);
+    g_variant_get_child (variant, retval++, "s", &desc->priv->language);
+    g_variant_get_child (variant, retval++, "s", &desc->priv->license);
+    g_variant_get_child (variant, retval++, "s", &desc->priv->author);
+    g_variant_get_child (variant, retval++, "s", &desc->priv->icon);
+    g_variant_get_child (variant, retval++, "s", &desc->priv->layout);
+    g_variant_get_child (variant, retval++, "s", &desc->priv->hotkeys);
+    g_variant_get_child (variant, retval++, "u", &desc->priv->rank);
 
     return retval;
 }
@@ -155,17 +418,16 @@ ibus_engine_desc_copy (IBusEngineDesc       *dest,
                                  (IBusSerializable *)src);
     g_return_val_if_fail (retval, FALSE);
 
-
-    dest->name          = g_strdup (src->name);
-    dest->longname      = g_strdup (src->longname);
-    dest->description   = g_strdup (src->description);
-    dest->language      = g_strdup (src->language);
-    dest->license       = g_strdup (src->license);
-    dest->author        = g_strdup (src->author);
-    dest->icon          = g_strdup (src->icon);
-    dest->layout        = g_strdup (src->layout);
-    dest->hotkeys       = g_strdup (src->hotkeys);
-
+    dest->priv->name             = g_strdup (src->priv->name);
+    dest->priv->longname         = g_strdup (src->priv->longname);
+    dest->priv->description      = g_strdup (src->priv->description);
+    dest->priv->language         = g_strdup (src->priv->language);
+    dest->priv->license          = g_strdup (src->priv->license);
+    dest->priv->author           = g_strdup (src->priv->author);
+    dest->priv->icon             = g_strdup (src->priv->icon);
+    dest->priv->layout           = g_strdup (src->priv->layout);
+    dest->priv->rank             = src->priv->rank;
+    dest->priv->hotkeys          = g_strdup (src->priv->hotkeys);
     return TRUE;
 }
 
@@ -184,13 +446,14 @@ ibus_engine_desc_output (IBusEngineDesc *desc,
 {
     g_string_append_indent (output, indent);
     g_string_append (output, "<engine>\n");
-#define OUTPUT_ENTRY(field, element)                                                    \
-    {                                                                                   \
-        gchar *escape_text = g_markup_escape_text (desc->field ? desc->field : "", -1); \
-        g_string_append_indent (output, indent + 1);                                    \
-        g_string_append_printf (output, "<"element">%s</"element">\n",                  \
-                                escape_text);                                           \
-        g_free (escape_text);                                                           \
+#define OUTPUT_ENTRY(field, element)                                        \
+    {                                                                       \
+        gchar *escape_text = g_markup_escape_text (                         \
+                        desc->priv->field ? desc->priv->field : "", -1);    \
+        g_string_append_indent (output, indent + 1);                        \
+        g_string_append_printf (output, "<"element">%s</"element">\n",      \
+                                escape_text);                               \
+        g_free (escape_text);                                               \
     }
 #define OUTPUT_ENTRY_1(name) OUTPUT_ENTRY(name, #name)
     OUTPUT_ENTRY_1(name);
@@ -203,7 +466,7 @@ ibus_engine_desc_output (IBusEngineDesc *desc,
     OUTPUT_ENTRY_1(layout);
     OUTPUT_ENTRY_1(hotkeys);
     g_string_append_indent (output, indent + 1);
-    g_string_append_printf (output, "<rank>%u</rank>\n", desc->rank);
+    g_string_append_printf (output, "<rank>%u</rank>\n", desc->priv->rank);
 #undef OUTPUT_ENTRY
 #undef OUTPUT_ENTRY_1
     g_string_append_indent (output, indent);
@@ -215,13 +478,14 @@ ibus_engine_desc_parse_xml_node (IBusEngineDesc *desc,
                                 XMLNode       *node)
 {
     GList *p;
+
     for (p = node->sub_nodes; p != NULL; p = p->next) {
         XMLNode *sub_node = (XMLNode *) p->data;
 
 #define PARSE_ENTRY(field_name, element_name)                   \
         if (g_strcmp0 (sub_node->name, element_name) == 0) {    \
-            g_free (desc->field_name);                          \
-            desc->field_name = g_strdup (sub_node->text);       \
+            g_free (desc->priv->field_name);                    \
+            desc->priv->field_name = g_strdup (sub_node->text); \
             continue;                                           \
         }
 #define PARSE_ENTRY_1(name) PARSE_ENTRY(name, #name)
@@ -237,7 +501,7 @@ ibus_engine_desc_parse_xml_node (IBusEngineDesc *desc,
 #undef PARSE_ENTRY
 #undef PARSE_ENTRY_1
         if (g_strcmp0 (sub_node->name , "rank") == 0) {
-            desc->rank = atoi (sub_node->text);
+            desc->priv->rank = atoi (sub_node->text);
             continue;
         }
         g_warning ("<engines> element contains invalidate element <%s>", sub_node->name);
@@ -245,6 +509,25 @@ ibus_engine_desc_parse_xml_node (IBusEngineDesc *desc,
     return TRUE;
 }
 
+#define IBUS_ENGINE_DESC_GET_PROPERTY(property, return_type)    \
+return_type                                                     \
+ibus_engine_desc_get_ ## property (IBusEngineDesc *desc)        \
+{                                                               \
+    return desc->priv->property;                                \
+}
+
+IBUS_ENGINE_DESC_GET_PROPERTY (name, const gchar *)
+IBUS_ENGINE_DESC_GET_PROPERTY (longname, const gchar *)
+IBUS_ENGINE_DESC_GET_PROPERTY (description, const gchar *)
+IBUS_ENGINE_DESC_GET_PROPERTY (language, const gchar *)
+IBUS_ENGINE_DESC_GET_PROPERTY (license, const gchar *)
+IBUS_ENGINE_DESC_GET_PROPERTY (author, const gchar *)
+IBUS_ENGINE_DESC_GET_PROPERTY (icon, const gchar *)
+IBUS_ENGINE_DESC_GET_PROPERTY (layout, const gchar *)
+IBUS_ENGINE_DESC_GET_PROPERTY (rank, guint)
+IBUS_ENGINE_DESC_GET_PROPERTY (hotkeys, const gchar *)
+#undef IBUS_ENGINE_DESC_GET_PROPERTY
+
 IBusEngineDesc *
 ibus_engine_desc_new (const gchar *name,
                       const gchar *longname,
@@ -255,43 +538,41 @@ ibus_engine_desc_new (const gchar *name,
                       const gchar *icon,
                       const gchar *layout)
 {
-    return ibus_engine_desc_new2 (name, longname, description, language,
-                                  license, author, icon, layout, "");
+    return ibus_engine_desc_new2 ("name", name,
+                                  "longname", longname,
+                                  "description", description,
+                                  "language", language,
+                                  "license", license,
+                                  "author", author,
+                                  "icon", icon,
+                                  "layout", layout,
+                                  NULL);
 }
 
 IBusEngineDesc *
-ibus_engine_desc_new2 (const gchar *name,
-                       const gchar *longname,
-                       const gchar *description,
-                       const gchar *language,
-                       const gchar *license,
-                       const gchar *author,
-                       const gchar *icon,
-                       const gchar *layout,
-                       const gchar *hotkeys)
+ibus_engine_desc_new2 (const gchar *first_property_name, ...)
 {
-    g_assert (name);
-    g_assert (longname);
-    g_assert (description);
-    g_assert (language);
-    g_assert (license);
-    g_assert (author);
-    g_assert (icon);
-    g_assert (layout);
-    g_assert (hotkeys);
-
+    va_list var_args;
     IBusEngineDesc *desc;
-    desc = (IBusEngineDesc *)g_object_new (IBUS_TYPE_ENGINE_DESC, NULL);
 
-    desc->name          = g_strdup (name);
-    desc->longname      = g_strdup (longname);
-    desc->description   = g_strdup (description);
-    desc->language      = g_strdup (language);
-    desc->license       = g_strdup (license);
-    desc->author        = g_strdup (author);
-    desc->icon          = g_strdup (icon);
-    desc->layout        = g_strdup (layout);
-    desc->hotkeys       = g_strdup (hotkeys);
+    g_assert (first_property_name);
+
+    va_start (var_args, first_property_name);
+    desc = (IBusEngineDesc *) g_object_new_valist (IBUS_TYPE_ENGINE_DESC,
+                                                   first_property_name,
+                                                   var_args);
+    va_end (var_args);
+
+    /* name is required. Other properties are set in class_init by default. */
+    g_assert (desc->priv->name);
+    g_assert (desc->priv->longname);
+    g_assert (desc->priv->description);
+    g_assert (desc->priv->language);
+    g_assert (desc->priv->license);
+    g_assert (desc->priv->author);
+    g_assert (desc->priv->icon);
+    g_assert (desc->priv->layout);
+    g_assert (desc->priv->hotkeys);
 
     return desc;
 }
index 7c41b35..d88b35a 100644 (file)
 G_BEGIN_DECLS
 
 typedef struct _IBusEngineDesc IBusEngineDesc;
+typedef struct _IBusEngineDescPrivate IBusEngineDescPrivate;
 typedef struct _IBusEngineDescClass IBusEngineDescClass;
 typedef struct _BusComponent BusComponent;
 
 /**
  * IBusEngineDesc:
- * @name: Name of the engine.
- * @longname: Long name of the input method engine.
- * @description: Input method engine description.
- * @language: Language (e.g. zh, jp) supported by this input method engine.
- * @license: License of the input method engine.
- * @author: Author of the input method engine.
- * @icon: Icon file of this engine.
- * @layout: Keyboard layout
- * @hotkeys: One or more hotkeys for switching to this engine, separated by
- *  semi-colon.
- * @rank: Preference rank among engines, the highest ranked IME will put in
- * the front.
  *
  * Input method engine description data.
+ * You can get extended values with g_object_get_properties.
+ * name: Name of the engine.
+ * longname: Long name of the input method engine.
+ * description: Input method engine description.
+ * language: Language (e.g. zh, jp) supported by this input method engine.
+ * license: License of the input method engine.
+ * author: Author of the input method engine.
+ * icon: Icon file of this engine.
+ * layout: Keyboard layout
+ * rank: Preference rank among engines, the highest ranked IME will put in
+ * the front.
+ * hotkeys: One or more hotkeys for switching to this engine, separated by
+ *  semi-colon.
  */
 struct _IBusEngineDesc {
     IBusSerializable parent;
     /* instance members */
 
     /*< public >*/
-    gchar *name;
-    gchar *longname;
-    gchar *description;
-    gchar *language;
-    gchar *license;
-    gchar *author;
-    gchar *icon;
-    gchar *layout;
-    gchar *hotkeys;
-    guint  rank;
+    /*< private >*/
+    IBusEngineDescPrivate *priv;
 };
 
 struct _IBusEngineDescClass {
@@ -139,28 +133,17 @@ IBusEngineDesc  *ibus_engine_desc_new           (const gchar    *name,
 
 /**
  * ibus_engine_desc_new2:
- * @name: Name of the engine.
- * @longname: Long name of the input method engine.
- * @description: Input method engine description.
- * @language: Language (e.g. zh, jp) supported by this input method engine.
- * @license: License of the input method engine.
- * @author: Author of the input method engine.
- * @icon: Icon file of this engine.
- * @layout: Keyboard layout
- * @hotkeys: Hotkeys for switching to this engine.
- * @returns: A newly allocated IBusEngineDesc.
+ * @first_property_name: Name of the first property.
+ * @Varargs: the NULL-terminated arguments of the properties and values.
  *
  * New a IBusEngineDesc.
+ * ibus_engine_desc_new2() supports the va_list format.
+ * name property is required. e.g.
+ * ibus_engine_desc_new2("name", "ibus-foo", "language", "us", NULL)
  */
-IBusEngineDesc  *ibus_engine_desc_new2          (const gchar    *name,
-                                                 const gchar    *longname,
-                                                 const gchar    *description,
-                                                 const gchar    *language,
-                                                 const gchar    *license,
-                                                 const gchar    *author,
-                                                 const gchar    *icon,
-                                                 const gchar    *layout,
-                                                 const gchar    *hotkeys);
+IBusEngineDesc  *ibus_engine_desc_new2          (const gchar *first_property_name,
+                                                 ...);
+
 
 /**
  * ibus_engine_desc_new_from_xml_node:
@@ -176,6 +159,97 @@ IBusEngineDesc  *ibus_engine_desc_new2          (const gchar    *name,
 IBusEngineDesc  *ibus_engine_desc_new_from_xml_node
                                                 (XMLNode        *node);
 /**
+ * ibus_engine_desc_get_name:
+ * @info: An IBusEngineDesc
+ * @returns: name property in IBusEngineDesc
+ *
+ * Return the name property in IBusEngineDesc. It should not be freed.
+ */
+const gchar     *ibus_engine_desc_get_name      (IBusEngineDesc *info);
+
+/**
+ * ibus_engine_desc_get_longname:
+ * @info: An IBusEngineDesc
+ * @returns: longname property in IBusEngineDesc
+ *
+ * Return the longname property in IBusEngineDesc. It should not be freed.
+ */
+const gchar     *ibus_engine_desc_get_longname  (IBusEngineDesc *info);
+
+/**
+ * ibus_engine_desc_get_description:
+ * @info: An IBusEngineDesc
+ * @returns: description property in IBusEngineDesc
+ *
+ * Return the description property in IBusEngineDesc. It should not be freed.
+ */
+const gchar     *ibus_engine_desc_get_description
+                                                (IBusEngineDesc *info);
+
+/**
+ * ibus_engine_desc_get_language:
+ * @info: An IBusEngineDesc
+ * @returns: language property in IBusEngineDesc
+ *
+ * Return the language property in IBusEngineDesc. It should not be freed.
+ */
+const gchar     *ibus_engine_desc_get_language  (IBusEngineDesc *info);
+
+/**
+ * ibus_engine_desc_get_license:
+ * @info: An IBusEngineDesc
+ * @returns: license property in IBusEngineDesc
+ *
+ * Return the license property in IBusEngineDesc. It should not be freed.
+ */
+const gchar     *ibus_engine_desc_get_license   (IBusEngineDesc *info);
+
+/**
+ * ibus_engine_desc_get_author:
+ * @info: An IBusEngineDesc
+ * @returns: author property in IBusEngineDesc
+ *
+ * Return the author property in IBusEngineDesc. It should not be freed.
+ */
+const gchar     *ibus_engine_desc_get_author    (IBusEngineDesc *info);
+
+/**
+ * ibus_engine_desc_get_icon:
+ * @info: An IBusEngineDesc
+ * @returns: icon property in IBusEngineDesc
+ *
+ * Return the icon property in IBusEngineDesc. It should not be freed.
+ */
+const gchar     *ibus_engine_desc_get_icon      (IBusEngineDesc *info);
+
+/**
+ * ibus_engine_desc_get_layout:
+ * @info: An IBusEngineDesc
+ * @returns: layout property in IBusEngineDesc
+ *
+ * Return the layout property in IBusEngineDesc. It should not be freed.
+ */
+const gchar     *ibus_engine_desc_get_layout    (IBusEngineDesc *info);
+
+/**
+ * ibus_engine_desc_get_rank:
+ * @info: An IBusEngineDesc
+ * @returns: rank property in IBusEngineDesc
+ *
+ * Return the rank property in IBusEngineDesc.
+ */
+guint            ibus_engine_desc_get_rank      (IBusEngineDesc *info);
+
+/**
+ * ibus_engine_desc_get_hotkeys:
+ * @info: An IBusEngineDesc
+ * @returns: hotkeys property in IBusEngineDesc
+ *
+ * Return the hotkeys property in IBusEngineDesc. It should not be freed.
+ */
+const gchar     *ibus_engine_desc_get_hotkeys   (IBusEngineDesc *info);
+
+/**
  * ibus_engine_desc_output:
  * @info: An IBusEngineDesc
  * @output: XML-formatted Input method engine description.
index a7cbc60..2c879bf 100644 (file)
@@ -9,11 +9,19 @@ void
 global_engine_changed_cb (IBusBus *bus)
 {
        IBusEngineDesc *global_engine = ibus_bus_get_global_engine (bus);
+       const gchar *name = NULL;
+
        g_assert (global_engine);
-       g_debug ("%s (id:%s, icon:%s)", global_engine->longname,
-                global_engine->name, global_engine->icon);
+
+       name = ibus_engine_desc_get_name (global_engine);
+       g_debug ("%s (id:%s, icon:%s)",
+                ibus_engine_desc_get_longname (global_engine),
+                name,
+                ibus_engine_desc_get_icon (global_engine));
        IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (current_engine->data);
-       g_assert (strcmp (engine_desc->name, global_engine->name) == 0);
+
+       g_assert (strcmp (name,
+                         ibus_engine_desc_get_name (engine_desc)) == 0);
        g_object_unref (global_engine);
 }
 
@@ -31,18 +39,25 @@ change_global_engine_cb (IBusBus *bus)
        }
 
        IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (current_engine->data);
-       ibus_bus_set_global_engine (bus, engine_desc->name);
+
+       ibus_bus_set_global_engine (bus,
+                                   ibus_engine_desc_get_name (engine_desc));
 
        return TRUE;
 }
 
 int main()
 {
+<<<<<<< HEAD:src/tests/ibus-global-engine.c
        g_type_init ();
     IBUS_TYPE_ENGINE_DESC;
 
+=======
+>>>>>>> 0d7730b... Use va_list for IBusEngineDesc for back compatibility.:src/test-global-engine.c
        IBusBus *bus;
 
+       g_type_init ();
+
        bus = ibus_bus_new ();
        engines = ibus_bus_list_active_engines (bus);
        g_assert (engines);