home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / communicator / pref / pref-winhooks.js < prev    next >
Text File  |  2003-06-08  |  5KB  |  151 lines

  1. /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; -*-
  2.  * 
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  *
  18.  * Contributor(s):
  19.  *  Bill Law       <law@netscape.com>
  20.  *  Aaron Kaluszka <ask@swva.net>
  21.  */
  22.  
  23. // Turn this on to get debug output.
  24. const debug = 1;
  25. function debugDump( text ) {
  26.     if ( debug ) {
  27.         dump( text + "\n" );
  28.     }
  29. }
  30. function dumpObject( obj, name ) {
  31.     for ( prop in obj ) {
  32.         debugDump( name + "." + prop + "=" + obj[prop] );
  33.     }
  34. }
  35.  
  36. // Top-level windows integration preferences.
  37. if ( !( "winHooks" in parent ) ) {
  38.     parent.winHooks = new Object;
  39.     
  40.     parent.winHooks.settings = null;
  41.     parent.winHooks.winhooks = null;
  42.     parent.winHooks.prefs = null;
  43. }
  44.  
  45. // This function is called when the user presses Ok to close the prefs window.
  46. function onOK() {
  47.     try {
  48.         // Get updates from dialog if we're displayed.
  49.         if ( "GetFields" in window ) {
  50.             GetFields();
  51.         }
  52.         // Update prefs.
  53.         parent.winHooks.winhooks.settings = parent.winHooks.prefs;
  54.     }
  55.     catch(e) {
  56.         dump( e + "\n" );
  57.     }
  58. }
  59.  
  60. var gPrefService = null;
  61. var gPrefBranch = null;
  62.  
  63. // This function is called when our pref panel is loaded.
  64. function Startup() {
  65.  
  66.     const prefbase = "system.windows.lock_ui.";
  67.  
  68.     // initialise preference component.
  69.     // While the data is coming from the system registry, we use a set
  70.     // of parallel preferences to indicate if the ui should be locked.
  71.     if (!gPrefService) {
  72.         gPrefService = Components.classes["@mozilla.org/preferences-service;1"];
  73.         gPrefService = gPrefService.getService();
  74.         gPrefService = gPrefService.QueryInterface(Components.interfaces.nsIPrefService);
  75.         gPrefBranch = gPrefService.getBranch(prefbase);
  76.     }
  77.  
  78.  
  79.     // Get globals.
  80.     var settings = parent.winHooks.settings;
  81.     var winhooks = parent.winHooks.winhooks;
  82.     var prefs    = parent.winHooks.prefs;
  83.     if ( !winhooks ) {
  84.         // Get component service.
  85.         try {
  86.             winhooks = Components.classes[ "@mozilla.org/winhooks;1" ].getService( Components.interfaces.nsIWindowsHooks );
  87.             if ( winhooks ) {
  88.                 // Try to get preferences.
  89.                 prefs = winhooks.settings;
  90.                 // Set globals.
  91.                 parent.winHooks.winhooks = winhooks;
  92.                 parent.winHooks.prefs    = prefs;
  93.             }
  94.         }
  95.         catch(e) {
  96.             dump( e + "\n" );
  97.         }
  98.     }         
  99.     if ( !settings ) {
  100.         // Set state specific to this panel (not shared with the "default browser"
  101.         // button state from the Navigator panel).
  102.         settings = parent.winHooks.settings = [ "isHandlingHTML",
  103.                                                 "isHandlingJPEG",
  104.                                                 "isHandlingGIF",
  105.                                                 "isHandlingPNG",
  106.                                                 "isHandlingMNG",
  107.                                                 "isHandlingXBM",
  108.                                                 "isHandlingBMP",
  109.                                                 "isHandlingICO",
  110.                                                 "isHandlingXML",
  111.                                                 "isHandlingXHTML",
  112.                                                 "isHandlingXUL",
  113.                                                 "isHandlingHTTP",
  114.                                                 "isHandlingHTTPS",
  115.                                                 "isHandlingFTP",
  116.                                                 "isHandlingCHROME",
  117.                                                 "isHandlingGOPHER",
  118.                                                 "showDialog" ];
  119.         // Register so we get called when pref window Ok is pressed.
  120.         parent.hPrefWindow.registerOKCallbackFunc( onOK );
  121.     }
  122.     // Transfer object settings to the dialog checkboxes.
  123.     for( var index in settings  ) {
  124.         var setting = settings[ index ];
  125.         var checkbox = document.getElementById( setting );
  126.         if ( checkbox && prefs[ setting ] ) {
  127.             checkbox.setAttribute( "checked", "true" );
  128.         }
  129.  
  130.         // disable the xul element if the appropriate pref is locked.
  131.         if (gPrefBranch && gPrefBranch.prefIsLocked(setting)) {
  132.             checkbox.disabled = true;
  133.         }
  134.     }
  135. }
  136.  
  137. function GetFields() {
  138.     // Get globals.
  139.     var settings = parent.winHooks.settings;
  140.     var winhooks = parent.winHooks.winhooks;
  141.     var prefs    = parent.winHooks.prefs;
  142.     // Transfer data from dialog to prefs object.
  143.     for( var index in settings ) {
  144.         var setting = settings[ index ];
  145.         var checkbox = document.getElementById( setting );
  146.         if ( checkbox ) {
  147.             prefs[ setting ] = checkbox.checked;
  148.         }
  149.     }
  150. }
  151.