Bug 71105: biff for all windows (behind-the-scenes patch); r=Neil, sr=bienvenu

git-svn-id: svn://10.0.0.236/trunk@252523 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mnyromyr%tprac.de
2008-06-23 19:59:20 +00:00
parent d316c9ca6f
commit cb3ffeddef
7 changed files with 361 additions and 155 deletions

View File

@@ -0,0 +1,248 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com>
* Josh Soref <timeless@bemail.org>
* Varada Parthasarathi <varada@netscape.com>
* Scott Putterman <putterman@netscape.com>
* Simon Fraser <sfraser@netscape.com>
* Chris McAfee <mcafee@netscape.com>
* Ray Whitmer <rayw@netscape.com>
* David Hyatt <hyatt@netscape.com>
* Blake Ross <blakeross@telocity.com>
* Andrew Wooldridge <andreww@netscape.com>
* Joe Hewitt <hewitt@netscape.com>
* Brian Nesse <bnesse@netscape.com>
* Håkan Waara <hwaara@chello.se>
* Neil Rashbrook <neil@parkwaycc.co.uk>
* Srilatha Moturi <srilatha@netscape.com>
* Peter Annema <jaggernaut@netscape.com>
* Brian Ryner <bryner@netscape.com>
* Alec Flett <alecf@netscape.com>
* <shliang@netscape.com>
* <riceman+bmo@mail.rit.edu>
* Serge Gautherie <sgautherie.bz@free.fr>
* Karsten Düsterloh <mnyromyr@tprac.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the LGPL or the GPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// biff observer topic
const BIFF_TOPIC = "mail:biff-state-changed";
// biff state constants used by themes
const BIFF_STATE_MESSAGES = "NewMail";
const BIFF_STATE_NOMESSAGES = "NoMail";
const BIFF_STATE_UNKNOWN = "UnknownMail";
// uses "toOpenWindowByType" function provided by utilityOverlay.js
// which is included by most clients.
function toMessengerWindow()
{
toOpenWindowByType("mail:3pane", "chrome://messenger/content/");
}
function toAddressBook()
{
toOpenWindowByType("mail:addressbook",
"chrome://messenger/content/addressbook/addressbook.xul");
}
function toNewsgroups()
{
dump("Sorry, command not implemented.\n");
}
function toImport()
{
window.openDialog("chrome://messenger/content/importDialog.xul",
"importDialog",
"chrome, modal, titlebar, centerscreen");
}
function CoalesceGetMsgsForPop3ServersByDestFolder(aCurrentServer,
aPOP3DownloadServersArray,
aLocalFoldersToDownloadTo)
{
const MSG_FOLDER_FLAG_INBOX = 0x1000; // XXX will be killed by bug 436044
// coalesce the servers that download into the same folder...
var inbox = aCurrentServer.rootMsgFolder.getFolderWithFlags(MSG_FOLDER_FLAG_INBOX);
var index = aLocalFoldersToDownloadTo.indexOf(inbox);
if (index == -1)
{
inbox.biffState = Components.interfaces.nsIMsgFolder.nsMsgBiffState_NoMail;
inbox.clearNewMessages();
aLocalFoldersToDownloadTo.push(inbox);
index = aPOP3DownloadServersArray.length;
aPOP3DownloadServersArray[index] =
Components.classes["@mozilla.org/supports-array;1"]
.createInstance(Components.interfaces.nsISupportsArray);
}
aPOP3DownloadServersArray[index].AppendElement(aCurrentServer);
}
function MailTasksGetMessagesForAllServers(aMsgWindow, aDefaultServer)
{
// now log into any server
try
{
var allServers = Components.classes["@mozilla.org/messenger/account-manager;1"]
.getService(Components.interfaces.nsIMsgAccountManager)
.allServers;
// array of ISupportsArrays of servers for a particular folder
var pop3DownloadServersArray = [];
// parallel array of folders to download to...
var localFoldersToDownloadTo = [];
var pop3Server = null;
for (let i = 0; i < allServers.Count(); ++i)
{
let currentServer = allServers.GetElementAt(i);
if (currentServer instanceof Components.interfaces.nsIMsgIncomingServer)
{
let protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + currentServer.type]
.getService(Components.interfaces.nsIMsgProtocolInfo);
if (protocolinfo.canLoginAtStartUp && currentServer.loginAtStartUp)
{
if (aDefaultServer &&
aDefaultServer.equals(currentServer) &&
!aDefaultServer.isDeferredTo &&
aDefaultServer.rootFolder == aDefaultServer.rootMsgFolder)
{
dump(currentServer.serverURI + " ... skipping, already opened\n");
}
else if (currentServer.type == "pop3" && currentServer.downloadOnBiff)
{
CoalesceGetMsgsForPop3ServersByDestFolder(currentServer,
pop3DownloadServersArray,
localFoldersToDownloadTo);
pop3Server = currentServer;
}
else
{
// check to see if there are new messages on the server
currentServer.performBiff(aMsgWindow);
}
}
}
}
if (pop3Server instanceof Components.interfaces.nsIPop3IncomingServer)
{
for (let i = 0; i < pop3DownloadServersArray.length; ++i)
{
// any ol' pop3Server will do -
// the serversArray specifies which servers to download from
pop3Server.downloadMailFromServers(pop3DownloadServersArray[i],
aMsgWindow,
localFoldersToDownloadTo[i],
null);
}
}
}
catch (e)
{
Components.utils.reportError(e);
}
}
const biffObserver =
{
observe: function observe(subject, topic, state)
{
// sanity check
if (topic == BIFF_TOPIC)
{
var biffManager = Components.classes["@mozilla.org/messenger/statusBarBiffManager;1"]
.getService(Components.interfaces.nsIStatusBarBiffManager);
document.getElementById("mini-mail")
.setAttribute("BiffState",
[BIFF_STATE_MESSAGES,
BIFF_STATE_NOMESSAGES,
BIFF_STATE_UNKNOWN][biffManager.biffState]);
}
}
};
function MailTasksOnLoad(aEvent)
{
// Without the mini-mail icon to show the biff state, there's no need to
// initialize this here. We won't start with the hidden window alone,
// so this early return doesn't break anything.
var miniMail = document.getElementById("mini-mail");
if (!miniMail)
return;
// initialize biff state
const kObserverService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
kObserverService.addObserver(biffObserver, BIFF_TOPIC, false);
biffObserver.observe(null, BIFF_TOPIC, null); // init mini-mail icon
addEventListener("unload", MailTasksOnUnload, false);
// Performing biff here will mean performing it for all new windows opened!
// This might make non-users of mailnews unhappy...
const kPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch(null);
if (!kPrefBranch.getBoolPref("mail.biff.on_new_window"))
return;
// The MailNews main window will perform biff later in its onload handler,
// so we don't need to do this here.
if (Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow("mail:3pane"))
return;
// If we already have a defined biff-state set on the mini-mail icon,
// we know that biff is already running.
const kBiffState = Components.classes["@mozilla.org/messenger/statusBarBiffManager;1"]
.getService(Components.interfaces.nsIStatusBarBiffManager)
.biffState;
if (kBiffState != Components.interfaces.nsIMsgFolder.nsMsgBiffState_Unknown)
return;
// still no excuse to refuse to use this ruse
MailTasksGetMessagesForAllServers(null, null);
}
function MailTasksOnUnload(aEvent)
{
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(biffObserver, BIFF_TOPIC);
}
addEventListener("load", MailTasksOnLoad, false);

View File

@@ -1,94 +1,120 @@
<?xml version="1.0"?>
<!DOCTYPE overlay [
<!ENTITY % mailTasksOverlayDTD SYSTEM "chrome://messenger/locale/mailTasksOverlay.dtd" >
%mailTasksOverlayDTD;
]>
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 2000
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Ben Goodger <ben@netscape.com>
- Josh Soref <timeless@bemail.org>
- Varada Parthasarathi <varada@netscape.com>
- Scott Putterman <putterman@netscape.com>
- Simon Fraser <sfraser@netscape.com>
- Chris McAfee <mcafee@netscape.com>
- Ray Whitmer <rayw@netscape.com>
- David Hyatt <hyatt@netscape.com>
- Blake Ross <blakeross@telocity.com>
- Andrew Wooldridge <andreww@netscape.com>
- Joe Hewitt <hewitt@netscape.com>
- Brian Nesse <bnesse@netscape.com>
- Håkan Waara <hwaara@chello.se>
- Neil Rashbrook <neil@parkwaycc.co.uk>
- Srilatha Moturi <srilatha@netscape.com>
- Peter Annema <jaggernaut@netscape.com>
- Brian Ryner <bryner@netscape.com>
- Alec Flett <alecf@netscape.com>
- <shliang@netscape.com>
- <riceman+bmo@mail.rit.edu>
- Serge Gautherie <sgautherie.bz@free.fr>
- Karsten Düsterloh <mnyromyr@tprac.de>
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the LGPL or the GPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<overlay id="mailPrefsOverlay"
<!DOCTYPE overlay SYSTEM "chrome://messenger/locale/mailTasksOverlay.dtd">
<overlay id="mailTasksOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript">
<![CDATA[
// uses "toOpenWindowByType" function provided by utilityOverlay.js
// which is included by most clients.
function toMessengerWindow()
{
toOpenWindowByType("mail:3pane", "chrome://messenger/content/");
}
function toAddressBook()
{
toOpenWindowByType("mail:addressbook", "chrome://messenger/content/addressbook/addressbook.xul");
}
function toNewsgroups()
{
dump ("Sorry, command not implemented.\n");
}
function toImport()
{
window.openDialog("chrome://messenger/content/importDialog.xul", "importDialog", "chrome, modal, titlebar, centerscreen");
}
const biffObserver =
{
observe: function observe(subject, topic, state)
{
// sanity check
if (topic == "mail:biff-state-changed") {
var biffManager = Components.classes["@mozilla.org/messenger/statusBarBiffManager;1"].getService(Components.interfaces.nsIStatusBarBiffManager);
document.getElementById("mini-mail").setAttribute("BiffState", ["NewMail", "NoMail", "UnknownMail"][biffManager.biffState]);
}
}
}
function mailTasksOnUnload(aEvent)
{
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(biffObserver, "mail:biff-state-changed");
}
function mailTasksOnLoad(aEvent)
{
if (!document.getElementById('mini-mail')) return;
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(biffObserver, "mail:biff-state-changed", false);
biffObserver.observe(null, "mail:biff-state-changed", null);
addEventListener("unload", mailTasksOnUnload, false);
}
addEventListener("load", mailTasksOnLoad, false);
]]>
</script>
<script type="application/x-javascript"
src="chrome://messenger/content/mailTasksOverlay.js"/>
<keyset id="tasksKeys">
<key id="key_mail" key="&messengerCmd.commandkey;" command="Tasks:Mail" modifiers="accel"/>
<key id="key_addressbook" key="&addressBookCmd.commandkey;" command="Tasks:AddressBook" modifiers="accel"/>
<key id="key_mail"
command="Tasks:Mail"
key="&messengerCmd.commandkey;"
modifiers="accel"/>
<key id="key_addressbook"
command="Tasks:AddressBook"
key="&addressBookCmd.commandkey;"
modifiers="accel"/>
</keyset>
<commandset id="tasksCommands">
<command id="Tasks:Mail" oncommand="toMessengerWindow();"/>
<command id="Tasks:AddressBook" oncommand="toAddressBook();"/>
</commandset>
<statusbarpanel id="component-bar">
<toolbarbutton class="taskbutton" id="mini-mail" oncommand="toMessengerWindow()"
position="2" tooltiptext="&taskMessenger.tooltip;"/>
<toolbarbutton id="mini-comp" insertafter="mini-mail"/>
<toolbarbutton class="taskbutton" id="mini-addr" oncommand="toAddressBook();"
insertafter="mini-comp" tooltiptext="&taskAddressBook.tooltip;"/>
<toolbarbutton id="mini-mail"
class="taskbutton"
oncommand="toMessengerWindow()"
position="2"
tooltiptext="&taskMessenger.tooltip;"/>
<toolbarbutton id="mini-comp"
insertafter="mini-mail"/>
<toolbarbutton id="mini-addr"
class="taskbutton"
oncommand="toAddressBook();"
insertafter="mini-comp"
tooltiptext="&taskAddressBook.tooltip;"/>
</statusbarpanel>
<menupopup id="windowPopup">
<menuitem accesskey="&messengerCmd.accesskey;" label="&messengerCmd.label;" key="key_mail" command="Tasks:Mail" id="tasksMenuMail" insertafter="tasksMenuNavigator" class="menuitem-iconic icon-mail16 menu-iconic"/>
<menuitem id="tasksMenuEditor" insertafter="tasksMenuMail"/>
<menuitem label="&addressBookCmd.label;" accesskey="&addressBookCmd.accesskey;" key="key_addressbook" command="Tasks:AddressBook" id="tasksMenuAddressBook" insertafter="tasksMenuEditor" class="menuitem-iconic icon-addressbook16 menu-iconic"/>
<menuitem id="tasksMenuMail"
class="menuitem-iconic icon-mail16 menu-iconic"
label="&messengerCmd.label;"
accesskey="&messengerCmd.accesskey;"
key="key_mail"
command="Tasks:Mail"
insertafter="tasksMenuNavigator"/>
<menuitem id="tasksMenuEditor"
insertafter="tasksMenuMail"/>
<menuitem id="tasksMenuAddressBook"
class="menuitem-iconic icon-addressbook16 menu-iconic"
label="&addressBookCmd.label;"
accesskey="&addressBookCmd.accesskey;"
key="key_addressbook"
command="Tasks:AddressBook"
insertafter="tasksMenuEditor"/>
</menupopup>
</overlay>
</overlay>

View File

@@ -885,51 +885,7 @@ function MsgGetMessage()
function MsgGetMessagesForAllServers(defaultServer)
{
// now log into any server
try
{
var allServers = accountManager.allServers;
var i;
// array of isupportsarrays of servers for a particular folder
var pop3DownloadServersArray = new Array();
// parallel isupports array of folders to download to...
var localFoldersToDownloadTo = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
var pop3Server;
for (i = 0; i < allServers.Count(); ++i)
{
var currentServer = allServers.GetElementAt(i).QueryInterface(Components.interfaces.nsIMsgIncomingServer);
var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + currentServer.type].getService(Components.interfaces.nsIMsgProtocolInfo);
if (protocolinfo.canLoginAtStartUp && currentServer.loginAtStartUp)
{
if (defaultServer && defaultServer.equals(currentServer) &&
!defaultServer.isDeferredTo &&
defaultServer.rootFolder == defaultServer.rootMsgFolder)
{
dump(currentServer.serverURI + "...skipping, already opened\n");
}
else if (currentServer.type == "pop3" && currentServer.downloadOnBiff)
{
CoalesceGetMsgsForPop3ServersByDestFolder(currentServer, pop3DownloadServersArray, localFoldersToDownloadTo);
pop3Server = currentServer.QueryInterface(Components.interfaces.nsIPop3IncomingServer);
}
else
{
// Check to see if there are new messages on the server
currentServer.performBiff(msgWindow);
}
}
}
for (i = 0; i < pop3DownloadServersArray.length; ++i)
{
// any ol' pop3Server will do - the serversArray specifies which servers to download from
pop3Server.downloadMailFromServers(pop3DownloadServersArray[i], msgWindow, localFoldersToDownloadTo.GetElementAt(i), null);
}
}
catch(ex)
{
dump(ex + "\n");
}
MailTasksGetMessagesForAllServers(msgWindow, defaultServer);
}
/**
@@ -2089,25 +2045,6 @@ function SendUnsentMessages()
}
}
function CoalesceGetMsgsForPop3ServersByDestFolder(currentServer, pop3DownloadServersArray, localFoldersToDownloadTo)
{
var inboxFolder = currentServer.rootMsgFolder.getFolderWithFlags(0x1000);
// coalesce the servers that download into the same folder...
var index = localFoldersToDownloadTo.GetIndexOf(inboxFolder);
if (index == -1)
{
if(inboxFolder)
{
inboxFolder.biffState = Components.interfaces.nsIMsgFolder.nsMsgBiffState_NoMail;
inboxFolder.clearNewMessages();
}
localFoldersToDownloadTo.AppendElement(inboxFolder);
index = pop3DownloadServersArray.length
pop3DownloadServersArray[index] = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
}
pop3DownloadServersArray[index].AppendElement(currentServer);
}
function GetMessagesForAllAuthenticatedAccounts()
{
// now log into any server

View File

@@ -3760,7 +3760,6 @@ NS_IMETHODIMP nsMsgDBFolder::GetBiffState(PRUint32 *aBiffState)
NS_IMETHODIMP nsMsgDBFolder::SetBiffState(PRUint32 aBiffState)
{
PRUint32 oldBiffState;
nsCOMPtr<nsIMsgIncomingServer> server;
nsresult rv = GetServer(getter_AddRefs(server));
if (NS_SUCCEEDED(rv) && server)
@@ -3768,23 +3767,16 @@ NS_IMETHODIMP nsMsgDBFolder::SetBiffState(PRUint32 aBiffState)
// Get the server and notify it and not inbox.
if (oldBiffState != aBiffState)
{
// if (aBiffState == nsMsgBiffState_NoMail)
// SetNumNewMessages(0);
// we don't distinguish between unknown and noMail for servers
if (! (oldBiffState == nsMsgBiffState_Unknown && aBiffState == nsMsgBiffState_NoMail))
if (!mIsServer)
{
if (!mIsServer)
{
nsCOMPtr<nsIMsgFolder> folder;
rv = GetRootFolder(getter_AddRefs(folder));
if (NS_SUCCEEDED(rv) && folder)
return folder->SetBiffState(aBiffState);
}
if (server)
server->SetBiffState(aBiffState);
NotifyIntPropertyChanged(kBiffStateAtom, oldBiffState, aBiffState);
nsCOMPtr<nsIMsgFolder> folder;
rv = GetRootFolder(getter_AddRefs(folder));
if (NS_SUCCEEDED(rv) && folder)
return folder->SetBiffState(aBiffState);
}
if (server)
server->SetBiffState(aBiffState);
NotifyIntPropertyChanged(kBiffStateAtom, oldBiffState, aBiffState);
}
else if (aBiffState == nsMsgBiffState_NoMail)
{

View File

@@ -84,7 +84,7 @@
nsMsgIncomingServer::nsMsgIncomingServer():
m_rootFolder(0),
m_numMsgsDownloaded(0),
m_biffState(nsIMsgFolder::nsMsgBiffState_NoMail),
m_biffState(nsIMsgFolder::nsMsgBiffState_Unknown),
m_serverBusy(PR_FALSE),
m_canHaveFilters(PR_TRUE),
m_displayStartupPage(PR_TRUE),

View File

@@ -153,6 +153,7 @@ messenger.jar:
content/messenger/msgPrintEngine.js (base/resources/content/msgPrintEngine.js)
content/messenger/msgPrintEngine.xul (base/resources/content/msgPrintEngine.xul)
content/messenger/mailTasksOverlay.xul (base/resources/content/mailTasksOverlay.xul)
content/messenger/mailTasksOverlay.js (base/resources/content/mailTasksOverlay.js)
content/messenger/mailEditorOverlay.xul (base/resources/content/mailEditorOverlay.xul)
content/messenger/mailABOverlay.xul (base/resources/content/mailABOverlay.xul)
content/messenger/mailMessengerOverlay.xul (base/resources/content/mailMessengerOverlay.xul)

View File

@@ -613,6 +613,8 @@ pref("mail.biff.play_sound.url", "");
pref("mail.biff.show_alert", true);
pref("mail.biff.show_tray_icon", true); // currently Windows-only
pref("mail.biff.animate_dock_icon", false);
// if true, check for new mail even when opening non-mail windows
pref("mail.biff.on_new_window", true);
pref("mail.content_disposition_type", 0);