From b7cf1a507516acbdbe31bc976a6a204138cba1b4 Mon Sep 17 00:00:00 2001 From: "scott%scott-macgregor.org" Date: Tue, 23 Nov 2004 06:39:47 +0000 Subject: [PATCH] Bug #267865 --> Virtual folders parented off of IMAP sub folders are forgotten on subsequent launches. Call LoadVirtualFolders after our folder hierarchy has been created in the UI. sr=bienvenu --- mail/base/content/msgMail3PaneWindow.js | 1 + mailnews/base/public/nsIMsgAccountManager.idl | 2 ++ .../resources/content/msgMail3PaneWindow.js | 1 + mailnews/base/src/nsMsgAccountManager.cpp | 18 ++++++++++++------ mailnews/base/src/nsMsgAccountManager.h | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/mail/base/content/msgMail3PaneWindow.js b/mail/base/content/msgMail3PaneWindow.js index 1988de9b7331..2425ab9b155e 100644 --- a/mail/base/content/msgMail3PaneWindow.js +++ b/mail/base/content/msgMail3PaneWindow.js @@ -786,6 +786,7 @@ function delayedOnLoadMessenger() InitPanes(); accountManager.setSpecialFolders(); + accountManager.loadVirtualFolders(); accountManager.addIncomingServerListener(gThreePaneIncomingServerListener); AddToSession(); diff --git a/mailnews/base/public/nsIMsgAccountManager.idl b/mailnews/base/public/nsIMsgAccountManager.idl index 76136a987331..bdd833de33a0 100644 --- a/mailnews/base/public/nsIMsgAccountManager.idl +++ b/mailnews/base/public/nsIMsgAccountManager.idl @@ -176,6 +176,8 @@ interface nsIMsgAccountManager : nsISupports { void setSpecialFolders(); + void loadVirtualFolders(); + /* unload accounts frees all the account manager data structures */ void UnloadAccounts(); diff --git a/mailnews/base/resources/content/msgMail3PaneWindow.js b/mailnews/base/resources/content/msgMail3PaneWindow.js index 73e089abdf02..5e4042dbe59e 100644 --- a/mailnews/base/resources/content/msgMail3PaneWindow.js +++ b/mailnews/base/resources/content/msgMail3PaneWindow.js @@ -669,6 +669,7 @@ function OnLoadMessenger() InitPanes(); accountManager.setSpecialFolders(); + accountManager.loadVirtualFolders(); accountManager.addIncomingServerListener(gThreePaneIncomingServerListener); AddToSession(); diff --git a/mailnews/base/src/nsMsgAccountManager.cpp b/mailnews/base/src/nsMsgAccountManager.cpp index ac98fcdc7c97..b6e38856a090 100644 --- a/mailnews/base/src/nsMsgAccountManager.cpp +++ b/mailnews/base/src/nsMsgAccountManager.cpp @@ -162,7 +162,8 @@ nsMsgAccountManager::nsMsgAccountManager() : m_cleanupInboxInProgress(PR_FALSE), m_haveShutdown(PR_FALSE), m_shutdownInProgress(PR_FALSE), - m_userAuthenticated(PR_FALSE) + m_userAuthenticated(PR_FALSE), + m_loadingVirtualFolders(PR_FALSE) { } @@ -1457,8 +1458,6 @@ nsMsgAccountManager::LoadAccounts() token = nsCRT::strtok(newStr, ",", &newStr); } - - LoadVirtualFolders(); nsCOMPtr mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) @@ -2827,13 +2826,15 @@ nsresult nsMsgAccountManager::GetVirtualFoldersFile(nsCOMPtr& file return rv; } -nsresult nsMsgAccountManager::LoadVirtualFolders() +NS_IMETHODIMP nsMsgAccountManager::LoadVirtualFolders() { nsCOMPtr file; GetVirtualFoldersFile(file); if (!file) return NS_ERROR_FAILURE; + m_loadingVirtualFolders = PR_TRUE; + nsresult rv; nsCOMPtr msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv); if (msgDBService) @@ -2895,9 +2896,11 @@ nsresult nsMsgAccountManager::LoadVirtualFolders() rv = db->GetDBFolderInfo(getter_AddRefs(dbFolderInfo)); else continue; - rv = parentFolder->AddSubfolder(currentFolderNameStr, getter_AddRefs(childFolder)); + parentFolder->AddSubfolder(currentFolderNameStr, getter_AddRefs(childFolder)); virtualFolder->SetFlag(MSG_FOLDER_FLAG_VIRTUAL); + if (childFolder) + parentFolder->NotifyItemAdded(childFolder); } } } @@ -2940,6 +2943,9 @@ nsresult nsMsgAccountManager::LoadVirtualFolders() } } } + + m_loadingVirtualFolders = PR_FALSE; + return rv; } @@ -3036,7 +3042,7 @@ NS_IMETHODIMP nsMsgAccountManager::OnItemAdded(nsIRDFResource *parentItem, nsISu folder->GetFlags(&folderFlags); nsresult rv = NS_OK; // need to make sure this isn't happening during loading of virtualfolders.dat - if (folderFlags & MSG_FOLDER_FLAG_VIRTUAL) + if (folderFlags & MSG_FOLDER_FLAG_VIRTUAL && !m_loadingVirtualFolders) { // When a new virtual folder is added, need to create a db Listener for it. nsCOMPtr msgDBService = do_GetService(NS_MSGDB_SERVICE_CONTRACTID, &rv); diff --git a/mailnews/base/src/nsMsgAccountManager.h b/mailnews/base/src/nsMsgAccountManager.h index 77e3dd9ff149..6bae9c4ac179 100644 --- a/mailnews/base/src/nsMsgAccountManager.h +++ b/mailnews/base/src/nsMsgAccountManager.h @@ -101,6 +101,7 @@ private: PRBool m_haveShutdown; PRBool m_shutdownInProgress; PRBool m_userAuthenticated; + PRBool m_loadingVirtualFolders; /* we call FindServer() a lot. so cache the last server found */ nsCOMPtr m_lastFindServerResult; @@ -203,7 +204,6 @@ private: // handle virtual folders nsresult GetVirtualFoldersFile(nsCOMPtr& file); - nsresult LoadVirtualFolders(); nsresult WriteLineToOutputStream(const char *prefix, const char * line, nsIOutputStream *outputStream); static void getUniqueKey(const char* prefix,