1999-09-01 23:49:47 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This is where functions related to the 3 pane window are kept */
|
|
|
|
|
|
|
|
/* globals for a particular window */
|
1999-09-15 05:16:29 +00:00
|
|
|
var messengerProgID = "component://netscape/messenger";
|
|
|
|
var statusFeedbackProgID = "component://netscape/messenger/statusfeedback";
|
|
|
|
var messageViewProgID = "component://netscape/messenger/messageview";
|
|
|
|
var mailSessionProgID = "component://netscape/messenger/services/session";
|
|
|
|
var prefProgID = "component://netscape/preferences";
|
|
|
|
|
|
|
|
var datasourceProgIDPrefix = "component://netscape/rdf/datasource?name=";
|
|
|
|
var accountManagerDSProgID = datasourceProgIDPrefix + "msgaccountmanager";
|
|
|
|
var folderDSProgID = datasourceProgIDPrefix + "mailnewsfolders";
|
|
|
|
var messageDSProgID = datasourceProgIDPrefix + "mailnewsmessages";
|
|
|
|
|
1999-09-15 08:29:01 +00:00
|
|
|
var gFolderTree;
|
1999-09-15 08:39:28 +00:00
|
|
|
var gThreadTree;
|
1999-09-21 21:04:52 +00:00
|
|
|
var gCurrentLoadingFolderURI
|
1999-09-15 08:29:01 +00:00
|
|
|
|
|
|
|
// get the messenger instance
|
1999-09-15 05:16:29 +00:00
|
|
|
var messenger = Components.classes[messengerProgID].createInstance();
|
1999-09-01 23:49:47 +00:00
|
|
|
messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
|
|
|
|
|
|
|
|
//Create datasources
|
1999-09-15 05:16:29 +00:00
|
|
|
var accountManagerDataSource = Components.classes[accountManagerDSProgID].createInstance();
|
|
|
|
var folderDataSource = Components.classes[folderDSProgID].createInstance();
|
|
|
|
var messageDataSource = Components.classes[messageDSProgID].createInstance();
|
1999-09-01 23:49:47 +00:00
|
|
|
|
|
|
|
//Create windows status feedback
|
1999-09-15 05:16:29 +00:00
|
|
|
var statusFeedback = Components.classes[statusFeedbackProgID].createInstance();
|
1999-09-01 23:49:47 +00:00
|
|
|
statusFeedback = statusFeedback.QueryInterface(Components.interfaces.nsIMsgStatusFeedback);
|
|
|
|
|
1999-09-09 06:18:40 +00:00
|
|
|
//Create message view object
|
1999-09-15 05:16:29 +00:00
|
|
|
var messageView = Components.classes[messageViewProgID].createInstance();
|
1999-09-09 06:18:40 +00:00
|
|
|
messageView = messageView.QueryInterface(Components.interfaces.nsIMessageView);
|
|
|
|
|
1999-09-13 21:11:45 +00:00
|
|
|
// the folderListener object
|
|
|
|
var folderListener = {
|
|
|
|
OnItemAdded: function(parentFolder, item) {},
|
|
|
|
|
1999-09-16 21:11:01 +00:00
|
|
|
OnItemRemoved: function(parentFolder, item){},
|
1999-09-13 21:11:45 +00:00
|
|
|
|
|
|
|
OnItemPropertyChanged: function(item, property, oldValue, newValue) {},
|
|
|
|
|
1999-09-16 21:11:01 +00:00
|
|
|
OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {},
|
|
|
|
|
|
|
|
OnFolderLoaded: function (folder)
|
|
|
|
{
|
|
|
|
if(folder)
|
|
|
|
{
|
|
|
|
var resource = folder.QueryInterface(Components.interfaces.nsIRDFResource);
|
|
|
|
if(resource)
|
|
|
|
{
|
|
|
|
var uri = resource.Value;
|
1999-09-21 21:04:52 +00:00
|
|
|
if(uri == gCurrentLoadingFolderURI)
|
1999-09-16 21:11:01 +00:00
|
|
|
{
|
1999-09-21 21:04:52 +00:00
|
|
|
gCurrentLoadingFolderURI="";
|
|
|
|
var msgFolder = folder.QueryInterface(Components.interfaces.nsIMsgFolder);
|
|
|
|
if(msgFolder)
|
|
|
|
msgFolder.EndFolderLoading();
|
|
|
|
RerootFolder(uri);
|
1999-09-16 21:11:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-13 21:11:45 +00:00
|
|
|
}
|
|
|
|
|
1999-09-01 23:49:47 +00:00
|
|
|
/* Functions related to startup */
|
|
|
|
function OnLoadMessenger()
|
|
|
|
{
|
|
|
|
|
1999-09-11 01:54:15 +00:00
|
|
|
verifyAccounts();
|
|
|
|
|
1999-09-11 00:43:18 +00:00
|
|
|
loadStartPage();
|
1999-09-01 23:49:47 +00:00
|
|
|
messenger.SetWindow(window, statusFeedback);
|
|
|
|
|
|
|
|
AddDataSources();
|
|
|
|
InitPanes();
|
|
|
|
|
1999-09-14 06:27:36 +00:00
|
|
|
loadStartFolder();
|
1999-09-13 21:11:45 +00:00
|
|
|
|
1999-09-15 04:57:24 +00:00
|
|
|
getFolderListener();
|
1999-09-01 23:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function OnUnloadMessenger()
|
|
|
|
{
|
|
|
|
dump("\nOnUnload from XUL\nClean up ...\n");
|
1999-09-15 05:16:29 +00:00
|
|
|
var mailSession = Components.classes[mailSessionProgID].getService();
|
1999-09-13 21:11:45 +00:00
|
|
|
if(mailSession)
|
|
|
|
{
|
|
|
|
mailSession = mailSession.QueryInterface(Components.interfaces.nsIMsgMailSession);
|
|
|
|
if(mailSession)
|
|
|
|
mailSession.RemoveFolderListener(folderListener);
|
|
|
|
}
|
1999-09-01 23:49:47 +00:00
|
|
|
messenger.OnUnload();
|
|
|
|
}
|
|
|
|
|
1999-09-11 01:54:15 +00:00
|
|
|
function verifyAccounts() {
|
|
|
|
try {
|
1999-09-15 05:16:29 +00:00
|
|
|
var mail = Components.classes[mailSessionProgID].getService(Components.interfaces.nsIMsgMailSession);
|
1999-09-11 01:54:15 +00:00
|
|
|
|
|
|
|
var am = mail.accountManager;
|
|
|
|
var accounts = am.accounts;
|
|
|
|
|
|
|
|
// as long as we have some accounts, we're fine.
|
1999-09-11 09:10:03 +00:00
|
|
|
if (accounts.Count() > 0) return;
|
1999-09-11 01:54:15 +00:00
|
|
|
|
|
|
|
try {
|
1999-09-11 19:10:06 +00:00
|
|
|
dump("attempt to UpgradePrefs. If that fails, open the account wizard.\n");
|
1999-09-11 01:54:15 +00:00
|
|
|
am.UpgradePrefs();
|
1999-09-15 04:49:43 +00:00
|
|
|
refreshFolderPane();
|
1999-09-11 01:54:15 +00:00
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
// upgrade prefs failed, so open account wizard
|
|
|
|
MsgAccountWizard();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
dump("error verifying accounts " + ex + "\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-11 00:43:18 +00:00
|
|
|
function loadStartPage() {
|
|
|
|
|
|
|
|
var startpage = "about:blank";
|
|
|
|
|
|
|
|
try {
|
1999-09-15 05:16:29 +00:00
|
|
|
var pref = Components.classes[prefProgID].getService(Components.interfaces.nsIPref);
|
1999-09-11 00:43:18 +00:00
|
|
|
|
|
|
|
startpageenabled= pref.GetBoolPref("mailnews.start_page.enabled");
|
|
|
|
|
|
|
|
if (startpageenabled)
|
|
|
|
startpage = pref.CopyCharPref("mailnews.start_page.url");
|
|
|
|
window.frames["messagepane"].location = startpage;
|
|
|
|
|
|
|
|
dump("start message pane with: " + startpage + "\n");
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
dump("Error loading start page.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-14 06:27:36 +00:00
|
|
|
function loadStartFolder()
|
|
|
|
{
|
|
|
|
//Load StartFolder
|
|
|
|
try {
|
1999-09-15 05:16:29 +00:00
|
|
|
var pref = Components.classes[prefProgID].getService(Components.interfaces.nsIPref);
|
1999-09-14 06:27:36 +00:00
|
|
|
|
|
|
|
var startFolder = pref.CopyCharPref("mailnews.start_folder");
|
|
|
|
ChangeFolderByURI(startFolder);
|
|
|
|
// var folder = OpenFolderTreeToFolder(startFolder);
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-09-15 04:57:24 +00:00
|
|
|
function getFolderListener()
|
|
|
|
{
|
|
|
|
try {
|
1999-09-15 05:16:29 +00:00
|
|
|
var mailSession = Components.classes[mailSessionProgID].getService(Components.interfaces.nsIMsgMailSession);
|
1999-09-15 04:57:24 +00:00
|
|
|
|
|
|
|
mailSession.AddFolderListener(folderListener);
|
|
|
|
} catch (ex) {
|
|
|
|
dump("Error adding folder listener\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-01 23:49:47 +00:00
|
|
|
function AddDataSources()
|
|
|
|
{
|
|
|
|
|
|
|
|
//to move menu item
|
|
|
|
accountManagerDataSource = accountManagerDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
folderDataSource = folderDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
var moveMenu = document.getElementById('moveMenu');
|
|
|
|
if(moveMenu)
|
|
|
|
{
|
|
|
|
moveMenu.database.AddDataSource(accountManagerDataSource);
|
|
|
|
moveMenu.database.AddDataSource(folderDataSource);
|
|
|
|
moveMenu.setAttribute('ref', 'msgaccounts:/');
|
|
|
|
}
|
|
|
|
|
|
|
|
//to copy menu item
|
|
|
|
var copyMenu = document.getElementById('copyMenu');
|
|
|
|
if(copyMenu)
|
|
|
|
{
|
|
|
|
copyMenu.database.AddDataSource(accountManagerDataSource);
|
|
|
|
copyMenu.database.AddDataSource(folderDataSource);
|
|
|
|
copyMenu.setAttribute('ref', 'msgaccounts:/');
|
|
|
|
}
|
|
|
|
//Add statusFeedback
|
|
|
|
var windowData = folderDataSource.QueryInterface(Components.interfaces.nsIMsgWindowData);
|
|
|
|
windowData.statusFeedback = statusFeedback;
|
1999-09-09 06:18:40 +00:00
|
|
|
windowData.messageView = messageView;
|
1999-09-01 23:49:47 +00:00
|
|
|
|
|
|
|
windowData = messageDataSource.QueryInterface(Components.interfaces.nsIMsgWindowData);
|
|
|
|
windowData.statusFeedback = statusFeedback;
|
1999-09-09 06:18:40 +00:00
|
|
|
windowData.messageView = messageView;
|
1999-09-01 23:49:47 +00:00
|
|
|
|
|
|
|
windowData = accountManagerDataSource.QueryInterface(Components.interfaces.nsIMsgWindowData);
|
|
|
|
windowData.statusFeedback = statusFeedback;
|
1999-09-09 06:18:40 +00:00
|
|
|
windowData.messageView = messageView;
|
1999-09-01 23:49:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function InitPanes()
|
|
|
|
{
|
1999-09-16 21:11:01 +00:00
|
|
|
var mailsidebar = new Object
|
|
|
|
mailsidebar.db = 'chrome://messenger/content/sidebar-messenger.rdf'
|
|
|
|
mailsidebar.resource = 'NC:MessengerSidebarRoot'
|
|
|
|
sidebarOverlayInit(mailsidebar);
|
|
|
|
|
|
|
|
var threadTree = GetThreadTree();
|
|
|
|
if(threadTree);
|
|
|
|
OnLoadThreadPane(threadTree);
|
|
|
|
|
|
|
|
var folderTree = GetFolderTree();
|
|
|
|
if(folderTree)
|
|
|
|
OnLoadFolderPane(folderTree);
|
1999-09-01 23:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function OnLoadFolderPane(folderTree)
|
|
|
|
{
|
1999-09-16 21:11:01 +00:00
|
|
|
dump('In onLoadfolderPane\n');
|
1999-09-15 08:29:01 +00:00
|
|
|
gFolderTree = folderTree;
|
1999-09-01 23:49:47 +00:00
|
|
|
SortFolderPane('FolderColumn', 'http://home.netscape.com/NC-rdf#Name');
|
|
|
|
//Add folderDataSource and accountManagerDataSource to folderPane
|
|
|
|
accountManagerDataSource = accountManagerDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
folderDataSource = folderDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
folderTree.database.AddDataSource(accountManagerDataSource);
|
|
|
|
folderTree.database.AddDataSource(folderDataSource);
|
|
|
|
folderTree.setAttribute('ref', 'msgaccounts:/');
|
1999-09-16 20:24:07 +00:00
|
|
|
|
|
|
|
SetupCommandUpdateHandlers();
|
1999-09-01 23:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function OnLoadThreadPane(threadTree)
|
|
|
|
{
|
1999-09-15 08:39:28 +00:00
|
|
|
gThreadTree = threadTree;
|
1999-09-09 06:18:40 +00:00
|
|
|
// add folderSource to thread pane
|
|
|
|
folderDataSource = folderDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
threadTree.database.AddDataSource(folderDataSource);
|
1999-09-01 23:49:47 +00:00
|
|
|
|
|
|
|
//Add message data source
|
|
|
|
messageDataSource = messageDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
threadTree.database.AddDataSource(messageDataSource);
|
|
|
|
|
|
|
|
ShowThreads(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Functions for accessing particular parts of the window*/
|
|
|
|
function GetFolderTree()
|
|
|
|
{
|
1999-09-15 08:29:01 +00:00
|
|
|
if (gFolderTree) return gFolderTree;
|
|
|
|
|
1999-09-16 21:11:01 +00:00
|
|
|
var folderTree = document.getElementById('folderTree');
|
1999-09-15 08:39:28 +00:00
|
|
|
gFolderTree = folderTree;
|
1999-09-01 23:49:47 +00:00
|
|
|
return folderTree;
|
|
|
|
}
|
|
|
|
|
|
|
|
function FindInSidebar(currentWindow, id)
|
|
|
|
{
|
|
|
|
var item = currentWindow.document.getElementById(id);
|
|
|
|
if(item)
|
|
|
|
return item;
|
|
|
|
|
1999-09-16 21:11:01 +00:00
|
|
|
for(var i = 0; i < currentWindow.frames.length; i++)
|
1999-09-01 23:49:47 +00:00
|
|
|
{
|
|
|
|
var frameItem = FindInSidebar(currentWindow.frames[i], id);
|
|
|
|
if(frameItem)
|
|
|
|
return frameItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetThreadTree()
|
|
|
|
{
|
1999-09-15 08:39:28 +00:00
|
|
|
if (gThreadTree) return gThreadTree;
|
1999-09-01 23:49:47 +00:00
|
|
|
var threadTree = document.getElementById('threadTree');
|
|
|
|
if(!threadTree)
|
|
|
|
dump('thread tree is null\n');
|
1999-09-15 08:39:28 +00:00
|
|
|
gThreadTree = threadTree;
|
1999-09-01 23:49:47 +00:00
|
|
|
return threadTree;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetThreadTreeFolder()
|
|
|
|
{
|
|
|
|
var tree = GetThreadTree();
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
function FindMessenger()
|
|
|
|
{
|
|
|
|
return messenger;
|
|
|
|
}
|
|
|
|
|
|
|
|
function RefreshThreadTreeView()
|
|
|
|
{
|
|
|
|
var currentFolder = GetThreadTreeFolder();
|
|
|
|
var currentFolderID = currentFolder.getAttribute('ref');
|
|
|
|
currentFolder.setAttribute('ref', currentFolderID);
|
|
|
|
}
|
|
|
|
|
1999-09-13 21:11:45 +00:00
|
|
|
function ClearThreadTreeSelection()
|
|
|
|
{
|
|
|
|
var tree = GetThreadTree();
|
|
|
|
if(tree)
|
1999-09-16 21:11:01 +00:00
|
|
|
{
|
|
|
|
dump('before clearItemSelection\n');
|
1999-09-13 21:11:45 +00:00
|
|
|
tree.clearItemSelection();
|
1999-09-16 21:11:01 +00:00
|
|
|
}
|
1999-09-13 21:11:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-09-01 23:49:47 +00:00
|
|
|
function ClearMessagePane()
|
|
|
|
{
|
|
|
|
messenger.OpenURL("about:blank");
|
|
|
|
|
1999-09-11 00:43:18 +00:00
|
|
|
}
|
1999-09-13 21:11:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|