home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / 01_03.iso / software / ghostzilla_hit / files / ghostzilla-1.0-plus-install.exe / chrome / toolkit.jar / content / global / config.js < prev    next >
Encoding:
JavaScript  |  2002-04-09  |  7.4 KB  |  264 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  * 
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributors:
  21.  *  Chip Clark <chipc@netscape.com>
  22.  *  Seth Spitzer <sspitzer@netscape.com>
  23.  */
  24.  
  25. var baseArray = new Array();
  26.  
  27. const kDefault = 0;
  28. const kUserSet = 1;
  29. const kLocked = 2;
  30.  
  31. const nsIAtomService = Components.interfaces.nsIAtomService;
  32. const nsAtomService_CONTRACTID = "@mozilla.org/atom-service;1";
  33.  
  34. var atomService = Components.classes[nsAtomService_CONTRACTID].getService(nsIAtomService);
  35. var gLockAtoms = [atomService.getAtom("default"), atomService.getAtom("user"), atomService.getAtom("locked")];
  36. // XXX get these from a string bundle
  37. var gLockStrs = ["default", "user set","locked"]; 
  38.  
  39. const kStrType = 0;
  40. const kIntType = 1;
  41. const kBoolType = 2;
  42.  
  43. var gTypeStrs = ["string","int","bool"];
  44.  
  45. var gTree;
  46.  
  47. var view = ({
  48.     rowCount : 0, 
  49.     getCellText : function(k, col) {    
  50.             if (!baseArray[k])
  51.                 return "";
  52.             
  53.             var value = baseArray[k][col];
  54.             var strvalue;
  55.  
  56.             switch (col) {
  57.               case "lockCol":           
  58.                 strvalue = gLockStrs[value];
  59.                 break;
  60.               case "typeCol":
  61.                 strvalue = gTypeStrs[value];
  62.                 break;
  63.               default:
  64.                 // already a str.
  65.                 strvalue = value;    
  66.                 break;
  67.             }
  68.             return strvalue;
  69.         },
  70.     getRowProperties : function(index, prop) {},
  71.     getCellProperties : function(index, col, prop) {
  72.       prop.AppendElement(gLockAtoms[baseArray[index]["lockCol"]]);
  73.     },
  74.     getColumnProperties : function(col, elt, prop) {},
  75.     treebox : null,
  76.     selection : null,
  77.     isContainer : function(index) { return false; },
  78.     isContainerOpen : function(index) { return false; },
  79.     isContainerEmpty : function(index) { return false; },
  80.     isSorted : function() { },
  81.     canDropOn : function(index) { return false; },
  82.     canDropBeforeAfter : function(index,before) { return false; },
  83.     drop : function(row,orientation) {},
  84.     setTree : function(out) { this.treebox = out; },
  85.     getParentIndex: function(rowIndex) { return -1 },
  86.     hasNextSibling: function(rowIndex, afterIndex) { return false },
  87.     getLevel: function(index) { return 1},
  88.     toggleOpenState : function(index) {},
  89.     cycleHeader: function(colID, elt) {},
  90.     selectionChanged : function() {},
  91.     cycleCell: function(row, colID) {},
  92.     isEditable: function(row, valueCol) {return true},
  93.     isEditable: function(row, colID) {return false},
  94.     setCellText: function(row, colID, value) {},
  95.     performAction: function(action) {},
  96.     performActionOnRow: function(action, row) {},
  97.     performActionOnCell: function(action, row, colID) {},
  98.     isSeparator: function(index) {return false}
  99. });
  100.  
  101. function onConfigLoad()
  102. {
  103.     document.title = "about:config";
  104.  
  105.     var prefCount = {value:0};
  106.     var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  107.     var prefBranch = prefService.getBranch(null);
  108.     var prefArray = prefBranch.getChildList("" , prefCount);
  109.     var prefName, prefType, prefValue, prefIndex, prefLockState;
  110.  
  111.     var i = 0;
  112.     var j = 0;   // This is used to avoid counting the "capability" preferences
  113.     var k = 0;     // This is to maintain a count of prefs (not including the "capability" prefs);
  114.  
  115.     prefArray.sort();
  116.     for (i = 0; i < prefCount.value; i++) 
  117.     {
  118.         if((prefArray[i].indexOf("capability", 0) + 1) > 0)    // avoid displaying "private" preferences
  119.         {
  120.             j++;
  121.             continue;
  122.         }
  123.  
  124.         k = (i - j);   // avoid numbering "capability" prefs
  125.  
  126.         prefIndex = k + 1;
  127.     
  128.         if (prefBranch.prefIsLocked(prefArray[i]))
  129.           prefLockState = kLocked;
  130.         else if(prefBranch.prefHasUserValue(prefArray[i]))
  131.           prefLockState = kUserSet;
  132.         else
  133.           prefLockState = kDefault;
  134.  
  135.         const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
  136.  
  137.         switch (prefBranch.getPrefType(prefArray[i])) {
  138.             case nsIPrefBranch.PREF_INT:
  139.             prefType = kIntType;
  140.             // convert to a string
  141.             prefValue = "" + prefBranch.getIntPref(prefArray[i]);
  142.                 break;
  143.             case nsIPrefBranch.PREF_BOOL:
  144.             prefType = kBoolType;
  145.             // convert to a string
  146.             if (prefBranch.getBoolPref(prefArray[i]))
  147.               prefValue = "true";
  148.             else
  149.               prefValue = "false";
  150.                 break;
  151.           case nsIPrefBranch.PREF_STRING:
  152.             default: 
  153.             prefType = kStrType;
  154.             prefValue = htmlEscape(prefBranch.getCharPref(prefArray[i]));
  155.                 break;
  156.         }
  157.  
  158.         prefArray[i] = htmlEscape(prefArray[i]);
  159.         baseArray[k] = {indexCol:prefIndex, prefCol:prefArray[i], lockCol:prefLockState, typeCol:prefType, valueCol:prefValue};
  160.     }
  161.  
  162.     view.rowCount = k + 1;
  163.  
  164.     gTree = document.getElementById("configTree");
  165.     gTree.treeBoxObject.view = view;
  166. }
  167.  
  168. function htmlEscape(s) 
  169.     s = s.replace(/\&/g, "&"); 
  170.     s = s.replace(/\>/g, ">"); 
  171.     s = s.replace(/\</g, "<"); 
  172.     return s; 
  173. }
  174.  
  175.  
  176. function ConfigOnClick(event)
  177. {
  178.     // we only care about button 0 (left click) events
  179.     if (event.button != 0) return;
  180.  
  181.     var t = event.originalTarget;
  182.  
  183.     if (t.localName == "treecol") {
  184.        HandleColumnClick(t.id);
  185.     }
  186. }
  187.  
  188. var gSortedColumn = "indexCol";
  189. var gSortAscending = true;
  190.  
  191. function stringSortFunction(a,b)
  192. {
  193.   var value;
  194.   if (a<b)
  195.     value = 1;
  196.   else if (a>b) 
  197.     value = -1;
  198.   else
  199.     value = 0;
  200.  
  201.   if (gSortAscending)
  202.     return value;
  203.   else
  204.     return (value * -1);
  205. }
  206.  
  207. function intSortFunction(a,b)
  208. {
  209.   if (gSortAscending) 
  210.     return (a - b);
  211.   else 
  212.     return (b - a);
  213. }
  214.  
  215. function indexColSortFunction(x,y)
  216. {
  217.   return intSortFunction(x.indexCol, y.indexCol);
  218. }
  219.  
  220. function prefColSortFunction(x,y)
  221. {
  222.   return stringSortFunction(x.prefCol, y.prefCol);
  223. }
  224.  
  225. function lockColSortFunction(x,y)
  226. {
  227.   return stringSortFunction(x.lockCol, y.lockCol);
  228. }
  229.  
  230. function typeColSortFunction(x,y)
  231. {
  232.   return intSortFunction(x.typeCol, y.typeCol);
  233. }
  234.  
  235. function valueColSortFunction(x,y)
  236. {
  237.   return stringSortFunction(x.valueCol, y.valueCol);
  238. }
  239.  
  240. var gSortFunctions = {indexCol:indexColSortFunction, 
  241.                  prefCol:prefColSortFunction, 
  242.                  lockCol:lockColSortFunction, 
  243.                  typeCol:typeColSortFunction, 
  244.                  valueCol:valueColSortFunction};
  245.  
  246. function HandleColumnClick(id)
  247. {
  248.   if (id == gSortedColumn) {
  249.     gSortAscending = !gSortAscending;
  250.     baseArray.reverse();
  251.   }
  252.   else {
  253.     baseArray.sort(gSortFunctions[id]);
  254.     gSortedColumn = id;
  255.   }
  256.  
  257.   gTree.treeBoxObject.invalidate();
  258. }
  259.  
  260.  
  261.  
  262.  
  263.