Bug 323911 - should not play sound when new feed items arrive. r=mkmelin
authoralta88 <alta88@gmail.com>
Sat, 16 Aug 2014 08:42:46 -0600
changeset 21234 735e411003de76107c695b27f09e9f145808058e
parent 21233 64e49d15dff7d5d53ce019adc6b9a9ae9e3b6d95
child 21235 5e5314dec210eb9fcadd334dd4fe509ab6c3a37f
push idunknown
push userunknown
push dateunknown
reviewersmkmelin
bugs323911
Bug 323911 - should not play sound when new feed items arrive. r=mkmelin
mailnews/base/src/nsStatusBarBiffManager.cpp
mailnews/base/src/nsStatusBarBiffManager.h
mailnews/mailnews.js
--- a/mailnews/base/src/nsStatusBarBiffManager.cpp
+++ b/mailnews/base/src/nsStatusBarBiffManager.cpp
@@ -36,16 +36,17 @@ nsStatusBarBiffManager::nsStatusBarBiffM
 
 nsStatusBarBiffManager::~nsStatusBarBiffManager()
 {
     NS_IF_RELEASE(kBiffStateAtom);
 }
 
 #define NEW_MAIL_PREF_BRANCH             "mail.biff."
 #define CHAT_PREF_BRANCH                 "mail.chat."
+#define FEED_PREF_BRANCH                 "mail.feed."
 #define PREF_PLAY_SOUND                  "play_sound"
 #define PREF_SOUND_URL                   "play_sound.url"
 #define PREF_SOUND_TYPE                  "play_sound.type"
 #define SYSTEM_SOUND_TYPE 0
 #define CUSTOM_SOUND_TYPE 1
 #define PREF_CHAT_ENABLED                "mail.chat.enabled"
 #define NEW_CHAT_MESSAGE_TOPIC           "new-directed-incoming-message"
 
@@ -85,17 +86,25 @@ nsresult nsStatusBarBiffManager::PlayBif
   nsresult rv;
   nsCOMPtr<nsIPrefService> prefSvc = (do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIPrefBranch> pref;
   rv = prefSvc->GetBranch(aPrefBranch, getter_AddRefs(pref));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool playSound;
-  rv = pref->GetBoolPref(PREF_PLAY_SOUND, &playSound);
+  if (mServerType.EqualsLiteral("rss")) {
+    nsCOMPtr<nsIPrefBranch> prefFeed;
+    rv = prefSvc->GetBranch(FEED_PREF_BRANCH, getter_AddRefs(prefFeed));
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = prefFeed->GetBoolPref(PREF_PLAY_SOUND, &playSound);
+  }
+  else {
+    rv = pref->GetBoolPref(PREF_PLAY_SOUND, &playSound);
+  }
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!playSound)
     return NS_OK;
 
   // lazily create the sound instance
   if (!mSound)
     mSound = do_CreateInstance("@mozilla.org/sound;1");
@@ -175,16 +184,22 @@ nsStatusBarBiffManager::OnItemPropertyCh
 NS_IMETHODIMP
 nsStatusBarBiffManager::OnItemIntPropertyChanged(nsIMsgFolder *item, nsIAtom *property, int32_t oldValue, int32_t newValue)
 {
   if (kBiffStateAtom == property && mCurrentBiffState != newValue) {
     // if we got new mail, attempt to play a sound.
     // if we fail along the way, don't return.
     // we still need to update the UI.    
     if (newValue == nsIMsgFolder::nsMsgBiffState_NewMail) {
+      // Get the folder's server type.
+      nsCOMPtr<nsIMsgIncomingServer> server;
+      nsresult rv = item->GetServer(getter_AddRefs(server));
+      if (NS_SUCCEEDED(rv) && server)
+        server->GetType(mServerType);
+
       // if we fail to play the biff sound, keep going.
       (void)PlayBiffSound(NEW_MAIL_PREF_BRANCH);
     }
     mCurrentBiffState = newValue;
 
     // don't care if notification fails
     nsCOMPtr<nsIObserverService> observerService =
       mozilla::services::GetObserverService();
--- a/mailnews/base/src/nsStatusBarBiffManager.h
+++ b/mailnews/base/src/nsStatusBarBiffManager.h
@@ -25,16 +25,17 @@ public:
   nsStatusBarBiffManager(); 
   nsresult Init();
 
 private:
   virtual ~nsStatusBarBiffManager();
 
   bool     mInitialized;
   int32_t  mCurrentBiffState;
+  nsCString mServerType;
   nsCOMPtr<nsISound> mSound;
   nsresult PlayBiffSound(const char *aPrefBranch);
 
 protected:
   static nsIAtom* kBiffStateAtom;
 };
 
 
--- a/mailnews/mailnews.js
+++ b/mailnews/mailnews.js
@@ -639,16 +639,19 @@ pref("mail.biff.add_interval_jitter", tr
 pref("mail.biff.on_new_window", true);
 #endif
 
 // 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);
 
+// 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);
 
 // Experimental option to send message in the background - don't wait to close window.
 pref("mailnews.sendInBackground", false);
 // Will show a progress dialog when saving or sending a message