From: Peng Huang Date: Thu, 13 May 2010 11:15:39 +0000 (+0800) Subject: Make bopomofo as a separate input engine. X-Git-Tag: 1.3.10~162^2~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c18e74986fb1e608e313497d3b3914ab22a4854b;p=platform%2Fupstream%2Fibus-libpinyin.git Make bopomofo as a separate input engine. --- diff --git a/src/BopomofoEditor.cc b/src/BopomofoEditor.cc index c5432aa..519b70e 100644 --- a/src/BopomofoEditor.cc +++ b/src/BopomofoEditor.cc @@ -287,7 +287,7 @@ BopomofoEditor::updateAuxiliaryText (void) updateAuxiliaryTextBefore (m_buffer); - for (String::iterator i = m_text.begin();i!=m_text.end();i++) { + for (String::iterator i = m_text.begin(); i != m_text.end(); i++) { if (m_cursor == i - m_text.begin()) m_buffer << '|'; m_buffer.appendUnichar(bopomofo_char[keyvalToBopomofo(*i)]); diff --git a/src/Engine.cc b/src/Engine.cc index 7894df0..7b6bcf5 100644 --- a/src/Engine.cc +++ b/src/Engine.cc @@ -36,6 +36,10 @@ struct _IBusPinyinEngineClass { /* functions prototype */ static void ibus_pinyin_engine_class_init (IBusPinyinEngineClass *klass); static void ibus_pinyin_engine_init (IBusPinyinEngine *pinyin); +static GObject* ibus_pinyin_engine_constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params); + static void ibus_pinyin_engine_destroy (IBusPinyinEngine *pinyin); static gboolean ibus_pinyin_engine_process_key_event (IBusEngine *engine, @@ -84,10 +88,11 @@ G_DEFINE_TYPE (IBusPinyinEngine, ibus_pinyin_engine, IBUS_TYPE_ENGINE) static void ibus_pinyin_engine_class_init (IBusPinyinEngineClass *klass) { - // GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); IBusEngineClass *engine_class = IBUS_ENGINE_CLASS (klass); + object_class->constructor = ibus_pinyin_engine_constructor; ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_pinyin_engine_destroy; engine_class->process_key_event = ibus_pinyin_engine_process_key_event; @@ -115,7 +120,22 @@ ibus_pinyin_engine_init (IBusPinyinEngine *pinyin) { if (g_object_is_floating (pinyin)) g_object_ref_sink (pinyin); // make engine sink - new (& (pinyin->engine)) PinyinEngine (IBUS_ENGINE (pinyin)); +} + +static GObject* +ibus_pinyin_engine_constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + IBusPinyinEngine *engine; + + engine = (IBusPinyinEngine *) G_OBJECT_CLASS (ibus_pinyin_engine_parent_class)->constructor ( + type, + n_construct_params, + construct_params); + new (& (engine->engine)) PinyinEngine (IBUS_ENGINE (engine)); + + return (GObject *) engine; } static void diff --git a/src/Engine.h b/src/Engine.h index 0b39081..b05ab6e 100644 --- a/src/Engine.h +++ b/src/Engine.h @@ -10,6 +10,7 @@ namespace PY { (PY::ibus_pinyin_engine_get_type ()) GType ibus_pinyin_engine_get_type (void); + }; #endif diff --git a/src/Main.cc b/src/Main.cc index c53f44b..99625a4 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -72,15 +72,26 @@ start_component (void) "Peng Huang ", PKGDATADIR"/icons/ibus-pinyin.svg", "us")); + ibus_component_add_engine (component, + ibus_engine_desc_new ("bopomofo-debug", + N_("Bopomofo (debug)"), + N_("Bopomofo input method (debug)"), + "zh_CN", + "GPL", + "Peng Huang ", + PKGDATADIR"/icons/ibus-pinyin.svg", // TODO: need a new icon + "us")); factory = ibus_factory_new (ibus_bus_get_connection (bus)); if (ibus) { ibus_factory_add_engine (factory, "pinyin", IBUS_TYPE_PINYIN_ENGINE); + ibus_factory_add_engine (factory, "bopomofo", IBUS_TYPE_PINYIN_ENGINE); ibus_bus_request_name (bus, "org.freedesktop.IBus.Pinyin", 0); } else { ibus_factory_add_engine (factory, "pinyin-debug", IBUS_TYPE_PINYIN_ENGINE); + ibus_factory_add_engine (factory, "bopomofo-debug", IBUS_TYPE_PINYIN_ENGINE); ibus_bus_register_component (bus, component); } diff --git a/src/PinyinEngine.cc b/src/PinyinEngine.cc index ec84bb5..0b5ed3f 100644 --- a/src/PinyinEngine.cc +++ b/src/PinyinEngine.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include "RawEditor.h" #include "ExtEditor.h" @@ -23,15 +24,25 @@ PinyinEngine::PinyinEngine (IBusEngine *engine) : m_engine (engine), m_prev_pressed_key (IBUS_VoidSymbol), m_input_mode (MODE_INIT), + m_bopomofo (FALSE), m_fallback_editor (new FallbackEditor (m_props)) { gint i; + + /* Is it bopomofo engine */ + m_bopomofo = std::strcmp (ibus_engine_get_name (engine), "bopomofo") == 0 || + std::strcmp (ibus_engine_get_name (engine), "bopomofo-debug") == 0; + /* create editors */ - if (Config::doublePinyin ()) - //m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props)); + if (!m_bopomofo) { + if (Config::doublePinyin ()) + m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props)); + else + m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props)); + } + else { m_editors[MODE_INIT].reset (new BopomofoEditor (m_props)); - else - m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props)); + } m_editors[MODE_RAW].reset (new RawEditor (m_props)); m_editors[MODE_EXTENSION].reset (new ExtEditor (m_props)); @@ -129,21 +140,21 @@ void PinyinEngine::focusIn (void) { /* reset pinyin editor */ - if (Config::doublePinyin ()) { - //if (dynamic_cast (m_editors[MODE_INIT].get ()) == NULL) { - // m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props)); - if (dynamic_cast (m_editors[MODE_INIT].get ()) == NULL) { - m_editors[MODE_INIT].reset (new BopomofoEditor (m_props)); - connectEditorSignals (m_editors[MODE_INIT]); + if (!m_bopomofo) { + if (Config::doublePinyin ()) { + if (dynamic_cast (m_editors[MODE_INIT].get ()) == NULL) { + m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props)); + connectEditorSignals (m_editors[MODE_INIT]); + } } - } - else { - if (dynamic_cast (m_editors[MODE_INIT].get ()) == NULL) { - m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props)); - connectEditorSignals (m_editors[MODE_INIT]); + else { + if (dynamic_cast (m_editors[MODE_INIT].get ()) == NULL) { + m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props)); + connectEditorSignals (m_editors[MODE_INIT]); + } } + ibus_engine_register_properties (m_engine, m_props.properties ()); } - ibus_engine_register_properties (m_engine, m_props.properties ()); } diff --git a/src/PinyinEngine.h b/src/PinyinEngine.h index 6f2d0b7..f39429c 100644 --- a/src/PinyinEngine.h +++ b/src/PinyinEngine.h @@ -84,6 +84,8 @@ private: MODE_LAST, } m_input_mode; + gboolean m_bopomofo; + EditorPtr m_editors[MODE_LAST]; EditorPtr m_fallback_editor; }; diff --git a/src/pinyin.xml.in.in b/src/pinyin.xml.in.in index 9e04313..ff7746c 100644 --- a/src/pinyin.xml.in.in +++ b/src/pinyin.xml.in.in @@ -22,6 +22,17 @@ Pinyin input method 99 + + bopomofo + zh + GPL + Peng Huang <shawn.p.huang@gmail.com> + ${pkgdatadir}/icons/ibus-pinyin.svg + us + Bopomofo + Bopomofo input method + 99 +