Bug 1144719 - Allow the user to decide whether or not to use libnotify for new-mail alerts on Linux. r=Neil, a=rkent
authorrsx11m <rsx11m.pub@gmail.com>
Sat, 21 Mar 2015 15:09:49 -0500
changeset 25851 de98ea1bf62103a23c001289b35daefd1a5f4dd3
parent 25850 f13db5b3038705c52fdcb599d851ef002744b052
child 25852 80ec65353d8f03d7ad85c4d17b5e22c2ef6313d3
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil, rkent
bugs1144719
Bug 1144719 - Allow the user to decide whether or not to use libnotify for new-mail alerts on Linux. r=Neil, a=rkent
mailnews/base/src/nsMessengerUnixIntegration.cpp
mailnews/mailnews.js
--- a/mailnews/base/src/nsMessengerUnixIntegration.cpp
+++ b/mailnews/base/src/nsMessengerUnixIntegration.cpp
@@ -54,16 +54,17 @@
 #define ALERT_CHROME_URL "chrome://messenger/content/newmailalert.xul"
 #define NEW_MAIL_ALERT_ICON "chrome://messenger/skin/icons/new-mail-alert.png"
 #define SHOW_ALERT_PREF "mail.biff.show_alert"
 #define SHOW_ALERT_PREVIEW_LENGTH "mail.biff.alert.preview_length"
 #define SHOW_ALERT_PREVIEW_LENGTH_DEFAULT 40
 #define SHOW_ALERT_PREVIEW "mail.biff.alert.show_preview"
 #define SHOW_ALERT_SENDER  "mail.biff.alert.show_sender"
 #define SHOW_ALERT_SUBJECT "mail.biff.alert.show_subject"
+#define SHOW_ALERT_SYSTEM  "mail.biff.use_system_alert"
 
 using namespace mozilla::mailnews;
 
 static void openMailWindow(const nsACString& aFolderUri)
 {
   nsresult rv;
   nsCOMPtr<nsIMsgMailSession> mailSession ( do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv));
   if (NS_FAILED(rv))
@@ -318,32 +319,42 @@ nsMessengerUnixIntegration::BuildNotific
 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;
 
   mAlertInProgress = true;
-  nsCOMPtr<nsIAlertsService> alertsService(do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID, &rv));
-  if (NS_SUCCEEDED(rv)) {
-    rv = alertsService->ShowAlertNotification(NS_LITERAL_STRING(NEW_MAIL_ALERT_ICON),
-                                              aAlertTitle,
-                                              aAlertText,
-                                              false,
-                                              NS_ConvertASCIItoUTF16(aFolderURI),
-                                              this,
-                                              EmptyString(),
-                                              NS_LITERAL_STRING("auto"),
-                                              EmptyString(),
-                                              EmptyString(),
-                                              nullptr,
-                                              false);
-    if (NS_SUCCEEDED(rv))
-      return rv;
+
+  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // determine if we should use libnotify or the built-in alert system
+  bool useSystemAlert = true;
+  prefBranch->GetBoolPref(SHOW_ALERT_SYSTEM, &useSystemAlert);
+
+  if (useSystemAlert) {
+    nsCOMPtr<nsIAlertsService> alertsService(do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID, &rv));
+    if (NS_SUCCEEDED(rv)) {
+      rv = alertsService->ShowAlertNotification(NS_LITERAL_STRING(NEW_MAIL_ALERT_ICON),
+                                                aAlertTitle,
+                                                aAlertText,
+                                                false,
+                                                NS_ConvertASCIItoUTF16(aFolderURI),
+                                                this,
+                                                EmptyString(),
+                                                NS_LITERAL_STRING("auto"),
+                                                EmptyString(),
+                                                EmptyString(),
+                                                nullptr,
+                                                false);
+      if (NS_SUCCEEDED(rv))
+        return rv;
+    }
   }
   AlertFinished();
   rv = ShowNewAlertNotification(false);
 
   if (NS_FAILED(rv)) // go straight to showing the system tray icon.
     AlertFinished();
 
   return rv;
--- a/mailnews/mailnews.js
+++ b/mailnews/mailnews.js
@@ -624,32 +624,39 @@ pref("mail.biff.alert.preview_length", 4
 
 pref("mail.biff.play_sound", true);
 // 0 == default system sound, 1 == user specified wav
 pref("mail.biff.play_sound.type", 0);
 // _moz_mailbeep is a magic key, for the default sound.
 // otherwise, this needs to be a file url
 pref("mail.biff.play_sound.url", "");
 pref("mail.biff.show_alert", true);
-pref("mail.biff.show_tray_icon", true); // currently Windows-only
-pref("mail.biff.show_balloon", false); // currently Windows-only
+#ifdef XP_WIN
+pref("mail.biff.show_tray_icon", true);
+pref("mail.biff.show_balloon", false);
+#elifdef XP_MACOSX
 pref("mail.biff.animate_dock_icon", false);
+#elifdef XP_UNIX
+pref("mail.biff.use_system_alert", true);
+#endif
 
 // add jitter to biff interval
 pref("mail.biff.add_interval_jitter", true);
 
 #ifdef MOZ_SUITE
 // if true, check for new mail even when opening non-mail windows
 pref("mail.biff.on_new_window", true);
 #endif
 
+#ifdef XP_MACOSX
 // If true, the number used in the Mac OS X dock notification will be the
 // the number of "new" messages, as per the classic Thunderbird definition.
 // Defaults to false, which notifies about the number of unread messages.
 pref("mail.biff.use_new_count_in_mac_dock", false);
+#endif
 
 // For feed account serverType=rss sound on biff; if true, mail.biff.play_sound.* settings are used.
 pref("mail.feed.play_sound", false);
 
 // Content disposition for attachments (except binary files and vcards).
 //   0= Content-Disposition: inline
 //   1= Content-Disposition: attachment
 pref("mail.content_disposition_type", 1);