1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Initial Developer of the Original Code is Fireinput Inc.
15 *
16 * Portions created by the Initial Developer are Copyright (C) 2007
17 * the Initial Developer. All Rights Reserved.
18 *
19 * Contributor(s):
20 * Olly Ja <ollyja@gmail.com>
21 *
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the MPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the MPL, the GPL or the LGPL.
33 *
34 * ***** END LICENSE BLOCK *****
35 */
36 const prefNames =
37 [
38 {name: "interfaceLanguage", type: "STRING", value: LANGUAGE_ZH},
39 {name: "defaultInputMethod", type: "STRING", value: SMART_PINYIN},
40 {name: "defaultInputEncoding", type: "STRING", value: ENCODING_ZH},
41 {name: "saveHistory", type: "BOOL", value: true},
42 {name: "autoInsert", type: "BOOL", value: true},
43 {name: "firstRun",type: "STRING", value: ""},
44 {name: "IMEBarPosition", type: "STRING", value: IME_BAR_TOP},
45 {name: "themeID", type: "STRING", value: "default"},
46 {name: "updateFreq", type: "BOOL", value: true},
47 {name: "autoLoad", type: "BOOL", value: true},
48 {name: "hiddenInputMethod", type: "STRING", value: null},
49 {name: "lastTableUpdate", type: "STRING", value: ''},
50 {name: "tableUpdateInterval", type: "INT", value: 12},
51 {name: "inputKeyExactMatch", type: "BOOL", value: false},
52
53 /* guest email/name for accessing server resouces */
54 {name: "serverGuestName", type: "STRING", value: ''},
55 {name: "serverGuestId", type: "STRING", value: ''},
56
57 /* popup gui css */
58 {name: "inputboxFontcolor", type: "STRING", value: "#123456"},
59 {name: "inputboxFontsize", type: "INT", value: 9},
60 {name: "wordselectionFontcolor", type: "STRING", value: "#080D13"},
61 {name: "wordselectionFontsize", type: "INT", value: 10},
62 {name: "wordselectionNum", type: "INT", value: 9},
63
64 /* key setup */
65 {name: "openKey", type: "STRING", value: "1970"},
66 {name: "openEditorKey", type: "STRING", value: "1107"},
67 {name: "toggleIMEKey", type: "STRING", value: "514"},
68 {name: "quickToggleIMEKey", type: "STRING", value: "256"},
69 {name: "switchInputMethodKey", type: "STRING", value: "1107"},
70 {name: "toggleHalfKey", type: "STRING", value: "1235"},
71 {name: "togglePuncKey", type: "STRING", value: "1283"},
72 {name: "toggleEncodingKey", type: "STRING", value: "1251"},
73 {name: "pageUpKey", type: "STRING", value: "3008"},
74 {name: "pageDownKey", type: "STRING", value: "3040"},
75 {name: "selectFirstKey", type: "STRING", value: "512"},
76 {name: "selectSecondKey", type: "STRING", value: "944"},
77 {name: "selectThirdKey", type: "STRING", value: "3056"}
78 ];
79
80 const prefInterfaceUI = [
81 {id: "fireinputSettingMenu", strKey: "fireinput.menu.setting.label", attribute: "label"},
82 {id: "fireinputDefaultIMEBarPos", strKey: "fireinput.pref.imebar.position", attribute: "label"},
83 {id: "fireinputIMEBarPosTop", strKey: "fireinput.pref.imebar.position.top", attribute: "label"},
84 {id: "fireinputIMEBarPosBottom", strKey: "fireinput.pref.imebar.position.bottom", attribute: "label"},
85 {id: "autoInsert", strKey: "fireinput.pref.auto.insert", attribute: "label"},
86 {id: "autoInsert", strKey: "fireinput.pref.auto.insert.tooltip", attribute: "tooltiptext"},
87 {id: "fireinputConfigInputWindow", strKey: "fireinput.pref.inputwindow.setting", attribute: "label"},
88 {id: "fireinputDefaultInputMethod", strKey: "fireinput.pref.input.method", attribute: "label"},
89 {id: "saveHistory", strKey: "fireinput.pref.save.history", attribute: "label"},
90 {id: "updateFreq", strKey: "fireinput.pref.update.freq", attribute: "label"},
91 {id: "autoLoad", strKey: "fireinput.pref.auto.load", attribute: "label"},
92 {id: "fireinputInterfaceLanguage", strKey: "fireinput.choose.interface.language", attribute: "label"},
93 {id: "fireinputLanguageChinese", strKey: "fireinput.chinese.label", attribute: "label"},
94 {id: "fireinputLanguageEnglish", strKey: "fireinput.english.label", attribute: "label"},
95 {id: "imePinyinQuan", strKey: "fireinput.pinyin.quan.label", attribute: "label"},
96 {id: "imePinyinShuangZiGuang", strKey: "fireinput.pinyin.shuang.ziguang.label", attribute: "label"},
97 {id: "imePinyinShuangMS", strKey: "fireinput.pinyin.shuang.ms.label", attribute: "label"},
98 {id: "imePinyinShuangChineseStar", strKey: "fireinput.pinyin.shuang.chinesestar.label", attribute: "label"},
99 {id: "imePinyinShuangSmartABC", strKey: "fireinput.pinyin.shuang.smartabc.label", attribute: "label"},
100 {id: "imeWubi86", strKey: "fireinput.wubi86.label", attribute: "label"},
101 {id: "imeWubi98", strKey: "fireinput.wubi98.label", attribute: "label"},
102 {id: "imeCangjie5", strKey: "fireinput.cangjie5.label", attribute: "label"},
103 {id: "fireinputAMB", strKey: "fireinput.pref.amb.label", attribute: "label"},
104 {id: "imeAdvancedConfig", strKey: "fireinput.pref.ime.advanced.label", attribute: "label"},
105 {id: "configHotKey", strKey: "fireinput.pref.hotkey.config.label", attribute: "label"},
106 {id: "fireinputKeyExactMatch", strKey: "fireinput.pref.amb.inputkey.match", attribute: "label"}
107 ];
108
109
110 function fireinputPrefInit()
111 {
112 // get default language first
113 var defaultLanguage = fireinputPrefGetDefault("interfaceLanguage");
114
115 // update UI
116 for(var i =prefInterfaceUI.length-1; i>=0; i--)
117 {
118 var id = prefInterfaceUI[i].id;
119 var strKey = prefInterfaceUI[i].strKey;
120 var attr = prefInterfaceUI[i].attribute;
121
122 var value = FireinputUtils.getLocaleString(strKey + defaultLanguage);
123 var handle = document.getElementById(id);
124 if(!handle)
125 handle = document.documentElement.getButton(id);
126 if(!handle)
127 continue;
128 handle.setAttribute(attr, value);
129 }
130 }
131
132 function fireinputPrefGetType(option)
133 {
134 for(var i =prefNames.length-1; i>=0; i--)
135 {
136 if(option == prefNames[i].name)
137 {
138 return prefNames[i].type;
139 }
140 }
141
142 return 'STRING';
143 }
144
145 function fireinputPrefGetDefValue(option)
146 {
147 for(var i =prefNames.length-1; i>=0; i--)
148 {
149 if(option == prefNames[i].name)
150 {
151 return prefNames[i].value;
152 }
153 }
154
155 return null;
156 }
157
158 function fireinputPrefGetDefault(option)
159 {
160 var type = fireinputPrefGetType(option);
161 var value = fireinputPrefGetDefValue(option);
162 try {
163 var getvalue = FireinputPref.getPref(option, type);
164 if(type == "BOOL")
165 {
166 if(getvalue == true)
167 value = true;
168 else
169 value = false;
170 }
171 else
172 value = getvalue;
173
174 } catch(e) {}
175
176 // special handling for certain options
177 if(option == "interfaceLanguage")
178 {
179 if(value.length > 0)
180 value = "." + value;
181 }
182
183 return value;
184 }
185
186
187 function fireinputPrefShowing(popup)
188 {
189 for (var child = popup.firstChild; child; child = child.nextSibling)
190 {
191 if (child.localName == "menuitem")
192 {
193 var option = child.getAttribute("option");
194 if (option)
195 {
196 var type = child.getAttribute("type");
197 if(type == "radio")
198 {
199 var value = child.getAttribute("value");
200 try
201 {
202 var optionType = fireinputPrefGetType(option);
203 var savedValue = FireinputPref.getPref(option, optionType);
204 child.setAttribute("checked", savedValue == value ? true : false);
205 }
206 catch(e)
207 {
208 var defaultValue = fireinputPrefGetDefault(option);
209 child.setAttribute("checked", defaultValue == value ? true : false);
210 }
211 }
212
213 if(type == "checkbox")
214 {
215 // checkbox is BOOL type.
216 try
217 {
218 var savedValue = FireinputPref.getPref(option, "BOOL");
219 child.setAttribute("checked", savedValue);
220 }
221 catch(e)
222 {
223 var defaultValue = fireinputPrefGetDefault(option);
224 child.setAttribute("checked", defaultValue);
225 }
226 }
227
228 }
229 } /* if menuitem */
230
231 }
232 }
233
234 function fireinputPrefSave(menuitem, ovalue)
235 {
236
237 var option = null;
238 if(menuitem.getAttribute)
239 option = menuitem.getAttribute("option");
240
241 if (option)
242 {
243 var type = menuitem.getAttribute("type");
244 if(type == "radio")
245 {
246 var value = menuitem.getAttribute("value");
247 try
248 {
249 FireinputPref.setPref(option,"STRING", value);
250 }
251 catch(e) {};
252 }
253
254 if(type == "checkbox")
255 {
256 try
257 {
258 FireinputPref.setPref(option,"BOOL", menuitem.getAttribute("checked") == "true");
259 }
260 catch(e) {};
261 }
262 }
263 else
264 {
265 // might be real option
266 var type = fireinputPrefGetType(menuitem);
267 if(type != 'undefined')
268 {
269 try
270 {
271 FireinputPref.setPref(menuitem,type, ovalue);
272 }
273 catch(e) {};
274 }
275 }
276
277 return true;
278 }
279
280 var FireinputPrefDefault = {
281 getAMBOption: function(option)
282 {
283 var ambEnabled = false;
284 try {
285 var value = FireinputPref.getPref(option, "BOOL");
286 if(value == true)
287 ambEnabled = true;
288 else
289 ambEnabled = false;
290 }
291 catch(e)
292 { };
293
294 return ambEnabled;
295 },
296
297 };
syntax highlighted by Code2HTML, v. 0.9.1