[Pkg-mozext-commits] [firetray] 182/399: prevent usage of msg count with type 'new messages'

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:39 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch dfsg-clean
in repository firetray.

commit 0fa7b30674c9577b23f321da9b5ab8b4f35105f1
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Tue Feb 21 00:09:40 2012 +0100

    prevent usage of msg count with type 'new messages'
    
    There seems to be no consistent way to count new messages. Tried with
    'BiffState', 'NumNewBiffMessages', 'NewMessages'... either the proper event is
    not fired, or the count is incorrect at a specific event... It was even
    non-trivial to display an accurate biff.
---
 README.md                           |    5 ++
 src/chrome/content/options.js       |   47 +++++++++++++--
 src/chrome/content/options.xul      |    3 +-
 src/chrome/locale/en-US/options.dtd |    1 +
 src/modules/FiretrayMessaging.jsm   |  114 +++++++++++++++++++----------------
 5 files changed, 112 insertions(+), 58 deletions(-)

diff --git a/README.md b/README.md
index 2cf3f38..6339194 100644
--- a/README.md
+++ b/README.md
@@ -58,6 +58,11 @@ KNOWN BUGS
 * child windows (compose message, preferences, ...)  are not handled by
   Firetray. For ex., they are not hidden along with there top-level window.
 
+* because of `getNumNewMessages()`'s
+  [strange behaviour](https://bugzilla.mozilla.org/show_bug.cgi?id=727460),
+  it's impossible to display an accurate count of *new messages*. The best we
+  can do is display a biff icon.
+
 Acknowledgment
 --------------
 
diff --git a/src/chrome/content/options.js b/src/chrome/content/options.js
index 6393079..862ba55 100644
--- a/src/chrome/content/options.js
+++ b/src/chrome/content/options.js
@@ -80,6 +80,7 @@ var firetrayUIOptions = {
     this.populateExcludedFoldersList();
     this.populateTreeAccountsOrServerTypes();
     this.initNotificationSettings();
+    this.initMessageCountSettings();
   },
 
   initNotificationSettings: function() {
@@ -98,15 +99,19 @@ var firetrayUIOptions = {
     radioMailNotify.selectedIndex = this.radioGetIndexByValue(radioMailNotify, prefMailNotificationType);
     this.disableNotificationMaybe(prefMailNotificationType);
 
+    this.toggleNotifications(firetray.Utils.prefService.getBoolPref("mail_notification_enabled"));
+  },
+
+  initMessageCountSettings: function() {
     document.getElementById("ui_message_count_type_unread").value =
       FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD;
     document.getElementById("ui_message_count_type_new").value =
       FIRETRAY_MESSAGE_COUNT_TYPE_NEW;
 
-    let prefMgsCountType = firetray.Utils.prefService.getIntPref("message_count_type");
-    document.getElementById("ui_message_count_type").selectedIndex = prefMgsCountType;
-
-    this.toggleNotifications(firetray.Utils.prefService.getBoolPref("mail_notification_enabled"));
+    let radioMessageCountType = document.getElementById("ui_message_count_type");
+    let prefMsgCountType = firetray.Utils.prefService.getIntPref("message_count_type");
+    radioMessageCountType.selectedIndex = this.radioGetIndexByValue(radioMessageCountType, prefMsgCountType);
+    this.disableMessageCountMaybe(prefMsgCountType);
   },
 
   radioGetIndexByValue: function(radio, value) {
@@ -124,6 +129,12 @@ var firetrayUIOptions = {
     firetray.Messaging.updateMsgCount();
   },
 
+  updateMessageCountSettings: function() {
+    let radioMessageCountType = document.getElementById("ui_message_count_type");
+    let messageCountType = +radioMessageCountType.getItemAtIndex(radioMessageCountType.selectedIndex).value;
+    this.disableMessageCountMaybe(messageCountType);
+  },
+
   disableNotificationMaybe: function(notificationSetting) {
     let iconTextColor = document.getElementById("icon_text_color");
     this.disableGroup(iconTextColor,
@@ -132,7 +143,31 @@ var firetrayUIOptions = {
     let customIconGroup = document.getElementById("custom_mail_icon");
     this.disableGroup(customIconGroup,
                       (notificationSetting !== FIRETRAY_NOTIFICATION_CUSTOM_ICON));
+  },
 
+  disableMessageCountMaybe: function(msgCountType) {
+    LOG("disableMessageCountMaybe: "+msgCountType);
+    let doDisable = (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW);
+
+    let radioNotificationUnreadCount = document.getElementById("ui_radio_mail_notification_unread_count");
+    radioNotificationUnreadCount.disabled = doDisable;
+
+    let iconTextColor = document.getElementById("icon_text_color");
+    this.disableGroup(iconTextColor, doDisable);
+
+    if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW) {
+      let radioNotificationNewmailIcon = document.getElementById("ui_radio_mail_notification_newmail_icon");
+      this.simulateClick(radioNotificationNewmailIcon);
+    }
+  },
+
+  simulateClick: function(target) {
+    var evt = document.createEvent("MouseEvents");
+    evt.initMouseEvent("click", true, true, window,
+                       0, 0, 0, 0, 0, false, false, false, false, 0, null);
+    var canceled = !target.dispatchEvent(evt);
+    if(canceled)
+      ERROR("could not fire click on "+target);
   },
 
   toggleNotifications: function(enabled) {
@@ -146,6 +181,10 @@ var firetrayUIOptions = {
         .setAttribute("disabled", "true"); // UI update
       firetray.Messaging.shutdown();
     }
+
+    let radioMessageCountType = document.getElementById("ui_message_count_type");
+    let messageCountType = +radioMessageCountType.getItemAtIndex(radioMessageCountType.selectedIndex).value;
+    this.disableMessageCountMaybe(messageCountType);
   },
 
   chooseMailIconFile: function() {
diff --git a/src/chrome/content/options.xul b/src/chrome/content/options.xul
index c6e5f88..6fe63a3 100644
--- a/src/chrome/content/options.xul
+++ b/src/chrome/content/options.xul
@@ -95,7 +95,8 @@
                     preference="pref_mail_notification_enabled"
                     oncommand="firetrayUIOptions.toggleNotifications(this.checked)"/>
 
-          <radiogroup id="ui_message_count_type" preference="pref_message_count_type">
+          <radiogroup id="ui_message_count_type" preference="pref_message_count_type"
+                      oncommand="firetrayUIOptions.updateMessageCountSettings()">
             <hbox align="center" flex="1">
               <label observes="broadcaster-notification-disabled">&message_count_type;</label>
               <radio id="ui_message_count_type_unread" label="&message_count_type_unread;"
diff --git a/src/chrome/locale/en-US/options.dtd b/src/chrome/locale/en-US/options.dtd
index 551a532..681d826 100644
--- a/src/chrome/locale/en-US/options.dtd
+++ b/src/chrome/locale/en-US/options.dtd
@@ -1,3 +1,4 @@
+<!-- if you need multiline/carriage return, use a .properties -->
 <!ENTITY prefwindow.title "FireTray preferences">
 <!ENTITY pane1.title "FireTray preferences">
 
diff --git a/src/modules/FiretrayMessaging.jsm b/src/modules/FiretrayMessaging.jsm
index b1eccb7..c5c2678 100644
--- a/src/modules/FiretrayMessaging.jsm
+++ b/src/modules/FiretrayMessaging.jsm
@@ -57,8 +57,8 @@ firetray.Messaging = {
       // Ci.nsIFolderListener.propertyChanged |
       // Ci.nsIFolderListener.propertyFlagChanged |
       // Ci.nsIFolderListener.event |
-      Ci.nsIFolderListener.intPropertyChanged |
-      Ci.nsIFolderListener.boolPropertyChanged,
+      Ci.nsIFolderListener.boolPropertyChanged |
+      Ci.nsIFolderListener.intPropertyChanged,
 
     OnItemPropertyChanged: function(item, property, oldValue, newValue) { // NumNewBiffMessages
       LOG("OnItemPropertyChanged "+property+" for folder "+item.prettyName+" was "+oldValue+" became "+newValue+" NEW MESSAGES="+item.getNumNewMessages(true));
@@ -90,11 +90,12 @@ firetray.Messaging = {
       if (!(item.flags & excludedFoldersFlags)) {
         let prop = property.toString();
         if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD &&
-            prop === "TotalUnreadMessages" ||
-            msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW &&
-            prop === "NewMessages") {
+            prop === "TotalUnreadMessages") {
+          firetray.Messaging.updateMsgCount();
+        } else if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW &&
+                   prop === "NewMessages") {
           if (oldValue === true && newValue === false)
-            item.setNumNewMessages(0);
+            item.setNumNewMessages(0); // https://bugzilla.mozilla.org/show_bug.cgi?id=727460
           firetray.Messaging.updateMsgCount();
         }
       }
@@ -102,59 +103,14 @@ firetray.Messaging = {
   },
 
   /**
-   * computes total unread message count.
-   * NOTE: new messages can(?) be filtered and mark read, but still be
-   * considered new, so we may have to use nsMsgFolderFlagType.GotNew on all
-   * folders
+   * computes and display new msg count
    */
   updateMsgCount: function() {
     LOG("updateMsgCount");
     if (!this.initialized)
       return;
 
-    let mailAccounts = firetray.Utils.getObjPref('mail_accounts');
-    LOG("mail accounts from pref: "+JSON.stringify(mailAccounts));
-    let serverTypes = mailAccounts["serverTypes"];
-    let excludedAccounts = mailAccounts["excludedAccounts"];
-    let excludedFoldersFlags = firetray.Utils.prefService
-      .getIntPref("excluded_folders_flags");
-
-    let msgCountType = firetray.Utils.prefService.getIntPref("message_count_type"),
-        getNewMessageCount   = '';
-    LOG("msgCountType="+msgCountType);
-    if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD)
-      getNewMessageCount = 'getNumUnread';
-    else if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW)
-      getNewMessageCount = 'getNumNewMessages';
-    else
-      ERROR('unknown message count type');
-
-    let newMsgCount = 0;
-    try {
-      let accounts = new this.Accounts();
-      for (let accountServer in accounts) {
-        LOG("is servertype excluded: "+serverTypes[accountServer.type].excluded+", account exclusion index: "+excludedAccounts.indexOf(accountServer.key));
-        if ( (serverTypes[accountServer.type].excluded)
-          || (excludedAccounts.indexOf(accountServer.key) >= 0) )
-          continue;
-
-        let rootFolder = accountServer.rootFolder; // nsIMsgFolder
-        if (rootFolder.hasSubFolders) {
-          let subFolders = rootFolder.subFolders; // nsIMsgFolder
-          while(subFolders.hasMoreElements()) {
-            let folder = subFolders.getNext().QueryInterface(Ci.nsIMsgFolder);
-            if (!(folder.flags & excludedFoldersFlags)) {
-              folderNewMsgCount = folder[getNewMessageCount](true); // includes subfolders
-              LOG(folder.prettyName+" "+getNewMessageCount+"="+folderNewMsgCount);
-              newMsgCount += folderNewMsgCount;
-            }
-          }
-        }
-      }
-    } catch (x) {
-      ERROR(x);
-    }
-    LOG("Total Unread="+newMsgCount);
+    let newMsgCount = this.countMessages();
 
     // update icon
     if (newMsgCount == 0) {
@@ -189,6 +145,58 @@ firetray.Messaging = {
       throw "negative message count"; // should never happen
     }
 
+  },
+
+  /**
+   * computes total unread message count.
+   * NOTE: new messages can(?) be filtered and mark read, but still be
+   * considered new, so we may have to use nsMsgFolderFlagType.GotNew on all
+   * folders
+   */
+  countMessages: function() {
+    let msgCountType = firetray.Utils.prefService.getIntPref("message_count_type");
+    LOG("msgCountType="+msgCountType);
+    if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD) {
+      folderCountFunctionName = 'getNumUnread';
+    } else if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW) {
+      folderCountFunctionName = 'getNumNewMessages'; // perfectly bogus if > 0
+    } else
+      ERROR('unknown message count type');
+
+    let mailAccounts = firetray.Utils.getObjPref('mail_accounts');
+    LOG("mail accounts from pref: "+JSON.stringify(mailAccounts));
+    let serverTypes = mailAccounts["serverTypes"];
+    let excludedAccounts = mailAccounts["excludedAccounts"];
+    let excludedFoldersFlags = firetray.Utils.prefService
+      .getIntPref("excluded_folders_flags");
+
+    let newMsgCount = 0;
+    try {
+      let accounts = new this.Accounts();
+      for (let accountServer in accounts) {
+        LOG("is servertype excluded: "+serverTypes[accountServer.type].excluded+", account exclusion index: "+excludedAccounts.indexOf(accountServer.key));
+        if ( (serverTypes[accountServer.type].excluded)
+          || (excludedAccounts.indexOf(accountServer.key) >= 0) )
+          continue;
+
+        let rootFolder = accountServer.rootFolder; // nsIMsgFolder
+        if (rootFolder.hasSubFolders) {
+          let subFolders = rootFolder.subFolders; // nsIMsgFolder
+          while(subFolders.hasMoreElements()) {
+            let folder = subFolders.getNext().QueryInterface(Ci.nsIMsgFolder);
+            if (!(folder.flags & excludedFoldersFlags)) {
+              let folderNewMsgCount = folder[folderCountFunctionName](true); // includes subfolders
+              LOG(folder.prettyName+" "+folderCountFunctionName+"="+folderNewMsgCount);
+              newMsgCount += folderNewMsgCount;
+            }
+          }
+        }
+      }
+    } catch (x) {
+      ERROR(x);
+    }
+    LOG("Total Unread="+newMsgCount);
+    return newMsgCount;
   }
 
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firetray.git



More information about the Pkg-mozext-commits mailing list