aboutsummaryrefslogtreecommitdiff
path: root/chrome/js
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/js')
-rw-r--r--chrome/js/redirectorprefs.js57
1 files changed, 41 insertions, 16 deletions
diff --git a/chrome/js/redirectorprefs.js b/chrome/js/redirectorprefs.js
index 75ef936..a0cd366 100644
--- a/chrome/js/redirectorprefs.js
+++ b/chrome/js/redirectorprefs.js
@@ -1,12 +1,37 @@
var EXPORTED_SYMBOLS = ['RedirectorPrefs'];
function RedirectorPrefs() {
- this.init();
+ this.init();
}
RedirectorPrefs.prototype = {
-
_listeners : null,
+
+ watch : function(prop_name, cb) {
+ Object.defineProperty(this, prop_name, {
+ set: function(val) {
+ cb(prop_name, null, val);
+ },
+ get: function() {
+ let pb = this._prefBranch;
+ switch (pb.getPrefType(prop_name)) {
+ case pb.PREF_STRING:
+ return pb.getCharPref(prop_name);
+ break;
+ case pb.PREF_INT:
+ return pb.getIntPref(prop_name);
+ break;
+ case pb.PREF_BOOL:
+ return pb.getBoolPref(prop_name);
+ break;
+ }
+ }});
+ },
+
+ unwatch : function(prop_name) {
+ delete this[prop_name];
+ },
+
init : function() {
this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.redirector.");
this.reload();
@@ -18,20 +43,20 @@ RedirectorPrefs.prototype = {
this._listeners = null;
this.service.removeObserver('extensions.redirector', this);
},
-
+
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);
- }
-
+ // 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) {
@@ -46,7 +71,7 @@ RedirectorPrefs.prototype = {
});
}
},
-
+
get service() {
return Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranchInternal);
},
@@ -57,14 +82,14 @@ RedirectorPrefs.prototype = {
}
this.reload(false);
for each (var listener in this._listeners) {
- listener && listener.changedPrefs && listener.changedPrefs(this);
+ listener && listener.changedPrefs && listener.changedPrefs(this);
}
},
addListener : function(listener) {
this._listeners.push(listener);
},
-
+
removeListener : function(listener) {
for (var i = 0; i < this._listeners.length; i++) {
this._listeners.splice(i,1);
@@ -73,4 +98,4 @@ RedirectorPrefs.prototype = {
}
}
},
-} \ No newline at end of file
+}