aboutsummaryrefslogtreecommitdiff
path: root/chrome/code/redirectorprefs.js
diff options
context:
space:
mode:
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;
}
}