1 /* vim:set et ts=4 sts=4:
2  *
3  * ibus-pinyin - The Chinese PinYin engine 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 St, 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 <PyZy/Const.h>
29 #include <PyZy/InputContext.h>
30 #include <PyZy/Variant.h>
31 #include <ibus.h>
32 #include <set>
33 #include <string>
34 
35 #include "PYObject.h"
36 #include "PYUtil.h"
37 
38 namespace PY {
39 
40 class Bus;
41 
42 class Config : public Object {
43 protected:
44     Config (Bus & bus, const std::string & name);
45     virtual ~Config (void);
46 
47 public:
option(void)48     guint option (void) const                   { return m_option & m_option_mask; }
orientation(void)49     guint orientation (void) const              { return m_orientation; }
pageSize(void)50     guint pageSize (void) const                 { return m_page_size; }
shiftSelectCandidate(void)51     gboolean shiftSelectCandidate (void) const  { return m_shift_select_candidate; }
minusEqualPage(void)52     gboolean minusEqualPage (void) const        { return m_minus_equal_page; }
commaPeriodPage(void)53     gboolean commaPeriodPage (void) const       { return m_comma_period_page; }
autoCommit(void)54     gboolean autoCommit (void) const            { return m_auto_commit; }
doublePinyin(void)55     gboolean doublePinyin (void) const          { return m_double_pinyin; }
doublePinyinSchema(void)56     gint doublePinyinSchema (void) const        { return m_double_pinyin_schema; }
doublePinyinShowRaw(void)57     gboolean doublePinyinShowRaw (void) const   { return m_double_pinyin_show_raw; }
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; }
specialPhrases(void)62     gboolean specialPhrases (void) const        { return m_special_phrases; }
bopomofoKeyboardMapping(void)63     gint bopomofoKeyboardMapping (void) const   { return m_bopomofo_keyboard_mapping; }
selectKeys(void)64     gint selectKeys (void) const                { return m_select_keys; }
guideKey(void)65     gboolean guideKey (void) const              { return m_guide_key; }
auxiliarySelectKeyF(void)66     gboolean auxiliarySelectKeyF (void) const   { return m_auxiliary_select_key_f; }
auxiliarySelectKeyKP(void)67     gboolean auxiliarySelectKeyKP (void) const  { return m_auxiliary_select_key_kp; }
enterKey(void)68     gboolean enterKey (void) const              { return m_enter_key; }
69 
70     virtual void addContext (PyZy::InputContext * context);
71     bool removeContext (PyZy::InputContext * context);
72 
73 protected:
74     bool read (const gchar * name, bool defval);
75     gint read (const gchar * name, gint defval);
76     std::string read (const gchar * name, const gchar * defval);
77     void initDefaultValues (void);
78 
79     virtual void readDefaultValues (void);
80     virtual gboolean valueChanged (const std::string  &section,
81                                    const std::string  &name,
82                                    GVariant           *value);
83 
84     void updateContext (PyZy::InputContext::PropertyName name,
85                         const PyZy::Variant & variant);
86 
87 private:
88     static void valueChangedCallback (IBusConfig     *config,
89                                       const gchar    *section,
90                                       const gchar    *name,
91                                       GVariant       *value,
92                                       Config         *self);
93 
94 protected:
95     std::string m_section;
96     guint m_option;
97     guint m_option_mask;
98 
99     gint m_orientation;
100     guint m_page_size;
101     gboolean m_shift_select_candidate;
102     gboolean m_minus_equal_page;
103     gboolean m_comma_period_page;
104     gboolean m_auto_commit;
105 
106     gboolean m_double_pinyin;
107     gint m_double_pinyin_schema;
108     gboolean m_double_pinyin_show_raw;
109 
110     gboolean m_init_chinese;
111     gboolean m_init_full;
112     gboolean m_init_full_punct;
113     gboolean m_init_simp_chinese;
114     gboolean m_special_phrases;
115 
116     gint m_bopomofo_keyboard_mapping;
117     gint m_select_keys;
118     gboolean m_guide_key;
119     gboolean m_auxiliary_select_key_f;
120     gboolean m_auxiliary_select_key_kp;
121 
122     gboolean m_enter_key;
123 
124     std::set<PyZy::InputContext *> m_contexts;
125 };
126 
127 /* PinyinConfig */
128 class PinyinConfig : public Config {
129 public:
130     static void init (Bus & bus);
instance(void)131     static PinyinConfig & instance (void) { return *m_instance; }
132     virtual void addContext (PyZy::InputContext * context);
133 
134 protected:
135     PinyinConfig (Bus & bus);
136     virtual void readDefaultValues (void);
137 
138     virtual gboolean valueChanged (const std::string &section,
139                                    const std::string &name,
140                                    GVariant          *value);
141 
142 
143 private:
144     static std::unique_ptr<PinyinConfig> m_instance;
145 };
146 
147 /* Bopomof Config */
148 class BopomofoConfig : public Config {
149 public:
150     static void init (Bus & bus);
instance(void)151     static BopomofoConfig & instance (void) { return *m_instance; }
152     virtual void addContext (PyZy::InputContext * context);
153 
154 protected:
155     BopomofoConfig (Bus & bus);
156     virtual void readDefaultValues (void);
157 
158     virtual gboolean valueChanged (const std::string &section,
159                                    const std::string &name,
160                                    GVariant          *value);
161 
162 private:
163     static std::unique_ptr<BopomofoConfig> m_instance;
164 };
165 
166 };
167 #endif
168