home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Complet / thunderbird / chrome / mail.jar / content / messenger-mapi / pref-mailnewsOverlay.js < prev    next >
Encoding:
JavaScript  |  2003-12-18  |  5.2 KB  |  142 lines

  1. /* 
  2.  * The contents of this file are subject to the Mozilla 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/MPL/
  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.org code.
  13.  * 
  14.  * The Initial Developer of the Original Code is Netscape
  15.  * Communications Corporation.  Portions created by Netscape are 
  16.  * Copyright (C) 2001 Netscape Communications Corporation.  All
  17.  * Rights Reserved.
  18.  * 
  19.  * Contributor(s): 
  20.  * Srilatha Moturi <srilatha@netscape.com>
  21.  * Rajiv Dayal <rdayal@netscape.com>
  22.  */
  23.  
  24. function mailnewsOverlayStartup() {
  25.     mailnewsOverlayInit();
  26.     if (!("mapiPref" in parent)) {
  27.         parent.mapiPref = new Object;
  28.         parent.mapiPref.isDefaultMailClient = 
  29.                document.getElementById("mailnewsEnableMapi").checked;
  30.         
  31.         var mailnewsEnableNews = document.getElementById("mailnewsEnableNews"); 
  32.         if (mailnewsEnableNews)
  33.           parent.mapiPref.isDefaultNewsClient = mailnewsEnableNews.checked;
  34.     }
  35.     else { 
  36.         // when we switch between different panes
  37.         // set the checkbox based on the saved state
  38.         var mailnewsEnableMapi = document.getElementById("mailnewsEnableMapi");
  39.         var mailnewsEnableNews = document.getElementById("mailnewsEnableNews"); 
  40.         
  41.         if (parent.mapiPref.isDefaultMailClient)
  42.             mailnewsEnableMapi.setAttribute("checked", "true");
  43.         else
  44.             mailnewsEnableMapi.setAttribute("checked", "false");
  45.         
  46.         if (mailnewsEnableNews)
  47.         {
  48.           if (parent.mapiPref.isDefaultNewsClient)
  49.              mailnewsEnableNews.setAttribute("checked", "true");
  50.           else
  51.              mailnewsEnableNews.setAttribute("checked", "false");
  52.         }
  53.     }
  54. }
  55.  
  56. function registerCallback(){
  57.     if ("mapiCallback" in parent && parent.mapiCallback)
  58.         return;
  59.     if ("hPrefWindow" in parent && parent.hPrefWindow) {
  60.         parent.hPrefWindow.registerOKCallbackFunc( onOK );
  61.         parent.mapiCallback = true;
  62.     }
  63. }
  64.  
  65. function mailnewsOverlayInit() {
  66.     try {
  67.         var mapiRegistry = Components.classes[ "@mozilla.org/mapiregistry;1" ].
  68.                    getService( Components.interfaces.nsIMapiRegistry );
  69.     }
  70.     catch(ex){
  71.         mapiRegistry = null;
  72.     }
  73.  
  74.     const prefbase = "system.windows.lock_ui.";
  75.     var mailnewsEnableMapi = document.getElementById("mailnewsEnableMapi");
  76.     var mailnewsEnableNews = document.getElementById("mailnewsEnableNews");
  77.     
  78.     if (mapiRegistry) {
  79.     // initialise preference component.
  80.     // While the data is coming from the system registry, we use a set
  81.     // of parallel preferences to indicate if the ui should be locked.
  82.         try { 
  83.             var prefService = Components.classes["@mozilla.org/preferences-service;1"]
  84.                           .getService()
  85.                           .QueryInterface(Components.interfaces.nsIPrefService);
  86.             var prefBranch = prefService.getBranch(prefbase);
  87.             if (prefBranch && prefBranch.prefIsLocked("defaultMailClient")) {
  88.                 mapiRegistry.isDefaultMailClient = prefBranch.getBoolPref("defaultMailClient") ;
  89.                 mailnewsEnableMapi.setAttribute("disabled", "true");
  90.            }
  91.         }
  92.         catch(ex) {}
  93.  
  94.         mailnewsEnableMapi.setAttribute("checked", mapiRegistry.isDefaultMailClient ? "true" : "false");
  95.         if (mailnewsEnableNews)
  96.           mailnewsEnableNews.setAttribute("checked", mapiRegistry.isDefaultNewsClient ? "true" : "false");
  97.     }
  98.     else
  99.     {
  100.         mailnewsEnableMapi.setAttribute("disabled", "true");
  101.         if (mailnewsEnableNews)
  102.           mailnewsEnableNews.setAttribute("disabled", "true");
  103.     }
  104. }
  105.  
  106. function onEnableMapi() {
  107.     // save the state of the checkbox
  108.     if ("mapiPref" in parent)
  109.         parent.mapiPref.isDefaultMailClient = 
  110.                document.getElementById("mailnewsEnableMapi").checked;
  111. }
  112.  
  113. function onEnableNews() {
  114.     // save the state of the checkbox
  115.     if ("mapiPref" in parent)
  116.         parent.mapiPref.isDefaultNewsClient = document.getElementById("mailnewsEnableNews").checked;
  117. }
  118.  
  119. function onOK()
  120. {
  121.     try {
  122.         var mapiRegistry = Components.classes[ "@mozilla.org/mapiregistry;1" ].getService( Components.interfaces.nsIMapiRegistry );
  123.     }
  124.     catch(ex){
  125.         mapiRegistry = null;
  126.     } 
  127.  
  128.     if (mapiRegistry && ("mapiPref" in parent)) {
  129.       if (mapiRegistry.isDefaultMailClient != parent.mapiPref.isDefaultMailClient)
  130.         mapiRegistry.isDefaultMailClient = parent.mapiPref.isDefaultMailClient ;
  131.       
  132.       if ("isDefaultNewsClient" in parent.mapiPref)
  133.       {
  134.         if (mapiRegistry.isDefaultNewsClient != parent.mapiPref.isDefaultNewsClient)
  135.           mapiRegistry.isDefaultNewsClient = parent.mapiPref.isDefaultNewsClient;
  136.       }
  137.     }
  138. }
  139.  
  140. // Install the onload handler
  141. addEventListener("load", mailnewsOverlayStartup, false);
  142.