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-themes.js < prev    next >
Text File  |  2003-06-08  |  9KB  |  253 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Mozilla.org Code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Doron Rosenberg.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Ben Goodger <ben@netscape.com> (Original Author)
  23.  *   Blake Ross <blaker@netscape.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39.  
  40. var gShowDescription = true;
  41. var gData;
  42.  
  43. try {
  44.   var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService();
  45.   if (chromeRegistry)
  46.     chromeRegistry = chromeRegistry.QueryInterface(Components.interfaces.nsIXULChromeRegistry);
  47. }
  48. catch(e) {}
  49.  
  50. function Startup()
  51. {
  52.   gData = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-themes.xul"];
  53.   var list = document.getElementById( "skinsList" );
  54.   if ("loaded" in gData && "themeIndex" in gData) {
  55.     list.selectedIndex = gData.themeIndex;    
  56.     return;
  57.   }
  58.   gData.loaded = true;
  59.   parent.hPrefWindow.registerOKCallbackFunc( applySkin );
  60.  
  61.   const kPrefSvcContractID = "@mozilla.org/preferences;1";
  62.   const kPrefSvcIID = Components.interfaces.nsIPref;
  63.   const kPrefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
  64.  
  65.   var theme = null;
  66.   try {
  67.     theme = kPrefSvc.getComplexValue("general.skins.selectedSkin",
  68.                                      Components.interfaces.nsISupportsString).data;
  69.   } catch (e) {
  70.   }
  71.   var matches;
  72.   for (var i = 0; i < list.childNodes.length; ++i) {
  73.     var child = list.childNodes[i];
  74.     var name = child.getAttribute("name");
  75.     if (!theme)
  76.       matches = chromeRegistry.isSkinSelected(name, true) == Components.interfaces.nsIChromeRegistry.FULL;
  77.     else
  78.       matches = name == theme;
  79.     if (matches) {
  80.       list.selectItem(child);
  81.       break;
  82.     }      
  83.   }
  84.  
  85.   var navbundle = document.getElementById("bundle_navigator");
  86.   var showSkinsDescription = navbundle.getString("showskinsdescription");
  87.   if( showSkinsDescription == "false" )
  88.   {
  89.     gShowDescription = false;
  90.     var description = document.getElementById("description");
  91.     while (description.hasChildNodes())
  92.       description.removeChild(description.firstChild);
  93.   }
  94. }
  95.  
  96. function applySkin()
  97. {
  98.   var data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-themes.xul"];
  99.   if (data.name == null)
  100.     return;
  101.  
  102.   const kPrefSvcContractID = "@mozilla.org/preferences;1";
  103.   const kPrefSvcIID = Components.interfaces.nsIPref;
  104.   const kPrefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
  105.  
  106.   var theme = null;
  107.   try {
  108.     theme = kPrefSvc.getComplexValue("general.skins.selectedSkin",
  109.                                      Components.interfaces.nsISupportsString).data;
  110.   } catch (e) {
  111.   }
  112.  
  113.   if (theme == data.name) return;
  114.  
  115.   try {
  116.     var reg = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService();
  117.     if (reg)
  118.       reg = reg.QueryInterface(Components.interfaces.nsIXULChromeRegistry);
  119.   }
  120.   catch(e) {}
  121.  
  122.   var inUse = reg.isSkinSelected(data.name, true);
  123.   if (!theme && inUse == Components.interfaces.nsIChromeRegistry.FULL) return;
  124.  
  125.   var str = Components.classes["@mozilla.org/supports-string;1"]
  126.                       .createInstance(Components.interfaces.nsISupportsString);
  127.   str.data = data.name;
  128.  
  129.   kPrefSvc.setComplexValue("general.skins.selectedSkin", Components.interfaces.nsISupportsString, str);
  130.  
  131.   // shut down quicklaunch so the next launch will have the new skin
  132.   var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService();
  133.   appShell = appShell.QueryInterface(Components.interfaces.nsIAppShellService);
  134.   try {
  135.     appShell.nativeAppSupport.isServerMode = false;
  136.   }
  137.   catch(ex) {
  138.   }
  139.  
  140.   var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  141.  
  142.   var strBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(); 
  143.   strBundleService = strBundleService.QueryInterface(Components.interfaces.nsIStringBundleService);
  144.   var navbundle = strBundleService.createBundle("chrome://navigator/locale/navigator.properties"); 
  145.   var brandbundle = strBundleService.createBundle("chrome://global/locale/brand.properties");
  146.   
  147.   if (promptService && navbundle && brandbundle) {                                                          
  148.     var dialogTitle = navbundle.GetStringFromName("switchskinstitle");          
  149.     var brandName = brandbundle.GetStringFromName("brandShortName");            
  150.     var msg = navbundle.formatStringFromName("switchskins", [brandName], 1);                                
  151.     promptService.alert(window, dialogTitle, msg); 
  152.   }
  153. }
  154.  
  155. function uninstallSkin()
  156. {
  157.   var list = document.getElementById("skinsList");
  158.   var selectedSkinItem = list.selectedItems[0];
  159.   var skinName = selectedSkinItem.getAttribute("name");
  160.   var inUse = chromeRegistry.isSkinSelected(skinName, true);
  161.   chromeRegistry.uninstallSkin(skinName, true);
  162.   if (inUse)
  163.     chromeRegistry.refreshSkins();
  164.   list.selectedIndex = 0;
  165. }
  166.  
  167. function themeSelect()
  168. {
  169.   var list = document.getElementById("skinsList");
  170.  
  171.   if (!list)
  172.     return;
  173.  
  174.   var prefbundle = document.getElementById("bundle_prefutilities");
  175.  
  176.   var selectedItem = list.selectedItems.length ? list.selectedItems[0] : null;
  177.   if (selectedItem && selectedItem.getAttribute("skin") == "true") {
  178.     var themeName = selectedItem.getAttribute("displayName");
  179.     var skinName = selectedItem.getAttribute("name");
  180.     gData.name = skinName;
  181.     gData.themeIndex = list.selectedIndex;
  182.  
  183.     var oldTheme;
  184.     try {
  185.       oldTheme = !chromeRegistry.checkThemeVersion(skinName);
  186.     }
  187.     catch(e) {
  188.       oldTheme = false;
  189.     }
  190.  
  191.     var nameField = document.getElementById("displayName");
  192.     var author = document.getElementById("author");
  193.     var image = document.getElementById("previewImage");
  194.     var descText = document.createTextNode(selectedItem.getAttribute("description"));
  195.     var description = document.getElementById("description");
  196.     var uninstallButton = document.getElementById("uninstallSkin");
  197.     var uninstallLabel = prefbundle.getString("uninstallThemePrefix");
  198.  
  199.     while (description.hasChildNodes())
  200.       description.removeChild(description.firstChild);
  201.  
  202.     nameField.setAttribute("value", themeName);
  203.     author.setAttribute("value", selectedItem.getAttribute("author"));
  204.     image.setAttribute("src", selectedItem.getAttribute("image"));
  205.  
  206.     // XXX - this sucks and should only be temporary.
  207.     var selectedSkin = "";
  208.     try {
  209.       const kPrefSvcContractID = "@mozilla.org/preferences;1";
  210.       const kPrefSvcIID = Components.interfaces.nsIPref;
  211.       const kPrefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
  212.       selectedSkin = kPrefSvc.CopyCharPref("general.skins.selectedSkin");
  213.     }
  214.     catch (e) {
  215.     }
  216.     if (!oldTheme) {    
  217.       if( gShowDescription ) 
  218.         description.appendChild(descText);
  219.  
  220.       var locType = selectedItem.getAttribute("loctype");
  221.       uninstallButton.disabled = (selectedSkin == skinName) || (locType == "install");
  222.       
  223.       uninstallLabel = uninstallLabel.replace(/%theme_name%/, themeName);
  224.       uninstallButton.label = uninstallLabel;
  225.     }
  226.     else {
  227.       var brandbundle = document.getElementById("bundle_brand");
  228.  
  229.       uninstallLabel = uninstallLabel.replace(/%theme_name%/, themeName);
  230.       uninstallButton.label = uninstallLabel;
  231.  
  232.       uninstallButton.disabled = selectedSkin == skinName;
  233.  
  234.       var newText = prefbundle.getString("oldTheme");
  235.       newText = newText.replace(/%theme_name%/, themeName);
  236.       
  237.       newText = newText.replace(/%brand%/g, brandbundle.getString("brandShortName"));
  238.  
  239.       if( gShowDescription )  {
  240.         descText = document.createTextNode(newText);
  241.         description.appendChild(descText);
  242.       }
  243.     }
  244.   }
  245.   else {
  246.     uninstallButton.disabled = true;
  247.     gData.name = null;
  248.   }
  249. }
  250.  
  251.  
  252.  
  253.