michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: * nsPreferences - a wrapper around nsIPrefService. Provides built in michael@0: * exception handling to make preferences access simpler. michael@0: **/ michael@0: var nsPreferences = { michael@0: get mPrefService() michael@0: { michael@0: return Components.classes["@mozilla.org/preferences-service;1"] michael@0: .getService(Components.interfaces.nsIPrefBranch); michael@0: }, michael@0: michael@0: setBoolPref: function (aPrefName, aPrefValue) michael@0: { michael@0: try michael@0: { michael@0: this.mPrefService.setBoolPref(aPrefName, aPrefValue); michael@0: } michael@0: catch(e) michael@0: { michael@0: } michael@0: }, michael@0: michael@0: getBoolPref: function (aPrefName, aDefVal) michael@0: { michael@0: try michael@0: { michael@0: return this.mPrefService.getBoolPref(aPrefName); michael@0: } michael@0: catch(e) michael@0: { michael@0: return aDefVal != undefined ? aDefVal : null; michael@0: } michael@0: return null; // quiet warnings michael@0: }, michael@0: michael@0: setUnicharPref: function (aPrefName, aPrefValue) michael@0: { michael@0: try michael@0: { michael@0: var str = Components.classes["@mozilla.org/supports-string;1"] michael@0: .createInstance(Components.interfaces.nsISupportsString); michael@0: str.data = aPrefValue; michael@0: this.mPrefService.setComplexValue(aPrefName, michael@0: Components.interfaces.nsISupportsString, str); michael@0: } michael@0: catch(e) michael@0: { michael@0: } michael@0: }, michael@0: michael@0: copyUnicharPref: function (aPrefName, aDefVal) michael@0: { michael@0: try michael@0: { michael@0: return this.mPrefService.getComplexValue(aPrefName, michael@0: Components.interfaces.nsISupportsString).data; michael@0: } michael@0: catch(e) michael@0: { michael@0: return aDefVal != undefined ? aDefVal : null; michael@0: } michael@0: return null; // quiet warnings michael@0: }, michael@0: michael@0: setIntPref: function (aPrefName, aPrefValue) michael@0: { michael@0: try michael@0: { michael@0: this.mPrefService.setIntPref(aPrefName, aPrefValue); michael@0: } michael@0: catch(e) michael@0: { michael@0: } michael@0: }, michael@0: michael@0: getIntPref: function (aPrefName, aDefVal) michael@0: { michael@0: try michael@0: { michael@0: return this.mPrefService.getIntPref(aPrefName); michael@0: } michael@0: catch(e) michael@0: { michael@0: return aDefVal != undefined ? aDefVal : null; michael@0: } michael@0: return null; // quiet warnings michael@0: }, michael@0: michael@0: getLocalizedUnicharPref: function (aPrefName, aDefVal) michael@0: { michael@0: try michael@0: { michael@0: return this.mPrefService.getComplexValue(aPrefName, michael@0: Components.interfaces.nsIPrefLocalizedString).data; michael@0: } michael@0: catch(e) michael@0: { michael@0: return aDefVal != undefined ? aDefVal : null; michael@0: } michael@0: return null; // quiet warnings michael@0: } michael@0: }; michael@0: