diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-03-30 09:44:21 +0200 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-03-30 09:44:21 +0200 |
commit | a1a007a4856fa50d6d811c2268f881e3666f4c67 (patch) | |
tree | 24b082c1bfb5777f1770c82a534bf765160bc1b8 /toolkit/content/nsUserSettings.js | |
parent | eddd0de2ae80e176011f41a5400e81522d53f4f3 (diff) | |
parent | 59bf4204a84f7638d3f89a29bc7c04e5dc401369 (diff) | |
download | UXP-a1a007a4856fa50d6d811c2268f881e3666f4c67.tar UXP-a1a007a4856fa50d6d811c2268f881e3666f4c67.tar.gz UXP-a1a007a4856fa50d6d811c2268f881e3666f4c67.tar.lz UXP-a1a007a4856fa50d6d811c2268f881e3666f4c67.tar.xz UXP-a1a007a4856fa50d6d811c2268f881e3666f4c67.zip |
Merge branch 'master' of https://github.com/MoonchildProductions/UXP into html_input_datetime_1
Diffstat (limited to 'toolkit/content/nsUserSettings.js')
-rw-r--r-- | toolkit/content/nsUserSettings.js | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/toolkit/content/nsUserSettings.js b/toolkit/content/nsUserSettings.js new file mode 100644 index 000000000..e0c378caf --- /dev/null +++ b/toolkit/content/nsUserSettings.js @@ -0,0 +1,108 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + * nsPreferences - a wrapper around nsIPrefService. Provides built in + * exception handling to make preferences access simpler. + **/ +var nsPreferences = { + get mPrefService() + { + return Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + }, + + setBoolPref: function (aPrefName, aPrefValue) + { + try + { + this.mPrefService.setBoolPref(aPrefName, aPrefValue); + } + catch (e) + { + } + }, + + getBoolPref: function (aPrefName, aDefVal) + { + try + { + return this.mPrefService.getBoolPref(aPrefName); + } + catch (e) + { + return aDefVal != undefined ? aDefVal : null; + } + return null; // quiet warnings + }, + + setUnicharPref: function (aPrefName, aPrefValue) + { + try + { + var str = Components.classes["@mozilla.org/supports-string;1"] + .createInstance(Components.interfaces.nsISupportsString); + str.data = aPrefValue; + this.mPrefService.setComplexValue(aPrefName, + Components.interfaces.nsISupportsString, str); + } + catch (e) + { + } + }, + + copyUnicharPref: function (aPrefName, aDefVal) + { + try + { + return this.mPrefService.getComplexValue(aPrefName, + Components.interfaces.nsISupportsString).data; + } + catch (e) + { + return aDefVal != undefined ? aDefVal : null; + } + return null; // quiet warnings + }, + + setIntPref: function (aPrefName, aPrefValue) + { + try + { + this.mPrefService.setIntPref(aPrefName, aPrefValue); + } + catch (e) + { + } + }, + + getIntPref: function (aPrefName, aDefVal) + { + try + { + return this.mPrefService.getIntPref(aPrefName); + } + catch (e) + { + return aDefVal != undefined ? aDefVal : null; + } + return null; // quiet warnings + }, + + getLocalizedUnicharPref: function (aPrefName, aDefVal) + { + try + { + return this.mPrefService.getComplexValue(aPrefName, + Components.interfaces.nsIPrefLocalizedString).data; + } + catch (e) + { + return aDefVal != undefined ? aDefVal : null; + } + return null; // quiet warnings + } +}; + |