home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / browser.jar / content / browser / pref / pref-winhooks.js < prev    next >
Text File  |  2002-10-10  |  5KB  |  130 lines

  1.  
  2. // Turn this on to get debug output.
  3. const debug = 1;
  4. function debugDump( text ) {
  5.     if ( debug ) {
  6.         dump( text + "\n" );
  7.     }
  8. }
  9. function dumpObject( obj, name ) {
  10.     for ( prop in obj ) {
  11.         debugDump( name + "." + prop + "=" + obj[prop] );
  12.     }
  13. }
  14.  
  15. // Top-level windows integration preferences.
  16. if ( !( "winHooks" in parent ) ) {
  17.     parent.winHooks = new Object;
  18.     
  19.     parent.winHooks.settings = null;
  20.     parent.winHooks.winhooks = null;
  21.     parent.winHooks.prefs = null;
  22. }
  23.  
  24. // This function is called when the user presses Ok to close the prefs window.
  25. function onOK() {
  26.     try {
  27.         // Get updates from dialog if we're displayed.
  28.         if ( "GetFields" in window ) {
  29.             GetFields();
  30.         }
  31.         // Update prefs.
  32.         parent.winHooks.winhooks.settings = parent.winHooks.prefs;
  33.     }
  34.     catch(e) {
  35.         dump( e + "\n" );
  36.     }
  37. }
  38.  
  39. var gPrefService = null;
  40. var gPrefBranch = null;
  41.  
  42. // This function is called when our pref panel is loaded.
  43. function Startup() {
  44.  
  45.     const prefbase = "system.windows.lock_ui.";
  46.  
  47.     // initialise preference component.
  48.     // While the data is coming from the system registry, we use a set
  49.     // of parallel preferences to indicate if the ui should be locked.
  50.     if (!gPrefService) {
  51.         gPrefService = Components.classes["@mozilla.org/preferences-service;1"];
  52.         gPrefService = gPrefService.getService();
  53.         gPrefService = gPrefService.QueryInterface(Components.interfaces.nsIPrefService);
  54.         gPrefBranch = gPrefService.getBranch(prefbase);
  55.     }
  56.  
  57.  
  58.     // Get globals.
  59.     var settings = parent.winHooks.settings;
  60.     var winhooks = parent.winHooks.winhooks;
  61.     var prefs    = parent.winHooks.prefs;
  62.     if ( !winhooks ) {
  63.         // Get component service.
  64.         try {
  65.             winhooks = Components.classes[ "@mozilla.org/winhooks;1" ].getService( Components.interfaces.nsIWindowsHooks );
  66.             if ( winhooks ) {
  67.                 // Try to get preferences.
  68.                 prefs = winhooks.settings;
  69.                 // Set globals.
  70.                 parent.winHooks.winhooks = winhooks;
  71.                 parent.winHooks.prefs    = prefs;
  72.             }
  73.         }
  74.         catch(e) {
  75.             dump( e + "\n" );
  76.         }
  77.     }         
  78.     if ( !settings ) {
  79.         // Set state specific to this panel (not shared with the "default browser"
  80.         // button state from the Navigator panel).
  81.         settings = parent.winHooks.settings = [ "isHandlingHTML",
  82.                                                 "isHandlingJPEG",
  83.                                                 "isHandlingGIF",
  84.                                                 "isHandlingPNG",
  85.                                                 "isHandlingMNG",
  86.                                                 "isHandlingXBM",
  87.                                                 "isHandlingBMP",
  88.                                                 "isHandlingICO",
  89.                                                 "isHandlingXML",
  90.                                                 "isHandlingXHTML",
  91.                                                 "isHandlingXUL",
  92.                                                 "isHandlingHTTP",
  93.                                                 "isHandlingHTTPS",
  94.                                                 "isHandlingFTP",
  95.                                                 "isHandlingCHROME",
  96.                                                 "isHandlingGOPHER",
  97.                                                 "showDialog" ];
  98.         // Register so we get called when pref window Ok is pressed.
  99.         parent.hPrefWindow.registerOKCallbackFunc( onOK );
  100.     }
  101.     // Transfer object settings to the dialog checkboxes.
  102.     for( var index in settings  ) {
  103.         var setting = settings[ index ];
  104.         var checkbox = document.getElementById( setting );
  105.         if ( checkbox && prefs[ setting ] ) {
  106.             checkbox.setAttribute( "checked", "true" );
  107.         }
  108.  
  109.         // disable the xul element if the appropriate pref is locked.
  110.         if (gPrefBranch && gPrefBranch.prefIsLocked(setting)) {
  111.             checkbox.disabled = true;
  112.         }
  113.     }
  114. }
  115.  
  116. function GetFields() {
  117.     // Get globals.
  118.     var settings = parent.winHooks.settings;
  119.     var winhooks = parent.winHooks.winhooks;
  120.     var prefs    = parent.winHooks.prefs;
  121.     // Transfer data from dialog to prefs object.
  122.     for( var index in settings ) {
  123.         var setting = settings[ index ];
  124.         var checkbox = document.getElementById( setting );
  125.         if ( checkbox ) {
  126.             prefs[ setting ] = checkbox.checked;
  127.         }
  128.     }
  129. }
  130.