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     "interfaceLanguage","defaultInputMethod", "saveHistory"
 39 ];
 40 
 41 const prefInterfaceUI = [ 
 42             {id: "autoInsert", strKey: "fireinput.pref.auto.insert", attribute: "label"},           
 43             {id: "autoInsert", strKey: "fireinput.pref.auto.insert.tooltip", attribute: "tooltiptext"},           
 44             {id: "fireinputDefaultInputMethod", strKey: "fireinput.pref.input.method", attribute: "label"},           
 45             {id: "saveHistory", strKey: "fireinput.pref.save.history", attribute: "label"},           
 46             {id: "fireinputInterfaceLanguage", strKey: "fireinput.choose.interface.language", attribute: "label"},
 47             {id: "fireinputLanguageChinese", strKey: "fireinput.chinese.label", attribute: "label"},           
 48             {id: "fireinputLanguageEnglish", strKey: "fireinput.english.label", attribute: "label"},           
 49             {id: "imePinyinQuan", strKey: "fireinput.pinyin.quan.label", attribute: "label"},           
 50             {id: "imePinyinShuangZiGuang", strKey: "fireinput.pinyin.shuang.ziguang.label", attribute: "label"},
 51             {id: "imePinyinShuangMS", strKey: "fireinput.pinyin.shuang.ms.label", attribute: "label"},
 52             {id: "imePinyinShuangChineseStar", strKey: "fireinput.pinyin.shuang.chinesestar.label", attribute: "label"},
 53             {id: "imePinyinShuangSmartABC", strKey: "fireinput.pinyin.shuang.smartabc.label", attribute: "label"},
 54             {id: "imeWubi86", strKey: "fireinput.wubi86.label", attribute: "label"},
 55             {id: "imeWubi98", strKey: "fireinput.wubi98.label", attribute: "label"},
 56             {id: "fireinputAMB", strKey: "fireinput.pref.amb.label", attribute: "label"},
 57             {id: "fireinputOpenKeyBinding", strKey: "fireinput.pref.open.hotkey", attribute: "label"},
 58             {id: "fireinputOpenKeyBinding", strKey: "fireinput.pref.open.hotkey.tooltip", attribute: "tooltiptext"},
 59             {id: "fireinputOpenKeyBindingCtrlF12", strKey: "fireinput.pref.open.hotkey.tooltip", attribute: "tooltiptext"},
 60             {id: "fireinputOpenKeyBindingCtrlF11", strKey: "fireinput.pref.open.hotkey.tooltip", attribute: "tooltiptext"},
 61             {id: "fireinputOpenKeyBindingAltF12", strKey: "fireinput.pref.open.hotkey.tooltip", attribute: "tooltiptext"},
 62             {id: "fireinputOpenKeyBindingAltF11", strKey: "fireinput.pref.open.hotkey.tooltip", attribute: "tooltiptext"}
 63       ]; 
 64 
 65 
 66 function fireinputPrefInit()
 67 {
 68     // get default language first 
 69     var defaultLanguage = FireinputPrefDefault.getInterfaceLanguage(); 
 70 
 71     // update UI 
 72     for(var i =prefInterfaceUI.length-1; i>=0; i--)
 73     {
 74        var id = prefInterfaceUI[i].id; 
 75        var strKey = prefInterfaceUI[i].strKey; 
 76        var attr = prefInterfaceUI[i].attribute; 
 77  
 78        var value = FireinputUtils.getLocaleString(strKey + defaultLanguage); 
 79        var handle = document.getElementById(id); 
 80        if(!handle)
 81           handle = document.documentElement.getButton(id); 
 82        if(!handle) 
 83           continue; 
 84        handle.setAttribute(attr, value); 
 85     }
 86 }
 87 
 88 function fireinputPrefGetDefault(option)
 89 {
 90     if(option == "interfaceLanguage")
 91        return FireinputPrefDefault.getLanguage(); 
 92 
 93     if(option == "defaultInputMethod")
 94        return FireinputPrefDefault.getSchema(); 
 95 
 96     return 'undefined'; 
 97 }
 98 
 99     
100 function fireinputPrefShowing(popup)
101 {
102     for (var child = popup.firstChild; child; child = child.nextSibling)
103     {
104        if (child.localName == "menuitem")
105        {
106           var option = child.getAttribute("option");
107           if (option)
108           {
109              var type = child.getAttribute("type"); 
110              if(type == "radio")
111              { 
112                 var value = child.getAttribute("value"); 
113                 try
114                 {
115                    var savedValue = FireinputPref.getPref(option, "STRING");
116                    child.setAttribute("checked", savedValue == value ? true : false); 
117                 }
118                 catch(e)
119                 {
120                    var defaultValue = fireinputPrefGetDefault(option); 
121                    child.setAttribute("checked", defaultValue == value ? true : false); 
122                 }
123              }
124 
125              if(type == "checkbox")
126              { 
127                 try
128                 {
129                    var savedValue = FireinputPref.getPref(option, "BOOL");
130                    child.setAttribute("checked", savedValue); 
131                 }
132                 catch(e)
133                 {
134                    child.setAttribute("checked", false); 
135                 }
136              }
137 
138           }
139        } /* if menuitem */
140 
141     }
142 }
143 
144 function fireinputPrefSave(menuitem)
145 {
146     var option = menuitem.getAttribute("option");
147     if (option)
148     {
149        var type = menuitem.getAttribute("type");
150        if(type == "radio")
151        { 
152           var value = menuitem.getAttribute("value");
153           try 
154           {
155              FireinputPref.setPref(option,"STRING", value); 
156           }
157           catch(e) {}; 
158        }
159 
160        if(type == "checkbox")
161        { 
162           try 
163           {
164              FireinputPref.setPref(option,"BOOL", menuitem.getAttribute("checked") == "true"); 
165           }
166           catch(e) {}; 
167        }
168     }
169 
170     return true; 
171 }
172 
173 var FireinputPrefDefault = {
174     
175     getInterfaceLanguage: function()
176     {
177        // get default language first 
178        var defaultLanguage = LANGUAGE_ZH; 
179 
180        try {
181           defaultLanguage = FireinputPref.getPref("interfaceLanguage", "STRING");
182        }
183        catch(e) 
184        { };
185 
186        if(defaultLanguage.length > 0)
187           defaultLanguage = "." + defaultLanguage; 
188 
189        return defaultLanguage; 
190     },
191 
192     getLanguage: function()
193     {
194        // get default language first 
195        var defaultLanguage = LANGUAGE_ZH; 
196 
197        try {
198           defaultLanguage = FireinputPref.getPref("interfaceLanguage", "STRING");
199        }
200        catch(e) 
201        { };
202 
203        return defaultLanguage; 
204     },
205 
206     getSchema: function()
207     {
208        var defaultMethod = SMART_PINYIN; 
209        try {
210           defaultMethod = FireinputPref.getPref("defaultInputMethod", "STRING");
211        }
212        catch(e)
213        { }
214 
215        return defaultMethod; 
216     },
217  
218     getSaveHistory: function()
219     {
220        var saveHistory = true; 
221        try {
222           var value = FireinputPref.getPref("saveHistory", "BOOL");
223           if(value == true)
224              saveHistory = true; 
225           else
226              saveHistory = false;
227        }
228        catch(e) 
229        { };
230 
231        return saveHistory; 
232     },
233 
234     getAutoInsert: function()
235     {
236        var autoInsert = false;
237        try {
238           var value = FireinputPref.getPref("autoInsert", "BOOL");
239           if(value == true)
240              autoInsert = true;
241           else
242              autoInsert = false;
243        }
244        catch(e)
245        { };
246 
247        return autoInsert;
248     },
249 
250     getOpenKeyBinding: function()
251     {
252        var defaultOpenKeyBinding = "control,VK_F12"; 
253        try {
254           defaultOpenKeyBinding = FireinputPref.getPref("fireinputOpenKeyBinding", "STRING");
255        }
256        catch(e)
257        { }
258 
259        return defaultOpenKeyBinding; 
260     },
261 
262     getAMBOption: function(option)
263     {
264        var ambEnabled = false; 
265        try {
266           var value = FireinputPref.getPref(option, "BOOL");
267           if(value == true)
268              ambEnabled = true;
269           else
270              ambEnabled = false;
271        }
272        catch(e)
273        { };
274 
275        return ambEnabled;
276     }
277 
278 }; 


syntax highlighted by Code2HTML, v. 0.9.1