1 /* vim:set et ts=4 sts=4:
2 *
3 * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
4 *
5 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 #ifndef __PY_CONFIG_H_
22 #define __PY_CONFIG_H_
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include <string>
29 #include <gio/gio.h>
30 #include <ibus.h>
31 #include <pinyin.h>
32 #include "PYUtil.h"
33 #include "PYObject.h"
34
35 namespace PY {
36
37 class Config {
38 protected:
39 Config (const std::string & name);
40 virtual ~Config (void);
41
42 public:
dictionaries(void)43 std::string dictionaries (void) const { return m_dictionaries; }
luaConverter(void)44 std::string luaConverter (void) const { return m_lua_converter; }
option(void)45 pinyin_option_t option (void) const { return m_option & m_option_mask; }
orientation(void)46 guint orientation (void) const { return m_orientation; }
pageSize(void)47 guint pageSize (void) const { return m_page_size; }
rememberEveryInput(void)48 gboolean rememberEveryInput (void) const { return m_remember_every_input; }
sortOption(void)49 sort_option_t sortOption (void) const { return m_sort_option; }
showSuggestion(void)50 gboolean showSuggestion (void) const { return m_show_suggestion; }
emojiCandidate(void)51 gboolean emojiCandidate (void) const { return m_emoji_candidate; }
shiftSelectCandidate(void)52 gboolean shiftSelectCandidate (void) const { return m_shift_select_candidate; }
minusEqualPage(void)53 gboolean minusEqualPage (void) const { return m_minus_equal_page; }
commaPeriodPage(void)54 gboolean commaPeriodPage (void) const { return m_comma_period_page; }
autoCommit(void)55 gboolean autoCommit (void) const { return m_auto_commit; }
doublePinyin(void)56 gboolean doublePinyin (void) const { return m_double_pinyin; }
doublePinyinSchema(void)57 DoublePinyinScheme doublePinyinSchema (void) const { return m_double_pinyin_schema; }
initChinese(void)58 gboolean initChinese (void) const { return m_init_chinese; }
initFull(void)59 gboolean initFull (void) const { return m_init_full; }
initFullPunct(void)60 gboolean initFullPunct (void) const { return m_init_full_punct; }
initSimpChinese(void)61 gboolean initSimpChinese (void) const { return m_init_simp_chinese; }
bopomofoKeyboardMapping(void)62 ZhuyinScheme bopomofoKeyboardMapping (void) const { return m_bopomofo_keyboard_mapping; }
selectKeys(void)63 gint selectKeys (void) const { return m_select_keys; }
guideKey(void)64 gboolean guideKey (void) const { return m_guide_key; }
auxiliarySelectKeyF(void)65 gboolean auxiliarySelectKeyF (void) const { return m_auxiliary_select_key_f; }
auxiliarySelectKeyKP(void)66 gboolean auxiliarySelectKeyKP (void) const { return m_auxiliary_select_key_kp; }
enterKey(void)67 gboolean enterKey (void) const { return m_enter_key; }
68
mainSwitch(void)69 std::string mainSwitch (void) const { return m_main_switch; }
letterSwitch(void)70 std::string letterSwitch (void) const { return m_letter_switch; }
punctSwitch(void)71 std::string punctSwitch (void) const { return m_punct_switch; }
bothSwitch(void)72 std::string bothSwitch (void) const { return m_both_switch; }
tradSwitch(void)73 std::string tradSwitch (void) const { return m_trad_switch; }
openccConfig(void)74 std::string openccConfig (void) const { return m_opencc_config; }
75
76 protected:
77 bool read (const gchar * name, bool defval);
78 gint read (const gchar * name, gint defval);
79 std::string read (const gchar * name, const gchar * defval);
80 void initDefaultValues (void);
81
82 virtual void readDefaultValues (void);
83 virtual gboolean valueChanged (const std::string &schema_id,
84 const std::string &name,
85 GVariant *value);
86 private:
87 static void valueChangedCallback (GSettings *settings,
88 const gchar *name,
89 Config *self);
90
91 protected:
92 GSettings *m_settings;
93 std::string m_schema_id;
94 std::string m_dictionaries;
95 std::string m_lua_converter;
96 std::string m_opencc_config;
97 pinyin_option_t m_option;
98 pinyin_option_t m_option_mask;
99
100 gint m_orientation;
101 guint m_page_size;
102 gboolean m_remember_every_input;
103 sort_option_t m_sort_option;
104 gboolean m_show_suggestion;
105 gboolean m_emoji_candidate;
106
107 gboolean m_shift_select_candidate;
108 gboolean m_minus_equal_page;
109 gboolean m_comma_period_page;
110 gboolean m_auto_commit;
111
112 gboolean m_double_pinyin;
113 DoublePinyinScheme m_double_pinyin_schema;
114
115 gboolean m_init_chinese;
116 gboolean m_init_full;
117 gboolean m_init_full_punct;
118 gboolean m_init_simp_chinese;
119
120 ZhuyinScheme m_bopomofo_keyboard_mapping;
121 gint m_select_keys;
122 gboolean m_guide_key;
123 gboolean m_auxiliary_select_key_f;
124 gboolean m_auxiliary_select_key_kp;
125
126 gboolean m_enter_key;
127
128 std::string m_main_switch;
129 std::string m_letter_switch;
130 std::string m_punct_switch;
131 std::string m_both_switch;
132 std::string m_trad_switch;
133
134 };
135
136
137 static inline bool
normalizeGVariant(GVariant * value,bool defval)138 normalizeGVariant (GVariant *value, bool defval)
139 {
140 if (value == NULL ||
141 g_variant_classify (value) != G_VARIANT_CLASS_BOOLEAN) {
142 g_warn_if_reached ();
143 return defval;
144 }
145 return g_variant_get_boolean (value);
146 }
147
148 static inline gint
normalizeGVariant(GVariant * value,gint defval)149 normalizeGVariant (GVariant *value, gint defval)
150 {
151 if (value == NULL ||
152 g_variant_classify (value) != G_VARIANT_CLASS_INT32) {
153 g_warn_if_reached ();
154 return defval;
155 }
156 return g_variant_get_int32 (value);
157 }
158
159 static inline std::string
normalizeGVariant(GVariant * value,const std::string & defval)160 normalizeGVariant (GVariant *value, const std::string &defval)
161 {
162 if (value == NULL ||
163 g_variant_classify (value) != G_VARIANT_CLASS_STRING) {
164 g_warn_if_reached ();
165 return defval;
166 }
167 return g_variant_get_string (value, NULL);
168 }
169
170 };
171 #endif
172