aboutsummaryrefslogtreecommitdiff
path: root/chrome/code/redirectorprefs.js
diff options
context:
space:
mode:
authorEinar Egilsson2011-09-01 21:33:28 +0200
committerEinar Egilsson2011-09-01 21:33:28 +0200
commit8fb65cf8aeaaf66636698310c0168929fc1a2ce0 (patch)
tree9daee91989a941852c14e017e36cb783ef174dbb /chrome/code/redirectorprefs.js
parent9ef693c6f7d0c720e33b5415bd78191d52e1eef8 (diff)
Better pref handling
Diffstat (limited to 'chrome/code/redirectorprefs.js')
-rw-r--r--chrome/code/redirectorprefs.js72
1 files changed, 28 insertions, 44 deletions
diff --git a/chrome/code/redirectorprefs.js b/chrome/code/redirectorprefs.js
index 40e8737..75ef936 100644
--- a/chrome/code/redirectorprefs.js
+++ b/chrome/code/redirectorprefs.js
@@ -6,42 +6,7 @@ function RedirectorPrefs() {
RedirectorPrefs.prototype = {
- //Preferences:
- _version : null,
- _enabled : null,
- _showStatusBarIcon : null,
- _showContextMenu : null,
- _debugEnabled : null,
- _defaultDir : null,
- _redirects : null,
- _proxyServerPort : null,
- _prefBranch : null,
-
_listeners : null,
-
- //Preferences props
-
- get version() { return this._version; },
- set version(value) { this._prefBranch.setCharPref('version', value); },
-
- get enabled() { return this._enabled; },
- set enabled(value) { this._prefBranch.setBoolPref('enabled', value); },
-
- get showStatusBarIcon() { return this._showStatusBarIcon; },
- set showStatusBarIcon(value) { this._prefBranch.setBoolPref('showStatusBarIcon', value); },
-
- get showContextMenu() { return this._showContextMenu; },
- set showContextMenu(value) { this._prefBranch.setBoolPref('showContextMenu', value); },
-
- get debugEnabled() { return this._debugEnabled; },
- set debugEnabled(value) { this._prefBranch.setBoolPref('debugEnabled', value); },
-
- get proxyServerPort() { return this._proxyServerPort; },
- set proxyServerPort(value) { this._prefBranch.setIntPref('proxyServerPort', value); },
-
- get defaultDir() { return this._defaultDir; },
- set defaultDir(value) { this._prefBranch.setCharPref('defaultDir', value); },
-
init : function() {
this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.redirector.");
this.reload();
@@ -54,13 +19,32 @@ RedirectorPrefs.prototype = {
this.service.removeObserver('extensions.redirector', this);
},
- reload : function() {
- this._version = this._prefBranch.getCharPref('version');
- this._enabled = this._prefBranch.getBoolPref('enabled');
- this._showStatusBarIcon = this._prefBranch.getBoolPref('showStatusBarIcon');
- this._showContextMenu = this._prefBranch.getBoolPref('showContextMenu');
- this._debugEnabled = this._prefBranch.getBoolPref('debugEnabled');
- this._defaultDir = this._prefBranch.getCharPref('defaultDir');
+ reload : function(addWatch) {
+ var b = this._prefBranch;
+ for each (var name in b.getChildList('')){
+ this.unwatch(name);
+ var type = b.getPrefType(name);
+ if (type == b.PREF_STRING) {
+ this[name] = b.getCharPref(name);
+ } else if (type == b.PREF_INT) {
+ this[name] = b.getIntPref(name);
+ } else if (type == b.PREF_BOOL) {
+ this[name] = b.getBoolPref(name);
+ }
+
+ this.watch(name, function(id,oldval,newval) {
+ var type = b.getPrefType(id);
+ if (type == b.PREF_STRING) {
+ b.setCharPref(id,newval);
+ } else if (type == b.PREF_INT) {
+ b.setIntPref(id, newval);
+ } else if (type == b.PREF_BOOL) {
+ dump(id+ ' ' + newval)
+ b.setBoolPref(id, newval);
+ }
+ return newval;
+ });
+ }
},
get service() {
@@ -71,7 +55,7 @@ RedirectorPrefs.prototype = {
if (topic != 'nsPref:changed') {
return;
}
- this.reload();
+ this.reload(false);
for each (var listener in this._listeners) {
listener && listener.changedPrefs && listener.changedPrefs(this);
}
@@ -83,8 +67,8 @@ RedirectorPrefs.prototype = {
removeListener : function(listener) {
for (var i = 0; i < this._listeners.length; i++) {
- if (this._listeners[i] == listener) {
this._listeners.splice(i,1);
+ if (this._listeners[i] == listener) {
return;
}
}