зеркало из https://github.com/mozilla/pjs.git
Add more work on Biff.
This commit is contained in:
Родитель
2582c3ba40
Коммит
50fe889735
|
@ -28,4 +28,6 @@ nsMsgAccount.h
|
|||
nsMsgAccountManager.h
|
||||
nsMsgRDFDataSource.h
|
||||
nsMsgBiffManager.h
|
||||
nsMsgNotificationManager.h
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ EXPORTS = \
|
|||
nsMsgServerDataSource.h \
|
||||
nsMsgRDFDataSource.h \
|
||||
nsMsgBiffManager.h \
|
||||
nsMsgNotificationManager.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
@ -64,6 +65,7 @@ CPPSRCS = \
|
|||
nsMsgServerDataSource.cpp \
|
||||
nsMsgRDFUtils.cpp \
|
||||
nsMsgBiffManager.cpp \
|
||||
nsMsgNotificationManager.cpp \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
|
|
|
@ -41,6 +41,7 @@ EXPORTS= \
|
|||
nsMsgIdentityDataSource.h \
|
||||
nsMsgServerDataSource.h \
|
||||
nsMsgBiffManager.h \
|
||||
nsMsgNotificationManager.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
|
@ -68,6 +69,7 @@ CPP_OBJS= \
|
|||
.\$(OBJDIR)\nsMsgIdentityDataSource.obj \
|
||||
.\$(OBJDIR)\nsMsgServerDataSource.obj \
|
||||
.\$(OBJDIR)\nsMsgBiffManager.obj \
|
||||
.\$(OBJDIR)\nsMsgNotificationManager.obj \
|
||||
$(NULL)
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ nsresult
|
|||
NS_NewMsgBiffManager(const nsIID& iid, void **result)
|
||||
{
|
||||
nsMsgBiffManager *biffManager = new nsMsgBiffManager();
|
||||
if(!biffManager)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return biffManager->QueryInterface(iid, result);
|
||||
}
|
||||
|
||||
|
@ -61,8 +63,7 @@ nsMsgBiffManager::nsMsgBiffManager()
|
|||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
NS_NewTimer(&mBiffTimer);
|
||||
|
||||
mBiffTimer = nsnull;
|
||||
mBiffArray = new nsVoidArray();
|
||||
}
|
||||
|
||||
|
@ -89,17 +90,15 @@ NS_IMETHODIMP nsMsgBiffManager::AddServerBiff(nsIMsgIncomingServer *server)
|
|||
//Only add it if it hasn't been added already.
|
||||
if(serverIndex == -1)
|
||||
{
|
||||
PRInt32 biffInterval;
|
||||
nsBiffEntry *biffEntry = new nsBiffEntry;
|
||||
if(!biffEntry)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
biffEntry->server = server;
|
||||
rv = server->GetBiffMinutes(&biffInterval);
|
||||
nsTime currentTime;
|
||||
rv = SetNextBiffTime(biffEntry, currentTime);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
//Add 60 secs/minute in microseconds to current time. biffEntry->nextBiffTime's
|
||||
//constructor makes it the current time.
|
||||
biffEntry->nextBiffTime += (60000000 * biffInterval);
|
||||
|
||||
AddBiffEntry(biffEntry);
|
||||
SetupNextBiff();
|
||||
}
|
||||
|
@ -124,7 +123,7 @@ NS_IMETHODIMP nsMsgBiffManager::ForceBiffAll()
|
|||
|
||||
void nsMsgBiffManager::Notify(nsITimer *timer)
|
||||
{
|
||||
|
||||
PerformBiff();
|
||||
}
|
||||
|
||||
PRInt32 nsMsgBiffManager::FindServer(nsIMsgIncomingServer *server)
|
||||
|
@ -142,8 +141,7 @@ PRInt32 nsMsgBiffManager::FindServer(nsIMsgIncomingServer *server)
|
|||
nsresult nsMsgBiffManager::AddBiffEntry(nsBiffEntry *biffEntry)
|
||||
{
|
||||
PRInt32 count = mBiffArray->Count();
|
||||
PRInt32 i;
|
||||
for(i = 0; i < count; i++)
|
||||
for(PRInt32 i = 0; i < count; i++)
|
||||
{
|
||||
nsBiffEntry *current = (nsBiffEntry*)mBiffArray->ElementAt(i);
|
||||
if(biffEntry->nextBiffTime < current->nextBiffTime)
|
||||
|
@ -154,33 +152,76 @@ nsresult nsMsgBiffManager::AddBiffEntry(nsBiffEntry *biffEntry)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgBiffManager::SetNextBiffTime(nsBiffEntry *biffEntry, nsTime startTime)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIMsgIncomingServer *server = biffEntry->server;
|
||||
|
||||
if(!server)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt32 biffInterval;
|
||||
rv = server->GetBiffMinutes(&biffInterval);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
//Add 60 secs/minute in microseconds to current time. biffEntry->nextBiffTime's
|
||||
//constructor makes it the current time.
|
||||
biffEntry->nextBiffTime = startTime;
|
||||
biffEntry->nextBiffTime += (60000000 * biffInterval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgBiffManager::SetupNextBiff()
|
||||
{
|
||||
/*
|
||||
|
||||
if(mBiffArray->Count() > 0)
|
||||
{
|
||||
|
||||
//Get the next biff entry
|
||||
nsBiffEntry *biffEntry = (nsBiffEntry*)mBiffArray->ElementAt(0);
|
||||
nsTime currentTime;
|
||||
nsTime biffDelay;
|
||||
|
||||
nsInt64 biffDelay;
|
||||
nsInt64 ms(1000);
|
||||
if(currentTime > biffEntry->nextBiffTime)
|
||||
biffDelay = LL_ZERO;
|
||||
biffDelay = 1;
|
||||
else
|
||||
biffDelay = biffEntry->nextBiffTime - currentTime;
|
||||
mBiffTimer->Cancel();
|
||||
//Convert biffDelay into milliseconds
|
||||
PRInt64 timeInMS;
|
||||
PRUint32 timeInMSUint32;
|
||||
PRInt64 ms;
|
||||
LL_I2L(ms, 1000);
|
||||
LL_DIV(timeInMS, biffDelay, ms);
|
||||
LL_L2UI(timeInMSUint32, timeInMS);
|
||||
nsInt64 timeInMS = biffDelay / ms;
|
||||
PRUint32 timeInMSUint32 = (PRUint32)timeInMS;
|
||||
//Can't currently reset a timer when it's in the process of
|
||||
//calling Notify. So, just release the timer here and create a new one.
|
||||
if(mBiffTimer)
|
||||
{
|
||||
mBiffTimer->Cancel();
|
||||
NS_RELEASE(mBiffTimer);
|
||||
}
|
||||
NS_NewTimer(&mBiffTimer);
|
||||
mBiffTimer->Init(this, timeInMSUint32);
|
||||
|
||||
}
|
||||
*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//This is the function that does a biff on all of the servers whose time it is to biff.
|
||||
nsresult nsMsgBiffManager::PerformBiff()
|
||||
{
|
||||
nsTime currentTime;
|
||||
for(PRInt32 i = 0; i < mBiffArray->Count(); i++)
|
||||
{
|
||||
nsBiffEntry *current = (nsBiffEntry*)mBiffArray->ElementAt(i);
|
||||
if(current->nextBiffTime < currentTime)
|
||||
{
|
||||
current->server->PerformBiff();
|
||||
mBiffArray->RemoveElementAt(i);
|
||||
i--; //Because we removed it we need to look at the one that just moved up.
|
||||
SetNextBiffTime(current, currentTime);
|
||||
AddBiffEntry(current);
|
||||
}
|
||||
else
|
||||
//since we're in biff order, there's no reason to keep checking
|
||||
break;
|
||||
}
|
||||
SetupNextBiff();
|
||||
return NS_OK;
|
||||
}
|
|
@ -52,8 +52,10 @@ public:
|
|||
|
||||
protected:
|
||||
PRInt32 FindServer(nsIMsgIncomingServer *server);
|
||||
nsresult SetNextBiffTime(nsBiffEntry *biffEntry, nsTime startTime);
|
||||
nsresult SetupNextBiff();
|
||||
nsresult AddBiffEntry(nsBiffEntry *biffEntry);
|
||||
nsresult PerformBiff();
|
||||
|
||||
protected:
|
||||
nsITimer *mBiffTimer;
|
||||
|
|
|
@ -52,6 +52,7 @@ nsIRDFResource* nsMsgFolderDataSource::kNC_SpecialFolder= nsnull;
|
|||
nsIRDFResource* nsMsgFolderDataSource::kNC_TotalMessages= nsnull;
|
||||
nsIRDFResource* nsMsgFolderDataSource::kNC_TotalUnreadMessages= nsnull;
|
||||
nsIRDFResource* nsMsgFolderDataSource::kNC_Charset = nsnull;
|
||||
nsIRDFResource* nsMsgFolderDataSource::kNC_BiffState = nsnull;
|
||||
|
||||
// commands
|
||||
nsIRDFResource* nsMsgFolderDataSource::kNC_Delete= nsnull;
|
||||
|
@ -99,6 +100,7 @@ nsMsgFolderDataSource::~nsMsgFolderDataSource (void)
|
|||
NS_RELEASE2(kNC_TotalMessages, refcnt);
|
||||
NS_RELEASE2(kNC_TotalUnreadMessages, refcnt);
|
||||
NS_RELEASE2(kNC_Charset, refcnt);
|
||||
NS_RELEASE2(kNC_BiffState, refcnt);
|
||||
|
||||
NS_RELEASE2(kNC_Delete, refcnt);
|
||||
NS_RELEASE2(kNC_NewFolder, refcnt);
|
||||
|
@ -149,6 +151,7 @@ NS_IMETHODIMP nsMsgFolderDataSource::Init(const char* uri)
|
|||
mRDFService->GetResource(NC_RDF_TOTALMESSAGES, &kNC_TotalMessages);
|
||||
mRDFService->GetResource(NC_RDF_TOTALUNREADMESSAGES, &kNC_TotalUnreadMessages);
|
||||
mRDFService->GetResource(NC_RDF_CHARSET, &kNC_Charset);
|
||||
mRDFService->GetResource(NC_RDF_BIFFSTATE, &kNC_BiffState);
|
||||
|
||||
mRDFService->GetResource(NC_RDF_DELETE, &kNC_Delete);
|
||||
mRDFService->GetResource(NC_RDF_NEWFOLDER, &kNC_NewFolder);
|
||||
|
@ -366,6 +369,7 @@ nsMsgFolderDataSource::getFolderArcLabelsOut(nsIMsgFolder *folder,
|
|||
(*arcs)->AppendElement(kNC_TotalMessages);
|
||||
(*arcs)->AppendElement(kNC_TotalUnreadMessages);
|
||||
(*arcs)->AppendElement(kNC_Charset);
|
||||
(*arcs)->AppendElement(kNC_BiffState);
|
||||
(*arcs)->AppendElement(kNC_Child);
|
||||
(*arcs)->AppendElement(kNC_MessageChild);
|
||||
|
||||
|
@ -573,6 +577,28 @@ NS_IMETHODIMP nsMsgFolderDataSource::OnItemPropertyChanged(nsISupports *item, co
|
|||
NS_IMETHODIMP nsMsgFolderDataSource::OnItemPropertyFlagChanged(nsISupports *item, const char *property,
|
||||
PRUint32 oldFlag, PRUint32 newFlag)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgFolder> folder(do_QueryInterface(item));
|
||||
if(folder)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource(do_QueryInterface(item));
|
||||
if(resource)
|
||||
{
|
||||
if(PL_strcmp("BiffState", property) == 0)
|
||||
{
|
||||
nsAutoString oldBiffStateStr((const char *)"",eOneByte), newBiffStateStr ((const char *)"", eOneByte);
|
||||
|
||||
rv = GetBiffStateString(oldFlag, oldBiffStateStr);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = GetBiffStateString(newFlag, newBiffStateStr);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
NotifyPropertyChanged(resource, kNC_BiffState, oldBiffStateStr.GetBuffer(), newBiffStateStr.GetBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
@ -607,6 +633,8 @@ nsresult nsMsgFolderDataSource::createFolderNode(nsIMsgFolder* folder,
|
|||
rv = createUnreadMessagesNode(folder, target);
|
||||
else if (peq(kNC_Charset, property))
|
||||
rv = createCharsetNode(folder, target);
|
||||
else if (peq(kNC_BiffState, property))
|
||||
rv = createBiffStateNode(folder, target);
|
||||
else if (peq(kNC_Child, property))
|
||||
rv = createFolderChildNode(folder, target);
|
||||
else if (peq(kNC_MessageChild, property))
|
||||
|
@ -692,6 +720,34 @@ nsMsgFolderDataSource::createCharsetNode(nsIMsgFolder *folder, nsIRDFNode **targ
|
|||
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgFolderDataSource::createBiffStateNode(nsIMsgFolder *folder, nsIRDFNode **target)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 biffState;
|
||||
rv = folder->GetBiffState(&biffState);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
|
||||
nsString biffString;
|
||||
|
||||
GetBiffStateString(biffState, biffString);
|
||||
createNode(biffString, target);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgFolderDataSource::GetBiffStateString(PRUint32 biffState, nsString& biffStateStr)
|
||||
{
|
||||
if(biffState == nsMsgBiffState_NewMail)
|
||||
biffStateStr = "NewMail";
|
||||
else if(biffState == nsMsgBiffState_NoMail)
|
||||
biffStateStr = "NoMail";
|
||||
else
|
||||
biffStateStr = "UnknownMail";
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgFolderDataSource::createUnreadMessagesNode(nsIMsgFolder *folder,
|
||||
nsIRDFNode **target)
|
||||
|
@ -857,17 +913,7 @@ nsresult nsMsgFolderDataSource::DoFolderHasAssertion(nsIMsgFolder *folder, nsIRD
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (peq(kNC_Name, property) || peq(kNC_SpecialFolder, property) || peq(kNC_TotalMessages, property)
|
||||
|| peq(kNC_TotalUnreadMessages, property) || peq(kNC_Charset, property))
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> folderResource(do_QueryInterface(folder, &rv));
|
||||
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = GetTargetHasAssertion(this, folderResource, property, tv, target, hasAssertion);
|
||||
}
|
||||
else if(peq(kNC_Child, property))
|
||||
if(peq(kNC_Child, property))
|
||||
{
|
||||
nsCOMPtr<nsIFolder> childFolder(do_QueryInterface(target, &rv));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
|
@ -885,7 +931,17 @@ nsresult nsMsgFolderDataSource::DoFolderHasAssertion(nsIMsgFolder *folder, nsIRD
|
|||
if(NS_SUCCEEDED(rv))
|
||||
rv = folder->HasMessage(message, hasAssertion);
|
||||
}
|
||||
else
|
||||
else if (peq(kNC_Name, property) || peq(kNC_SpecialFolder, property) || peq(kNC_TotalMessages, property)
|
||||
|| peq(kNC_TotalUnreadMessages, property) || peq(kNC_Charset, property) || peq(kNC_BiffState, property))
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> folderResource(do_QueryInterface(folder, &rv));
|
||||
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = GetTargetHasAssertion(this, folderResource, property, tv, target, hasAssertion);
|
||||
}
|
||||
else
|
||||
*hasAssertion = PR_FALSE;
|
||||
|
||||
return rv;
|
||||
|
|
|
@ -132,6 +132,7 @@ protected:
|
|||
nsresult createTotalMessagesNode(nsIMsgFolder *folder, nsIRDFNode **target);
|
||||
nsresult createUnreadMessagesNode(nsIMsgFolder *folder, nsIRDFNode **target);
|
||||
nsresult createCharsetNode(nsIMsgFolder *folder, nsIRDFNode **target);
|
||||
nsresult createBiffStateNode(nsIMsgFolder *folder, nsIRDFNode **target);
|
||||
|
||||
nsresult createFolderChildNode(nsIMsgFolder *folder, nsIRDFNode **target);
|
||||
nsresult createFolderMessageNode(nsIMsgFolder *folder, nsIRDFNode **target);
|
||||
|
@ -153,6 +154,7 @@ protected:
|
|||
nsresult DoFolderHasAssertion(nsIMsgFolder *folder, nsIRDFResource *property, nsIRDFNode *target,
|
||||
PRBool tv, PRBool *hasAssertion);
|
||||
|
||||
nsresult GetBiffStateString(PRUint32 biffState, nsString& biffStateStr);
|
||||
|
||||
static nsIRDFResource* kNC_Child;
|
||||
static nsIRDFResource* kNC_MessageChild;
|
||||
|
@ -164,6 +166,7 @@ protected:
|
|||
static nsIRDFResource* kNC_TotalMessages;
|
||||
static nsIRDFResource* kNC_TotalUnreadMessages;
|
||||
static nsIRDFResource* kNC_Charset;
|
||||
static nsIRDFResource* kNC_BiffState;
|
||||
|
||||
// commands
|
||||
static nsIRDFResource* kNC_Delete;
|
||||
|
|
|
@ -0,0 +1,344 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#include "msgCore.h"
|
||||
#include "nsMsgNotificationManager.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "rdf.h"
|
||||
#include "nsIMsgMailSession.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "MailNewsTypes.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
|
||||
nsIRDFResource* nsMsgNotificationManager::kNC_FlashRoot = nsnull;
|
||||
nsIRDFResource* nsMsgNotificationManager::kNC_Type = nsnull;
|
||||
nsIRDFResource* nsMsgNotificationManager::kNC_Source = nsnull;
|
||||
nsIRDFResource* nsMsgNotificationManager::kNC_Description = nsnull;
|
||||
nsIRDFResource* nsMsgNotificationManager::kNC_TimeStamp = nsnull;
|
||||
nsIRDFResource* nsMsgNotificationManager::kNC_URL = nsnull;
|
||||
nsIRDFResource* nsMsgNotificationManager::kNC_Child = nsnull;
|
||||
|
||||
nsIRDFResource* nsMsgNotificationManager::kNC_NewMessages = nsnull;
|
||||
|
||||
|
||||
#define NC_RDF_FLASHROOT "NC:FlashRoot"
|
||||
#define NC_RDF_TYPE "http://home.netscape.com/NC-rdf#type"
|
||||
#define NC_RDF_SOURCE "http://home.netscape.com/NC-rdf#source"
|
||||
#define NC_RDF_DESCRIPTION "http://home.netscape.com/NC-rdf#description"
|
||||
#define NC_RDF_TIMESTAMP "http://home.netscape.com/NC-rdf#timestamp"
|
||||
#define NC_RDF_URL "http://home.netscape.com/NC-rdf#url"
|
||||
#define NC_RDF_CHILD "http://home.netscape.com/NC-rdf#child"
|
||||
|
||||
#define NC_RDF_NEWMESSAGES "http://home.netscape.com/NC-rdf#MsgNewMessages"
|
||||
|
||||
NS_BEGIN_EXTERN_C
|
||||
|
||||
nsresult
|
||||
NS_NewMsgNotificationManager(const nsIID& iid, void **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsMsgNotificationManager *notificationManager = new nsMsgNotificationManager();
|
||||
if(!notificationManager)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = notificationManager->Init();
|
||||
|
||||
if(!NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
return notificationManager->QueryInterface(iid, result);
|
||||
}
|
||||
|
||||
NS_END_EXTERN_C
|
||||
|
||||
nsMsgNotificationManager::nsMsgNotificationManager()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
}
|
||||
|
||||
nsMsgNotificationManager::~nsMsgNotificationManager()
|
||||
{
|
||||
NS_IF_RELEASE(kNC_FlashRoot);
|
||||
NS_IF_RELEASE(kNC_Type);
|
||||
NS_IF_RELEASE(kNC_Source);
|
||||
NS_IF_RELEASE(kNC_Description);
|
||||
NS_IF_RELEASE(kNC_TimeStamp);
|
||||
NS_IF_RELEASE(kNC_URL);
|
||||
NS_IF_RELEASE(kNC_Child);
|
||||
NS_IF_RELEASE(kNC_NewMessages);
|
||||
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsMsgNotificationManager)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgNotificationManager::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kISupportsIID))
|
||||
{
|
||||
*result = NS_STATIC_CAST(nsISupports*, this);
|
||||
}
|
||||
else if(iid.Equals(nsIFolderListener::GetIID()))
|
||||
{
|
||||
*result = NS_STATIC_CAST(nsIFolderListener*, this);
|
||||
}
|
||||
else if(iid.Equals(nsIRDFDataSource::GetIID()))
|
||||
{
|
||||
*result = mInMemoryDataSource;
|
||||
}
|
||||
|
||||
if(*result)
|
||||
{
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsMsgNotificationManager::Release()
|
||||
{
|
||||
|
||||
--mRefCnt;
|
||||
if (mRefCnt == 1 && mInMemoryDataSource) {
|
||||
mInMemoryDataSource = nsnull; /* nsCOMPtr triggers Release() */
|
||||
}
|
||||
else if (mRefCnt == 0) {
|
||||
delete this;
|
||||
}
|
||||
return mRefCnt;
|
||||
|
||||
}
|
||||
|
||||
nsresult nsMsgNotificationManager::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
|
||||
this,
|
||||
nsIRDFDataSource::GetIID(),
|
||||
getter_AddRefs(mInMemoryDataSource));
|
||||
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kMsgMailSessionCID, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
rv = mailSession->AddFolderListener(this);
|
||||
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (! kNC_FlashRoot)
|
||||
{
|
||||
rdfService->GetResource(NC_RDF_FLASHROOT, &kNC_FlashRoot);
|
||||
rdfService->GetResource(NC_RDF_TYPE, &kNC_Type);
|
||||
rdfService->GetResource(NC_RDF_SOURCE, &kNC_Source);
|
||||
rdfService->GetResource(NC_RDF_DESCRIPTION, &kNC_Description);
|
||||
rdfService->GetResource(NC_RDF_TIMESTAMP, &kNC_TimeStamp);
|
||||
rdfService->GetResource(NC_RDF_URL, &kNC_URL);
|
||||
rdfService->GetResource(NC_RDF_CHILD, &kNC_Child);
|
||||
rdfService->GetResource(NC_RDF_NEWMESSAGES, &kNC_NewMessages);
|
||||
}
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgNotificationManager::OnItemAdded(nsIFolder *parentFolder, nsISupports *item)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgNotificationManager::OnItemRemoved(nsIFolder *parentFolder, nsISupports *item)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgNotificationManager::OnItemPropertyChanged(nsISupports *item, const char *property, const char *oldValue, const char *newValue)
|
||||
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIMsgFolder> folder(do_QueryInterface(item));
|
||||
if(folder)
|
||||
{
|
||||
if(PL_strcmp("NumNewBiffMessages", property) == 0)
|
||||
{
|
||||
PRUint32 biffState;
|
||||
rv = folder->GetBiffState(&biffState);
|
||||
if(NS_SUCCEEDED(rv) && (biffState == nsMsgBiffState_NewMail))
|
||||
{
|
||||
rv = AddNewMailNotification(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgNotificationManager::OnItemPropertyFlagChanged(nsISupports *item, const char *property, PRUint32 oldFlag, PRUint32 newFlag)
|
||||
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIMsgFolder> folder(do_QueryInterface(item));
|
||||
if(folder)
|
||||
{
|
||||
if(PL_strcmp("BiffState", property) == 0)
|
||||
{
|
||||
if(newFlag == nsMsgBiffState_NewMail)
|
||||
{
|
||||
rv = AddNewMailNotification(folder);
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = RemoveNewMailNotification(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgNotificationManager::AddNewMailNotification(nsIMsgFolder *folder)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
//If there's currently a notification for this folder, remove it.
|
||||
RemoveNewMailNotification(folder);
|
||||
|
||||
|
||||
nsCOMPtr<nsIRDFResource> notificationResource;
|
||||
rv = rdfService->GetResource("newmail:test", getter_AddRefs(notificationResource));
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> type, source, description, timeStamp, url;
|
||||
nsString typeString, sourceString, descriptionString, timeStampString, urlString;
|
||||
|
||||
sourceString = "Messenger";
|
||||
descriptionString = "You have mail";
|
||||
timeStampString = "3:33pm";
|
||||
urlString = "test";
|
||||
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_Type, kNC_NewMessages, PR_TRUE);
|
||||
|
||||
PRUnichar* folderDescription;
|
||||
rv = folder->GetNewMessagesNotificationDescription(&folderDescription);
|
||||
if(NS_SUCCEEDED(rv) && folderDescription)
|
||||
{
|
||||
sourceString = folderDescription;
|
||||
PR_Free(folderDescription);
|
||||
}
|
||||
rv = rdfService->GetLiteral(sourceString.GetUnicode(), getter_AddRefs(source));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_Source, source, PR_TRUE);
|
||||
}
|
||||
|
||||
PRInt32 newMessages;
|
||||
rv = folder->GetNumNewMessages(&newMessages);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
char *str = PR_smprintf("%d new %s", newMessages, (newMessages == 1) ? "message" : "messages");
|
||||
descriptionString = str;
|
||||
PR_smprintf_free(str);
|
||||
}
|
||||
rv = rdfService->GetLiteral(descriptionString.GetUnicode(), getter_AddRefs(description));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_Description, description, PR_TRUE);
|
||||
}
|
||||
|
||||
//Supposedly rdf will convert this into a localized time string.
|
||||
time_t currentTime = time(nsnull);
|
||||
struct tm *localTime = localtime(¤tTime);
|
||||
timeStampString = asctime(localTime);
|
||||
rv = rdfService->GetLiteral(timeStampString.GetUnicode(), getter_AddRefs(timeStamp));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_TimeStamp, timeStamp, PR_TRUE);
|
||||
}
|
||||
|
||||
rv = rdfService->GetLiteral(urlString.GetUnicode(), getter_AddRefs(url));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mInMemoryDataSource->Assert(notificationResource, kNC_URL, url, PR_TRUE);
|
||||
}
|
||||
|
||||
mInMemoryDataSource->Assert(kNC_FlashRoot, kNC_Child, notificationResource, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgNotificationManager::RemoveNewMailNotification(nsIMsgFolder *folder)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> notificationResource;
|
||||
rv = rdfService->GetResource("newmail:test", getter_AddRefs(notificationResource));
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
RemoveOldValues(notificationResource);
|
||||
|
||||
mInMemoryDataSource->Unassert(kNC_FlashRoot, kNC_Child, notificationResource);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgNotificationManager::RemoveOldValues(nsIRDFResource *notificationResource)
|
||||
{
|
||||
nsCOMPtr<nsIRDFNode> target;
|
||||
nsresult rv;
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_Description, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_Description, target);
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_Type, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_Type, target);
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_Source, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_Source, target);
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_TimeStamp, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_TimeStamp, target);
|
||||
|
||||
rv = mInMemoryDataSource->GetTarget(notificationResource, kNC_URL, PR_TRUE, getter_AddRefs(target));
|
||||
if(NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))
|
||||
mInMemoryDataSource->Unassert(notificationResource, kNC_URL, target);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef NSMSGNOTIFICATION_H
|
||||
#define NSMSGNOTIFICATION_H
|
||||
|
||||
#include "nsIFolderListener.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIMsgFolder.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
|
||||
class nsMsgNotificationManager : public nsIFolderListener
|
||||
{
|
||||
public:
|
||||
|
||||
nsMsgNotificationManager();
|
||||
virtual ~nsMsgNotificationManager();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsresult Init();
|
||||
//nsIFolderListener
|
||||
NS_IMETHOD OnItemAdded(nsIFolder *parentFolder, nsISupports *item);
|
||||
NS_IMETHOD OnItemRemoved(nsIFolder *parentFolder, nsISupports *item);
|
||||
NS_IMETHOD OnItemPropertyChanged(nsISupports *item, const char *property, const char *oldValue, const char *newValue);
|
||||
NS_IMETHOD OnItemPropertyFlagChanged(nsISupports *item, const char *property, PRUint32 oldFlag, PRUint32 newFlag);
|
||||
|
||||
protected:
|
||||
nsresult AddNewMailNotification(nsIMsgFolder *folder);
|
||||
nsresult RemoveNewMailNotification(nsIMsgFolder *folder);
|
||||
nsresult RemoveOldValues(nsIRDFResource *notificationResource);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIRDFDataSource> mInMemoryDataSource;
|
||||
|
||||
static nsIRDFResource* kNC_FlashRoot;
|
||||
static nsIRDFResource* kNC_Type;
|
||||
static nsIRDFResource* kNC_Source;
|
||||
static nsIRDFResource* kNC_Description;
|
||||
static nsIRDFResource* kNC_TimeStamp;
|
||||
static nsIRDFResource* kNC_URL;
|
||||
static nsIRDFResource* kNC_Child;
|
||||
static nsIRDFResource* kNC_NewMessages;
|
||||
|
||||
};
|
||||
|
||||
NS_BEGIN_EXTERN_C
|
||||
|
||||
nsresult
|
||||
NS_NewMsgNotificationManager(const nsIID& iid, void **result);
|
||||
|
||||
NS_END_EXTERN_C
|
||||
|
||||
#endif
|
|
@ -46,6 +46,7 @@ typedef struct _nsMsgRDFNotification {
|
|||
#define NC_RDF_TOTALMESSAGES "http://home.netscape.com/NC-rdf#TotalMessages"
|
||||
#define NC_RDF_TOTALUNREADMESSAGES "http://home.netscape.com/NC-rdf#TotalUnreadMessages"
|
||||
#define NC_RDF_CHARSET "http://home.netscape.com/NC-rdf#Charset"
|
||||
#define NC_RDF_BIFFSTATE "http://home.netscape.com/NC-rdf#BiffState"
|
||||
|
||||
//Folder Commands
|
||||
#define NC_RDF_DELETE "http://home.netscape.com/NC-rdf#Delete"
|
||||
|
|
Загрузка…
Ссылка в новой задаче