Bug 478463 - Add libnotify (+ libindicate) support to Thunderbird. r=standard8
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 08 Mar 2010 11:57:37 +0900
changeset 5100 5c4928d99bad
parent 5099 9cd2ab3fc5e5
child 5101 1bdaa5d0b1cf
push id3951
push userm_kato@ga2.so-net.ne.jp
push date2010-03-08 03:04 +0000
treeherdercomm-central@5c4928d99bad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs478463
Bug 478463 - Add libnotify (+ libindicate) support to Thunderbird. r=standard8
mailnews/base/src/nsMessengerUnixIntegration.cpp
mailnews/base/src/nsMessengerUnixIntegration.h
--- a/mailnews/base/src/nsMessengerUnixIntegration.cpp
+++ b/mailnews/base/src/nsMessengerUnixIntegration.cpp
@@ -157,17 +157,16 @@ nsresult nsMessengerUnixIntegration::Get
   nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
   nsCOMPtr<nsIStringBundle> bundle;
   if (bundleService && NS_SUCCEEDED(rv))
     bundleService->CreateBundle("chrome://messenger/locale/messenger.properties", getter_AddRefs(bundle));
   bundle.swap(*aBundle);
   return rv;
 }
 
-#ifndef MOZ_THUNDERBIRD
 nsresult nsMessengerUnixIntegration::ShowAlertMessage(const nsAString& aAlertTitle, const nsAString& aAlertText, const nsACString& aFolderURI)
 {
   nsresult rv;
   
   // if we are already in the process of showing an alert, don't try to show another....
   if (mAlertInProgress) 
     return NS_OK; 
 
@@ -190,106 +189,28 @@ nsresult nsMessengerUnixIntegration::Sho
     }
   }
 
   if (!showAlert || NS_FAILED(rv)) // go straight to showing the system tray icon.
     AlertFinished();
 
   return rv;
 }
-#else
-// Opening Thunderbird's new mail alert notification window
-// aUserInitiated --> true if we are opening the alert notification in response to a user action
-//                    like clicking on the biff icon
-nsresult nsMessengerUnixIntegration::ShowNewAlertNotification(PRBool aUserInitiated)
-{
-  nsresult rv;
-
-  // if we are already in the process of showing an alert, don't try to show another....
-  if (mAlertInProgress)
-    return NS_OK;
-
-  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRBool showAlert = PR_TRUE;
-  prefBranch->GetBoolPref(SHOW_ALERT_PREF, &showAlert);
-
-  if (showAlert)
-  {
-    nsCOMPtr<nsISupportsArray> argsArray;
-    rv = NS_NewISupportsArray(getter_AddRefs(argsArray));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // pass in the array of folders with unread messages
-    nsCOMPtr<nsISupportsInterfacePointer> ifptr = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-    ifptr->SetData(mFoldersWithNewMail);
-    ifptr->SetDataIID(&NS_GET_IID(nsISupportsArray));
-    argsArray->AppendElement(ifptr);
-
-    // pass in the observer
-    ifptr = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-    nsCOMPtr <nsISupports> supports = do_QueryInterface(static_cast<nsIMessengerOSIntegration*>(this));
-    ifptr->SetData(supports);
-    ifptr->SetDataIID(&NS_GET_IID(nsIObserver));
-    argsArray->AppendElement(ifptr);
-
-    // pass in the animation flag
-    nsCOMPtr<nsISupportsPRBool> scriptableUserInitiated (do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID, &rv));
-    NS_ENSURE_SUCCESS(rv, rv);
-    scriptableUserInitiated->SetData(aUserInitiated);
-    argsArray->AppendElement(scriptableUserInitiated);
-
-    nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
-    nsCOMPtr<nsIDOMWindow> newWindow;
-    rv = wwatch->OpenWindow(0, ALERT_CHROME_URL, "_blank",
-                            "chrome,dialog=yes,titlebar=no,popup=yes", argsArray,
-                            getter_AddRefs(newWindow));
-
-    mAlertInProgress = PR_TRUE;
-  }
-
-  // if the user has turned off the mail alert, or  openWindow generated an error,
-  // then go straight to the system tray.
-  if (!showAlert || NS_FAILED(rv))
-    AlertFinished();
-
-  return rv;
-}
-#endif
 
 nsresult nsMessengerUnixIntegration::AlertFinished()
 {
   mAlertInProgress = PR_FALSE;
   return NS_OK;
 }
 
 nsresult nsMessengerUnixIntegration::AlertClicked()
 {
-#ifdef MOZ_THUNDERBIRD
-  nsresult rv;
-  nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-  nsCOMPtr<nsIMsgWindow> topMostMsgWindow;
-  rv = mailSession->GetTopmostMsgWindow(getter_AddRefs(topMostMsgWindow));
-  if (topMostMsgWindow)
-  {
-    nsCOMPtr<nsIDOMWindowInternal> domWindow;
-    rv = topMostMsgWindow->GetDomWindow(getter_AddRefs(domWindow));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    domWindow->Focus();
-  }
-#else
   nsCString folderURI;
   GetFirstFolderWithNewMail(folderURI);
   openMailWindow(folderURI);
-#endif
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMessengerUnixIntegration::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData)
 {
   if (strcmp(aTopic, "alertfinished") == 0)
     return AlertFinished();
@@ -324,21 +245,17 @@ void nsMessengerUnixIntegration::FillToo
       };
      
       nsString finalText; 
       if (numNewMessages == 1)
         bundle->FormatStringFromName(NS_LITERAL_STRING("biffNotification_message").get(), formatStrings, 1, getter_Copies(finalText));
       else
         bundle->FormatStringFromName(NS_LITERAL_STRING("biffNotification_messages").get(), formatStrings, 1, getter_Copies(finalText));
 
-#ifndef MOZ_THUNDERBIRD
       ShowAlertMessage(accountName, finalText, EmptyCString());
-#else
-      ShowNewAlertNotification(PR_FALSE);
-#endif
     } // if we got a bundle
   } // if we got a folder
 }
 
 // get the first top level folder which we know has new mail, then enumerate over all the subfolders
 // looking for the first real folder with new mail. Return the folderURI for that folder.
 nsresult nsMessengerUnixIntegration::GetFirstFolderWithNewMail(nsACString& aFolderURI)
 {
--- a/mailnews/base/src/nsMessengerUnixIntegration.h
+++ b/mailnews/base/src/nsMessengerUnixIntegration.h
@@ -62,24 +62,18 @@ public:
   nsMessengerUnixIntegration();
   virtual nsresult Init();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIMESSENGEROSINTEGRATION
   NS_DECL_NSIFOLDERLISTENER
   NS_DECL_NSIOBSERVER
 
-#ifdef MOZ_THUNDERBIRD
-  nsresult ShowNewAlertNotification(PRBool aUserInitiated);
-#endif
-
 private:
-#ifndef MOZ_THUNDERBIRD
   nsresult ShowAlertMessage(const nsAString& aAlertTitle, const nsAString& aAlertText, const nsACString& aFolderURI);
-#endif
   nsresult GetFirstFolderWithNewMail(nsACString& aFolderURI);
   nsresult GetStringBundle(nsIStringBundle **aBundle);
   nsresult AlertFinished();
   nsresult AlertClicked();
   void FillToolTipInfo();
 
   nsCOMPtr<nsISupportsArray> mFoldersWithNewMail;  // keep track of all the root folders with pending new mail
   nsCOMPtr<nsIAtom> mBiffStateAtom;