clean db
[platform/upstream/ibus-libpinyin.git] / src / PYPinyinProperties.cc
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 #include "PYPinyinProperties.h"
22 #include <libintl.h>
23 #include "PYText.h"
24 #include "PYConfig.h"
25
26 namespace PY {
27
28 #define _(text) (dgettext (GETTEXT_PACKAGE, text))
29
30 PinyinProperties::PinyinProperties (Config & config)
31     : m_config (config),
32       m_mode_chinese (m_config.initChinese ()),
33       m_mode_full (m_config.initFull ()),
34       m_mode_full_punct (m_config.initFullPunct ()),
35       m_mode_simp (m_config.initSimpChinese ()),
36       m_prop_chinese ("mode.chinese",
37                 PROP_TYPE_NORMAL,
38                 StaticText ("CN"),
39                 m_mode_chinese ?
40                     PKGDATADIR"/icons/chinese.svg" :
41                     PKGDATADIR"/icons/english.svg",
42                 StaticText (_("Chinese"))),
43       m_prop_full ("mode.full",
44                 PROP_TYPE_NORMAL,
45                 StaticText (m_mode_full ? "Aa" : "Aa"),
46                 m_mode_full ?
47                     PKGDATADIR"/icons/full.svg" :
48                     PKGDATADIR"/icons/half.svg",
49                 StaticText (_("Full/Half width"))),
50       m_prop_full_punct ("mode.full_punct",
51                 PROP_TYPE_NORMAL,
52                 StaticText (m_mode_full_punct ? ",。" : ",."),
53                 m_mode_full_punct ?
54                     PKGDATADIR"/icons/full-punct.svg" :
55                     PKGDATADIR"/icons/half-punct.svg",
56                 StaticText (_("Full/Half width punctuation"))),
57       m_prop_simp ( "mode.simp",
58                 PROP_TYPE_NORMAL,
59                 StaticText (m_mode_simp ? "简" : "繁"),
60                 m_mode_simp ?
61                     PKGDATADIR"/icons/simp-chinese.svg" :
62                     PKGDATADIR"/icons/trad-chinese.svg",
63                 StaticText (_("Simplfied/Traditional Chinese"))),
64       m_prop_setup ("setup",
65                 PROP_TYPE_NORMAL,
66                 StaticText (_("Preferences")),
67                 "ibus-setup",
68                 StaticText (_("Preferences")))
69 {
70     m_props.append (m_prop_chinese);
71     m_props.append (m_prop_full);
72     m_props.append (m_prop_full_punct);
73     m_props.append (m_prop_simp);
74     m_props.append (m_prop_setup);
75
76 }
77
78 void
79 PinyinProperties::toggleModeChinese (void)
80 {
81     m_mode_chinese = ! m_mode_chinese;
82     m_prop_chinese.setLabel (m_mode_chinese ? "CN" : "EN");
83     m_prop_chinese.setIcon (m_mode_chinese ?
84                                 PKGDATADIR"/icons/chinese.svg" :
85                                 PKGDATADIR"/icons/english.svg");
86     updateProperty (m_prop_chinese);
87     
88     m_prop_full_punct.setSensitive (m_mode_chinese);
89     updateProperty (m_prop_full_punct);
90 }
91
92 void
93 PinyinProperties::toggleModeFull (void)
94 {
95     m_mode_full = !m_mode_full;
96     m_prop_full.setLabel (m_mode_full ? "Aa" : "Aa");
97     m_prop_full.setIcon (m_mode_full ?
98                             PKGDATADIR"/icons/full.svg" :
99                             PKGDATADIR"/icons/half.svg");
100     updateProperty (m_prop_full);
101 }
102
103 void
104 PinyinProperties::toggleModeFullPunct (void)
105 {
106     m_mode_full_punct = !m_mode_full_punct;
107     m_prop_full_punct.setLabel (m_mode_full_punct ? ",。" : ",.");
108     m_prop_full_punct.setIcon (m_mode_full_punct ?
109                                 PKGDATADIR"/icons/full-punct.svg" :
110                                 PKGDATADIR"/icons/half-punct.svg");
111     updateProperty (m_prop_full_punct);
112 }
113
114 void
115 PinyinProperties::toggleModeSimp (void)
116 {
117     m_mode_simp = ! m_mode_simp;
118     m_prop_simp.setLabel (m_mode_simp ? "简" : "繁");
119     m_prop_simp.setIcon (m_mode_simp ?
120                             PKGDATADIR"/icons/simp-chinese.svg" :
121                             PKGDATADIR"/icons/trad-chinese.svg");
122     updateProperty (m_prop_simp);
123 }
124
125 void
126 PinyinProperties::reset (void)
127 {
128     if (modeChinese () != m_config.initChinese ()) {
129         toggleModeChinese ();
130     }
131     if (modeFull () != m_config.initFull ()) {
132         toggleModeFull ();
133     }
134     if (modeFullPunct () != m_config.initFullPunct ()) {
135         toggleModeFullPunct ();
136     }
137     if (modeSimp () != m_config.initSimpChinese ()) {
138         toggleModeSimp ();
139     }
140 }
141
142 gboolean
143 PinyinProperties::propertyActivate (const gchar *prop_name, guint prop_state) {
144     const static std::string mode_chinese ("mode.chinese");
145     const static std::string mode_full ("mode.full");
146     const static std::string mode_full_punct ("mode.full_punct");
147     const static std::string mode_simp ("mode.simp");
148
149     if (mode_chinese == prop_name) {
150         toggleModeChinese ();
151         return TRUE;
152     }
153     else if (mode_full == prop_name) {
154         toggleModeFull ();
155         return TRUE;
156     }
157     else if (mode_full_punct == prop_name) {
158         toggleModeFullPunct ();
159         return TRUE;
160     }
161     else if (mode_simp == prop_name) {
162         toggleModeSimp ();
163         return TRUE;
164     }
165     return FALSE;
166 }
167
168
169 };