home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / messenger.jar / content / messenger / mailWindow.js < prev    next >
Text File  |  2001-02-14  |  11KB  |  340 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.  
  21.  //This file stores variables common to mail windows
  22. var messengerContractID        = "@mozilla.org/messenger;1";
  23. var statusFeedbackContractID   = "@mozilla.org/messenger/statusfeedback;1";
  24. var messageViewContractID      = "@mozilla.org/messenger/messageview;1";
  25. var mailSessionContractID      = "@mozilla.org/messenger/services/session;1";
  26.  
  27. var prefContractID             = "@mozilla.org/preferences;1";
  28. var msgWindowContractID           = "@mozilla.org/messenger/msgwindow;1";
  29.  
  30. var messenger;
  31. var pref;
  32. var statusFeedback;
  33. var messageView;
  34. var msgWindow;
  35.  
  36. var msgComposeService;
  37. var accountManager;
  38. var RDF;
  39. var msgComposeType;
  40. var msgComposeFormat;
  41.  
  42. var mailSession;
  43.  
  44. var Bundle;
  45. var BrandBundle;
  46.  
  47. var datasourceContractIDPrefix = "@mozilla.org/rdf/datasource;1?name=";
  48. var accountManagerDSContractID = datasourceContractIDPrefix + "msgaccountmanager";
  49. var folderDSContractID         = datasourceContractIDPrefix + "mailnewsfolders";
  50. var messageDSContractID        = datasourceContractIDPrefix + "mailnewsmessages";
  51.  
  52. var accountManagerDataSource;
  53. var folderDataSource;
  54. var messageDataSource;
  55.  
  56. //Progress and Status variables
  57. var gStatusText;
  58. var gStatusBar;
  59. var gThrobber;
  60. var gStopMenu;
  61. var gStopButton;
  62. var bindCount = 0;
  63. var startTime = 0;
  64. //End progress and Status variables
  65.  
  66. function OnMailWindowUnload()
  67. {
  68.     dump("we get here\n");
  69.     var mailSession = Components.classes[mailSessionContractID].getService();
  70.     if(mailSession)
  71.     {
  72.         mailSession = mailSession.QueryInterface(Components.interfaces.nsIMsgMailSession);
  73.         if(mailSession)
  74.         {
  75.             mailSession.RemoveFolderListener(folderListener);
  76.         }
  77.     }
  78.  
  79.     mailSession.RemoveMsgWindow(msgWindow);
  80.     messenger.SetWindow(null, null);
  81.  
  82.     var msgDS = folderDataSource.QueryInterface(Components.interfaces.nsIMsgRDFDataSource);
  83.     msgDS.window = null;
  84.  
  85.     msgDS = messageDataSource.QueryInterface(Components.interfaces.nsIMsgRDFDataSource);
  86.     msgDS.window = null;
  87.  
  88.     msgDS = accountManagerDataSource.QueryInterface(Components.interfaces.nsIMsgRDFDataSource);
  89.     msgDS.window = null;
  90.  
  91.  
  92.       msgWindow.closeWindow();
  93.  
  94. }
  95.  
  96. function CreateMailWindowGlobals()
  97. {
  98.     // get the messenger instance
  99.     messenger = Components.classes[messengerContractID].createInstance();
  100.     messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
  101.  
  102.     pref = Components.classes[prefContractID].getService(Components.interfaces.nsIPref);
  103.  
  104.     //Create windows status feedback
  105.   // set the JS implementation of status feedback before creating the c++ one..
  106.   window.MsgStatusFeedback = new nsMsgStatusFeedback();
  107.     statusFeedback           = Components.classes[statusFeedbackContractID].createInstance();
  108.     statusFeedback = statusFeedback.QueryInterface(Components.interfaces.nsIMsgStatusFeedback);
  109.  
  110.     window.MsgWindowCommands = new nsMsgWindowCommands();
  111.     //Create message view object
  112.     messageView = Components.classes[messageViewContractID].createInstance();
  113.     messageView = messageView.QueryInterface(Components.interfaces.nsIMessageView);
  114.  
  115.     //Create message window object
  116.     msgWindow = Components.classes[msgWindowContractID].createInstance();
  117.     msgWindow = msgWindow.QueryInterface(Components.interfaces.nsIMsgWindow);
  118.  
  119.     msgComposeService = Components.classes['@mozilla.org/messengercompose;1'].getService();
  120.     msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService);
  121.  
  122.     mailSession = Components.classes["@mozilla.org/messenger/services/session;1"].getService(Components.interfaces.nsIMsgMailSession); 
  123.  
  124.     accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
  125.  
  126.     RDF = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService();
  127.     RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
  128.  
  129.     msgComposeType = Components.interfaces.nsIMsgCompType;
  130.     msgComposeFormat = Components.interfaces.nsIMsgCompFormat;
  131.  
  132.     Bundle = srGetStrBundle("chrome://messenger/locale/messenger.properties");
  133.   BrandBundle = srGetStrBundle("chrome://global/locale/brand.properties");
  134.  
  135.     //Create datasources
  136.     accountManagerDataSource = Components.classes[accountManagerDSContractID].createInstance();
  137.     folderDataSource         = Components.classes[folderDSContractID].createInstance();
  138.     messageDataSource        = Components.classes[messageDSContractID].createInstance();
  139.  
  140. }
  141.  
  142. function InitMsgWindow()
  143. {
  144.     msgWindow.statusFeedback = statusFeedback;
  145.     msgWindow.messageView = messageView;
  146.     msgWindow.msgHeaderSink = messageHeaderSink;
  147.     msgWindow.SetDOMWindow(window);
  148.     mailSession.AddMsgWindow(msgWindow);
  149.  
  150. }
  151.  
  152. function AddDataSources()
  153. {
  154.  
  155.     accountManagerDataSource = accountManagerDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource);
  156.     folderDataSource = folderDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource);
  157.     //to move menu item
  158.     SetupMoveCopyMenus('moveMenu', accountManagerDataSource, folderDataSource);
  159.  
  160.     //to copy menu item
  161.     SetupMoveCopyMenus('copyMenu', accountManagerDataSource, folderDataSource);
  162.  
  163.  
  164.     //To FileButton menu
  165.     SetupMoveCopyMenus('FileButtonMenu', accountManagerDataSource, folderDataSource);
  166.  
  167.     //To move and copy menus in message pane context
  168.     SetupMoveCopyMenus("messagePaneContext-copyMenu", accountManagerDataSource, folderDataSource);
  169.     SetupMoveCopyMenus("messagePaneContext-moveMenu", accountManagerDataSource, folderDataSource);
  170.  
  171.     //Add statusFeedback
  172.  
  173.     var msgDS = folderDataSource.QueryInterface(Components.interfaces.nsIMsgRDFDataSource);
  174.     msgDS.window = msgWindow;
  175.  
  176.     msgDS = messageDataSource.QueryInterface(Components.interfaces.nsIMsgRDFDataSource);
  177.     msgDS.window = msgWindow;
  178.  
  179.     msgDS = accountManagerDataSource.QueryInterface(Components.interfaces.nsIMsgRDFDataSource);
  180.     msgDS.window = msgWindow;
  181.  
  182. }    
  183.  
  184. function SetupMoveCopyMenus(menuid, accountManagerDataSource, folderDataSource)
  185. {
  186.     var menu = document.getElementById(menuid);
  187.     if(menu)
  188.     {
  189.         menu.database.AddDataSource(accountManagerDataSource);
  190.         menu.database.AddDataSource(folderDataSource);
  191.         menu.setAttribute('ref', 'msgaccounts:/');
  192.     }
  193. }
  194. function dumpProgress() {
  195.     var broadcaster = document.getElementById("Messenger:LoadingProgress");
  196.  
  197.     dump( "bindCount=" + bindCount + "\n" );
  198.     dump( "broadcaster mode=" + broadcaster.getAttribute("mode") + "\n" );
  199.     dump( "broadcaster value=" + broadcaster.getAttribute("value") + "\n" );
  200.     dump( "meter mode=" + meter.getAttribute("mode") + "\n" );
  201.     dump( "meter value=" + meter.getAttribute("value") + "\n" );
  202. }
  203.  
  204. // We're going to implement our status feedback for the mail window in JS now.
  205. // the following contains the implementation of our status feedback object
  206.  
  207. function nsMsgStatusFeedback()
  208. {
  209. }
  210.  
  211. nsMsgStatusFeedback.prototype = 
  212. {
  213.     QueryInterface : function(iid)
  214.         {
  215.         if(iid.equals(Components.interfaces.nsIMsgStatusFeedback))
  216.             return this;
  217.         throw Components.results.NS_NOINTERFACE;
  218.         return null;
  219.         },
  220.     ShowStatusString : function(statusText)
  221.         {
  222.        if (!gStatusText ) gStatusText = document.getElementById("statusText");
  223.        if ( statusText == "" )
  224.           statusText = defaultStatus;
  225.        gStatusText.value = statusText;
  226.         },
  227.     StartMeteors : function()
  228.         {
  229.       if (!gStatusBar) gStatusBar = document.getElementById("statusbar-icon");
  230.       if(!gThrobber) gThrobber = document.getElementById("navigator-throbber");
  231.       if(!gStopButton) gStopButton = document.getElementById("button-stop");
  232.       if(!gStopMenu) gStopMenu = document.getElementById("stopMenuitem");
  233.  
  234.       // Turn progress meter on.
  235.       gStatusBar.setAttribute("mode","undetermined");
  236.       
  237.       // turn throbber on 
  238.       gThrobber.setAttribute("busy", true);
  239.  
  240.       //turn on stop button and menu
  241.       gStopButton.setAttribute("disabled", false);
  242.       gStopMenu.setAttribute("disabled", false);
  243.       
  244.       // Remember when loading commenced.
  245.         startTime = (new Date()).getTime();
  246.         },
  247.     StopMeteors : function()
  248.         {
  249.             dump("stopping meteors 1\n");
  250.             if (!gStatusBar)
  251.                 gStatusBar = document.getElementById("statusbar-icon");
  252.             if(!gThrobber)
  253.                 gThrobber = document.getElementById("navigator-throbber");
  254.             if(!gStopButton) gStopButton = document.getElementById("button-stop");
  255.             if(!gStopMenu) gStopMenu = document.getElementById("stopMenuitem");
  256.  
  257.             // Record page loading time.
  258.             var elapsed = ( (new Date()).getTime() - startTime ) / 1000;
  259.             var msg = Bundle.GetStringFromName("documentDonePrefix") +
  260.                 elapsed + Bundle.GetStringFromName("documentDonePostfix");
  261.             dump( msg + "\n" );
  262.       window.MsgStatusFeedback.ShowStatusString(msg);
  263.       defaultStatus = msg;
  264.  
  265.       gThrobber.setAttribute("busy", false);
  266.       dump("stopping meteors\n");
  267.       // Turn progress meter off.
  268.       gStatusBar.setAttribute("mode","normal");
  269.       gStatusBar.value = 0;  // be sure to clear the progress bar
  270.       gStatusBar.progresstext = "";
  271.       gStopButton.setAttribute("disabled", true);
  272.       gStopMenu.setAttribute("disabled", true);
  273.  
  274.         },
  275.     ShowProgress : function(percentage)
  276.         {
  277.       if (!gStatusBar) gStatusBar = document.getElementById("statusbar-icon");
  278.       if (percentage >= 0)
  279.       {
  280.         gStatusBar.setAttribute("mode", "normal");
  281.         gStatusBar.value = percentage; 
  282.         gStatusBar.progresstext = Math.round(percentage) + "%";
  283.       }
  284.         },
  285.     closeWindow : function(percent)
  286.         {
  287.         }
  288. }
  289.  
  290.  
  291. function nsMsgWindowCommands()
  292. {
  293. }
  294.  
  295. nsMsgWindowCommands.prototype = 
  296. {
  297.     QueryInterface : function(iid)
  298.     {
  299.         if(iid.equals(Components.interfaces.nsIMsgWindowCommands))
  300.             return this;
  301.         throw Components.results.NS_NOINTERFACE;
  302.         return null;
  303.     },
  304.     SelectFolder: function(folderUri)
  305.     {
  306.  
  307.         SelectFolder(folderUri);
  308.  
  309.     },
  310.     SelectMessage: function(messageUri)
  311.     {
  312.         SelectMessage(messageUri);
  313.     }
  314. }
  315.  
  316. function StopUrls()
  317. {
  318.     msgWindow.StopUrls();
  319. }
  320.  
  321. function loadStartPage() {
  322.     try {
  323.         var startpageenabled= pref.GetBoolPref("mailnews.start_page.enabled");
  324.         
  325.         if (startpageenabled) {
  326.             var startpage = pref.getLocalizedUnicharPref("mailnews.start_page.url");
  327.             if (startpage != "") {
  328.                 window.frames["messagepane"].location = startpage;
  329.                 dump("start message pane with: " + startpage + "\n");
  330.                 ClearMessageSelection();
  331.             }
  332.         }
  333.     }
  334.     catch (ex) {
  335.         dump("Error loading start page.\n");
  336.         return;
  337.     }
  338. }
  339.  
  340.