Make bopomofo as a separate input engine.
authorPeng Huang <shawn.p.huang@gmail.com>
Thu, 13 May 2010 11:15:39 +0000 (19:15 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Thu, 13 May 2010 11:15:39 +0000 (19:15 +0800)
src/BopomofoEditor.cc
src/Engine.cc
src/Engine.h
src/Main.cc
src/PinyinEngine.cc
src/PinyinEngine.h
src/pinyin.xml.in.in

index c5432aa..519b70e 100644 (file)
@@ -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)]);
index 7894df0..7b6bcf5 100644 (file)
@@ -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
index 0b39081..b05ab6e 100644 (file)
@@ -10,6 +10,7 @@ namespace PY {
        (PY::ibus_pinyin_engine_get_type ())
 
 GType   ibus_pinyin_engine_get_type    (void);
+
 };
 
 #endif
index c53f44b..99625a4 100644 (file)
@@ -72,15 +72,26 @@ start_component (void)
                                                      "Peng Huang <shawn.p.huang@gmail.com>",
                                                      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 <shawn.p.huang@gmail.com>",
+                                                     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);
     }
 
index ec84bb5..0b5ed3f 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <libintl.h>
 #include <string>
+#include <cstdlib>
 #include <ibus.h>
 #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 <DoublePinyinEditor *> (m_editors[MODE_INIT].get ()) == NULL) {
-        //    m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props));
-        if (dynamic_cast <BopomofoEditor *> (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 <DoublePinyinEditor *> (m_editors[MODE_INIT].get ()) == NULL) {
+                m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props));
+                connectEditorSignals (m_editors[MODE_INIT]);
+            }
         }
-    }
-    else {
-        if (dynamic_cast <FullPinyinEditor *> (m_editors[MODE_INIT].get ()) == NULL) {
-            m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props));
-            connectEditorSignals (m_editors[MODE_INIT]);
+        else {
+            if (dynamic_cast <FullPinyinEditor *> (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 ());
 }
 
 
index 6f2d0b7..f39429c 100644 (file)
@@ -84,6 +84,8 @@ private:
         MODE_LAST,
     } m_input_mode;
 
+    gboolean m_bopomofo;
+
     EditorPtr m_editors[MODE_LAST];
     EditorPtr m_fallback_editor;
 };
index 9e04313..ff7746c 100644 (file)
                        <description>Pinyin input method</description>
                        <rank>99</rank>
                </engine>
+               <engine>
+                       <name>bopomofo</name>
+                       <language>zh</language>
+                       <license>GPL</license>
+                       <author>Peng Huang &lt;shawn.p.huang@gmail.com&gt;</author>
+                       <icon>${pkgdatadir}/icons/ibus-pinyin.svg</icon>
+                       <layout>us</layout>
+                       <longname>Bopomofo</longname>
+                       <description>Bopomofo input method</description>
+                       <rank>99</rank>
+               </engine>
        </engines>
 
 </component>