diff options
author | Peng Wu <alexepico@gmail.com> | 2014-04-29 12:54:01 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2014-04-29 12:54:01 +0800 |
commit | f30491806fa5d7f6a95db074edd65128119e71bb (patch) | |
tree | 3d0a59637a075e85931745e5119addc7f2ef282c | |
parent | f8ea5c5665399c19d481f27acdaba81936b1cc38 (diff) | |
download | ibus-libzhuyin-f30491806fa5d7f6a95db074edd65128119e71bb.tar.gz ibus-libzhuyin-f30491806fa5d7f6a95db074edd65128119e71bb.tar.xz ibus-libzhuyin-f30491806fa5d7f6a95db074edd65128119e71bb.zip |
improves m_keyboard_layout read
-rw-r--r-- | src/ZYConfig.cc | 2 | ||||
-rw-r--r-- | src/ZYConfig.h | 4 | ||||
-rw-r--r-- | src/ZYLibZhuyin.cc | 40 | ||||
-rw-r--r-- | src/ZYZConfig.cc | 65 |
4 files changed, 60 insertions, 51 deletions
diff --git a/src/ZYConfig.cc b/src/ZYConfig.cc index aa3c8e7..204c4f6 100644 --- a/src/ZYConfig.cc +++ b/src/ZYConfig.cc @@ -46,7 +46,7 @@ Config::initDefaultValues (void) { m_page_size = 5; - m_keyboard_layout = 0; + m_keyboard_layout = CHEWING_DEFAULT; m_init_chinese = TRUE; m_init_full_english = FALSE; diff --git a/src/ZYConfig.h b/src/ZYConfig.h index aaa3db0..2754bd8 100644 --- a/src/ZYConfig.h +++ b/src/ZYConfig.h @@ -44,7 +44,7 @@ public: zhuyin_option_t option (void) const { return m_option & m_option_mask; } guint orientation (void) const { return m_orientation; } guint pageSize (void) const { return m_page_size; } - gint keyboardLayout (void) const { return m_keyboard_layout; } + ZhuyinScheme keyboardLayout (void) const { return m_keyboard_layout; } gboolean initChinese (void) const { return m_init_chinese; } gboolean initFullEnglish (void) const { return m_init_full_english; } gboolean initFullPunct (void) const { return m_init_full_punct; } @@ -76,7 +76,7 @@ protected: gint m_orientation; guint m_page_size; - gint m_keyboard_layout; + ZhuyinScheme m_keyboard_layout; gboolean m_init_chinese; gboolean m_init_full_english; diff --git a/src/ZYLibZhuyin.cc b/src/ZYLibZhuyin.cc index 3abff84..30ff4b7 100644 --- a/src/ZYLibZhuyin.cc +++ b/src/ZYLibZhuyin.cc @@ -72,44 +72,20 @@ LibZhuyinBackEnd::initZhuyinContext (Config *config) return context; } -/* Here are the zhuyin keyboard layout mapping table. */ -static const struct { - gint layout; - ZhuyinScheme scheme; -} zhuyin_options [] = { - {0, CHEWING_STANDARD}, - {1, CHEWING_HSU}, - {2, CHEWING_IBM}, - {3, CHEWING_GINYIEH}, - {4, CHEWING_ETEN}, - {5, CHEWING_ETEN26}, - {6, CHEWING_STANDARD_DVORAK}, - {7, CHEWING_HSU_DVORAK}, - {8, CHEWING_DACHEN_CP26}, - {9, FULL_PINYIN_HANYU}, - {10, FULL_PINYIN_LUOMA}, - {11, FULL_PINYIN_SECONDARY_BOPOMOFO}, -}; - gboolean LibZhuyinBackEnd::setZhuyinOptions (Config *config) { if (NULL == m_zhuyin_context) return FALSE; - gint layout = config->keyboardLayout (); - for (guint i = 0; i < G_N_ELEMENTS (zhuyin_options); ++i) { - if (zhuyin_options[i].layout == layout) { - ZhuyinScheme scheme = zhuyin_options[i].scheme; - switch (scheme) { - case CHEWING_STANDARD ... CHEWING_DACHEN_CP26: - zhuyin_set_chewing_scheme (m_zhuyin_context, scheme); - break; - case FULL_PINYIN_HANYU ... FULL_PINYIN_SECONDARY_BOPOMOFO: - zhuyin_set_full_pinyin_scheme (m_zhuyin_context, scheme); - break; - } - } + ZhuyinScheme scheme = config->keyboardLayout (); + switch (scheme) { + case CHEWING_STANDARD ... CHEWING_DACHEN_CP26: + zhuyin_set_chewing_scheme (m_zhuyin_context, scheme); + break; + case FULL_PINYIN_HANYU ... FULL_PINYIN_SECONDARY_BOPOMOFO: + zhuyin_set_full_pinyin_scheme (m_zhuyin_context, scheme); + break; } zhuyin_option_t options = config->option (); diff --git a/src/ZYZConfig.cc b/src/ZYZConfig.cc index ca463ba..a9d1fcb 100644 --- a/src/ZYZConfig.cc +++ b/src/ZYZConfig.cc @@ -77,7 +77,7 @@ ZhuyinConfig::initDefaultValues (void) m_orientation = IBUS_ORIENTATION_VERTICAL; m_page_size = 10; - m_keyboard_layout = 0; + m_keyboard_layout = CHEWING_DEFAULT; m_init_chinese = TRUE; m_init_full_english = FALSE; @@ -87,10 +87,29 @@ ZhuyinConfig::initDefaultValues (void) m_candidate_keys = "1234567890"; } +/* Here are the zhuyin keyboard layout mapping table. */ +static const struct { + gint layout; + ZhuyinScheme scheme; +} zhuyin_schemes [] = { + {0, CHEWING_STANDARD}, + {1, CHEWING_HSU}, + {2, CHEWING_IBM}, + {3, CHEWING_GINYIEH}, + {4, CHEWING_ETEN}, + {5, CHEWING_ETEN26}, + {6, CHEWING_STANDARD_DVORAK}, + {7, CHEWING_HSU_DVORAK}, + {8, CHEWING_DACHEN_CP26}, + {9, FULL_PINYIN_HANYU}, + {10, FULL_PINYIN_LUOMA}, + {11, FULL_PINYIN_SECONDARY_BOPOMOFO}, +}; + static const struct { const gchar * const name; guint option; -} options [] = { +} fuzzy_zhuyin_options [] = { /* fuzzy pinyin */ { "fuzzyzhuyin_c_ch", ZHUYIN_AMB_C_CH }, { "fuzzyzhuyin_z_zh", ZHUYIN_AMB_Z_ZH }, @@ -138,7 +157,14 @@ ZhuyinConfig::readDefaultValues (void) g_warn_if_reached (); } - m_keyboard_layout = read (CONFIG_KEYBOARD_LAYOUT, 0); + gint layout = read (CONFIG_KEYBOARD_LAYOUT, 0); + m_keyboard_layout = CHEWING_DEFAULT; + + for (guint i = 0; i < G_N_ELEMENTS (zhuyin_schemes); ++i) { + if (zhuyin_schemes[i].layout == layout) { + m_keyboard_layout = zhuyin_schemes[i].scheme; + } + } /* init states */ m_init_chinese = read (CONFIG_INIT_CHINESE, true); @@ -155,13 +181,13 @@ ZhuyinConfig::readDefaultValues (void) m_option_mask &= ~ZHUYIN_AMB_ALL; /* read values */ - for (guint i = 0; i < G_N_ELEMENTS (options); i++) { - if (read (options[i].name, - (options[i].option & PINYIN_DEFAULT_OPTION) != 0)) { - m_option |= options[i].option; + for (guint i = 0; i < G_N_ELEMENTS (fuzzy_zhuyin_options); i++) { + if (read (fuzzy_zhuyin_options[i].name, + (fuzzy_zhuyin_options[i].option & PINYIN_DEFAULT_OPTION) != 0)) { + m_option |= fuzzy_zhuyin_options[i].option; } else { - m_option &= ~options[i].option; + m_option &= ~fuzzy_zhuyin_options[i].option; } } #endif @@ -187,9 +213,16 @@ ZhuyinConfig::valueChanged (const std::string §ion, m_init_full_punct = normalizeGVariant (value, true); else if (CONFIG_INIT_TRAD_CHINESE == name) m_init_trad_chinese = normalizeGVariant (value, false); - else if (CONFIG_KEYBOARD_LAYOUT == name) - m_keyboard_layout = normalizeGVariant (value, 0); - else if (CONFIG_CANDIDATE_KEYS == name) { + else if (CONFIG_KEYBOARD_LAYOUT == name) { + gint layout = normalizeGVariant (value, 0); + m_keyboard_layout = CHEWING_DEFAULT; + + for (guint i = 0; i < G_N_ELEMENTS (zhuyin_schemes); ++i) { + if (zhuyin_schemes[i].layout == layout) { + m_keyboard_layout = zhuyin_schemes[i].scheme; + } + } + } else if (CONFIG_CANDIDATE_KEYS == name) { m_candidate_keys = normalizeGVariant (value, "1234567890"); } /* lookup table page size */ else if (CONFIG_ORIENTATION == name) { @@ -214,14 +247,14 @@ ZhuyinConfig::valueChanged (const std::string §ion, m_option_mask &= ~ZHUYIN_AMB_ALL; } else { - for (guint i = 0; i < G_N_ELEMENTS (options); i++) { - if (G_LIKELY (options[i].name != name)) + for (guint i = 0; i < G_N_ELEMENTS (fuzzy_zhuyin_options); i++) { + if (G_LIKELY (fuzzy_zhuyin_options[i].name != name)) continue; if (normalizeGVariant (value, - (options[i].option & ZHUYIN_DEFAULT_OPTION) != 0)) - m_option |= options[i].option; + (fuzzy_zhuyin_options[i].option & ZHUYIN_DEFAULT_OPTION) != 0)) + m_option |= fuzzy_zhuyin_options[i].option; else - m_option &= ~options[i].option; + m_option &= ~fuzzy_zhuyin_options[i].option; return TRUE; } return FALSE; |