Bug 689992 - Improve status bar text when compacting folders: display account name too. r=Neil,jorgk
authorSuyash Agarwal <syshagarwal@gmail.com>
Sun, 26 Mar 2017 01:20:00 +0100
changeset 21345 92ed8653017e7e7ae522997a1d9b0607282b4bfb
parent 21344 bc7105f7a94e60be9e498932925ef9795f311358
child 21346 c30484eedecc8d09f2e6158fa4b85c957cee84da
push id12979
push usermozilla@jorgk.com
push dateMon, 27 Mar 2017 06:33:53 +0000
treeherdercomm-central@c30484eedecc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil, jorgk
bugs689992
Bug 689992 - Improve status bar text when compacting folders: display account name too. r=Neil,jorgk
mailnews/base/src/nsMsgFolderCompactor.cpp
--- a/mailnews/base/src/nsMsgFolderCompactor.cpp
+++ b/mailnews/base/src/nsMsgFolderCompactor.cpp
@@ -66,16 +66,28 @@ nsFolderCompactState::~nsFolderCompactSt
   CloseOutputStream();
   if (NS_FAILED(m_status))
   {
     CleanupTempFilesAfterError();
     // if for some reason we failed remove the temp folder and database
   }
 }
 
+nsresult
+GetBaseStringBundle(nsIStringBundle **aBundle)
+{
+  NS_ENSURE_ARG_POINTER(aBundle);
+  nsCOMPtr<nsIStringBundleService> bundleService =
+    mozilla::services::GetStringBundleService();
+  NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
+  nsCOMPtr<nsIStringBundle> bundle;
+  return bundleService->CreateBundle(
+    "chrome://messenger/locale/messenger.properties", aBundle);
+}
+
 void nsFolderCompactState::CloseOutputStream()
 {
   if (m_fileStream)
   {
     m_fileStream->Close();
     m_fileStream = nullptr;
   }
 
@@ -301,24 +313,48 @@ nsFolderCompactState::Compact(nsIMsgFold
   if (m_compactAll)
     return CompactNextFolder();
   else
     return NS_OK;
 }
 
 nsresult nsFolderCompactState::ShowStatusMsg(const nsString& aMsg)
 {
-  nsCOMPtr <nsIMsgStatusFeedback> statusFeedback;
-  if (m_window)
-  {
-    m_window->GetStatusFeedback(getter_AddRefs(statusFeedback));
-    if (statusFeedback && !aMsg.IsEmpty())
-      return statusFeedback->SetStatusString(aMsg);
-  }
-  return NS_OK;
+  if (!m_window || aMsg.IsEmpty())
+    return NS_OK;
+
+  nsCOMPtr<nsIMsgStatusFeedback> statusFeedback;
+  nsresult rv = m_window->GetStatusFeedback(getter_AddRefs(statusFeedback));
+  if (NS_FAILED(rv) || !statusFeedback)
+    return NS_OK;
+
+  // Try to prepend account name to the message.
+  nsString statusMessage;
+  do {
+    nsCOMPtr<nsIMsgIncomingServer> server;
+    rv = m_folder->GetServer(getter_AddRefs(server));
+    if (NS_FAILED(rv))
+      break;
+    nsAutoString accountName;
+    rv = server->GetPrettyName(accountName);
+    if (NS_FAILED(rv))
+      break;
+    nsCOMPtr<nsIStringBundle> bundle;
+    rv = GetBaseStringBundle(getter_AddRefs(bundle));
+    if (NS_FAILED(rv))
+      break;
+    const char16_t *params[] = { accountName.get(), aMsg.get() };
+    rv = bundle->FormatStringFromName(u"statusMessage",
+                                      params, 2, getter_Copies(statusMessage));
+  } while (false);
+
+  // If fetching any of the needed info failed, just show the original message.
+  if (NS_FAILED(rv))
+    statusMessage.Assign(aMsg);
+  return statusFeedback->SetStatusString(statusMessage);
 }
 
 nsresult
 nsFolderCompactState::Init(nsIMsgFolder *folder, const char *baseMsgUri, nsIMsgDatabase *db,
                            nsIFile *path, nsIMsgWindow *aMsgWindow)
 {
   nsresult rv;
 
@@ -611,27 +647,16 @@ nsFolderCompactState::FinishCompact()
   if (m_compactAll)
     rv = CompactNextFolder();
   else
     CompactCompleted(rv);
       
   return rv;
 }
 
-nsresult
-GetBaseStringBundle(nsIStringBundle **aBundle)
-{
-  NS_ENSURE_ARG_POINTER(aBundle);
-  nsCOMPtr<nsIStringBundleService> bundleService =
-    mozilla::services::GetStringBundleService();
-  NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
-  nsCOMPtr<nsIStringBundle> bundle;
-  return bundleService->CreateBundle(
-    "chrome://messenger/locale/messenger.properties", aBundle);
-}
 
 void nsFolderCompactState::CompactCompleted(nsresult exitCode)
 {
   NS_WARNING_ASSERTION(NS_SUCCEEDED(exitCode),
                        "nsFolderCompactState::CompactCompleted failed");
   if (m_listener)
     m_listener->OnStopRunningUrl(nullptr, exitCode);
   ShowDoneStatus();