[Pkg-mozext-commits] [firetray] 168/399: * add 'message_count_type' option for counting unread or new messages. * minor change to UI of mail preferences * split pref 'mail_notification' into 'mail_notification_enabled', 'mail_notification_type'

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:36 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 15dace0b32e92109d8613d28c03632455b3e15a5
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Thu Feb 9 00:03:29 2012 +0100

    * add 'message_count_type' option for counting unread or new messages.
    * minor change to UI of mail preferences
    * split pref 'mail_notification' into 'mail_notification_enabled',
      'mail_notification_type'
    
    previous 'mail_notification' pref will be erased.
---
 src/chrome/content/options.js       |   73 +++++++++++++++--------
 src/chrome/content/options.xul      |  111 ++++++++++++++++++++++-------------
 src/chrome/content/overlay.js       |    2 +-
 src/chrome/locale/en-US/options.dtd |   15 +++--
 src/defaults/preferences/prefs.js   |    4 +-
 src/modules/FiretrayHandler.jsm     |   20 ++++---
 src/modules/FiretrayMessaging.jsm   |   70 ++++++++++++----------
 src/modules/commons.js              |   19 +++---
 8 files changed, 196 insertions(+), 118 deletions(-)

diff --git a/src/chrome/content/options.js b/src/chrome/content/options.js
index 8c06b61..6393079 100644
--- a/src/chrome/content/options.js
+++ b/src/chrome/content/options.js
@@ -83,48 +83,75 @@ var firetrayUIOptions = {
   },
 
   initNotificationSettings: function() {
-    let radioMailNotify = document.getElementById("radiogroup_mail_notification");
-    let prefMailNotification = firetray.Utils.prefService.getIntPref("mail_notification");
-    radioMailNotify.selectedIndex = prefMailNotification;
-    this._disableNotificationMaybe(radioMailNotify.selectedIndex);
+    document.getElementById("ui_radio_mail_notification_unread_count").value =
+      FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT;
+    document.getElementById("ui_radio_mail_notification_newmail_icon").value =
+      FIRETRAY_NOTIFICATION_NEWMAIL_ICON;
+    document.getElementById("ui_radio_mail_notification_custom_mail_icon").value =
+      FIRETRAY_NOTIFICATION_CUSTOM_ICON;
+
+    document.getElementById("ui_mail_notification_enabled").checked =
+      (firetray.Utils.prefService.getBoolPref("mail_notification_enabled"));
+
+    let radioMailNotify = document.getElementById("ui_radiogroup_mail_notification");
+    let prefMailNotificationType = firetray.Utils.prefService.getIntPref("mail_notification_type");
+    radioMailNotify.selectedIndex = this.radioGetIndexByValue(radioMailNotify, prefMailNotificationType);
+    this.disableNotificationMaybe(prefMailNotificationType);
+
+    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"));
+  },
+
+  radioGetIndexByValue: function(radio, value) {
+    for (let i=0, len=radio.itemCount; i<len; ++i)
+      if (+radio.getItemAtIndex(i).value == value) return i;
+    return -1;
   },
 
   updateNotificationSettings: function() {
-    let radioMailNotify = document.getElementById("radiogroup_mail_notification");
-    let notificationSetting = radioMailNotify.selectedIndex;
-    let prefMailNotification =
-      firetray.Utils.prefService.setIntPref("mail_notification", notificationSetting);
-    this._disableNotificationMaybe(notificationSetting);
+    let radioMailNotify = document.getElementById("ui_radiogroup_mail_notification");
+    let mailNotificationType = +radioMailNotify.getItemAtIndex(radioMailNotify.selectedIndex).value;
+    firetray.Utils.prefService.setIntPref("mail_notification_type", mailNotificationType);
+    this.disableNotificationMaybe(mailNotificationType);
+
+    firetray.Messaging.updateMsgCount();
   },
 
-  _disableNotificationMaybe: function(notificationSetting) {
+  disableNotificationMaybe: function(notificationSetting) {
     let iconTextColor = document.getElementById("icon_text_color");
     this.disableGroup(iconTextColor,
-                      (notificationSetting !== FT_NOTIFICATION_UNREAD_MESSAGE_COUNT));
+                      (notificationSetting !== FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT));
 
     let customIconGroup = document.getElementById("custom_mail_icon");
     this.disableGroup(customIconGroup,
-                      (notificationSetting !== FT_NOTIFICATION_CUSTOM_ICON));
+                      (notificationSetting !== FIRETRAY_NOTIFICATION_CUSTOM_ICON));
 
-    let isNotificationDisabled = (notificationSetting === FT_NOTIFICATION_DISABLED);
+  },
 
-    if (isNotificationDisabled) {
-      document.getElementById("broadcaster-notification-disabled")
-        .setAttribute("disabled", "true"); // UI update
-      firetray.Messaging.shutdown();
-    } else {
+  toggleNotifications: function(enabled) {
+    if (enabled) {
       document.getElementById("broadcaster-notification-disabled")
         .removeAttribute("disabled"); // UI update (enables!)
       firetray.Messaging.init();
-      firetray.Messaging.updateUnreadMsgCount();
+      firetray.Messaging.updateMsgCount();
+    } else {
+      document.getElementById("broadcaster-notification-disabled")
+        .setAttribute("disabled", "true"); // UI update
+      firetray.Messaging.shutdown();
     }
-
   },
 
   chooseMailIconFile: function() {
     var filepath = document.getElementById("custom_mail_icon_filename");
     this._chooseIconFile(filepath);
-    firetray.Messaging.updateUnreadMsgCount();
+    firetray.Messaging.updateMsgCount();
   },
 
   _chooseIconFile: function(iconFilename) {
@@ -177,7 +204,7 @@ var firetrayUIOptions = {
     firetray.Utils.prefService.setIntPref("excluded_folders_flags",
                                           excludedFoldersFlags);
 
-    firetray.Messaging.updateUnreadMsgCount();
+    firetray.Messaging.updateMsgCount();
   },
 
   /**
@@ -220,7 +247,7 @@ var firetrayUIOptions = {
     document.getElementById("pane1")
       .userChangedValue(document.getElementById("ui_tree_mail_accounts"));
 
-    firetray.Messaging.updateUnreadMsgCount();
+    firetray.Messaging.updateMsgCount();
   },
 
   _userChangeValueTreeServerTypes: function(event) {
diff --git a/src/chrome/content/options.xul b/src/chrome/content/options.xul
index d068558..c6e5f88 100644
--- a/src/chrome/content/options.xul
+++ b/src/chrome/content/options.xul
@@ -19,17 +19,19 @@
   <prefpane id="pane1" label="&pane1.title;">
 
     <preferences>
-      <preference id="pref_bool_hides_on_close" name="extensions.firetray.hides_on_close" type="bool"/>
-      <preference id="pref_bool_hides_on_minimize" name="extensions.firetray.hides_on_minimize" type="bool"/>
-      <preference id="pref_bool_hides_single_window" name="extensions.firetray.hides_single_window" type="bool"/>
-      <preference id="pref_bool_start_hidden" name="extensions.firetray.start_hidden" type="bool"/>
-      <preference id="pref_bool_show_activates" name="extensions.firetray.show_activates" type="bool"/>
-      <preference id="pref_bool_show_icon_on_hide" name="extensions.firetray.show_icon_on_hide" type="bool"/>
-      <preference id="pref_bool_scroll_hides" name="extensions.firetray.scroll_hides" type="bool" />
-      <preference id="pref_string_scroll_mode" name="extensions.firetray.scroll_mode" type="string" />
-      <preference id="pref_string_icon_text_color" name="extensions.firetray.icon_text_color" type="string" />
-      <preference id="pref_string_custom_mail_icon" name="extensions.firetray.custom_mail_icon" type="string" />
-      <preference id="pref_string_mail_accounts" name="extensions.firetray.mail_accounts" type="string"/>
+      <preference id="pref_hides_on_close" name="extensions.firetray.hides_on_close" type="bool"/>
+      <preference id="pref_hides_on_minimize" name="extensions.firetray.hides_on_minimize" type="bool"/>
+      <preference id="pref_hides_single_window" name="extensions.firetray.hides_single_window" type="bool"/>
+      <preference id="pref_start_hidden" name="extensions.firetray.start_hidden" type="bool"/>
+      <preference id="pref_show_activates" name="extensions.firetray.show_activates" type="bool"/>
+      <preference id="pref_show_icon_on_hide" name="extensions.firetray.show_icon_on_hide" type="bool"/>
+      <preference id="pref_scroll_hides" name="extensions.firetray.scroll_hides" type="bool" />
+      <preference id="pref_scroll_mode" name="extensions.firetray.scroll_mode" type="string" />
+      <preference id="pref_icon_text_color" name="extensions.firetray.icon_text_color" type="string" />
+      <preference id="pref_mail_notification_enabled" name="extensions.firetray.mail_notification_enabled" type="bool" />
+      <preference id="pref_message_count_type" name="extensions.firetray.message_count_type" type="int" />
+      <preference id="pref_custom_mail_icon" name="extensions.firetray.custom_mail_icon" type="string" />
+      <preference id="pref_mail_accounts" name="extensions.firetray.mail_accounts" type="string"/>
     </preferences>
 
     <tabbox>
@@ -44,22 +46,22 @@
 
           <groupbox>
             <caption label="&windows_behaviour;" />
-            <checkbox id="ui_hides_on_close" preference="pref_bool_hides_on_close"
+            <checkbox id="ui_hides_on_close" preference="pref_hides_on_close"
                       label="&bool_hides_on_close.label;"
                       accesskey="&bool_hides_on_close.accesskey;"
                       oncommand="firetrayUIOptions.updateWindowAndIconOptions();"/>
-            <checkbox id="ui_hides_on_minimize" preference="pref_bool_hides_on_minimize"
+            <checkbox id="ui_hides_on_minimize" preference="pref_hides_on_minimize"
                       label="&bool_hides_on_minimize.label;"
                       accesskey="&bool_hides_on_minimize.accesskey;"
                       oncommand="firetrayUIOptions.updateWindowAndIconOptions();"/>
-            <checkbox id="ui_hides_single_window" preference="pref_bool_hides_single_window"
+            <checkbox id="ui_hides_single_window" preference="pref_hides_single_window"
                       label="&bool_hides_single_window.label;"
                       accesskey="&bool_hides_single_window.accesskey;"
                       tooltiptext="&bool_hides_single_window.tooltip;"/>
-            <checkbox id="ui_start_hidden" preference="pref_bool_start_hidden"
+            <checkbox id="ui_start_hidden" preference="pref_start_hidden"
                       label="&bool_start_hidden.label;"
                       accesskey="&bool_start_hidden.accesskey;"/>
-            <checkbox id="ui_show_activates" preference="pref_bool_show_activates"
+            <checkbox id="ui_show_activates" preference="pref_show_activates"
                       label="&bool_show_activates.label;"
                       accesskey="&bool_show_activates.accesskey;"
                       tooltiptext="&bool_show_activates.tooltip;"/>
@@ -67,14 +69,14 @@
 
           <groupbox>
             <caption label="&icon_settings;" />
-            <checkbox id="ui_show_icon_on_hide" preference="pref_bool_show_icon_on_hide"
+            <checkbox id="ui_show_icon_on_hide" preference="pref_show_icon_on_hide"
                       label="&bool_show_icon_on_hide.label;"
                       accesskey="&bool_show_icon_on_hide.accesskey;"/>
-            <checkbox id="ui_scroll_hides" preference="pref_bool_scroll_hides"
+            <checkbox id="ui_scroll_hides" preference="pref_scroll_hides"
                       label="&enable_mouse_scroll.label;"
                       accesskey="&enable_mouse_scroll.accesskey;"
                       oncommand="firetrayUIOptions.updateScrollOptions()" />
-            <radiogroup id="ui_radiogroup_scroll" preference="pref_string_scroll_mode">
+            <radiogroup id="ui_radiogroup_scroll" preference="pref_scroll_mode">
               <radio id="ui_radio_scroll_down_hides" label="&down;=&hide;, &up;=&restore;" value="down_hides" />
               <radio id="ui_radio_scroll_up_hides" label="&up;=&hide;, &down;=&restore;" value="up_hides" />
             </radiogroup>
@@ -86,48 +88,76 @@
         <tabpanel id="mail_tabpanel" flex="1">
           <vbox align="left" flex="1">
 
-          <!-- <label value="&mail_notification;" class="header" /> -->
-          <groupbox flex="1">
-            <caption label="&mail_notification.label;" />
-            <radiogroup id="radiogroup_mail_notification">
-              <radio id="radio_mail_icon1" label="&mail_notification_disabled.label;"
-                     accesskey="&mail_notification_disabled.accesskey;"
-                     oncommand="firetrayUIOptions.updateNotificationSettings()" />
+          <checkbox id="ui_mail_notification_enabled"
+                    label="&mail_notification_enabled.label;"
+                    class="header"
+                    accesskey="&mail_notification_enabled.accesskey;"
+                    preference="pref_mail_notification_enabled"
+                    oncommand="firetrayUIOptions.toggleNotifications(this.checked)"/>
+
+          <radiogroup id="ui_message_count_type" preference="pref_message_count_type">
+            <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;"
+                     observes="broadcaster-notification-disabled"/>
+              <radio id="ui_message_count_type_new" label="&message_count_type_new;"
+                     tooltiptext="&message_count_type_new.tooltip;"
+                     observes="broadcaster-notification-disabled"/>
+            </hbox>
+          </radiogroup>
+
+          <groupbox id="ui_mail_notification" flex="1">
+            <caption>
+              <label id="ui_mail_notification_type_label"
+                     value="&mail_notification_type.label;"
+                     tooltiptext="&mail_notification_type.tooltip;"
+                     observes="broadcaster-notification-disabled" />
+            </caption>
+
+            <radiogroup id="ui_radiogroup_mail_notification">
               <hbox>
-                <radio id="radio_mail_icon2" label="&mail_notification_unread_count.label;"
+                <radio id="ui_radio_mail_notification_unread_count" label="&mail_notification_unread_count.label;"
                        accesskey="&mail_notification_unread_count.accesskey;"
-                       oncommand="firetrayUIOptions.updateNotificationSettings()" />
+                       oncommand="firetrayUIOptions.updateNotificationSettings()"
+                       observes="broadcaster-notification-disabled" />
                 <hbox id="icon_text_color" align="center">
-                  <label value="&icon_text_color;" accesskey="&icon_text_color.accesskey;"/>
+                  <label value="&icon_text_color;" accesskey="&icon_text_color.accesskey;"
+                         observes="broadcaster-notification-disabled"/>
                   <colorpicker id="btn_icon_text_color" type="button"
-                               preference="pref_string_icon_text_color"
-                               onchange="firetray.Messaging.updateUnreadMsgCount();"/>
+                               preference="pref_icon_text_color"
+                               onchange="firetray.Messaging.updateMsgCount();"
+                               observes="broadcaster-notification-disabled"/>
                 </hbox>
               </hbox>
-              <radio id="radio_mail_icon3" label="&mail_notification_newmail_icon.label;"
+              <radio id="ui_radio_mail_notification_newmail_icon" label="&mail_notification_newmail_icon.label;"
                      accesskey="&mail_notification_newmail_icon.accesskey;"
-                     oncommand="firetrayUIOptions.updateNotificationSettings()" />
+                     oncommand="firetrayUIOptions.updateNotificationSettings()"
+                     observes="broadcaster-notification-disabled" />
               <hbox>
-                <radio id="radio_mail_icon4" label="&mail_notification_custom_mail_icon.label;"
+                <radio id="ui_radio_mail_notification_custom_mail_icon" label="&mail_notification_custom_mail_icon.label;"
                        accesskey="&mail_notification_custom_mail_icon.accesskey;"
-                       oncommand="firetrayUIOptions.updateNotificationSettings()" />
+                       oncommand="firetrayUIOptions.updateNotificationSettings()" 
+                       observes="broadcaster-notification-disabled" />
                 <hbox id="custom_mail_icon" align="center" flex="1" >
-                  <textbox id="custom_mail_icon_filename" preference="pref_string_custom_mail_icon"
-                           onblur="firetray.Messaging.updateUnreadMsgCount();" flex="1" />
+                  <textbox id="custom_mail_icon_filename" preference="pref_custom_mail_icon"
+                           onblur="firetray.Messaging.updateMsgCount();" flex="1" />
                   <button id="custom_mail_icon_select" label="&choose;"
                           accesskey="&choose.accesskey;"
                           oncommand="firetrayUIOptions.chooseMailIconFile()" />
                 </hbox>
               </hbox>
+
             </radiogroup>
+
           </groupbox>
 
           <!-- NOTE: groupbox and caption don't have a 'disabled' attribute !! -->
           <groupbox id="unread_count_folder_exceptions" flex="1">
             <!-- label extracted from caption so we can disable it -->
-            <caption tooltiptext="&unread_count_folder_exceptions.tooltip;">
+            <caption>
               <label id="unread_count_folder_exceptions_caption_label"
                      value="&unread_count_folder_exceptions.label;"
+                     tooltiptext="&unread_count_folder_exceptions.tooltip;"
                      observes="broadcaster-notification-disabled" />
             </caption>
 
@@ -139,9 +169,10 @@
 
           <groupbox id="unread_count_account_exceptions" flex="1">
             <!-- label extracted from caption so we can disable it -->
-            <caption tooltiptext="&unread_count_account_exceptions.tooltip;">
+            <caption>
               <label id="unread_count_account_exceptions_caption_label"
                      value="&unread_count_account_exceptions.label;"
+                     tooltiptext="&unread_count_account_exceptions.tooltip;"
                      observes="broadcaster-notification-disabled" />
             </caption>
 
@@ -149,7 +180,7 @@
                   seltype="single" editable="true" hidecolumnpicker="false"
                   observes="broadcaster-notification-disabled"
                   preference-editable="true"
-                  preference="pref_string_mail_accounts"
+                  preference="pref_mail_accounts"
                   onsynctopreference="return firetrayUIOptions.saveTreeAccountsOrServerTypes();">
               <treecols>
                 <treecol id="account_or_server_type_name" editable="false" flex="2"
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index f93652e..e975b6c 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -21,7 +21,7 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
 
     // update unread messages count
     if (firetray.Handler.inMailApp && firetray.Messaging.initialized)
-      firetray.Messaging.updateUnreadMsgCount();
+      firetray.Messaging.updateMsgCount();
 
     // prevent window closing.
     win.addEventListener('close', firetrayChrome.onClose, true);
diff --git a/src/chrome/locale/en-US/options.dtd b/src/chrome/locale/en-US/options.dtd
index 8c0c46e..551a532 100644
--- a/src/chrome/locale/en-US/options.dtd
+++ b/src/chrome/locale/en-US/options.dtd
@@ -1,4 +1,4 @@
-<!ENTITY prefwindow.title "y preferences">
+<!ENTITY prefwindow.title "FireTray preferences">
 <!ENTITY pane1.title "FireTray preferences">
 
 <!ENTITY NOT_IMPLEMENTED_YET "NOT IMPLEMENTED YET">
@@ -31,10 +31,11 @@
 <!ENTITY hide "hide" >
 <!ENTITY restore "restore" >
 
-<!ENTITY mail_notification.label "Mail notification">
-<!ENTITY mail_notification_disabled.label "disabled">
-<!ENTITY mail_notification_disabled.accesskey "D">
-<!ENTITY mail_notification_unread_count.label "display unread messages count">
+<!ENTITY mail_notification_enabled.label "Enable mail notification">
+<!ENTITY mail_notification_enabled.accesskey "a">
+<!ENTITY mail_notification_type.label "Mail notification type">
+<!ENTITY mail_notification_type.tooltip "aka. Biff">
+<!ENTITY mail_notification_unread_count.label "display new message count">
 <!ENTITY mail_notification_unread_count.accesskey "U">
 <!ENTITY mail_notification_newmail_icon.label "display newmail icon">
 <!ENTITY mail_notification_newmail_icon.accesskey "N">
@@ -44,6 +45,10 @@
 <!ENTITY icon_text_color.accesskey "T">
 <!ENTITY choose "Choose">
 <!ENTITY choose.accesskey "O">
+<!ENTITY message_count_type "message count type :">
+<!ENTITY message_count_type_unread "unread messages">
+<!ENTITY message_count_type_new "new messages">
+<!ENTITY message_count_type_new.tooltip "new messages since a folder was last visited">
 
 <!ENTITY unread_count_folder_exceptions.label "Included special folders">
 <!ENTITY unread_count_folder_exceptions.tooltip "Included special folders for unread message count">
diff --git a/src/defaults/preferences/prefs.js b/src/defaults/preferences/prefs.js
index 7affa6a..e24b252 100644
--- a/src/defaults/preferences/prefs.js
+++ b/src/defaults/preferences/prefs.js
@@ -17,7 +17,9 @@ pref("extensions.firetray.show_icon_on_hide", false);
 pref("extensions.firetray.scroll_hides", true);
 pref("extensions.firetray.scroll_mode", "down_hides");
 
-pref("extensions.firetray.mail_notification", 1);
+pref("extensions.firetray.message_count_type", 0);
+pref("extensions.firetray.mail_notification_enabled", true);
+pref("extensions.firetray.mail_notification_type", 0);
 pref("extensions.firetray.icon_text_color", "#000000");
 pref("extensions.firetray.custom_mail_icon", "");
 // Ci.nsMsgFolderFlags.Archive|Drafts|Junk|Queue|SentMail|Trash
diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm
index af83cd7..2485405 100644
--- a/src/modules/FiretrayHandler.jsm
+++ b/src/modules/FiretrayHandler.jsm
@@ -87,10 +87,9 @@ firetray.Handler = {
     if (this.inMailApp) {
       try {
         Cu.import("resource://firetray/FiretrayMessaging.jsm");
-        let prefMailNotification = firetray.Utils.prefService.getIntPref("mail_notification");
-        if (prefMailNotification !== FT_NOTIFICATION_DISABLED) {
+        if (firetray.Utils.prefService.getBoolPref("mail_notification_enabled")) {
           firetray.Messaging.init();
-          firetray.Messaging.updateUnreadMsgCount();
+          firetray.Messaging.updateMsgCount();
         }
       } catch (x) {
         ERROR(x);
@@ -103,11 +102,11 @@ firetray.Handler = {
 
     firetray.VersionChange.setInstallHook(function(ver) {
       firetray.Handler.openTab(FIRETRAY_SPLASH_PAGE+"#"+ver);
-      firetray.Handler.tryEraseV03Options();
+      firetray.Handler.tryEraseOldOptions();
     });
     firetray.VersionChange.setUpgradeHook(function(ver) {
       firetray.Handler.openTab(FIRETRAY_SPLASH_PAGE+"#"+ver);
-      firetray.Handler.tryEraseV03Options(); // FIXME: should check versions here
+      firetray.Handler.tryEraseOldOptions();
     });
     firetray.VersionChange.setReinstallHook(function(ver) {
       firetray.Handler.openTab(FIRETRAY_SPLASH_PAGE+"#"+ver);
@@ -317,8 +316,8 @@ firetray.Handler = {
     }
   },
 
-  tryEraseV03Options: function() {
-    let v03options = [
+  tryEraseOldOptions: function() {
+    let v03Options = [
       "close_to_tray", "minimize_to_tray", "start_minimized", "confirm_exit",
       "restore_to_next_unread", "mail_count_type", "show_mail_count",
       "dont_count_spam", "dont_count_archive", "dont_count_drafts",
@@ -327,8 +326,10 @@ firetray.Handler = {
       "use_custom_special_icon", "custom_normal_icon", "custom_special_icon",
       "text_color", "scroll_to_hide", "scroll_action", "grab_multimedia_keys",
       "hide_show_mm_key", "accounts_to_exclude" ];
+    let v040b2Options = [ 'mail_notification' ];
+    let oldOptions = v03Options.concat(v040b2Options);
 
-    for (let i = 0, length = v03options.length; i<length; ++i) {
+    for (let i = 0, length = oldOptions.length; i<length; ++i) {
       try {
         firetray.Utils.prefService.clearUserPref(v03options[i]);
       } catch (x) {}
@@ -359,6 +360,9 @@ firetray.PrefListener = new PrefListener(
     case 'show_icon_on_hide':
       firetray.Handler.showHideIcon();
       break;
+    case 'message_count_type':
+      firetray.Messaging.updateMsgCount();
+      break;
     default:
     }
   });
diff --git a/src/modules/FiretrayMessaging.jsm b/src/modules/FiretrayMessaging.jsm
index 5847c59..fadd11b 100644
--- a/src/modules/FiretrayMessaging.jsm
+++ b/src/modules/FiretrayMessaging.jsm
@@ -20,16 +20,8 @@ const FLDRS_UNINTERESTING = {
   Trash:     Ci.nsMsgFolderFlags.Trash
 };
 
-/**
- * firetray namespace.
- */
-if ("undefined" == typeof(firetray)) {
-  var firetray = {};
-};
-
 
 firetray.Messaging = {
-  _unreadMsgCount: 0,
   initialized: false,
 
   init: function() {
@@ -66,13 +58,17 @@ firetray.Messaging = {
      * @param newFlag: New header flag (long).
      */
     OnItemIntPropertyChanged: function(folder, property, oldValue, newValue) {
-      let excludedFoldersFlags = firetray.Utils.prefService
-        .getIntPref("excluded_folders_flags");
-      if (property.toString() === "TotalUnreadMessages" &&
-          !(folder.flags & excludedFoldersFlags)) {
-        LOG("Unread msgs for folder "+folder.prettyName+" was "+oldValue+" became "+newValue);
-        firetray.Messaging.updateUnreadMsgCount();
+      let excludedFoldersFlags = firetray.Utils.prefService.getIntPref("excluded_folders_flags");
+      let msgCountType = firetray.Utils.prefService.getIntPref("message_count_type");
+
+      if (!(folder.flags & excludedFoldersFlags)) {
+        let prop = property.toString();
+        LOG("intProperty "+prop+" for folder "+folder.prettyName+" was "+oldValue+" became "+newValue);
+        if (prop === "TotalUnreadMessages" && msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD ||
+            prop === "BiffState" && msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW)
+          firetray.Messaging.updateMsgCount();
       }
+
     }
   },
 
@@ -82,10 +78,9 @@ firetray.Messaging = {
    * considered new, so we may have to use nsMsgFolderFlagType.GotNew on all
    * folders
    */
-  updateUnreadMsgCount: function() {
-    LOG("unreadMsgCount");
-    let prefMailNotification = firetray.Utils.prefService.getIntPref("mail_notification");
-    if (prefMailNotification === FT_NOTIFICATION_DISABLED)
+  updateMsgCount: function() {
+    LOG("updateMsgCount");
+    if (!this.initialized)
       return;
 
     let mailAccounts = firetray.Utils.getObjPref('mail_accounts');
@@ -95,7 +90,17 @@ firetray.Messaging = {
     let excludedFoldersFlags = firetray.Utils.prefService
       .getIntPref("excluded_folders_flags");
 
-    this._unreadMsgCount = 0;   // reset
+    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) {
@@ -110,8 +115,9 @@ firetray.Messaging = {
           while(subFolders.hasMoreElements()) {
             let folder = subFolders.getNext().QueryInterface(Ci.nsIMsgFolder);
             if (!(folder.flags & excludedFoldersFlags)) {
-              LOG(folder.prettyName+" unread="+folder.getNumUnread(true));
-              this._unreadMsgCount += folder.getNumUnread(true); // includes subfolders
+              folderNewMsgCount = folder[getNewMessageCount](true); // includes subfolders
+              LOG(folder.prettyName+" "+getNewMessageCount+"="+folderNewMsgCount);
+              newMsgCount += folderNewMsgCount;
             }
           }
         }
@@ -119,35 +125,35 @@ firetray.Messaging = {
     } catch (x) {
       ERROR(x);
     }
-    LOG("TotalUnread="+this._unreadMsgCount);
+    LOG("Total Unread="+newMsgCount);
 
     // update icon
-    if (this._unreadMsgCount == 0) {
+    if (newMsgCount == 0) {
       firetray.Handler.setIconImageDefault();
       firetray.Handler.setIconTooltipDefault();
 
-    } else if (this._unreadMsgCount > 0) {
+    } else if (newMsgCount > 0) {
+      let prefMailNotification = firetray.Utils.prefService.getIntPref('mail_notification_type');
       switch (prefMailNotification) {
-
-      case FT_NOTIFICATION_UNREAD_MESSAGE_COUNT:
+      case FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT:
         let prefIconTextColor = firetray.Utils.prefService.getCharPref("icon_text_color");
-        firetray.Handler.setIconText(this._unreadMsgCount.toString(), prefIconTextColor);
+        firetray.Handler.setIconText(newMsgCount.toString(), prefIconTextColor);
         break;
-      case FT_NOTIFICATION_NEWMAIL_ICON:
+      case FIRETRAY_NOTIFICATION_NEWMAIL_ICON:
         firetray.Handler.setIconImage(firetray.Handler.FILENAME_NEWMAIL);
         break;
-      case FT_NOTIFICATION_CUSTOM_ICON:
+      case FIRETRAY_NOTIFICATION_CUSTOM_ICON:
         let prefCustomIconPath = firetray.Utils.prefService.getCharPref("custom_mail_icon");
         firetray.Handler.setIconImage(prefCustomIconPath);
         break;
       default:
-        ERROR("Unknown notification mode");
+        ERROR("Unknown notification mode: "+prefMailNotification);
       }
 
       let localizedMessage = PluralForm.get(
-        this._unreadMsgCount,
+        newMsgCount,
         firetray.Utils.strings.GetStringFromName("tooltip.unread_messages"))
-        .replace("#1", this._unreadMsgCount);;
+        .replace("#1", newMsgCount);;
       firetray.Handler.setIconTooltip(localizedMessage);
 
     } else {
diff --git a/src/modules/commons.js b/src/modules/commons.js
index ffdef9c..6b64292 100644
--- a/src/modules/commons.js
+++ b/src/modules/commons.js
@@ -5,11 +5,12 @@
 var EXPORTED_SYMBOLS =
   [ "firetray", "LOG", "WARN", "ERROR", "FIREFOX_ID", "THUNDERBIRD_ID",
     "SEAMONKEY_ID", "FIRETRAY_ID", "FIRETRAY_SPLASH_PAGE", "getType",
-    "isArray", "isEmpty", "strEquals", "FT_NOTIFICATION_DISABLED",
-    "FT_NOTIFICATION_UNREAD_MESSAGE_COUNT", "FT_NOTIFICATION_NEWMAIL_ICON",
-    "FT_NOTIFICATION_CUSTOM_ICON",
+    "isArray", "isEmpty", "strEquals",
+    "FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT",
+    "FIRETRAY_NOTIFICATION_NEWMAIL_ICON", "FIRETRAY_NOTIFICATION_CUSTOM_ICON",
     "FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS",
-    "FIRETRAY_DELAY_NOWAIT_MILLISECONDS" ];
+    "FIRETRAY_DELAY_NOWAIT_MILLISECONDS", "FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD",
+    "FIRETRAY_MESSAGE_COUNT_TYPE_NEW" ];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
@@ -28,14 +29,16 @@ const CHATZILLA_ID   = "{59c81df5-4b7a-477b-912d-4e0fdf64e5f2}";
 const FIRETRAY_ID          = "{9533f794-00b4-4354-aa15-c2bbda6989f8}";
 const FIRETRAY_SPLASH_PAGE = "http://foudfou.github.com/FireTray/";
 
-const FT_NOTIFICATION_DISABLED = 0;
-const FT_NOTIFICATION_UNREAD_MESSAGE_COUNT = 1;
-const FT_NOTIFICATION_NEWMAIL_ICON = 2;
-const FT_NOTIFICATION_CUSTOM_ICON = 3;
+const FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT = 0;
+const FIRETRAY_NOTIFICATION_NEWMAIL_ICON         = 1;
+const FIRETRAY_NOTIFICATION_CUSTOM_ICON          = 3;
 
 const FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS = 500;
 const FIRETRAY_DELAY_NOWAIT_MILLISECONDS          = 0;
 
+const FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD = 0;
+const FIRETRAY_MESSAGE_COUNT_TYPE_NEW    = 1;
+
 /**
  * firetray namespace.
  */

-- 
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