Bug 536048 Cannot distinguish the log for "Empty Trash" from folder deletion in Activity manager. r=bwinton,sr=Standard8,ui-review=clarkbw
authorMarcel Guzman <marcel@marcelguzman.com>
Sat, 20 Feb 2010 18:00:23 -0800
changeset 5417 ac77cab73bd17c29b56820593ffc0405e8af363a
parent 5416 1db689c775097ecac246301b8407488646a74b6a
child 5418 96ad66a27b32df1f790128cf7662262c344a98f8
push idunknown
push userunknown
push dateunknown
reviewersbwinton, Standard8
bugs536048
Bug 536048 Cannot distinguish the log for "Empty Trash" from folder deletion in Activity manager. r=bwinton,sr=Standard8,ui-review=clarkbw
mail/components/activity/modules/moveCopy.js
mail/locales/en-US/chrome/messenger/activity.properties
--- a/mail/components/activity/modules/moveCopy.js
+++ b/mail/components/activity/modules/moveCopy.js
@@ -44,28 +44,30 @@ const Ci = Components.interfaces;
 const Cr = Components.results;
 
 const nsActProcess = Components.Constructor("@mozilla.org/activity-process;1",
                                             "nsIActivityProcess", "init");
 const nsActEvent = Components.Constructor("@mozilla.org/activity-event;1",
                                           "nsIActivityEvent", "init");
 const nsActWarning = Components.Constructor("@mozilla.org/activity-warning;1",
                                             "nsIActivityWarning", "init");
+const nsMsgFolderFlags = Ci.nsMsgFolderFlags;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/PluralForm.jsm");
 Components.utils.import("resource:///modules/gloda/log4moz.js");
 
 
 
 // This module provides a link between the move/copy code and the activity
 // manager.
 let moveCopyModule =
 {
   lastMessage: {},
+  lastFolder: {},
 
   get log() {
     delete this.log;
     return this.log = Log4Moz.getConfiguredLogger("moveCopyModule");
   },
 
   get activityMgr() {
     delete this.activityMgr;
@@ -224,30 +226,41 @@ let moveCopyModule =
                             .getService(Components.interfaces.nsIMsgAccountManager);
     let server = aFolder.server;
     // If the account has been removed, we're going to ignore this notification.
     try {
       acctMgr.FindServer(server.username, server.hostName, server.type);
     }
     catch(ex) {return;}
 
-    let displayText = this.getString("deletedFolder").replace("#1", aFolder.prettiestName);
+    let displayText;
     let statusText = aFolder.server.prettyName;
+
+    // Display a different message depending on whether we emptied the trash
+    // or actually deleted a folder
+    if (aFolder.isSpecialFolder(nsMsgFolderFlags.Trash, false))
+      displayText = this.getString("emptiedTrash");
+    else
+      displayText = this.getString("deletedFolder").replace("#1", aFolder.prettiestName);
     
     // create an activity event
     let event = new nsActEvent(displayText,
                                aFolder.server,
                                statusText,
                                Date.now(),  // start time
                                Date.now()); // completion time
 
     event.addSubject(aFolder);
     event.iconClass = "deleteMail";
         
-    this.activityMgr.addActivity(event);
+    // When we rename, we get a delete event as well as a rename, so store
+    // the last folder we deleted
+    this.lastFolder = {};
+    this.lastFolder.URI = aFolder.URI;
+    this.lastFolder.event = this.activityMgr.addActivity(event);
   },
 
   folderMoveCopyCompleted: function(aMove, aSrcFolder, aDestFolder) {
     this.log.info("in folderMoveCopyCompleted, aMove = " + aMove);
 
     let displayText;
     if (aMove)
       displayText = this.getString("movedFolder");
@@ -281,21 +294,36 @@ let moveCopyModule =
 
     this.activityMgr.addActivity(event);
   },
 
   folderRenamed: function(aOrigFolder, aNewFolder) {
     this.log.info("in folderRenamed, aOrigFolder = "+ aOrigFolder.prettiestName+", aNewFolder = "+ 
              aNewFolder.prettiestName);
 
-    let displayText = this.getString("renamedFolder");
-    displayText = displayText.replace("#1", aOrigFolder.prettiestName);
-    displayText = displayText.replace("#2", aNewFolder.prettiestName);
+    let displayText;
+    let statusText = aNewFolder.server.prettyName;
 
-    let statusText = aNewFolder.server.prettyName;
+    // Display a different message depending on whether we moved the folder
+    // to the trash or actually renamed the folder.
+    if (aNewFolder.isSpecialFolder(nsMsgFolderFlags.Trash, true))
+    {
+      displayText = this.getString("movedFolderToTrash");
+      displayText = displayText.replace("#1", aOrigFolder.prettiestName);
+    }
+    else
+    {
+      displayText = this.getString("renamedFolder");
+      displayText = displayText.replace("#1", aOrigFolder.prettiestName);
+      displayText = displayText.replace("#2", aNewFolder.prettiestName);
+    }
+
+    // When renaming a folder, a delete event is always fired first
+    if (this.lastFolder.URI == aOrigFolder.URI)
+      this.activityMgr.removeActivity(this.lastFolder.event);
 
     // create an activity event
     let event = new nsActEvent(displayText,
                                aOrigFolder.server,
                                statusText,
                                Date.now(),  // start time
                                Date.now()); // completion time
 
--- a/mail/locales/en-US/chrome/messenger/activity.properties
+++ b/mail/locales/en-US/chrome/messenger/activity.properties
@@ -58,18 +58,21 @@ deletedMessages2=Deleted #1 message from
 # LOCALIZATION NOTE (movedMessages): #1 number of messages, #2 and #3: folder names
 movedMessages=Moved #1 message from #2 to #3;Moved #1 messages from #2 to #3
 # LOCALIZATION NOTE (copiedMessages): #1 number of messages, #2 and #3: folder names
 copiedMessages=Copied #1 message from #2 to #3;Copied #1 messages from #2 to #3
 # LOCALIZATION NOTE (fromServerToServer): #1 source server, #2 destination server
 fromServerToServer=from #1 to #2
 # LOCALIZATION NOTE (deletedFolder): #1 folder name
 deletedFolder=Deleted folder #1
+emptiedTrash=Emptied Trash
 # LOCALIZATION NOTE (movedFolder): #1 and #2 are folder names
 movedFolder=Moved folder #1 into folder #2
+# LOCALIZATION NOTE (movedFolderToTrash): #1 is the folder name
+movedFolderToTrash=Moved folder #1 to Trash
 # LOCALIZATION NOTE (copiedFolder): #1 and #2 are folder names
 copiedFolder=Copied folder #1 into folder #2
 # LOCALIZATION NOTE (renamedFolder): #1 and #2 are folder names
 renamedFolder=Renamed folder #1 to #2
 indexing=Indexing messages
 # LOCALIZATION NOTE (indexingFolder): #1 is a folder name
 indexingFolder=Indexing messages in #1
 indexingStatusVague=Determining which messages to index