Bug 806254 - Add back Growl support for TB / SM Aurora. r+a=mbanner
authorNomis101
Mon, 05 Nov 2012 20:40:29 +0100
changeset 12561 92762a5802d4324b4dff2bef951aa66a1bf15444
parent 12560 62f41d117099a2554f99390c13c8710e4739bde5
child 12562 030433ea8826ea937e4696f9e42c42b788d1e679
push id788
push userryanvm@gmail.com
push dateWed, 14 Nov 2012 02:11:07 +0000
treeherdercomm-aurora@92762a5802d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs806254
Bug 806254 - Add back Growl support for TB / SM Aurora. r+a=mbanner
mail/locales/en-US/chrome/messenger/messenger.properties
mailnews/base/src/nsMessengerOSXIntegration.mm
suite/locales/en-US/chrome/mailnews/messenger.properties
--- a/mail/locales/en-US/chrome/messenger/messenger.properties
+++ b/mail/locales/en-US/chrome/messenger/messenger.properties
@@ -470,16 +470,19 @@ copyToFolderAgainAccessKey=t
 #LOCALIZATION NOTE %1$S is the e-mail address of the person we will allow remote content for
 alwaysLoadRemoteContentForSender2= Always load remote content from %1$S
 
 #LOCALIZATION NOTE(mdnBarMessageNormal) %1$S is the name of the sender
 mdnBarMessageNormal=%1$S has asked to be notified when you read this message.
 #LOCALIZATION NOTE(mdnBarMessageAddressDiffers) %1$S is the name of the sender, %2$S is the address(es) to send return receipt to
 mdnBarMessageAddressDiffers=%1$S has asked to be notified (on %2$S) when you read this message.
 
+# Strings for growl notifications on Mac OS X
+growlNotification=New Mail
+
 # mailCommands.js
 emptyJunkTitle=Confirm
 emptyJunkMessage=Are you sure you want to permanently delete all messages and subfolders in the Junk folder?
 emptyJunkDontAsk=Don't ask me again.
 emptyTrashTitle=Confirm
 emptyTrashMessage=Are you sure you want to permanently delete all messages and subfolders in the Trash folder?
 emptyTrashDontAsk=Don't ask me again.
 
--- a/mailnews/base/src/nsMessengerOSXIntegration.mm
+++ b/mailnews/base/src/nsMessengerOSXIntegration.mm
@@ -27,16 +27,17 @@
 #include "nsIObserverService.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIMessengerWindowService.h"
 #include "prprf.h"
 #include "nsIAlertsService.h"
 #include "nsIStringBundle.h"
 #include "nsToolkitCompsCID.h"
+#include "nsINotificationsList.h"
 #include "nsIMsgDatabase.h"
 #include "nsIMsgHdr.h"
 #include "nsIMsgHeaderParser.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIWindowWatcher.h"
 #include "nsMsgLocalCID.h"
 #include "nsIMsgMailNewsUrl.h"
 #include "nsIMsgWindow.h"
@@ -177,19 +178,21 @@ NS_INTERFACE_MAP_BEGIN(nsMessengerOSXInt
    NS_INTERFACE_MAP_ENTRY(nsIObserver)
    NS_INTERFACE_MAP_ENTRY(mozINewMailListener)
 NS_INTERFACE_MAP_END
 
 
 nsresult
 nsMessengerOSXIntegration::Init()
 {
+  // need to register a named Growl notification
   nsresult rv;
   nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
+  observerService->AddObserver(this, "before-growl-registration", false);
   return observerService->AddObserver(this, "mail-startup-done", false);
 }
 
 NS_IMETHODIMP
 nsMessengerOSXIntegration::OnItemPropertyChanged(nsIMsgFolder *, nsIAtom *, char const *, char const *)
 {
   return NS_OK;
 }
@@ -245,16 +248,38 @@ nsMessengerOSXIntegration::Observe(nsISu
     // register with the mail sesson for folder events
     // we care about new count, biff status
     nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return mailSession->AddFolderListener(this, nsIFolderListener::boolPropertyChanged | nsIFolderListener::intPropertyChanged);
   }
 
+  // register named Growl notification for new mail alerts.
+  if (!strcmp(aTopic, "before-growl-registration"))
+  {
+    nsresult rv;
+    nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
+    if (NS_SUCCEEDED(rv))
+      observerService->RemoveObserver(this, "before-growl-registration");
+
+    nsCOMPtr<nsINotificationsList> notifications = do_QueryInterface(aSubject, &rv);
+    if (NS_SUCCEEDED(rv))
+    {
+      nsCOMPtr<nsIStringBundle> bundle;
+      GetStringBundle(getter_AddRefs(bundle));
+      if (bundle)
+      {
+        nsString growlNotification;
+        bundle->GetStringFromName(NS_LITERAL_STRING("growlNotification").get(), getter_Copies(growlNotification));
+        notifications->AddNotification(growlNotification, true);
+      }
+    }
+  }
+
   if (!strcmp(aTopic, kNewChatMessageTopic)) {
     // We don't have to bother about checking if the window is already focused
     // before attempting to bounce the dock icon, as BounceDockIcon is
     // implemented by a getAttention call which won't do anything if the window
     // requesting attention is already focused.
     return BounceDockIcon();
   }
 
@@ -377,24 +402,35 @@ nsMessengerOSXIntegration::ShowAlertMess
   nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool showAlert = true;
   prefBranch->GetBoolPref(kBiffShowAlertPref, &showAlert);
 
   if (showAlert)
   {
+    // Use growl if installed
     nsCOMPtr<nsIAlertsService> alertsService (do_GetService(NS_ALERTSERVICE_CONTRACTID, &rv));
-    // If we have an nsIAlertsService implementation, use it:
     if (NS_SUCCEEDED(rv))
     {
-      alertsService->ShowAlertNotification(NS_LITERAL_STRING(kNewMailAlertIcon),
-                                           aAlertTitle, aAlertText, true,
-                                           NS_ConvertASCIItoUTF16(aFolderURI),
-                                           this, EmptyString());
+      nsCOMPtr<nsIStringBundle> bundle;
+      GetStringBundle(getter_AddRefs(bundle));
+      if (bundle)
+      {
+        nsString growlNotification;
+        bundle->GetStringFromName(NS_LITERAL_STRING("growlNotification").get(),
+                                  getter_Copies(growlNotification));
+        rv = alertsService->ShowAlertNotification(NS_LITERAL_STRING(kNewMailAlertIcon),
+                                                  aAlertTitle,
+                                                  aAlertText,
+                                                  true,
+                                                  NS_ConvertASCIItoUTF16(aFolderURI),
+                                                  this,
+                                                  growlNotification);
+      }
     }
 
     BounceDockIcon();
   }
 
   if (!showAlert || NS_FAILED(rv))
     OnAlertFinished();
 
--- a/suite/locales/en-US/chrome/mailnews/messenger.properties
+++ b/suite/locales/en-US/chrome/mailnews/messenger.properties
@@ -385,16 +385,19 @@ confirmPhishingUrl2=%1$S thinks this web
 #LOCALIZATION NOTE %1$S is the e-mail address of the person we will allow remote content for
 alwaysLoadRemoteContentForSender=Click here to always load remote content from %1$S.
 
 #LOCALIZATION NOTE(mdnBarMessageNormal) %1$S is the name of the sender
 mdnBarMessageNormal=%1$S has asked to be notified when you read this message.
 #LOCALIZATION NOTE(mdnBarMessageAddressDiffers) %1$S is the name of the sender, %2$S is the address(es) to send return receipt to
 mdnBarMessageAddressDiffers=%1$S has asked to be notified at %2$S when you read this message.
 
+# Strings for growl notifications on Mac OS X
+growlNotification=New Mail
+
 # mailCommands.js
 emptyJunkTitle=Confirm
 emptyJunkMessage=Are you sure you want to permanently delete all messages and subfolders in the Junk folder?
 emptyJunkDontAsk=Don't ask me again.
 emptyTrashTitle=Confirm
 emptyTrashMessage=Are you sure you want to permanently delete all messages and subfolders in the Trash folder?
 emptyTrashDontAsk=Don't ask me again.