]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/panes/options.js
make hue overridding more logical
[irc/quakenet/qwebirc.git] / js / ui / panes / options.js
index da3d7ca1ff8f85587e0444b441563fe0dc59a594..e3fd86ca90db67c83a9840bfb2797d2dd76ac61b 100644 (file)
@@ -14,15 +14,21 @@ qwebirc.ui.supportsFocus = function() {
  * settableByURL...
  */
 qwebirc.config.DEFAULT_OPTIONS = [
-  [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity (requires Flash)", true, {
+  [1, "BEEP_ON_MENTION", "Beep on activity", true, {
+    applyChanges: function(value, ui) {
+      if(ui.setBeepOnMention)
+        ui.setBeepOnMention(value);
+    }
+  }],
+  [16, "NOTIFICATIONS", "Emit HTML5 notifications on activity", false, {
     enabled: function() {
-      if(!$defined(Browser.Plugins.Flash) || Browser.Plugins.Flash.version < 8)
+      if(!("Notification" in window))
         return [false, false]; /* [disabled, default_value] */
       return [true];
     },
-    get: function(value, ui) {
-      if(ui.setBeepOnMention)
-        ui.setBeepOnMention(value);
+    applyChanges: function(value, ui) {
+      if(ui.setNotifications)
+        ui.setNotifications(value);
     }
   }],
   [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, {
@@ -42,14 +48,26 @@ qwebirc.config.DEFAULT_OPTIONS = [
   }],
   [9, "NICK_COLOURS", "Automatically colour nicknames", false],
   [10, "HIDE_JOINPARTS", "Hide JOINS/PARTS/QUITS", false],
-  [11, "STYLE_HUE", "Adjust user interface hue", function() {
-    return {class_: qwebirc.config.HueOption, default_: 210};
+  [11, "STYLE_HUE", "Adjust user interface hue", function(ui) {
+    return {class_: qwebirc.config.HueOption, default_: ui.__styleValues.hue};
   }, {
-    get: function(value, ui) {
-      ui.setModifiableStylesheetValues(value, 0, 0);
+    applyChanges: function(value, ui) {
+      ui.setModifiableStylesheetValues({hue: value});
     }
   }],
-  [12, "QUERY_ON_NICK_CLICK", "Query on nickname click in channel", false]
+  [12, "QUERY_ON_NICK_CLICK", "Query on nickname click in channel", false],
+  [13, "SHOW_NICKLIST", "Show nickname list in channels", qwebirc.util.deviceHasKeyboard()],
+  [14, "SHOW_TIMESTAMPS", "Show timestamps", true], /* we rely on the hue update */
+  [15, "SIDE_TABS", "Show tabs on the side", false, {
+    enabled: function() {
+      if(Browser.Engine.trident && Browser.Engine.version < 8)
+        return [false, false]; /* [disabled, default_value] */
+      return [true];
+    },
+    applyChanges: function(value, ui) {
+      ui.setSideTabs(value);
+    }
+  }]
 ];
 
 qwebirc.config.DefaultOptions = null;
@@ -85,9 +103,8 @@ qwebirc.config.Input = new Class({
   render: function() {
     this.event("render", this.mainElement);
   },
-  get: function(value) {
-    this.event("get", [value, this.parentObject.optionObject.ui]);
-    return value;
+  applyChanges: function() {
+    this.event("applyChanges", [this.get(), this.parentObject.optionObject.ui]);
   },
   event: function(name, x) {
     if(!$defined(this.option.extras))
@@ -114,7 +131,7 @@ qwebirc.config.TextInput = new Class({
     this.parent();
   },
   get: function() {
-    return this.parent(this.mainElement.value);
+    return this.mainElement.value;
   }
 });
 
@@ -141,7 +158,7 @@ qwebirc.config.HueInput = new Class({
     
     slider.addEvent("change", function(step) {
       this.value = step;
-      this.get();
+      this.applyChanges();
     }.bind(this));
     this.mainElement = i;
     
@@ -151,11 +168,11 @@ qwebirc.config.HueInput = new Class({
     this.parent();
   },
   get: function() {
-    return this.parent(this.value);
+    return this.value;
   },
   cancel: function() {
     this.value = this.startValue;
-    this.get();
+    this.applyChanges();
   }
 });
 
@@ -171,7 +188,7 @@ qwebirc.config.CheckInput = new Class({
     this.parent();
   },
   get: function() {
-    return this.parent(this.mainElement.checked);
+    return this.mainElement.checked;
   }
 });
 
@@ -200,7 +217,7 @@ qwebirc.config.RadioInput = new Class({
       var x = this.elements[i];
       if(x.checked) {
         this.option.position = i;
-        return this.parent(this.option.options[i][1]);
+        return this.option.options[i][1];
       }
     }
   }
@@ -280,13 +297,14 @@ qwebirc.config.HueOption = new Class({
 
 qwebirc.ui.Options = new Class({
   initialize: function(ui) {
+    this.ui = ui;
+
     if(!$defined(qwebirc.config.DefaultOptions))
       this.__configureDefaults();
     
     this.optionList = qwebirc.config.DefaultOptions.slice();
-    this.optionHash = {}
-    this.ui = ui;
-    
+    this.optionHash = {};
+
     this._setup();
     this.optionList.forEach(function(x) {
       x.setSavedValue(this._get(x));
@@ -311,7 +329,7 @@ qwebirc.ui.Options = new Class({
         if(stype == "boolean") {
           type = qwebirc.config.CheckOption;
         } else if(stype == "function") {
-          var options = default_();
+          var options = default_.call(this, this.ui);
           type = options.class_;
           default_ = options.default_;
         } else {
@@ -319,12 +337,16 @@ qwebirc.ui.Options = new Class({
         }
         return new type(optionId, prefix, label, default_, moreextras);
       }
-    });
+    }, this);
   },
   setValue: function(option, value) {
     this.optionHash[option.prefix].value = value;
     this[option.prefix] = value;
   },
+  setValueByPrefix: function(prefix, value) {
+    this.optionHash[prefix].value = value;
+    this[prefix] = value;
+  },
   getOptionList: function() {
     return this.optionList;
   },
@@ -398,6 +420,9 @@ qwebirc.ui.OptionsPane = new Class({
       var box = x[1];
       this.optionObject.setValue(option, box.get());
     }.bind(this));
+    this.boxList.forEach(function(x) {
+      x[1].applyChanges();
+    }.bind(this));
     this.optionObject.flush();
   },
   cancel: function() {
@@ -433,14 +458,18 @@ qwebirc.ui.CookieOptions = new Class({
 qwebirc.ui.SuppliedArgOptions = new Class({
   Extends: qwebirc.ui.CookieOptions,
   initialize: function(ui, arg) {
-    var p = {};
+    var p = new QHash();
     
     if($defined(arg) && arg != "" && arg.length > 2) {
       var checksum = arg.substr(arg.length - 2, 2);
       var decoded = qwebirc.util.b64Decode(arg.substr(0, arg.length - 2));
       
-      if(decoded && (new qwebirc.util.crypto.MD5().digest(decoded).slice(0, 2) == checksum))
-        p = qwebirc.util.parseURI("?" + decoded);
+      if(decoded && (new qwebirc.util.crypto.MD5().digest(decoded).slice(0, 2) == checksum)) {
+        var p2 = qwebirc.util.parseURI("?" + decoded);
+        p2.each(function(k, v) {
+          p.put(k, JSON.decode(v, true));
+        });
+      }
     }
     
     this.parsedOptions = p;
@@ -450,7 +479,7 @@ qwebirc.ui.SuppliedArgOptions = new Class({
     if(x.settableByURL !== true)
       return this.parent(x);
 
-    var opt = this.parsedOptions[x.optionId];
+    var opt = this.parsedOptions.get(String(x.optionId));
     if(!$defined(opt))
       return this.parent(x);
       
@@ -460,7 +489,7 @@ qwebirc.ui.SuppliedArgOptions = new Class({
     var result = [];
     this.getOptionList().forEach(function(x) {
       if(x.settableByURL && x.default_ != x.value)
-        result.push(x.optionId + "=" + x.value);
+        result.push(x.optionId + "=" + JSON.encode(x.value));
     }.bind(this));
     
     var raw = result.join("&");