From 163587a5185b137df364194d862a671019e3528c Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Sun, 23 May 2010 11:59:06 +0800 Subject: [PATCH] Separate Config to PinyinConfig and BopomofoConfig --- src/BopomofoEditor.cc | 9 ++- src/BopomofoEditor.h | 2 +- src/BopomofoEngine.cc | 11 ++-- src/Config.cc | 138 ++++++++++++++++++++++++++++++---------------- src/Config.h | 115 +++++++++++++++++++++++--------------- src/DoublePinyinEditor.cc | 25 ++++----- src/DoublePinyinEditor.h | 2 +- src/Editor.cc | 5 +- src/Editor.h | 4 +- src/ExtEditor.cc | 4 +- src/ExtEditor.h | 2 +- src/FallbackEditor.h | 4 +- src/FullPinyinEditor.cc | 9 ++- src/FullPinyinEditor.h | 2 +- src/Main.cc | 3 +- src/PhraseEditor.cc | 10 ++-- src/PhraseEditor.h | 4 +- src/PinyinEditor.cc | 29 +++++----- src/PinyinEditor.h | 2 +- src/PinyinEngine.cc | 21 +++---- src/PinyinProperties.cc | 11 ++-- src/PinyinProperties.h | 3 +- src/PunctEditor.cc | 10 ++-- src/PunctEditor.h | 2 +- src/RawEditor.h | 3 +- src/SpecialPhraseTable.cc | 2 +- 26 files changed, 255 insertions(+), 177 deletions(-) diff --git a/src/BopomofoEditor.cc b/src/BopomofoEditor.cc index ef292fc..6e18133 100644 --- a/src/BopomofoEditor.cc +++ b/src/BopomofoEditor.cc @@ -19,7 +19,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "Config.h" #include "BopomofoEditor.h" #include "SimpTradConverter.h" @@ -38,8 +37,8 @@ namespace PY { #include "Bopomofo.h" #include "BopomofoKeyboard.h" -BopomofoEditor::BopomofoEditor (PinyinProperties & props) - : PinyinEditor (props), +BopomofoEditor::BopomofoEditor (PinyinProperties & props, Config & config) + : PinyinEditor (props, config), m_select_mode (FALSE) { } @@ -64,7 +63,7 @@ BopomofoEditor::insert (gint ch) m_text.insert (m_cursor++, ch); - if (G_UNLIKELY (!(Config::option () & PINYIN_INCOMPLETE_PINYIN))) { + if (G_UNLIKELY (!(m_config.option () & PINYIN_INCOMPLETE_PINYIN))) { updateSpecialPhrases (); updatePinyin (); } @@ -422,7 +421,7 @@ BopomofoEditor::updatePinyin (void) m_pinyin_len = PinyinParser::parseBopomofo (bopomofo, // bopomofo m_cursor, // text length - Config::option (), // option + m_config.option (), // option m_pinyin, // result MAX_PHRASE_LEN); // max result length } diff --git a/src/BopomofoEditor.h b/src/BopomofoEditor.h index ce87322..184858e 100644 --- a/src/BopomofoEditor.h +++ b/src/BopomofoEditor.h @@ -29,7 +29,7 @@ namespace PY { class BopomofoEditor : public PinyinEditor { public: - BopomofoEditor (PinyinProperties & props); + BopomofoEditor (PinyinProperties & props, Config & config = BopomofoConfig::instance ()); ~BopomofoEditor (void); public: diff --git a/src/BopomofoEngine.cc b/src/BopomofoEngine.cc index 773fb18..30b1d5f 100644 --- a/src/BopomofoEngine.cc +++ b/src/BopomofoEngine.cc @@ -42,18 +42,19 @@ namespace PY { /* constructor */ BopomofoEngine::BopomofoEngine (IBusEngine *engine) : Engine (engine), + m_props (BopomofoConfig::instance ()), m_prev_pressed_key (IBUS_VoidSymbol), m_input_mode (MODE_INIT), - m_fallback_editor (new FallbackEditor (m_props)) + m_fallback_editor (new FallbackEditor (m_props, BopomofoConfig::instance ())) { gint i; /* create editors */ - m_editors[MODE_INIT].reset (new BopomofoEditor (m_props)); - m_editors[MODE_PUNCT].reset (new PunctEditor (m_props)); + m_editors[MODE_INIT].reset (new BopomofoEditor (m_props, BopomofoConfig::instance ())); + m_editors[MODE_PUNCT].reset (new PunctEditor (m_props, BopomofoConfig::instance ())); - m_editors[MODE_RAW].reset (new RawEditor (m_props)); - m_editors[MODE_EXTENSION].reset (new ExtEditor (m_props)); + m_editors[MODE_RAW].reset (new RawEditor (m_props, BopomofoConfig::instance ())); + m_editors[MODE_EXTENSION].reset (new ExtEditor (m_props, BopomofoConfig::instance ())); m_props.signalUpdateProperty ().connect (bind (&BopomofoEngine::updateProperty, this, _1)); diff --git a/src/Config.cc b/src/Config.cc index a971f06..415295f 100644 --- a/src/Config.cc +++ b/src/Config.cc @@ -18,32 +18,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include "Types.h" #include "Config.h" #include "Util.h" namespace PY { -guint Config::m_option = PINYIN_INCOMPLETE_PINYIN | PINYIN_CORRECT_ALL; -guint Config::m_option_mask = PINYIN_INCOMPLETE_PINYIN | PINYIN_CORRECT_ALL; +PinyinConfig * PinyinConfig::m_instance = NULL; +BopomofoConfig * BopomofoConfig::m_instance = NULL; -gint Config::m_orientation = IBUS_ORIENTATION_HORIZONTAL; -guint Config::m_page_size = 5; -gboolean Config::m_shift_select_candidate = FALSE; -gboolean Config::m_minus_equal_page = TRUE; -gboolean Config::m_comma_period_page = TRUE; -gboolean Config::m_auto_commit = FALSE; - -gboolean Config::m_double_pinyin = FALSE; -gint Config::m_double_pinyin_schema = 0; -gboolean Config::m_double_pinyin_show_raw = FALSE; - -gboolean Config::m_init_chinese = TRUE; -gboolean Config::m_init_full = FALSE; -gboolean Config::m_init_full_punct = TRUE; -gboolean Config::m_init_simp_chinese = TRUE; -gboolean Config::m_trad_candidate = FALSE; -gboolean Config::m_special_phrases = TRUE; +#if 0 +#endif static const std::string engine_pinyin ("engine/Pinyin"); static const std::string correct_pinyin ("CorrectPinyin"); @@ -67,6 +53,40 @@ static const std::string init_simp_chinese ("InitSimplifiedChinese"); static const std::string trad_candidate ("TradCandidate"); static const std::string special_phrases ("SpecialPhrases"); + + +Config::Config (Bus & bus, const std::string & name) + : Object (ibus_bus_get_config (bus)), + m_section ("engine/" + name) +{ + m_option = PINYIN_INCOMPLETE_PINYIN | PINYIN_CORRECT_ALL; + m_option_mask = PINYIN_INCOMPLETE_PINYIN | PINYIN_CORRECT_ALL; + + m_orientation = IBUS_ORIENTATION_HORIZONTAL; + m_page_size = 5; + m_shift_select_candidate = FALSE; + m_minus_equal_page = TRUE; + m_comma_period_page = TRUE; + m_auto_commit = FALSE; + + m_double_pinyin = FALSE; + m_double_pinyin_schema = 0; + m_double_pinyin_show_raw = FALSE; + + m_init_chinese = TRUE; + m_init_full = FALSE; + m_init_full_punct = TRUE; + m_init_simp_chinese = TRUE; + m_trad_candidate = FALSE; + m_special_phrases = TRUE; + + readDefaultValues (); + g_signal_connect (get (), + "value-changed", + G_CALLBACK (valueChangedCallback), + this); +} + static const struct { std::string name; guint option; @@ -114,55 +134,55 @@ void Config::readDefaultValues (void) { /* double pinyin */ - m_double_pinyin = read (engine_pinyin, double_pinyin, false); - m_double_pinyin_schema = read (engine_pinyin, double_pinyin_schema, 0); + m_double_pinyin = read (double_pinyin, false); + m_double_pinyin_schema = read (double_pinyin_schema, 0); if (m_double_pinyin_schema >= 5) { m_double_pinyin_schema = 0; g_warn_if_reached (); } - m_double_pinyin_show_raw = read (engine_pinyin, double_pinyin_show_raw, false); + m_double_pinyin_show_raw = read (double_pinyin_show_raw, false); /* init states */ - m_init_chinese = read (engine_pinyin, init_chinese, true); - m_init_full = read (engine_pinyin, init_full, false); - m_init_full_punct = read (engine_pinyin, init_full_punct, true); - m_init_simp_chinese = read (engine_pinyin, init_simp_chinese, true); + m_init_chinese = read (init_chinese, true); + m_init_full = read (init_full, false); + m_init_full_punct = read (init_full_punct, true); + m_init_simp_chinese = read (init_simp_chinese, true); - m_trad_candidate = read (engine_pinyin, trad_candidate, false); - m_special_phrases = read (engine_pinyin, special_phrases, true); + m_trad_candidate = read (trad_candidate, false); + m_special_phrases = read (special_phrases, true); /* others */ - m_orientation = read (engine_pinyin, PY::orientation, 0); + m_orientation = read (PY::orientation, 0); if (m_orientation != IBUS_ORIENTATION_VERTICAL && m_orientation != IBUS_ORIENTATION_HORIZONTAL) { m_orientation = IBUS_ORIENTATION_HORIZONTAL; g_warn_if_reached (); } - m_page_size = read (engine_pinyin, page_size, 5); + m_page_size = read (page_size, 5); if (m_page_size > 10) { m_page_size = 5; g_warn_if_reached (); } - m_shift_select_candidate = read (engine_pinyin, shift_select_candidate, false); - m_minus_equal_page = read (engine_pinyin, minus_equal_page, true); - m_comma_period_page = read (engine_pinyin, comma_period_page, true); - m_auto_commit = read (engine_pinyin, auto_commit, false); + m_shift_select_candidate = read (shift_select_candidate, false); + m_minus_equal_page = read (minus_equal_page, true); + m_comma_period_page = read (comma_period_page, true); + m_auto_commit = read (auto_commit, false); /* correct pinyin */ - if (read (engine_pinyin, correct_pinyin, true)) + if (read (correct_pinyin, true)) m_option_mask |= PINYIN_CORRECT_ALL; else m_option_mask &= ~PINYIN_CORRECT_ALL; /* fuzzy pinyin */ - if (read (engine_pinyin, fuzzy_pinyin, false)) + if (read (fuzzy_pinyin, false)) m_option_mask |= PINYIN_FUZZY_ALL; else m_option_mask &= ~PINYIN_FUZZY_ALL; /* read values */ for (guint i = 0; i < G_N_ELEMENTS (options); i++) { - if (read (engine_pinyin, options[i].name, options[i].defval)) + if (read (options[i].name, options[i].defval)) m_option |= options[i].option; else m_option &= ~options[i].option; @@ -170,12 +190,11 @@ Config::readDefaultValues (void) } inline bool -Config::read (const std::string & section, - const std::string & name, +Config::read (const std::string & name, bool defval) { GValue value = {0}; - if (ibus_config_get_value (get (), section.c_str (), name.c_str (), &value)) { + if (ibus_config_get_value (get (), m_section.c_str (), name.c_str (), &value)) { if (G_VALUE_TYPE (&value) == G_TYPE_BOOLEAN) return g_value_get_boolean (&value); } @@ -183,12 +202,11 @@ Config::read (const std::string & section, } inline gint -Config::read (const std::string & section, - const std::string & name, +Config::read (const std::string & name, gint defval) { GValue value = {0}; - if (ibus_config_get_value (get (), section.c_str (), name.c_str (), &value)) { + if (ibus_config_get_value (get (), m_section.c_str (), name.c_str (), &value)) { if (G_VALUE_TYPE (&value) == G_TYPE_INT) return g_value_get_int (&value); } @@ -211,12 +229,11 @@ normalizeGValue (const GValue *value, gint defval) return g_value_get_int (value); } + void -Config::valueChangedCallback (IBusConfig *config, - const gchar *section, - const gchar *name, - const GValue *value, - Config *self) +Config::valueChanged (const std::string & section, + const std::string & name, + const GValue *value) { if (engine_pinyin != section) return; @@ -298,5 +315,30 @@ Config::valueChangedCallback (IBusConfig *config, } +void +Config::valueChangedCallback (IBusConfig *config, + const gchar *section, + const gchar *name, + const GValue *value, + Config *self) +{ + self->valueChanged (section, name, value); +} + +void +PinyinConfig::init (Bus & bus) +{ + if (PinyinConfig::m_instance == NULL) { + PinyinConfig::m_instance = new PinyinConfig (bus); + } +} + +void +BopomofoConfig::init (Bus & bus) +{ + if (BopomofoConfig::m_instance == NULL) { + BopomofoConfig::m_instance = new BopomofoConfig (bus); + } +} }; diff --git a/src/Config.h b/src/Config.h index be8a7bc..24d3da1 100644 --- a/src/Config.h +++ b/src/Config.h @@ -31,33 +31,35 @@ namespace PY { class Config : Object { +protected: + Config (Bus & bus, const std::string & name); + public: - Config (Bus & bus) : Object (ibus_bus_get_config (bus)) { - readDefaultValues (); - g_signal_connect (get (), "value-changed", G_CALLBACK (valueChangedCallback), this); - } - - static guint option (void) { return m_option & m_option_mask; } - static guint orientation (void) { return m_orientation; } - static guint pageSize (void) { return m_page_size; } - static gboolean shiftSelectCandidate (void) { return m_shift_select_candidate; } - static gboolean minusEqualPage (void) { return m_minus_equal_page; } - static gboolean commaPeriodPage (void) { return m_comma_period_page; } - static gboolean autoCommit (void) { return m_auto_commit; } - static gboolean doublePinyin (void) { return m_double_pinyin; } - static gint doublePinyinSchema (void) { return m_double_pinyin_schema; } - static gboolean doublePinyinShowRaw (void) { return m_double_pinyin_show_raw; } - static gboolean initChinese (void) { return m_init_chinese; } - static gboolean initFull (void) { return m_init_full; } - static gboolean initFullPunct (void) { return m_init_full_punct; } - static gboolean initSimpChinese (void) { return m_init_simp_chinese; } - static gboolean tradCandidate (void) { return m_trad_candidate; } - static gboolean specialPhrases (void) { return m_special_phrases; } + guint option (void) { return m_option & m_option_mask; } + guint orientation (void) { return m_orientation; } + guint pageSize (void) { return m_page_size; } + gboolean shiftSelectCandidate (void) { return m_shift_select_candidate; } + gboolean minusEqualPage (void) { return m_minus_equal_page; } + gboolean commaPeriodPage (void) { return m_comma_period_page; } + gboolean autoCommit (void) { return m_auto_commit; } + gboolean doublePinyin (void) { return m_double_pinyin; } + gint doublePinyinSchema (void) { return m_double_pinyin_schema; } + gboolean doublePinyinShowRaw (void) { return m_double_pinyin_show_raw; } + gboolean initChinese (void) { return m_init_chinese; } + gboolean initFull (void) { return m_init_full; } + gboolean initFullPunct (void) { return m_init_full_punct; } + gboolean initSimpChinese (void) { return m_init_simp_chinese; } + gboolean tradCandidate (void) { return m_trad_candidate; } + gboolean specialPhrases (void) { return m_special_phrases; } private: - bool read (const std::string & section, const std::string & name, bool defval); - int read (const std::string & section, const std::string & name, int defval); + bool read (const std::string & name, bool defval); + int read (const std::string & name, int defval); void readDefaultValues (void); + + virtual void valueChanged (const std::string & section, + const std::string & name, + const GValue *value); static void valueChangedCallback (IBusConfig *config, const gchar *section, const gchar *name, @@ -65,26 +67,53 @@ private: Config *self); private: - static guint m_option; - static guint m_option_mask; - - static gint m_orientation; - static guint m_page_size; - static gboolean m_shift_select_candidate; - static gboolean m_minus_equal_page; - static gboolean m_comma_period_page; - static gboolean m_auto_commit; - - static gboolean m_double_pinyin; - static gint m_double_pinyin_schema; - static gboolean m_double_pinyin_show_raw; - - static gboolean m_init_chinese; - static gboolean m_init_full; - static gboolean m_init_full_punct; - static gboolean m_init_simp_chinese; - static gboolean m_trad_candidate; - static gboolean m_special_phrases; + std::string m_section; + guint m_option; + guint m_option_mask; + + gint m_orientation; + guint m_page_size; + gboolean m_shift_select_candidate; + gboolean m_minus_equal_page; + gboolean m_comma_period_page; + gboolean m_auto_commit; + + gboolean m_double_pinyin; + gint m_double_pinyin_schema; + gboolean m_double_pinyin_show_raw; + + gboolean m_init_chinese; + gboolean m_init_full; + gboolean m_init_full_punct; + gboolean m_init_simp_chinese; + gboolean m_trad_candidate; + gboolean m_special_phrases; +}; + +/* PinyinConfig */ +class PinyinConfig : public Config { +public: + static void init (Bus & bus); + static PinyinConfig & instance (void) { return *m_instance; } + +protected: + PinyinConfig (Bus & bus, const std::string & name = "Pinyin") : Config (bus, name) { } + +private: + static PinyinConfig * m_instance; +}; + +/* Bopomof Config */ +class BopomofoConfig : public PinyinConfig { +public: + static void init (Bus & bus); + static BopomofoConfig & instance (void) { return *m_instance; } + +protected: + BopomofoConfig (Bus & bus) : PinyinConfig (bus, "Bopomofo") { } + +private: + static BopomofoConfig * m_instance; }; }; diff --git a/src/DoublePinyinEditor.cc b/src/DoublePinyinEditor.cc index 57b182f..e27dc72 100644 --- a/src/DoublePinyinEditor.cc +++ b/src/DoublePinyinEditor.cc @@ -18,7 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "Config.h" #include "DoublePinyinEditor.h" namespace PY { @@ -34,15 +33,15 @@ namespace PY { ((c >= IBUS_a && c <= IBUS_z) ? c - IBUS_a : (c == IBUS_semicolon ? 26 : -1)) #define ID_TO_SHENG(id) \ - (double_pinyin_map[Config::doublePinyinSchema ()].sheng[id]) + (double_pinyin_map[m_config.doublePinyinSchema ()].sheng[id]) #define ID_TO_YUNS(id) \ - (double_pinyin_map[Config::doublePinyinSchema ()].yun[id]) + (double_pinyin_map[m_config.doublePinyinSchema ()].yun[id]) #define IS_ALPHA(c) \ ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) -DoublePinyinEditor::DoublePinyinEditor (PinyinProperties & props) - : PinyinEditor (props) +DoublePinyinEditor::DoublePinyinEditor (PinyinProperties & props, Config & config) + : PinyinEditor (props, config) { } @@ -324,7 +323,7 @@ DoublePinyinEditor::reset (void) inline const Pinyin * DoublePinyinEditor::isPinyin (gint i) { - if ((Config::option () & PINYIN_INCOMPLETE_PINYIN) == 0) { + if ((m_config.option () & PINYIN_INCOMPLETE_PINYIN) == 0) { return NULL; } @@ -352,19 +351,19 @@ DoublePinyinEditor::isPinyin (gint i, gint j) if (yun[1] == PINYIN_ID_VOID) { return PinyinParser::isPinyin (sheng, yun[0], - Config::option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); + m_config.option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); } pinyin = PinyinParser::isPinyin (sheng, yun[0], - Config::option () & (PINYIN_FUZZY_ALL)); + m_config.option () & (PINYIN_FUZZY_ALL)); if (pinyin == NULL) pinyin = PinyinParser::isPinyin (sheng, yun[1], - Config::option () & (PINYIN_FUZZY_ALL)); + m_config.option () & (PINYIN_FUZZY_ALL)); if (pinyin != NULL) return pinyin; /* if sheng == j q x y and yun == v, try to correct v to u */ - if ((Config::option () & PINYIN_CORRECT_V_TO_U) == 0) + if ((m_config.option () & PINYIN_CORRECT_V_TO_U) == 0) return NULL; if (yun[0] != PINYIN_ID_V && yun[1] != PINYIN_ID_V) @@ -376,7 +375,7 @@ DoublePinyinEditor::isPinyin (gint i, gint j) case PINYIN_ID_X: case PINYIN_ID_Y: return PinyinParser::isPinyin (sheng, PINYIN_ID_V, - Config::option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); + m_config.option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); default: return NULL; } @@ -448,10 +447,10 @@ DoublePinyinEditor::updatePinyin (gboolean all) void DoublePinyinEditor::updateAuxiliaryTextAfter (String &buffer) { - if (G_LIKELY (!Config::doublePinyinShowRaw ())) + if (G_LIKELY (!m_config.doublePinyinShowRaw ())) return; - if (G_LIKELY (Config::orientation () == IBUS_ORIENTATION_HORIZONTAL)) { + if (G_LIKELY (m_config.orientation () == IBUS_ORIENTATION_HORIZONTAL)) { buffer << " [ "; } else { diff --git a/src/DoublePinyinEditor.h b/src/DoublePinyinEditor.h index f1c5d42..a343dc8 100644 --- a/src/DoublePinyinEditor.h +++ b/src/DoublePinyinEditor.h @@ -28,7 +28,7 @@ namespace PY { class DoublePinyinEditor : public PinyinEditor { public: - DoublePinyinEditor (PinyinProperties & props); + DoublePinyinEditor (PinyinProperties & props, Config & config = PinyinConfig::instance ()); gboolean insert (gint ch); diff --git a/src/Editor.cc b/src/Editor.cc index 98ac84f..a5bd32a 100644 --- a/src/Editor.cc +++ b/src/Editor.cc @@ -22,10 +22,11 @@ namespace PY { -Editor::Editor (PinyinProperties & props) +Editor::Editor (PinyinProperties & props, Config & config) : m_text (128), m_cursor (0), - m_props (props) + m_props (props), + m_config (config) { } diff --git a/src/Editor.h b/src/Editor.h index 12d33b5..6e0bbbb 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -28,6 +28,7 @@ #include "Text.h" #include "LookupTable.h" #include "PinyinProperties.h" +#include "Config.h" namespace PY { @@ -36,7 +37,7 @@ typedef boost::shared_ptr EditorPtr; class Editor { public: - Editor (PinyinProperties & prop); + Editor (PinyinProperties & prop, Config & config); virtual ~Editor (void); virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); @@ -131,6 +132,7 @@ protected: String m_text; guint m_cursor; PinyinProperties & m_props; + Config & m_config; }; }; diff --git a/src/ExtEditor.cc b/src/ExtEditor.cc index 04ff97e..73407e9 100644 --- a/src/ExtEditor.cc +++ b/src/ExtEditor.cc @@ -22,8 +22,8 @@ namespace PY { -ExtEditor::ExtEditor (PinyinProperties & props) - : Editor (props) +ExtEditor::ExtEditor (PinyinProperties & props, Config & config) + : Editor (props, config) { } diff --git a/src/ExtEditor.h b/src/ExtEditor.h index ff9d5ea..09941e6 100644 --- a/src/ExtEditor.h +++ b/src/ExtEditor.h @@ -28,7 +28,7 @@ namespace PY { class ExtEditor : public Editor { public: - ExtEditor (PinyinProperties &props); + ExtEditor (PinyinProperties & props, Config & config); virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual void pageUp (void); diff --git a/src/FallbackEditor.h b/src/FallbackEditor.h index a361af3..cf8e4be 100644 --- a/src/FallbackEditor.h +++ b/src/FallbackEditor.h @@ -28,8 +28,8 @@ namespace PY { class FallbackEditor : public Editor { public: - FallbackEditor (PinyinProperties &props) - : Editor (props), + FallbackEditor (PinyinProperties &props, Config & config) + : Editor (props, config), m_quote (TRUE), m_double_quote (TRUE), m_prev_committed_char (0) {} diff --git a/src/FullPinyinEditor.cc b/src/FullPinyinEditor.cc index 719c7e2..673dd10 100644 --- a/src/FullPinyinEditor.cc +++ b/src/FullPinyinEditor.cc @@ -18,13 +18,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "Config.h" #include "FullPinyinEditor.h" namespace PY { -FullPinyinEditor::FullPinyinEditor (PinyinProperties & props) - : PinyinEditor (props) +FullPinyinEditor::FullPinyinEditor (PinyinProperties & props, Config & config) + : PinyinEditor (props, config) { } @@ -47,7 +46,7 @@ FullPinyinEditor::insert (gint ch) m_text.insert (m_cursor++, ch); - if (G_UNLIKELY (!(Config::option () & PINYIN_INCOMPLETE_PINYIN))) { + if (G_UNLIKELY (!(m_config.option () & PINYIN_INCOMPLETE_PINYIN))) { updateSpecialPhrases (); updatePinyin (); } @@ -229,7 +228,7 @@ FullPinyinEditor::updatePinyin (void) else { m_pinyin_len = PinyinParser::parse (m_text, // text m_cursor, // text length - Config::option (), // option + m_config.option (), // option m_pinyin, // result MAX_PHRASE_LEN); // max result length } diff --git a/src/FullPinyinEditor.h b/src/FullPinyinEditor.h index 0306d7f..1977a83 100644 --- a/src/FullPinyinEditor.h +++ b/src/FullPinyinEditor.h @@ -28,7 +28,7 @@ namespace PY { class FullPinyinEditor : public PinyinEditor { public: - FullPinyinEditor (PinyinProperties & props); + FullPinyinEditor (PinyinProperties & props, Config & config = PinyinConfig::instance ()); ~FullPinyinEditor (void); public: diff --git a/src/Main.cc b/src/Main.cc index 8c8c384..6dc4b45 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -70,7 +70,8 @@ start_component (void) exit (0); } - Config config (bus); + PinyinConfig::init (bus); + BopomofoConfig::init (bus); g_signal_connect ((IBusBus *)bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL); diff --git a/src/PhraseEditor.cc b/src/PhraseEditor.cc index 73a1cba..8a256c7 100644 --- a/src/PhraseEditor.cc +++ b/src/PhraseEditor.cc @@ -18,20 +18,20 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "Config.h" #include "PhraseEditor.h" #include "SimpTradConverter.h" namespace PY { -PhraseEditor::PhraseEditor (PinyinProperties & props) +PhraseEditor::PhraseEditor (PinyinProperties & props, Config & config) : m_candidates (32), m_selected_phrases (8), m_selected_string (32), m_candidate_0_phrases (8), m_pinyin (16), m_cursor (0), - m_props (props) + m_props (props), + m_config (config) { } @@ -114,7 +114,7 @@ PhraseEditor::updateCandidates (void) m_query.reset (new Query (m_pinyin, m_cursor, m_pinyin.size () - m_cursor, - Config::option ())); + m_config.option ())); fillCandidates (); } @@ -137,7 +137,7 @@ PhraseEditor::updateTheFirstCandidate (void) Query query (m_pinyin, begin, end - begin, - Config::option ()); + m_config.option ()); ret = query.fill (m_candidate_0_phrases, 1); g_assert (ret == 1); begin += m_candidate_0_phrases.back ().len; diff --git a/src/PhraseEditor.h b/src/PhraseEditor.h index 93abbb4..2b59dcd 100644 --- a/src/PhraseEditor.h +++ b/src/PhraseEditor.h @@ -22,6 +22,7 @@ #define __PY_PHRASE_EDITOR_H_ #include "String.h" +#include "Config.h" #include "Database.h" #include "PhraseArray.h" #include "PinyinProperties.h" @@ -32,7 +33,7 @@ namespace PY { class PhraseEditor { public: - PhraseEditor (PinyinProperties & props); + PhraseEditor (PinyinProperties & props, Config & config); ~PhraseEditor (void); const String & selectedString (void) const { return m_selected_string; } @@ -128,6 +129,7 @@ private: guint m_cursor; PinyinProperties & m_props; QueryPtr m_query; + Config & m_config; }; }; diff --git a/src/PinyinEditor.cc b/src/PinyinEditor.cc index 6197cd1..3064638 100644 --- a/src/PinyinEditor.cc +++ b/src/PinyinEditor.cc @@ -18,7 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "Config.h" #include "PinyinEditor.h" #include "SimpTradConverter.h" #include "HalfFullConverter.h" @@ -28,13 +27,13 @@ namespace PY { #define MAX_PINYIN_LEN 64 /* init static members */ -PinyinEditor::PinyinEditor (PinyinProperties & props) - : Editor (props), +PinyinEditor::PinyinEditor (PinyinProperties & props, Config & config) + : Editor (props, config), m_pinyin (MAX_PHRASE_LEN), m_pinyin_len (0), m_buffer (64), - m_lookup_table (Config::pageSize ()), - m_phrase_editor (props) + m_lookup_table (m_config.pageSize ()), + m_phrase_editor (props, config) { } @@ -121,32 +120,32 @@ PinyinEditor::processPunct (guint keyval, guint keycode, guint modifiers) case IBUS_apostrophe: return insert (keyval); case IBUS_comma: - if (Config::commaPeriodPage ()) { + if (m_config.commaPeriodPage ()) { pageUp (); return TRUE; } break; case IBUS_minus: - if (Config::minusEqualPage ()) { + if (m_config.minusEqualPage ()) { pageUp (); return TRUE; } break; case IBUS_period: - if (Config::commaPeriodPage ()) { + if (m_config.commaPeriodPage ()) { pageDown (); return TRUE; } break; case IBUS_equal: - if (Config::minusEqualPage ()) { + if (m_config.minusEqualPage ()) { pageDown (); return TRUE; } break; } - if (Config::autoCommit ()) { + if (m_config.autoCommit ()) { if (m_phrase_editor.pinyinExistsAfterCursor ()) { selectCandidate (m_lookup_table.cursorPos ()); } @@ -172,13 +171,13 @@ PinyinEditor::processOthers (guint keyval, guint keycode, guint modifiers) if (modifiers == 0) { switch (keyval) { case IBUS_Shift_L: - if (!Config::shiftSelectCandidate ()) + if (!m_config.shiftSelectCandidate ()) return FALSE; selectCandidateInPage (1); return TRUE; case IBUS_Shift_R: - if (!Config::shiftSelectCandidate ()) + if (!m_config.shiftSelectCandidate ()) return FALSE; selectCandidateInPage (2); return TRUE; @@ -504,8 +503,8 @@ void PinyinEditor::updateLookupTable (void) { m_lookup_table.clear (); - m_lookup_table.setPageSize (Config::pageSize ()); - m_lookup_table.setOrientation (Config::orientation ()); + m_lookup_table.setPageSize (m_config.pageSize ()); + m_lookup_table.setOrientation (m_config.orientation ()); fillLookupTableByPage (); if (m_lookup_table.size ()) { @@ -542,7 +541,7 @@ PinyinEditor::fillLookupTableByPage (void) m_lookup_table.appendCandidate (text); } else { - if (G_LIKELY (m_props.modeSimp () || !Config::tradCandidate ())) { + if (G_LIKELY (m_props.modeSimp () || !m_config.tradCandidate ())) { Text text (m_phrase_editor.candidate (i - m_special_phrases.size ())); if (m_phrase_editor.candidateIsUserPhease (i - m_special_phrases.size ())) text.appendAttribute (IBUS_ATTR_TYPE_FOREGROUND, 0x000000ef, 0, -1); diff --git a/src/PinyinEditor.h b/src/PinyinEditor.h index 3d1746b..0f40eb5 100644 --- a/src/PinyinEditor.h +++ b/src/PinyinEditor.h @@ -36,7 +36,7 @@ class SpecialPhraseTable; class PinyinEditor : public Editor { public: - PinyinEditor (PinyinProperties & props); + PinyinEditor (PinyinProperties & props, Config & config = PinyinConfig::instance ()); public: /* virtual functions */ diff --git a/src/PinyinEngine.cc b/src/PinyinEngine.cc index fb2357a..ae3f119 100644 --- a/src/PinyinEngine.cc +++ b/src/PinyinEngine.cc @@ -41,20 +41,21 @@ namespace PY { /* constructor */ PinyinEngine::PinyinEngine (IBusEngine *engine) : Engine (engine), + m_props (PinyinConfig::instance ()), m_prev_pressed_key (IBUS_VoidSymbol), m_input_mode (MODE_INIT), - m_fallback_editor (new FallbackEditor (m_props)) + m_fallback_editor (new FallbackEditor (m_props, PinyinConfig::instance ())) { gint i; - if (Config::doublePinyin ()) - m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props)); + if (PinyinConfig::instance ().doublePinyin ()) + m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props, PinyinConfig::instance ())); else - m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props)); + m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props, PinyinConfig::instance ())); - m_editors[MODE_PUNCT].reset (new PunctEditor (m_props)); - m_editors[MODE_RAW].reset (new RawEditor (m_props)); - m_editors[MODE_EXTENSION].reset (new ExtEditor (m_props)); + m_editors[MODE_PUNCT].reset (new PunctEditor (m_props, PinyinConfig::instance ())); + m_editors[MODE_RAW].reset (new RawEditor (m_props, PinyinConfig::instance ())); + m_editors[MODE_EXTENSION].reset (new ExtEditor (m_props, PinyinConfig::instance ())); m_props.signalUpdateProperty ().connect (bind (&PinyinEngine::updateProperty, this, _1)); @@ -153,15 +154,15 @@ PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) void PinyinEngine::focusIn (void) { - if (Config::doublePinyin ()) { + if (PinyinConfig::instance ().doublePinyin ()) { if (dynamic_cast (m_editors[MODE_INIT].get ()) == NULL) { - m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props)); + m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props, PinyinConfig::instance ())); connectEditorSignals (m_editors[MODE_INIT]); } } else { if (dynamic_cast (m_editors[MODE_INIT].get ()) == NULL) { - m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props)); + m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props, PinyinConfig::instance ())); connectEditorSignals (m_editors[MODE_INIT]); } } diff --git a/src/PinyinProperties.cc b/src/PinyinProperties.cc index c5413b8..25b504f 100644 --- a/src/PinyinProperties.cc +++ b/src/PinyinProperties.cc @@ -25,11 +25,12 @@ namespace PY { #define _(text) (dgettext (GETTEXT_PACKAGE, text)) -PinyinProperties::PinyinProperties (void) - : m_mode_chinese (Config::initChinese ()), - m_mode_full (Config::initFull ()), - m_mode_full_punct (Config::initFullPunct ()), - m_mode_simp (Config::initSimpChinese ()), +PinyinProperties::PinyinProperties (Config & config) + : m_config (config), + m_mode_chinese (m_config.initChinese ()), + m_mode_full (m_config.initFull ()), + m_mode_full_punct (m_config.initFullPunct ()), + m_mode_simp (m_config.initSimpChinese ()), m_prop_chinese ("mode.chinese", PROP_TYPE_NORMAL, StaticText ("CN"), diff --git a/src/PinyinProperties.h b/src/PinyinProperties.h index ccf5ac0..8edbd40 100644 --- a/src/PinyinProperties.h +++ b/src/PinyinProperties.h @@ -32,7 +32,7 @@ namespace PY { class PinyinProperties { public: - PinyinProperties (void); + PinyinProperties (Config & config); void toggleModeChinese (void); void toggleModeFull (void); @@ -58,6 +58,7 @@ private: signal m_signal_update_property; private: + Config & m_config; gboolean m_mode_chinese; gboolean m_mode_full; gboolean m_mode_full_punct; diff --git a/src/PunctEditor.cc b/src/PunctEditor.cc index e36beb2..30986e6 100644 --- a/src/PunctEditor.cc +++ b/src/PunctEditor.cc @@ -36,10 +36,10 @@ namespace PY { #include "PunctTable.h" -PunctEditor::PunctEditor (PinyinProperties & props) - : Editor (props), +PunctEditor::PunctEditor (PinyinProperties & props, Config & config) + : Editor (props, config), m_punct_mode (MODE_DISABLE), - m_lookup_table (Config::pageSize ()) + m_lookup_table (m_config.pageSize ()) { } @@ -509,8 +509,8 @@ void PunctEditor::fillLookupTable (void) { m_lookup_table.clear (); - m_lookup_table.setPageSize (Config::pageSize ()); - m_lookup_table.setOrientation (Config::orientation ()); + m_lookup_table.setPageSize (m_config.pageSize ()); + m_lookup_table.setOrientation (m_config.orientation ()); for (std::vector::iterator it = m_punct_candidates.begin (); it != m_punct_candidates.end (); it++) { diff --git a/src/PunctEditor.h b/src/PunctEditor.h index 27db01d..ae3d4a5 100644 --- a/src/PunctEditor.h +++ b/src/PunctEditor.h @@ -30,7 +30,7 @@ namespace PY { class PunctEditor : public Editor { public: - PunctEditor (PinyinProperties &props); + PunctEditor (PinyinProperties &props, Config & config); virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual void pageUp (void); diff --git a/src/RawEditor.h b/src/RawEditor.h index 9a0110c..28190b0 100644 --- a/src/RawEditor.h +++ b/src/RawEditor.h @@ -28,7 +28,8 @@ namespace PY { class RawEditor : public Editor { public: - RawEditor (PinyinProperties &props) : Editor (props) {} + RawEditor (PinyinProperties &props, Config & config) + : Editor (props, config) { } }; }; diff --git a/src/SpecialPhraseTable.cc b/src/SpecialPhraseTable.cc index 13a0855..d79978d 100644 --- a/src/SpecialPhraseTable.cc +++ b/src/SpecialPhraseTable.cc @@ -58,7 +58,7 @@ SpecialPhraseTable::lookup (const std::string &command, { result.clear (); - if (!Config::specialPhrases ()) + if (!PinyinConfig::instance ().specialPhrases ()) return FALSE; std::pair range = m_map.equal_range (command); -- 2.7.4