From 9e2c1a9793f686544108716905480cf8c7e6a3a1 Mon Sep 17 00:00:00 2001 From: "naving%netscape.com" Date: Wed, 13 Feb 2002 01:46:37 +0000 Subject: [PATCH] 107598 r=racham sr=bienvenu. Imap folder creation is first done on server then on client so we need to notify filterEditor window that we are done with folder creation and then we can set the folder picker to new folder. Added SetBusyCursor for this action. Also remove alert code from imap and local and use existing "ThrowAlertMsg" in base. --- .../locale/en-US/messenger.properties | 1 + .../search/resources/content/FilterEditor.js | 88 ++++++++++++++++++- .../search/resources/content/FilterEditor.xul | 1 + .../locale/en-US/imapMsgs.properties | 4 - mailnews/imap/src/nsImapMailFolder.cpp | 52 ++++++----- mailnews/imap/src/nsImapMailFolder.h | 2 - mailnews/imap/src/nsImapStringBundle.h | 1 - .../locale/en-US/localMsgs.properties | 4 - mailnews/local/src/nsLocalMailFolder.cpp | 28 +----- mailnews/local/src/nsLocalMailFolder.h | 1 - mailnews/local/src/nsLocalStringBundle.h | 1 - 11 files changed, 114 insertions(+), 69 deletions(-) diff --git a/mailnews/base/resources/locale/en-US/messenger.properties b/mailnews/base/resources/locale/en-US/messenger.properties index 10cdccdad5bf..dfb2ef15176e 100644 --- a/mailnews/base/resources/locale/en-US/messenger.properties +++ b/mailnews/base/resources/locale/en-US/messenger.properties @@ -65,6 +65,7 @@ downloadingNewsgroups=Downloading Newsgroups for Offline Use downloadingMail=Downloading Mail for Offline Use sendingUnsent=Sending Unsent Messages +folderExists=A folder with that name already exists. Please enter a different name. compactingFolder=Compacting folder %S... autoCompactAllFolders=Do you wish to compact all local and offline folders to save disk space? confirmFolderDeletionForFilter=Deleting the folder '%S' will disable its associated filter(s). Are you sure you want to delete the folder? diff --git a/mailnews/base/search/resources/content/FilterEditor.js b/mailnews/base/search/resources/content/FilterEditor.js index ca01a041ef5f..bf88520e0a82 100644 --- a/mailnews/base/search/resources/content/FilterEditor.js +++ b/mailnews/base/search/resources/content/FilterEditor.js @@ -52,6 +52,7 @@ var gPreFillName; var nsMsgSearchScope = Components.interfaces.nsMsgSearchScope; var gPref; var gPrefBranch; +var gMailSession = null; var nsMsgFilterAction = Components.interfaces.nsMsgFilterAction; @@ -129,6 +130,12 @@ function filterEditorOnLoad() moveToAlertPosition(); } +function filterEditorOnUnload() +{ + if (gMailSession) + gMailSession.RemoveFolderListener(gFolderListener); +} + function onEnterInSearchTerm() { // do nothing. onOk() will get called since this is a dialog @@ -169,6 +176,36 @@ function onCancel() return true; } + +// the folderListener object +var gFolderListener = { + OnItemAdded: function(parentItem, item, view) {}, + + OnItemRemoved: function(parentItem, item, view){}, + + OnItemPropertyChanged: function(item, property, oldValue, newValue) {}, + + OnItemIntPropertyChanged: function(item, property, oldValue, newValue) {}, + + OnItemBoolPropertyChanged: function(item, property, oldValue, newValue) {}, + + OnItemUnicharPropertyChanged: function(item, property, oldValue, newValue){}, + OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {}, + + OnItemEvent: function(folder, event) { + var eventType = event.GetUnicode(); + + if (eventType == "FolderCreateCompleted") { + SetFolderPicker(folder.URI, gActionTargetElement.id); + SetBusyCursor(window, false); + } + else if (eventType == "FolderCreateFailed") { + SetBusyCursor(window, false); + } + + } +} + function duplicateFilterNameExists(filterName) { var args = window.arguments[0]; @@ -433,18 +470,49 @@ function GetFirstSelectedMsgFolder() function SearchNewFolderOkCallback(name,uri) { - var msgFolder = GetMsgFolderFromUri(uri, true); - var msgWindow = GetFilterEditorMsgWindow(); - msgFolder.createSubfolder(name, msgWindow); + var msgFolder = GetMsgFolderFromUri(uri, true); + var imapFolder = null; + try + { + imapFolder = msgFolder.QueryInterface(Components.interfaces.nsIMsgImapMailFolder); + } + catch(ex) {} + var mailSessionContractID = "@mozilla.org/messenger/services/session;1"; + if (imapFolder) //imapFolder creation is asynchronous. + { + if (!gMailSession) + gMailSession = Components.classes[mailSessionContractID].getService(Components.interfaces.nsIMsgMailSession); + try + { + var nsIFolderListener = Components.interfaces.nsIFolderListener; + var notifyFlags = nsIFolderListener.event; + gMailSession.AddFolderListener(gFolderListener, notifyFlags); + } + catch (ex) + { + dump("Error adding to session: " +ex + "\n"); + } + } + var msgWindow = GetFilterEditorMsgWindow(); + + if (imapFolder) + SetBusyCursor(window, true); + + msgFolder.createSubfolder(name, msgWindow); + + if (!imapFolder) + { var curFolder = uri+"/"+name; SetFolderPicker(curFolder, gActionTargetElement.id); + } } function UpdateAfterCustomHeaderChange() { updateSearchAttributes(); } + //if you use msgWindow, please make sure that destructor gets called when you close the "window" function GetFilterEditorMsgWindow() { @@ -457,3 +525,17 @@ function GetFilterEditorMsgWindow() } return gFilterEditorMsgWindow; } + +function SetBusyCursor(window, enable) +{ + // setCursor() is only available for chrome windows. + // However one of our frames is the start page which + // is a non-chrome window, so check if this window has a + // setCursor method + if ("setCursor" in window) { + if (enable) + window.setCursor("wait"); + else + window.setCursor("auto"); + } +} diff --git a/mailnews/base/search/resources/content/FilterEditor.xul b/mailnews/base/search/resources/content/FilterEditor.xul index 13f6ac8f24cc..0481891c9197 100644 --- a/mailnews/base/search/resources/content/FilterEditor.xul +++ b/mailnews/base/search/resources/content/FilterEditor.xul @@ -39,6 +39,7 @@ Contributor(s): width="510" height="360" persist="width height screenX screenY" onload="filterEditorOnLoad();" + onunload="filterEditorOnUnload();" ondialogaccept="return onAccept();" ondialogcancel="return onCancel();"> diff --git a/mailnews/imap/resources/locale/en-US/imapMsgs.properties b/mailnews/imap/resources/locale/en-US/imapMsgs.properties index 1ac98fec2917..e91be9bf4626 100644 --- a/mailnews/imap/resources/locale/en-US/imapMsgs.properties +++ b/mailnews/imap/resources/locale/en-US/imapMsgs.properties @@ -293,10 +293,6 @@ ## @loc None 5058=Deleting this folder is not undoable and will delete all of the messages it contains. Are you sure you still want to delete this folder? -## @name IMAP_MAILBOX_ALREADY_EXISTS -## @loc None -5061=The mailbox already exists. - ## @name IMAP_PERSONAL_FILING_CABINET ## @loc None 5062=Personal Filing Cabinet diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 36d1661a5f37..4cab4eb03e7d 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -708,44 +708,26 @@ NS_IMETHODIMP nsImapMailFolder::GetMessages(nsIMsgWindow *aMsgWindow, nsISimpleE NS_IMETHODIMP nsImapMailFolder::CreateSubfolder(const PRUnichar* folderName, nsIMsgWindow *msgWindow ) { nsresult rv = NS_ERROR_NULL_POINTER; - if (!folderName) return rv; + if (!folderName) + return rv; if ( nsDependentString(folderName).Equals(NS_LITERAL_STRING("Trash"),nsCaseInsensitiveStringComparator()) ) // Trash , a special folder { - AlertSpecialFolderExists(msgWindow); + ThrowAlertMsg("folderExists", msgWindow); return NS_MSG_FOLDER_EXISTS; } else if ( nsDependentString(folderName).Equals(NS_LITERAL_STRING("Inbox"),nsCaseInsensitiveStringComparator()) ) // Inbox, a special folder { - AlertSpecialFolderExists(msgWindow); + ThrowAlertMsg("folderExists", msgWindow); return NS_MSG_FOLDER_EXISTS; } nsCOMPtr imapService(do_GetService(kCImapService, &rv)); if (NS_SUCCEEDED(rv)) + { rv = imapService->CreateFolder(m_eventQueue, this, folderName, this, nsnull); - return rv; -} - -nsresult -nsImapMailFolder::AlertSpecialFolderExists(nsIMsgWindow *msgWindow) -{ - nsresult rv = NS_OK; - nsCOMPtr docShell; - msgWindow->GetRootDocShell(getter_AddRefs(docShell)); - nsXPIDLString alertString; - IMAPGetStringByID(IMAP_MAILBOX_ALREADY_EXISTS, getter_Copies(alertString)); - if (!alertString) return rv; - if (docShell) - { - nsCOMPtr dialog(do_GetInterface(docShell)); - if (dialog) - { - rv = dialog->Alert(nsnull, alertString); - return rv; - } - } + } return rv; } @@ -869,6 +851,7 @@ NS_IMETHODIMP nsImapMailFolder::CreateClientSubfolderInfo(const char *folderName unusedDB->Close(PR_TRUE); } } + nsCOMPtr folderCreateAtom; if(NS_SUCCEEDED(rv) && child) { nsCOMPtr childSupports(do_QueryInterface(child)); @@ -876,10 +859,16 @@ NS_IMETHODIMP nsImapMailFolder::CreateClientSubfolderInfo(const char *folderName rv = QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(folderSupports)); if(childSupports && NS_SUCCEEDED(rv)) { - NotifyItemAdded(folderSupports, childSupports, "folderView"); + folderCreateAtom = getter_AddRefs(NS_NewAtom("FolderCreateCompleted")); + child->NotifyFolderEvent(folderCreateAtom); } } + else + { + folderCreateAtom = getter_AddRefs(NS_NewAtom("FolderCreateFailed")); + NotifyFolderEvent(folderCreateAtom); + } return rv; } @@ -4298,11 +4287,19 @@ nsImapMailFolder::OnStopRunningUrl(nsIURI *aUrl, nsresult aExitCode) } break; - case nsIImapUrl::nsImapRefreshFolderUrls: - // we finished getting an admin url for the folder. + case nsIImapUrl::nsImapRefreshFolderUrls: + // we finished getting an admin url for the folder. if (!m_adminUrl.IsEmpty()) FolderPrivileges(aWindow); break; + case nsIImapUrl::nsImapCreateFolder: + if (NS_FAILED(aExitCode)) //if success notification already done + { + nsCOMPtr folderCreateAtom; + folderCreateAtom = getter_AddRefs(NS_NewAtom("FolderCreateFailed")); + NotifyFolderEvent(folderCreateAtom); + } + break; default: break; } @@ -6703,6 +6700,7 @@ NS_IMETHODIMP nsImapMailFolder::RenameClient(nsIMsgWindow *msgWindow, nsIMsgFold nsCOMPtr childSupports(do_QueryInterface(child)); nsCOMPtr parentSupports; rv = QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(parentSupports)); + if(childSupports && NS_SUCCEEDED(rv)) { NotifyItemAdded(parentSupports, childSupports, "folderView"); diff --git a/mailnews/imap/src/nsImapMailFolder.h b/mailnews/imap/src/nsImapMailFolder.h index 0ad1b657e580..200ce71c73b3 100644 --- a/mailnews/imap/src/nsImapMailFolder.h +++ b/mailnews/imap/src/nsImapMailFolder.h @@ -359,8 +359,6 @@ public: protected: // Helper methods - nsresult AlertSpecialFolderExists(nsIMsgWindow *msgWindow); - void FindKeysToAdd(const nsMsgKeyArray &existingKeys, nsMsgKeyArray &keysToFetch, nsIImapFlagAndUidState *flagState); void FindKeysToDelete(const nsMsgKeyArray &existingKeys, nsMsgKeyArray diff --git a/mailnews/imap/src/nsImapStringBundle.h b/mailnews/imap/src/nsImapStringBundle.h index ebe746db8ee7..1cbd5ef3bf1c 100644 --- a/mailnews/imap/src/nsImapStringBundle.h +++ b/mailnews/imap/src/nsImapStringBundle.h @@ -102,7 +102,6 @@ NS_END_EXTERN_C #define IMAP_DELETE_NO_TRASH 5058 #define IMAP_HTML_NO_CACHED_BODY_TITLE 5059 #define IMAP_HTML_NO_CACHED_BODY_BODY 5060 -#define IMAP_MAILBOX_ALREADY_EXISTS 5061 #define IMAP_PERSONAL_FILING_CABINET 5062 #define IMAP_PFC_READ_MAIL 5063 #define IMAP_PFC_SENT_MAIL 5064 diff --git a/mailnews/local/resources/locale/en-US/localMsgs.properties b/mailnews/local/resources/locale/en-US/localMsgs.properties index a81355c84688..fe3ef008da2d 100644 --- a/mailnews/local/resources/locale/en-US/localMsgs.properties +++ b/mailnews/local/resources/locale/en-US/localMsgs.properties @@ -167,10 +167,6 @@ ## @loc None 4021=Are you sure you want to move the selected folder into the Trash? -## @name POP3_FOLDER_ALREADY_EXISTS -## @loc None -4022=A folder with that name already exists. - ## @name POP3_FOLDER_FOR_TRASH ## @loc None 4023=The Trash already contained a folder named %s. The folder which you just deleted can be found in the Trash under the new name %s. diff --git a/mailnews/local/src/nsLocalMailFolder.cpp b/mailnews/local/src/nsLocalMailFolder.cpp index 0062841a3b8c..c1517aa8cafb 100644 --- a/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mailnews/local/src/nsLocalMailFolder.cpp @@ -763,30 +763,6 @@ NS_IMETHODIMP nsMsgLocalMailFolder::CreateStorageIfMissing(nsIUrlListener* urlLi return status; } -nsresult -nsMsgLocalMailFolder::AlertFolderExists(nsIMsgWindow *msgWindow) -{ - nsresult rv = NS_OK; - nsCOMPtr docShell; - msgWindow->GetRootDocShell(getter_AddRefs(docShell)); - if (!mMsgStringService) - mMsgStringService = do_GetService(NS_MSG_POPSTRINGSERVICE_CONTRACTID); - if (!mMsgStringService) return NS_ERROR_FAILURE; - PRUnichar *alertString = nsnull; - mMsgStringService->GetStringByID(POP3_FOLDER_ALREADY_EXISTS, &alertString); - if (!alertString) return rv; - if (docShell) - { - nsCOMPtr dialog(do_GetInterface(docShell)); - if (dialog) - { - rv = dialog->Alert(nsnull, alertString); - return rv; - } - } - return rv; -} - nsresult nsMsgLocalMailFolder::CheckIfFolderExists(const PRUnichar *folderName, nsFileSpec &path, nsIMsgWindow *msgWindow) { @@ -805,7 +781,7 @@ nsMsgLocalMailFolder::CheckIfFolderExists(const PRUnichar *folderName, nsFileSpe nsCaseInsensitiveStringComparator())) { if (msgWindow) - AlertFolderExists(msgWindow); + ThrowAlertMsg("folderExists", msgWindow); return NS_MSG_FOLDER_EXISTS; } } @@ -1265,7 +1241,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Rename(const PRUnichar *aNewName, nsIMsgWind if (PL_strcasecmp(oldLeafName, convertedNewName) == 0) { if(msgWindow) - rv=AlertFolderExists(msgWindow); + rv=ThrowAlertMsg("folderExists", msgWindow); return NS_MSG_FOLDER_EXISTS; } else diff --git a/mailnews/local/src/nsLocalMailFolder.h b/mailnews/local/src/nsLocalMailFolder.h index 67539b07a573..a9fc321975fc 100644 --- a/mailnews/local/src/nsLocalMailFolder.h +++ b/mailnews/local/src/nsLocalMailFolder.h @@ -178,7 +178,6 @@ protected: nsresult WriteStartOfNewMessage(); nsresult IsChildOfTrash(PRBool *result); nsresult RecursiveSetDeleteIsMoveTrash(PRBool bVal); - nsresult AlertFolderExists(nsIMsgWindow *msgWindow); nsresult CheckIfFolderExists(const PRUnichar *folderName, nsFileSpec &path, nsIMsgWindow *msgWindow); diff --git a/mailnews/local/src/nsLocalStringBundle.h b/mailnews/local/src/nsLocalStringBundle.h index d39b3bb2899c..15caa8512913 100644 --- a/mailnews/local/src/nsLocalStringBundle.h +++ b/mailnews/local/src/nsLocalStringBundle.h @@ -79,7 +79,6 @@ private: #define POP3_NO_ANSWER 4019 #define POP3_ENTER_PASSWORD_PROMPT_TITLE 4020 #define POP3_MOVE_FOLDER_TO_TRASH 4021 -#define POP3_FOLDER_ALREADY_EXISTS 4022 #define POP3_FOLDER_FOR_TRASH 4023 #define POP3_STAT_FAILURE 4024 #define POP3_SERVER_SAID 4025