ibus/ibus-xx-icon-symbol.patch

399 lines
14 KiB
Diff
Raw Normal View History

2011-06-22 03:38:34 +00:00
From 1a7d35e5a29bec75dcc98e934d39cfdb3950ae48 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
2011-06-22 03:38:34 +00:00
Date: Wed, 22 Jun 2011 12:21:55 +0900
Subject: [PATCH] Add icon_symbol property in IBusEngineDesc.
---
bus/engineproxy.c | 22 +++++++++++++++
bus/ibusimpl.c | 33 ++++++++++++++++++++++
bus/ibusimpl.h | 4 +++
ibus/engine.py | 3 ++
2011-06-22 03:38:34 +00:00
ibus/enginedesc.py | 18 +++++++++---
ibus/interface/iengine.py | 3 ++
src/ibusenginedesc.c | 66 +++++++++++++++++++++++++++++++++++++++++++++
src/ibusenginedesc.h | 10 +++++++
2011-06-22 03:38:34 +00:00
8 files changed, 155 insertions(+), 4 deletions(-)
diff --git a/bus/engineproxy.c b/bus/engineproxy.c
index f74af12..5c0cbb2 100644
--- a/bus/engineproxy.c
+++ b/bus/engineproxy.c
@@ -591,6 +591,28 @@ bus_engine_proxy_g_signal (GDBusProxy *proxy,
return;
}
+ if (g_strcmp0 (signal_name, "SetIconSymbol") == 0) {
+ const gchar *name = NULL;
+ gchar *icon_symbol = NULL;
+ GValue value = { 0, };
+
+ name = ibus_engine_desc_get_name (engine->desc);
+ g_return_if_fail (name != NULL);
+ g_variant_get (parameters, "(s)", &icon_symbol);
+ g_return_if_fail (icon_symbol != NULL);
+
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, icon_symbol);
+ g_object_set_property (G_OBJECT (engine->desc), "icon_symbol", &value);
+ g_value_unset (&value);
+
+ bus_ibus_impl_set_icon_symbol_with_engine_name (BUS_DEFAULT_IBUS,
+ name,
+ icon_symbol);
+ g_free (icon_symbol);
+ return;
+ }
+
g_return_if_reached ();
}
diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c
index b356b2c..38d6d11 100644
--- a/bus/ibusimpl.c
+++ b/bus/ibusimpl.c
@@ -2342,3 +2342,36 @@ bus_ibus_impl_get_focused_input_context (BusIBusImpl *ibus)
return ibus->focused_context;
}
+
+void
+bus_ibus_impl_set_icon_symbol_with_engine_name (BusIBusImpl *ibus,
+ const gchar *name,
+ const gchar *icon_symbol)
+{
+ IBusEngineDesc *desc = NULL;
+ GValue value = { 0, };
+
+ g_assert (BUS_IS_IBUS_IMPL (ibus));
+ g_assert (name != NULL);
+ g_assert (icon_symbol != NULL);
+
+ desc = bus_ibus_impl_get_engine_desc (ibus, name);
+
+ if (desc == NULL) {
+ return;
+ }
+
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, icon_symbol);
+ g_object_set_property (G_OBJECT (desc), "icon_symbol", &value);
+ g_value_unset (&value);
+
+ /* Update status icon.
+ * "enabled" signal is caught by ibus->panel and ibus->panel calls
+ * StateChanged dbus method. */
+ if (ibus->panel && ibus->focused_context) {
+ if (bus_input_context_is_enabled (ibus->focused_context)) {
+ bus_input_context_enable (ibus->focused_context);
+ }
+ }
+}
diff --git a/bus/ibusimpl.h b/bus/ibusimpl.h
index 42edbf8..4f37cbc 100644
--- a/bus/ibusimpl.h
+++ b/bus/ibusimpl.h
@@ -99,6 +99,10 @@ gboolean bus_ibus_impl_is_embed_preedit_text
(BusIBusImpl *ibus);
BusInputContext *bus_ibus_impl_get_focused_input_context
(BusIBusImpl *ibus);
+void bus_ibus_impl_set_icon_symbol_with_engine_name
+ (BusIBusImpl *ibus,
+ const gchar *name,
+ const gchar *icon_symbol);
G_END_DECLS
#endif
diff --git a/ibus/engine.py b/ibus/engine.py
index fe5dd98..e827408 100644
--- a/ibus/engine.py
+++ b/ibus/engine.py
@@ -176,6 +176,9 @@ class EngineBase(object.Object):
self.__proxy = None
super(EngineBase,self).do_destroy()
+ def set_icon_symbol(self, icon_symbol):
+ return self.__proxy.SetIconSymbol(icon_symbol)
+
class EngineProxy(interface.IEngine):
def __init__(self, engine, conn, object_path):
2011-06-22 03:38:34 +00:00
diff --git a/ibus/enginedesc.py b/ibus/enginedesc.py
index e8a8982..f6b4110 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, icon_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.__icon_symbol = icon_symbol
def get_name(self):
return self.__name
@@ -74,6 +75,9 @@ class EngineDesc(Serializable):
def get_hotkeys(self):
return self.__hotkeys
+ def get_icon_symbol(self):
+ return self.__icon_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)
+ icon_symbol = property(get_icon_symbol)
def serialize(self, struct):
super(EngineDesc, self).serialize(struct)
@@ -98,7 +103,9 @@ class EngineDesc(Serializable):
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))
+ extension = dbus.Dictionary(signature="sv")
+ extension[dbus.String('icon_symbol')] = dbus.String(self.__icon_symbol)
+ struct.append(extension)
def deserialize(self, struct):
super(EngineDesc, self).deserialize(struct)
@@ -113,10 +120,13 @@ class EngineDesc(Serializable):
self.__rank = struct.pop(0)
self.__hotkeys = struct.pop(0)
# New properties of EngineDesc will use dict for serialize
- #value = struct.pop(0)
+ l = struct.pop(0)
+ for key, value in l.items():
+ if key == 'icon_symbol':
+ self.__icon_symbol= unicode(value)
def test():
- engine = EngineDesc("Hello", "", "", "", "", "", "", "", "")
+ engine = EngineDesc("Hello", "", "", "", "", "", "", "", "", 0, "")
value = serialize_object(engine)
engine = deserialize_object(value)
diff --git a/ibus/interface/iengine.py b/ibus/interface/iengine.py
index 9e0d981..7cefcdf 100644
--- a/ibus/interface/iengine.py
+++ b/ibus/interface/iengine.py
@@ -157,3 +157,6 @@ class IEngine(dbus.service.Object):
@signal()
def RequireSurroundingText(self): pass
+
+ @signal(signature="s")
+ def SetIconSymbol(self, icon_symbol): pass
diff --git a/src/ibusenginedesc.c b/src/ibusenginedesc.c
index ca5ef60..d3800e1 100644
--- a/src/ibusenginedesc.c
+++ b/src/ibusenginedesc.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include "ibusenginedesc.h"
#include "ibusxml.h"
+#include "ibusenumtypes.h"
enum {
LAST_SIGNAL,
@@ -39,6 +40,7 @@ enum {
PROP_LAYOUT,
PROP_RANK,
PROP_HOTKEYS,
+ PROP_ICON_SYMBOL,
};
@@ -54,6 +56,7 @@ struct _IBusEngineDescPrivate {
gchar *layout;
guint rank;
gchar *hotkeys;
+ gchar *icon_symbol;
};
#define IBUS_ENGINE_DESC_GET_PRIVATE(o) \
@@ -232,6 +235,19 @@ ibus_engine_desc_class_init (IBusEngineDescClass *class)
"The hotkeys of engine description",
"",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ /**
+ * IBusEngineDesc:icon_symbol:
+ *
+ * The symbol chars of engine description instead of icon image
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_ICON_SYMBOL,
+ g_param_spec_string ("icon_symbol",
+ "description icon_symbol",
+ "The icon symbol chars of engine description",
+ "",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
@@ -249,6 +265,7 @@ ibus_engine_desc_init (IBusEngineDesc *desc)
desc->priv->layout = NULL;
desc->priv->rank = 0;
desc->priv->hotkeys = NULL;
+ desc->priv->icon_symbol = NULL;
}
static void
@@ -263,6 +280,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->icon_symbol);
IBUS_OBJECT_CLASS (ibus_engine_desc_parent_class)->destroy (IBUS_OBJECT (desc));
}
@@ -313,6 +331,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_ICON_SYMBOL:
+ g_free (desc->priv->icon_symbol);
+ desc->priv->icon_symbol = g_value_dup_string (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (desc, prop_id, pspec);
}
@@ -355,6 +377,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_ICON_SYMBOL:
+ g_value_set_string (value, ibus_engine_desc_get_icon_symbol (desc));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (desc, prop_id, pspec);
}
@@ -382,9 +407,28 @@ ibus_engine_desc_serialize (IBusEngineDesc *desc,
g_variant_builder_add (builder, "u", desc->priv->rank);
g_variant_builder_add (builder, "s", NOTNULL (desc->priv->hotkeys));
#undef NOTNULL
+
+ /* append extra properties */
+ GVariantBuilder array;
+ g_variant_builder_init (&array, G_VARIANT_TYPE ("a{sv}"));
+ g_variant_builder_add (&array, "{sv}", "icon_symbol", g_variant_new_string (desc->priv->icon_symbol));
+ g_variant_builder_add (builder, "v", g_variant_builder_end (&array));
+
return TRUE;
}
+static gboolean
+ibus_engine_desc_deserialize_property (IBusEngineDesc *desc,
+ const gchar *name,
+ GVariant *variant)
+{
+ if (g_strcmp0 (name, "icon_symbol") == 0) {
+ g_variant_get (variant, "s", &desc->priv->icon_symbol);
+ return TRUE;
+ }
+ return FALSE;
+}
+
static gint
ibus_engine_desc_deserialize (IBusEngineDesc *desc,
GVariant *variant)
@@ -405,6 +449,23 @@ ibus_engine_desc_deserialize (IBusEngineDesc *desc,
g_variant_get_child (variant, retval++, "u", &desc->priv->rank);
g_variant_get_child (variant, retval++, "s", &desc->priv->hotkeys);
+ /* extract extra properties */
+ GVariantIter iter;
+ GVariant *child, *array;
+
+ g_variant_get_child (variant, retval++, "v", &array);
+ g_variant_iter_init (&iter, array);
+ while ((child = g_variant_iter_next_value (&iter))) {
+ gchar *name;
+ GVariant *value;
+ g_variant_get (child, "{sv}", &name, &value);
+ if (ibus_engine_desc_deserialize_property (desc, name, value))
+ retval++;
+ g_free (name);
+ g_variant_unref (value);
+ g_variant_unref (child);
+ }
+
return retval;
}
@@ -428,6 +489,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->icon_symbol = g_strdup (src->priv->icon_symbol);
return TRUE;
}
@@ -465,6 +527,7 @@ ibus_engine_desc_output (IBusEngineDesc *desc,
OUTPUT_ENTRY_1(icon);
OUTPUT_ENTRY_1(layout);
OUTPUT_ENTRY_1(hotkeys);
+ OUTPUT_ENTRY_1(icon_symbol);
g_string_append_indent (output, indent + 1);
g_string_append_printf (output, "<rank>%u</rank>\n", desc->priv->rank);
#undef OUTPUT_ENTRY
@@ -498,6 +561,7 @@ ibus_engine_desc_parse_xml_node (IBusEngineDesc *desc,
PARSE_ENTRY_1(icon);
PARSE_ENTRY_1(layout);
PARSE_ENTRY_1(hotkeys);
+ PARSE_ENTRY_1(icon_symbol);
#undef PARSE_ENTRY
#undef PARSE_ENTRY_1
if (g_strcmp0 (sub_node->name , "rank") == 0) {
@@ -526,6 +590,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 (icon_symbol, const gchar *)
#undef IBUS_ENGINE_DESC_GET_PROPERTY
IBusEngineDesc *
@@ -573,6 +638,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->icon_symbol);
return desc;
}
diff --git a/src/ibusenginedesc.h b/src/ibusenginedesc.h
index 9718b15..e3194c3 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_icon_symbol:
+ * @info: An IBusEngineDesc
+ * @returns: icon_symbol property in IBusEngineDesc
+ *
+ * Return the icon_symbol property in IBusEngineDesc. It should not be freed.
+ */
+const gchar *ibus_engine_desc_get_icon_symbol
+ (IBusEngineDesc *info);
+
+/**
* ibus_engine_desc_output:
* @info: An IBusEngineDesc
* @output: XML-formatted Input method engine description.
--
1.7.4.4