home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2006 October / wn148cd2.iso / Windows / S'informer / Netcraft / netcrafttoolbar.xpi / chrome / netcrafttoolbar.jar / content / options.js < prev    next >
Text File  |  2005-08-04  |  3KB  |  141 lines

  1. /*
  2.  * NetcraftToolbar - Options Window
  3.  *
  4.  * Copyright (C) 2005 Netcraft Ltd
  5.  * http://toolbar.netcraft.com/
  6.  *
  7.  * $Id: chrome:content:options.js,v 1.28 2005/06/10 00:52:02 jez Exp $
  8.  */
  9.  
  10. const PT_VERSION = "1.0.3.3";
  11.  
  12. const PT_BRANCHNAME = "netcrafttoolbar.";
  13. const PT_VERSIONPREF = "version";
  14. const PT_IDPREF = "id";
  15. const PT_EXTLASTUPDATE = "extensions.update.lastUpdateDate";
  16. const PT_BROWSEROFFLINE = "browser.offline";
  17. const PT_BROWSEROPEN = "browser.link.open_external";
  18. const PT_BROWSERBG = "browser.tabs.loadBookmarksInBackground";
  19.  
  20. const PT_ABOUTWINDOWURI = "chrome://netcrafttoolbar/content/about.xul";
  21. const PT_ABOUTWINDOWTITLE = "About NetcraftToolbar";
  22. const PT_ABOUTWINDOWPARAMS = "chrome,centerscreen";
  23. const PT_BUILDHEX = "123C710F44FA";
  24. var ptPrefs = Components.classes["@mozilla.org/preferences-service;1"].
  25.     getService(Components.interfaces.nsIPrefService);
  26. function PtPreferences(node) {
  27.     this.branch = ptPrefs.getBranch(node);
  28. }
  29.  
  30. PtPreferences.prototype.setIntPref = function (pref, i) {
  31.     try {
  32.     this.branch.setIntPref(pref, i);
  33.     }
  34.     catch (e) {
  35.     }
  36. }
  37.  
  38. PtPreferences.prototype.getIntPref = function (pref,dflt) {
  39.     var i;
  40.     try {
  41.     i = this.branch.getIntPref(pref);
  42.     }
  43.     catch (e) {
  44.     this.branch.setIntPref(pref, dflt);
  45.     i = this.branch.getIntPref(pref);
  46.     }
  47.     return i;
  48. }
  49.  
  50. PtPreferences.prototype.setCharPref = function (pref, s) {
  51.     try {
  52.     this.branch.setCharPref(pref, s);
  53.     }
  54.     catch (e) {
  55.     }
  56. }
  57.  
  58. PtPreferences.prototype.getCharPref = function (pref,dflt) {
  59.     var s;
  60.     try {
  61.     s = this.branch.getCharPref(pref);
  62.     }
  63.     catch (e) {
  64.     this.branch.setCharPref(pref, dflt);
  65.     s = this.branch.getCharPref(pref);
  66.     }
  67.     return s;
  68. }
  69.  
  70. PtPreferences.prototype.setBoolPref = function (pref, b) {
  71.     try {
  72.     this.branch.setBoolPref(pref, b);
  73.     }
  74.     catch (e) {
  75.     }
  76. }
  77.  
  78. PtPreferences.prototype.getBoolPref = function (pref,dflt) {
  79.     var b;
  80.     try {
  81.     b = this.branch.getBoolPref(pref);
  82.     }
  83.     catch (e) {
  84.     this.branch.setBoolPref(pref, dflt);
  85.     b = this.branch.getBoolPref(pref);
  86.     }
  87.     return b;
  88. }
  89.  
  90. PtPreferences.prototype.deletePrefsBranch = function () {
  91.     this.branch.deleteBranch("");
  92. }
  93.  
  94. var ptToolbarPrefs = {
  95.  
  96.     _root: (new PtPreferences(null)),
  97.     _tree: (new PtPreferences(PT_BRANCHNAME)),
  98.  
  99.     getUpdateInterval: function () {
  100.     return this._root.setIntPref(PT_EXTLASTUPDATE, 0);
  101.     },
  102.     setUpdateInterval: function () {
  103.     this._root.setIntPref(PT_EXTLASTUPDATE, 0);
  104.     },
  105.  
  106.     isOffline: function () {
  107.     return this._root.getBoolPref(PT_BROWSEROFFLINE);
  108.     },
  109.  
  110.     _genid: function () {
  111.     var datepart = new Date().getTime().toString(16).toUpperCase();
  112.     var randpart =
  113.         ("000000000" + (Math.floor(Math.random() * 1e17)).toString(16)).
  114.         substr(-9).toUpperCase();
  115.     return(randpart + PT_BUILDHEX + datepart);
  116.     },
  117.  
  118.     newWindow: function () {
  119.     return this._root.getIntPref(PT_BROWSEROPEN);
  120.     },
  121.  
  122.     bg: function () {
  123.     return this._root.getBoolPref(PT_BROWSERBG);
  124.     },
  125.  
  126.     getVersion: function () {
  127.     return this._tree.getCharPref(PT_VERSIONPREF);
  128.     },
  129.     setVersion: function (vers) {
  130.     this._tree.setCharPref(PT_VERSIONPREF,vers);
  131.     }
  132. };
  133. ptToolbarPrefs.uuid =
  134.     ptToolbarPrefs._tree.getCharPref(PT_IDPREF,ptToolbarPrefs._genid());
  135.  
  136. function PtOpenToolbarAboutWindow() {
  137.     window.openDialog(PT_ABOUTWINDOWURI, PT_ABOUTWINDOWTITLE, PT_ABOUTWINDOWPARAMS);
  138. }
  139.  
  140. ptToolbarPrefs.setVersion(PT_VERSION);
  141.