From cf1fa1bc72d6d7ad71e928df1c3aa938069cfd9e Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Wed, 29 Jun 2011 16:50:51 +0900 Subject: [PATCH] Add symbol property in IBusEngineDesc. --- ibus/enginedesc.py | 15 +++++++++------ src/ibusenginedesc.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/ibusenginedesc.h | 10 ++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/ibus/enginedesc.py b/ibus/enginedesc.py index e8a8982..3ca7f24 100644 --- a/ibus/enginedesc.py +++ b/ibus/enginedesc.py @@ -31,7 +31,7 @@ from serializable import * class EngineDesc(Serializable): __gtype_name__ = "PYIBusEngineDesc" __NAME__ = "IBusEngineDesc" - def __init__(self, name="", longname="", description="", language="", license="", author="", icon="", layout="", hotkeys="", rank=0): + def __init__(self, name="", longname="", description="", language="", license="", author="", icon="", layout="", hotkeys="", rank=0, symbol=""): super(EngineDesc, self).__init__() self.__name = name self.__longname = longname @@ -43,6 +43,7 @@ class EngineDesc(Serializable): self.__layout = layout self.__rank = rank self.__hotkeys = hotkeys + self.__symbol = symbol def get_name(self): return self.__name @@ -74,6 +75,9 @@ class EngineDesc(Serializable): def get_hotkeys(self): return self.__hotkeys + def get_symbol(self): + return self.__symbol + name = property(get_name) longname = property(get_longname) description = property(get_description) @@ -84,6 +88,7 @@ class EngineDesc(Serializable): layout = property(get_layout) rank = property(get_rank) hotkeys = property(get_hotkeys) + symbol = property(get_symbol) def serialize(self, struct): super(EngineDesc, self).serialize(struct) @@ -97,8 +102,7 @@ class EngineDesc(Serializable): struct.append(dbus.String(self.__layout)) 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)) + struct.append(dbus.String(self.__symbol)) def deserialize(self, struct): super(EngineDesc, self).deserialize(struct) @@ -112,11 +116,10 @@ class EngineDesc(Serializable): self.__layout = 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) + self.__symbol = struct.pop(0) def test(): - engine = EngineDesc("Hello", "", "", "", "", "", "", "", "") + engine = EngineDesc("Hello", "", "", "", "", "", "", "", "", 0, "") value = serialize_object(engine) engine = deserialize_object(value) diff --git a/src/ibusenginedesc.c b/src/ibusenginedesc.c index ca5ef60..fa3a768 100644 --- a/src/ibusenginedesc.c +++ b/src/ibusenginedesc.c @@ -39,6 +39,7 @@ enum { PROP_LAYOUT, PROP_RANK, PROP_HOTKEYS, + PROP_SYMBOL, }; @@ -54,6 +55,7 @@ struct _IBusEngineDescPrivate { gchar *layout; guint rank; gchar *hotkeys; + gchar *symbol; }; #define IBUS_ENGINE_DESC_GET_PRIVATE(o) \ @@ -232,6 +234,19 @@ ibus_engine_desc_class_init (IBusEngineDescClass *class) "The hotkeys of engine description", "", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + /** + * IBusEngineDesc:symbol: + * + * The symbol chars of engine description instead of icon image + */ + g_object_class_install_property (gobject_class, + PROP_SYMBOL, + g_param_spec_string ("symbol", + "description symbol", + "The icon symbol chars of engine description", + "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } static void @@ -249,6 +264,7 @@ ibus_engine_desc_init (IBusEngineDesc *desc) desc->priv->layout = NULL; desc->priv->rank = 0; desc->priv->hotkeys = NULL; + desc->priv->symbol = NULL; } static void @@ -263,6 +279,7 @@ ibus_engine_desc_destroy (IBusEngineDesc *desc) g_free (desc->priv->icon); g_free (desc->priv->layout); g_free (desc->priv->hotkeys); + g_free (desc->priv->symbol); IBUS_OBJECT_CLASS (ibus_engine_desc_parent_class)->destroy (IBUS_OBJECT (desc)); } @@ -313,6 +330,10 @@ ibus_engine_desc_set_property (IBusEngineDesc *desc, g_assert (desc->priv->hotkeys == NULL); desc->priv->hotkeys = g_value_dup_string (value); break; + case PROP_SYMBOL: + g_assert (desc->priv->symbol == NULL); + desc->priv->symbol = g_value_dup_string (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (desc, prop_id, pspec); } @@ -355,6 +376,9 @@ ibus_engine_desc_get_property (IBusEngineDesc *desc, case PROP_HOTKEYS: g_value_set_string (value, ibus_engine_desc_get_hotkeys (desc)); break; + case PROP_SYMBOL: + g_value_set_string (value, ibus_engine_desc_get_symbol (desc)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (desc, prop_id, pspec); } @@ -371,6 +395,10 @@ ibus_engine_desc_serialize (IBusEngineDesc *desc, /* End dict iter */ #define NOTNULL(s) ((s) != NULL ? (s) : "") + /* If you will add a new property, you can append it at the end and + * you should not change the serialized order of name, longname, + * description, ... because the order is also used in other applications + * likes ibus-qt. */ 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)); @@ -381,7 +409,9 @@ ibus_engine_desc_serialize (IBusEngineDesc *desc, g_variant_builder_add (builder, "s", NOTNULL (desc->priv->layout)); g_variant_builder_add (builder, "u", desc->priv->rank); g_variant_builder_add (builder, "s", NOTNULL (desc->priv->hotkeys)); + g_variant_builder_add (builder, "s", NOTNULL (desc->priv->symbol)); #undef NOTNULL + return TRUE; } @@ -394,6 +424,10 @@ 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); + /* If you will add a new property, you can append it at the end and + * you should not change the serialized order of name, longname, + * description, ... because the order is also used in other applications + * likes ibus-qt. */ 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); @@ -404,6 +438,7 @@ ibus_engine_desc_deserialize (IBusEngineDesc *desc, g_variant_get_child (variant, retval++, "s", &desc->priv->layout); g_variant_get_child (variant, retval++, "u", &desc->priv->rank); g_variant_get_child (variant, retval++, "s", &desc->priv->hotkeys); + g_variant_get_child (variant, retval++, "s", &desc->priv->symbol); return retval; } @@ -428,6 +463,7 @@ ibus_engine_desc_copy (IBusEngineDesc *dest, dest->priv->layout = g_strdup (src->priv->layout); dest->priv->rank = src->priv->rank; dest->priv->hotkeys = g_strdup (src->priv->hotkeys); + dest->priv->symbol = g_strdup (src->priv->symbol); return TRUE; } @@ -465,6 +501,7 @@ ibus_engine_desc_output (IBusEngineDesc *desc, OUTPUT_ENTRY_1(icon); OUTPUT_ENTRY_1(layout); OUTPUT_ENTRY_1(hotkeys); + OUTPUT_ENTRY_1(symbol); g_string_append_indent (output, indent + 1); g_string_append_printf (output, "%u\n", desc->priv->rank); #undef OUTPUT_ENTRY @@ -498,6 +535,7 @@ ibus_engine_desc_parse_xml_node (IBusEngineDesc *desc, PARSE_ENTRY_1(icon); PARSE_ENTRY_1(layout); PARSE_ENTRY_1(hotkeys); + PARSE_ENTRY_1(symbol); #undef PARSE_ENTRY #undef PARSE_ENTRY_1 if (g_strcmp0 (sub_node->name , "rank") == 0) { @@ -526,6 +564,7 @@ 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 *) +IBUS_ENGINE_DESC_GET_PROPERTY (symbol, const gchar *) #undef IBUS_ENGINE_DESC_GET_PROPERTY IBusEngineDesc * @@ -573,6 +612,7 @@ ibus_engine_desc_new_varargs (const gchar *first_property_name, ...) g_assert (desc->priv->icon); g_assert (desc->priv->layout); g_assert (desc->priv->hotkeys); + g_assert (desc->priv->symbol); return desc; } diff --git a/src/ibusenginedesc.h b/src/ibusenginedesc.h index 9718b15..76a7adc 100644 --- a/src/ibusenginedesc.h +++ b/src/ibusenginedesc.h @@ -249,6 +249,16 @@ guint ibus_engine_desc_get_rank (IBusEngineDesc *info); const gchar *ibus_engine_desc_get_hotkeys (IBusEngineDesc *info); /** + * ibus_engine_desc_get_symbol: + * @info: An IBusEngineDesc + * @returns: symbol property in IBusEngineDesc + * + * Return the symbol property in IBusEngineDesc. It should not be freed. + */ +const gchar *ibus_engine_desc_get_symbol + (IBusEngineDesc *info); + +/** * ibus_engine_desc_output: * @info: An IBusEngineDesc * @output: XML-formatted Input method engine description. -- 1.7.5.4