From: Peng Huang Date: Sun, 18 Apr 2010 04:27:37 +0000 (+0800) Subject: Use Object as the base class to replace Pointer. X-Git-Tag: 1.3.10~197 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cbbfa1fbec89ab312fc132c465404b8c0da754aa;p=platform%2Fupstream%2Fibus-libpinyin.git Use Object as the base class to replace Pointer. --- diff --git a/src/Bus.h b/src/Bus.h index 6de9d66..74b0ad4 100644 --- a/src/Bus.h +++ b/src/Bus.h @@ -2,19 +2,22 @@ #define __PY_BUS_H_ #include -#include "Pointer.h" +#include "Object.h" namespace PY { -class Bus : public Pointer { +class Bus : Object { public: - Bus (void) { - set (ibus_bus_new ()); + Bus (void) : Object (ibus_bus_new ()) { } bool isConnected (void) { return ibus_bus_is_connected (*this); } + + operator IBusBus * (void) const { + return get (); + } }; }; diff --git a/src/Config.cc b/src/Config.cc index e01d40f..c73b2de 100644 --- a/src/Config.cc +++ b/src/Config.cc @@ -152,7 +152,7 @@ inline bool Config::read (const gchar *section, const gchar *name, bool defval) { GValue value = {0}; - if (ibus_config_get_value (m_config, section, name, &value)) { + if (ibus_config_get_value (get (), section, name, &value)) { if (G_VALUE_TYPE (&value) == G_TYPE_BOOLEAN) return g_value_get_boolean (&value); } @@ -163,7 +163,7 @@ inline gint Config::read (const gchar *section, const gchar *name, gint defval) { GValue value = {0}; - if (ibus_config_get_value (m_config, section, name, &value)) { + if (ibus_config_get_value (get (), section, name, &value)) { if (G_VALUE_TYPE (&value) == G_TYPE_INT) return g_value_get_int (&value); } diff --git a/src/Config.h b/src/Config.h index 07f16f1..e2f5a05 100644 --- a/src/Config.h +++ b/src/Config.h @@ -4,16 +4,16 @@ #include #include #include -#include "Pointer.h" +#include "Object.h" +#include "Bus.h" namespace PY { -class Config { +class Config : Object { public: - Config (Pointer & bus) { - m_config = ibus_bus_get_config (bus); + Config (Bus & bus) : Object (ibus_bus_get_config (bus)) { readDefaultValues (); - g_signal_connect ((IBusConfig *) m_config, "value-changed", G_CALLBACK (valueChangedCallback), this); + g_signal_connect (get (), "value-changed", G_CALLBACK (valueChangedCallback), this); } static guint option (void) { return m_option & m_option_mask; } @@ -44,9 +44,6 @@ private: Config *self); private: - Pointer m_config; - -private: static guint m_option; static guint m_option_mask; diff --git a/src/LookupTable.h b/src/LookupTable.h index 91ff809..2fd8fb2 100644 --- a/src/LookupTable.h +++ b/src/LookupTable.h @@ -2,18 +2,18 @@ #define __PY_LOOKUP_TABLE_H_ #include -#include "Pointer.h" +#include "Object.h" #include "Text.h" namespace PY { -class LookupTable : public Pointer { +class LookupTable : Object { public: LookupTable (guint page_size = 10, guint cursor_pos = 0, gboolean cursor_visible = TRUE, gboolean round = FALSE) - : Pointer (ibus_lookup_table_new (page_size, cursor_pos, cursor_visible, round)) { } + : Object (ibus_lookup_table_new (page_size, cursor_pos, cursor_visible, round)) { } guint pageSize (void) { return ibus_lookup_table_get_page_size (*this); } guint orientation (void) { return ibus_lookup_table_get_orientation (*this); } @@ -32,6 +32,10 @@ public: void appendCandidate (IBusText *text) { ibus_lookup_table_append_candidate (*this, text); } + + operator IBusLookupTable * (void) const { + return get (); + } }; }; diff --git a/src/Main.cc b/src/Main.cc index f2e1126..d7a11cc 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -50,7 +50,7 @@ start_component (void) Config config (bus); - g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL); + g_signal_connect ((IBusBus *)bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL); component = ibus_component_new ("org.freedesktop.IBus.Pinyin", N_("Pinyin input method"), diff --git a/src/Makefile.am b/src/Makefile.am index 1b56c86..a936803 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -73,6 +73,7 @@ ibus_engine_h_sources = \ FullPinyinEditor.h \ HalfFullConverter.h \ LookupTable.h \ + Object.h \ Phrase.h \ PhraseArray.h \ PhraseEditor.h \ diff --git a/src/Object.h b/src/Object.h new file mode 100644 index 0000000..8b1a6c8 --- /dev/null +++ b/src/Object.h @@ -0,0 +1,30 @@ +#ifndef __PY_OBJECT_H_ +#define __PY_OBJECT_H_ + +#include +#include "Pointer.h" + +namespace PY { + +class Object { +protected: + template + Object (T *p) : m_p ((GObject *)p) { + } + + operator GObject * (void) const { + return m_p; + } + + template + T * get (void) const { + return (T *) (GObject *) m_p; + } + +private: + Pointer m_p; +}; + +}; + +#endif diff --git a/src/PinyinEngine.cc b/src/PinyinEngine.cc index 89cb515..5451021 100644 --- a/src/PinyinEngine.cc +++ b/src/PinyinEngine.cc @@ -194,7 +194,7 @@ PinyinEngine::candidateClicked (guint index, guint button, guint state) void PinyinEngine::slotCommitText (Text & text) { - m_last_commit_text = text; + // m_last_commit_text = text; ibus_engine_commit_text (m_engine, text); if (m_input_mode != MODE_INIT) m_input_mode = MODE_INIT; diff --git a/src/PinyinEngine.h b/src/PinyinEngine.h index bbcced0..6d81ec8 100644 --- a/src/PinyinEngine.h +++ b/src/PinyinEngine.h @@ -35,7 +35,7 @@ public: m_editors[i]->reset (); } m_fallback_editor->reset (); - m_last_commit_text = NULL; + // m_last_commit_text = NULL; } @@ -90,7 +90,7 @@ private: EditorPtr m_editors[MODE_LAST]; EditorPtr m_fallback_editor; - Text m_last_commit_text; + // Text m_last_commit_text; }; }; diff --git a/src/PinyinProperties.cc b/src/PinyinProperties.cc index 94b7a80..b884f3f 100644 --- a/src/PinyinProperties.cc +++ b/src/PinyinProperties.cc @@ -9,70 +9,45 @@ PinyinProperties::PinyinProperties (void) : m_mode_chinese (Config::initChinese ()), m_mode_full (Config::initFull ()), m_mode_full_punct (Config::initFullPunct ()), - m_mode_simp (Config::initSimpChinese ()) + m_mode_simp (Config::initSimpChinese ()), + m_prop_chinese ("mode.chinese", + PROP_TYPE_NORMAL, + StaticText ("CN"), + m_mode_chinese ? + PKGDATADIR"/icons/chinese.svg" : + PKGDATADIR"/icons/english.svg", + StaticText (_("Chinese"))), + m_prop_full ("mode.full", + PROP_TYPE_NORMAL, + StaticText (m_mode_full ? "Aa" : "Aa"), + m_mode_full ? + PKGDATADIR"/icons/full.svg" : + PKGDATADIR"/icons/half.svg", + StaticText (_("Full/Half width"))), + m_prop_full_punct ("mode.full_punct", + PROP_TYPE_NORMAL, + StaticText (m_mode_full_punct ? ",。" : ",."), + m_mode_full_punct ? + PKGDATADIR"/icons/full-punct.svg" : + PKGDATADIR"/icons/half-punct.svg", + StaticText (_("Full/Half width punctuation"))), + m_prop_simp ( "mode.simp", + PROP_TYPE_NORMAL, + StaticText (m_mode_simp ? "简" : "繁"), + m_mode_simp ? + PKGDATADIR"/icons/simp-chinese.svg" : + PKGDATADIR"/icons/trad-chinese.svg", + StaticText (_("Simplfied/Traditional Chinese"))), + m_prop_setup ("setup", + PROP_TYPE_NORMAL, + StaticText (_("Pinyin preferences")), + "ibus-setup", + StaticText (_("Pinyin preferences"))) { - /* create properties */ - m_prop_chinese = ibus_property_new ("mode.chinese", - PROP_TYPE_NORMAL, - StaticText ("CN"), - m_mode_chinese ? - PKGDATADIR"/icons/chinese.svg" : - PKGDATADIR"/icons/english.svg", - StaticText (_("Chinese")), - TRUE, - TRUE, - PROP_STATE_UNCHECKED, - NULL); m_props.append (m_prop_chinese); - - m_prop_full = ibus_property_new ("mode.full", - PROP_TYPE_NORMAL, - StaticText (m_mode_full? "Aa" : "Aa"), - m_mode_full ? - PKGDATADIR"/icons/full.svg" : - PKGDATADIR"/icons/half.svg", - StaticText (_("Full/Half width")), - TRUE, - TRUE, - PROP_STATE_UNCHECKED, - NULL); m_props.append (m_prop_full); - - m_prop_full_punct = ibus_property_new ("mode.full_punct", - PROP_TYPE_NORMAL, - StaticText (m_mode_full_punct ? ",。" : ",."), - m_mode_full_punct ? - PKGDATADIR"/icons/full-punct.svg" : - PKGDATADIR"/icons/half-punct.svg", - StaticText (_("Full/Half width punctuation")), - TRUE, - TRUE, - PROP_STATE_UNCHECKED, - NULL); m_props.append (m_prop_full_punct); - - m_prop_simp = ibus_property_new ("mode.simp", - PROP_TYPE_NORMAL, - StaticText (m_mode_simp ? "简" : "繁"), - m_mode_simp ? - PKGDATADIR"/icons/simp-chinese.svg" : - PKGDATADIR"/icons/trad-chinese.svg", - StaticText (_("Simplfied/Traditional Chinese")), - TRUE, - TRUE, - PROP_STATE_UNCHECKED, - NULL); m_props.append (m_prop_simp); - - m_prop_setup = ibus_property_new ("setup", - PROP_TYPE_NORMAL, - StaticText (_("Pinyin preferences")), - "ibus-setup", - StaticText (_("Pinyin preferences")), - TRUE, - TRUE, - PROP_STATE_UNCHECKED, - NULL); m_props.append (m_prop_setup); } diff --git a/src/Property.h b/src/Property.h index 5237cd7..0d7b72c 100644 --- a/src/Property.h +++ b/src/Property.h @@ -2,39 +2,56 @@ #define __PY_PROPERTY_H_ #include -#include "Pointer.h" +#include "Object.h" #include "Text.h" namespace PY { -class Property : public Pointer { +class Property : public Object { public: - Property & operator= (IBusProperty *p) { - set (p); - return *this; + Property (const gchar *key, + IBusPropType type = PROP_TYPE_NORMAL, + IBusText *label = NULL, + const gchar *icon = NULL, + IBusText *tooltip = NULL, + gboolean sensitive = TRUE, + gboolean visible = TRUE, + IBusPropState state = PROP_STATE_UNCHECKED, + IBusPropList *props = NULL) + : Object (ibus_property_new (key, type, label, icon, tooltip, sensitive, visible, state, props)) { } + + void setLabel (IBusText *text) { + ibus_property_set_label (get (), text); } - void setLabel (const Text & text) { - ibus_property_set_label (*this, text); - } void setLabel (const gchar *text) { setLabel (Text (text)); } + void setIcon (const gchar *icon) { - ibus_property_set_icon (*this, icon); + ibus_property_set_icon (get (), icon); } + void setSensitive (gboolean sensitive) { - ibus_property_set_sensitive (*this, sensitive); + ibus_property_set_sensitive (get (), sensitive); + } + + operator IBusProperty * (void) const { + return get (); } }; -class PropList : public Pointer { +class PropList : Object { public: - PropList (void) : Pointer (ibus_prop_list_new ()) { } + PropList (void) : Object (ibus_prop_list_new ()) { } void append (Property &prop) { - ibus_prop_list_append (*this, prop); + ibus_prop_list_append (get (), prop); + } + + operator IBusPropList * (void) const { + return get (); } }; diff --git a/src/Text.h b/src/Text.h index 983295c..451cd63 100644 --- a/src/Text.h +++ b/src/Text.h @@ -2,32 +2,30 @@ #define __PY_TEXT_H_ #include -#include "Pointer.h" +#include "Object.h" #include "String.h" namespace PY { -class Text : public Pointer { +class Text : Object { public: - Text () : Pointer () {} Text (IBusText *text) - : Pointer (text) {} + : Object (text) {} Text (const gchar *str) - : Pointer (ibus_text_new_from_string (str)) {} + : Object (ibus_text_new_from_string (str)) {} Text (const String & str) - : Pointer (ibus_text_new_from_string ((const gchar *) str)) {} + : Object (ibus_text_new_from_string ((const gchar *) str)) {} Text (gunichar ch) - : Pointer (ibus_text_new_from_unichar (ch)) {} + : Object (ibus_text_new_from_unichar (ch)) {} void appendAttribute (guint type, guint value, guint start, guint end) { - ibus_text_append_attribute (*this, type, value, start, end); + ibus_text_append_attribute (get (), type, value, start, end); } - Text & operator= (IBusText *p) { - set (p); - return *this; + operator IBusText * (void) const { + return get (); } }; @@ -42,6 +40,10 @@ public: StaticText (gunichar ch) : Text (ch) {} + + operator IBusText * (void) const { + return Text::operator IBusText * (); + } }; };