From 70413c64452a14629d6d95aeaf53216f7a0ef3a1 Mon Sep 17 00:00:00 2001 From: "bienvenu%nventure.com" Date: Thu, 8 Jan 2004 18:46:46 +0000 Subject: [PATCH] fix rename of parent folder when one of the child folders has been opened in the ui, r/sr=mscott 209022 --- mailnews/base/util/nsMsgDBFolder.cpp | 26 +++++++++++++----- mailnews/db/msgdb/public/nsIMsgDatabase.idl | 7 ++--- mailnews/db/msgdb/src/nsMsgDatabase.cpp | 30 +++++++++++++++++++-- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/mailnews/base/util/nsMsgDBFolder.cpp b/mailnews/base/util/nsMsgDBFolder.cpp index 3c136c16cdd..46b9f21cb9c 100644 --- a/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mailnews/base/util/nsMsgDBFolder.cpp @@ -74,6 +74,7 @@ #include "nsIRDFService.h" #include "nsTextFormatter.h" #include "nsCPasswordManager.h" +#include "nsMsgDBCID.h" #include @@ -89,6 +90,7 @@ static PRTime gtimeOfLastPurgeCheck; //variable to know when to check for pur static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID); +static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID); nsIAtom* nsMsgDBFolder::mFolderLoadedAtom=nsnull; nsIAtom* nsMsgDBFolder::mDeleteOrMoveMsgCompletedAtom=nsnull; @@ -250,6 +252,13 @@ NS_IMETHODIMP nsMsgDBFolder::ForceDBClosed() mDatabase->ForceClosed(); mDatabase = nsnull; } + else + { + nsCOMPtr mailDBFactory; + nsresult rv = nsComponentManager::CreateInstance(kCMailDB, nsnull, NS_GET_IID(nsIMsgDatabase), (void **) getter_AddRefs(mailDBFactory)); + if (NS_SUCCEEDED(rv) && mailDBFactory) + mailDBFactory->ForceFolderDBClosed(this); + } return NS_OK; } @@ -3153,13 +3162,16 @@ void nsMsgDBFolder::ChangeNumPendingUnread(PRInt32 delta) mNumPendingUnreadMessages += delta; PRInt32 newUnreadMessages = mNumUnreadMessages + mNumPendingUnreadMessages; NS_ASSERTION(newUnreadMessages >= 0, "shouldn't have negative unread message count"); - nsCOMPtr db; - nsCOMPtr folderInfo; - nsresult rv = GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(db)); - if (NS_SUCCEEDED(rv) && folderInfo) - folderInfo->SetImapUnreadPendingMessages(mNumPendingUnreadMessages); + if (newUnreadMessages >= 0) + { + nsCOMPtr db; + nsCOMPtr folderInfo; + nsresult rv = GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(db)); + if (NS_SUCCEEDED(rv) && folderInfo) + folderInfo->SetImapUnreadPendingMessages(mNumPendingUnreadMessages); - NotifyIntPropertyChanged(kTotalUnreadMessagesAtom, oldUnreadMessages, newUnreadMessages); + NotifyIntPropertyChanged(kTotalUnreadMessagesAtom, oldUnreadMessages, newUnreadMessages); + } } } @@ -3660,7 +3672,7 @@ NS_IMETHODIMP nsMsgDBFolder::GetNumNewMessages(PRBool deep, PRInt32 *aNumNewMess { PRInt32 num; folder->GetNumNewMessages(deep, &num); - if (num >= 0) // it's legal for counts to be negative if we don't know + if (num > 0) // it's legal for counts to be negative if we don't know numNewMessages += num; } } diff --git a/mailnews/db/msgdb/public/nsIMsgDatabase.idl b/mailnews/db/msgdb/public/nsIMsgDatabase.idl index d00c1a3a73c..d0711602778 100644 --- a/mailnews/db/msgdb/public/nsIMsgDatabase.idl +++ b/mailnews/db/msgdb/public/nsIMsgDatabase.idl @@ -108,9 +108,10 @@ interface nsMsgDBCommitType [scriptable, uuid(9188bc83-f92e-11d2-81ef-0060083a0bcf)] interface nsIMsgDatabase : nsIDBChangeAnnouncer { - nsIMsgDatabase Open(in nsIFileSpec folderName, in boolean create, in boolean upgrading); - nsIMsgDatabase OpenFolderDB(in nsIMsgFolder folder, in boolean create, in boolean upgrading); - void Close(in boolean forceCommit); + nsIMsgDatabase Open(in nsIFileSpec aFolderName, in boolean aCreate, in boolean aUpgrading); + nsIMsgDatabase OpenFolderDB(in nsIMsgFolder aFolder, in boolean aCreate, in boolean aUpgrading); + void forceFolderDBClosed(in nsIMsgFolder aFolder); + void Close(in boolean aForceCommit); void Commit(in nsMsgDBCommit commitType); // Force closed is evil, and we should see if we can do without it. diff --git a/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mailnews/db/msgdb/src/nsMsgDatabase.cpp index 0fdbe01c4b5..a701a12fa1b 100644 --- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -63,6 +63,7 @@ #include "prprf.h" #include "nsTime.h" #include "nsIFileSpec.h" +#include "nsLocalFolderSummarySpec.h" #include "nsILocale.h" #include "nsLocaleCID.h" @@ -787,10 +788,10 @@ nsMsgDatabase::~nsMsgDatabase() if (m_mdbAllThreadsTable) m_mdbAllThreadsTable->Release(); + if (m_mdbStore) - { m_mdbStore->Release(); - } + if (m_mdbEnv) { m_mdbEnv->Release(); //??? is this right? @@ -1072,6 +1073,31 @@ nsresult nsMsgDatabase::CloseMDB(PRBool commit) return(NS_OK); } +NS_IMETHODIMP nsMsgDatabase::ForceFolderDBClosed(nsIMsgFolder *aFolder) +{ + NS_ENSURE_ARG(aFolder); + nsCOMPtr folderPath; + nsFileSpec folderName; + + nsresult rv = aFolder->GetPath(getter_AddRefs(folderPath)); + NS_ENSURE_SUCCESS(rv, rv); + folderPath->GetFileSpec(&folderName); + nsLocalFolderSummarySpec summarySpec(folderName); + + + nsFileSpec dbPath(summarySpec); + + nsIMsgDatabase *mailDB = (nsMsgDatabase *) FindInCache(dbPath); + if (mailDB) + { + mailDB->ForceClosed(); + //FindInCache AddRef's + mailDB->Release(); + } + return(NS_OK); + } + + // force the database to close - this'll flush out anybody holding onto // a database without having a listener! // This is evil in the com world, but there are times we need to delete the file.