Fix problem with ibus-2.0
[platform/upstream/ibus-libpinyin.git] / src / PYConfig.h
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 #ifndef __PY_CONFIG_H_
22 #define __PY_CONFIG_H_
23
24 #include <string>
25 #include <ibus.h>
26 #include "PYUtil.h"
27 #include "PYObject.h"
28
29 namespace PY {
30
31 class Bus;
32
33 class Config : Object {
34 protected:
35     Config (Bus & bus, const std::string & name);
36     virtual ~Config (void);
37
38 public:
39     guint option (void) const                   { return m_option & m_option_mask; }
40     guint orientation (void) const              { return m_orientation; }
41     guint pageSize (void) const                 { return m_page_size; }
42     gboolean shiftSelectCandidate (void) const  { return m_shift_select_candidate; }
43     gboolean minusEqualPage (void) const        { return m_minus_equal_page; }
44     gboolean commaPeriodPage (void) const       { return m_comma_period_page; }
45     gboolean autoCommit (void) const            { return m_auto_commit; }
46     gboolean doublePinyin (void) const          { return m_double_pinyin; }
47     gint doublePinyinSchema (void) const        { return m_double_pinyin_schema; }
48     gboolean doublePinyinShowRaw (void) const   { return m_double_pinyin_show_raw; }
49     gboolean initChinese (void) const           { return m_init_chinese; }
50     gboolean initFull (void) const              { return m_init_full; }
51     gboolean initFullPunct (void) const         { return m_init_full_punct; }
52     gboolean initSimpChinese (void) const       { return m_init_simp_chinese; }
53     gboolean specialPhrases (void) const        { return m_special_phrases; }
54     gint bopomofoKeyboardMapping (void) const   { return m_bopomofo_keyboard_mapping; }
55     gint selectKeys (void) const                { return m_select_keys; }
56     gboolean guideKey (void) const              { return m_guide_key; }
57     gboolean auxiliarySelectKeyF (void) const   { return m_auxiliary_select_key_f; }
58     gboolean auxiliarySelectKeyKP (void) const  { return m_auxiliary_select_key_kp; }
59     gboolean enterKey (void) const  { return m_enter_key; }
60
61 protected:
62     bool read (const gchar * name, bool defval);
63     gint read (const gchar * name, gint defval);
64     std::string read (const gchar * name, const gchar * defval);
65
66     virtual void readDefaultValues (void);
67
68     virtual gboolean valueChanged (const std::string  &section,
69                                    const std::string  &name,
70                                    GVariant           *value);
71 private:
72     static void valueChangedCallback (IBusConfig     *config,
73                                       const gchar    *section,
74                                       const gchar    *name,
75                                       GVariant       *value,
76                                       Config         *self);
77
78 protected:
79     std::string m_section;
80     guint m_option;
81     guint m_option_mask;
82
83     gint m_orientation;
84     guint m_page_size;
85     gboolean m_shift_select_candidate;
86     gboolean m_minus_equal_page;
87     gboolean m_comma_period_page;
88     gboolean m_auto_commit;
89
90     gboolean m_double_pinyin;
91     gint m_double_pinyin_schema;
92     gboolean m_double_pinyin_show_raw;
93
94     gboolean m_init_chinese;
95     gboolean m_init_full;
96     gboolean m_init_full_punct;
97     gboolean m_init_simp_chinese;
98     gboolean m_special_phrases;
99
100     gint m_bopomofo_keyboard_mapping;
101     gint m_select_keys;
102     gboolean m_guide_key;
103     gboolean m_auxiliary_select_key_f;
104     gboolean m_auxiliary_select_key_kp;
105
106     gboolean m_enter_key;
107 };
108
109 /* PinyinConfig */
110 class PinyinConfig : public Config {
111 public:
112     static void init (Bus & bus);
113     static PinyinConfig & instance (void) { return *m_instance; }
114
115 protected:
116     PinyinConfig (Bus & bus);
117     virtual void readDefaultValues (void);
118
119     virtual gboolean valueChanged (const std::string &section,
120                                    const std::string &name,
121                                    GVariant          *value);
122
123 private:
124     static std::unique_ptr<PinyinConfig> m_instance;
125 };
126
127 /* Bopomof Config */
128 class BopomofoConfig : public Config {
129 public:
130     static void init (Bus & bus);
131     static BopomofoConfig & instance (void) { return *m_instance; }
132
133 protected:
134     BopomofoConfig (Bus & bus);
135     virtual void readDefaultValues (void);
136
137     virtual gboolean valueChanged (const std::string &section,
138                                    const std::string &name,
139                                    GVariant          *value);
140
141 private:
142     static std::unique_ptr<BopomofoConfig> m_instance;
143 };
144
145 };
146 #endif