[Pkg-mozext-commits] [firetray] 250/399: * refactor SeniorSpielbergo's work * keep only one mail trigger on msg count change * refactor FiretrayMessaging.jsm * cleaning

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:52 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 de08f67324d1c8778eafd3de06866a9e7934e8b6
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Fri May 25 01:18:28 2012 +0200

    * refactor SeniorSpielbergo's work
    * keep only one mail trigger on msg count change
    * refactor FiretrayMessaging.jsm
    * cleaning
---
 src/chrome/content/options.js       |   35 ++++--------
 src/chrome/content/options.xul      |   53 +++++-------------
 src/chrome/content/overlay.js       |    3 -
 src/chrome/locale/en-US/options.dtd |    9 ++-
 src/defaults/preferences/prefs.js   |    5 +-
 src/modules/FiretrayMessaging.jsm   |  105 ++++++++++++++++++-----------------
 src/modules/commons.js              |    2 +-
 7 files changed, 89 insertions(+), 123 deletions(-)

diff --git a/src/chrome/content/options.js b/src/chrome/content/options.js
index 8b715b6..b655b8c 100644
--- a/src/chrome/content/options.js
+++ b/src/chrome/content/options.js
@@ -31,8 +31,6 @@ var firetrayUIOptions = {
     this.updateScrollOptions();
     this.initAppIconType();
     this.initAppIconNames();
-    this.initNewMailScript();
-    this.initNoNewMailScript();
     if (firetray.Handler.inMailApp)
       this.initNewMailIconNames();
   },
@@ -170,6 +168,7 @@ var firetrayUIOptions = {
 
     this.initMessageCountSettings();
     this.initNotificationSettings();
+    this.initMailTrigger();
 
     this.toggleNotifications(firetray.Utils.prefService.getBoolPref("mail_notification_enabled"));
   },
@@ -208,25 +207,15 @@ var firetrayUIOptions = {
       if (+radio.getItemAtIndex(i).value == value) return i;
     return -1;
   },
-  
-  initNewMailScript : function() {
-    document.getElementById("ui_new_mail_script").value =
-    firetray.Utils.prefService.getCharPref("new_mail_script");
-  },
-  
-  initNoNewMailScript : function() {
-    document.getElementById("ui_no_new_mail_script").value =
-    firetray.Utils.prefService.getCharPref("no_new_mail_script");
-  },
-  
-  updateNewMailScript : function() {
-    let newMailScript = document.getElementById("ui_new_mail_script").value;
-    firetray.Utils.prefService.setCharPref("new_mail_script", newMailScript);
+
+  initMailTrigger: function() {
+    document.getElementById("ui_mail_change_trigger").value =
+      firetray.Utils.prefService.getCharPref("mail_change_trigger");
   },
-  
-  updateNoNewMailScript : function() {
-    let noNewMailScript = document.getElementById("ui_no_new_mail_script").value;
-    firetray.Utils.prefService.setCharPref("no_new_mail_script", noNewMailScript);
+
+  updateMailTrigger: function() {
+    let mailTrigger = document.getElementById("ui_mail_change_trigger").value.trim();
+    firetray.Utils.prefService.setCharPref("mail_change_trigger", mailTrigger);
   },
 
   updateNotificationSettings: function() {
@@ -236,7 +225,7 @@ var firetrayUIOptions = {
     firetray.Utils.prefService.setIntPref("mail_notification_type", mailNotificationType);
     this.disableNotificationMaybe(mailNotificationType);
 
-    firetray.Messaging.updateMsgCount();
+    firetray.Messaging.updateIcon();
   },
 
   updateMessageCountSettings: function() {
@@ -283,7 +272,7 @@ var firetrayUIOptions = {
       document.getElementById("broadcaster-notification-disabled")
         .removeAttribute("disabled"); // UI update (enables!)
       if (!firetray.Messaging.initialized) firetray.Messaging.init();
-      firetray.Messaging.updateMsgCount();
+      firetray.Messaging.updateIcon();
 
       let prefMailNotificationType = firetray.Utils.prefService.getIntPref("mail_notification_type");
       this.disableNotificationMaybe(prefMailNotificationType);
@@ -308,7 +297,7 @@ var firetrayUIOptions = {
   chooseMailIconFile: function() {
     var filepath = document.getElementById("custom_mail_icon_filename");
     this._chooseIconFile(filepath);
-    firetray.Messaging.updateMsgCount();
+    firetray.Messaging.updateIcon();
   },
 
   _chooseIconFile: function(iconFilename) {
diff --git a/src/chrome/content/options.xul b/src/chrome/content/options.xul
index 3060307..c42002a 100644
--- a/src/chrome/content/options.xul
+++ b/src/chrome/content/options.xul
@@ -30,14 +30,13 @@
       <preference id="pref_app_icon_filename" name="extensions.firetray.app_icon_filename" type="string"/>
       <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_folder_count_recursive" name="extensions.firetray.folder_count_recursive" type="bool" />
+      <preference id="pref_message_count_type" name="extensions.firetray.message_count_type" type="int" />
+      <preference id="pref_icon_text_color" name="extensions.firetray.icon_text_color" type="string" />
       <preference id="pref_custom_mail_icon" name="extensions.firetray.custom_mail_icon" type="string" />
+      <preference id="pref_mail_change_trigger" name="extensions.firetray.mail_change_trigger" type="string"/>
       <preference id="pref_mail_accounts" name="extensions.firetray.mail_accounts" type="string"/>
-      <preference id="pref_new_mail_script" name="extensions.firetray.new_mail_script" type="string"/>
-      <preference id="pref_no_new_mail_script" name="extensions.firetray.no_new_mail_script" type="string"/>
     </preferences>
 
     <tabbox>
@@ -151,6 +150,12 @@
             </hbox>
           </radiogroup>
 
+          <checkbox id="ui_folder_count_recursive"
+                    label="&folder_count_recursive.label;"
+                    accesskey="&folder_count_recursive.accesskey;"
+                    preference="pref_folder_count_recursive"
+                    observes="broadcaster-notification-disabled"/>
+
           <groupbox id="ui_mail_notification" flex="1">
             <caption>
               <label id="ui_mail_notification_type_label"
@@ -170,7 +175,7 @@
                          observes="broadcaster-notification-disabled"/>
                   <colorpicker id="btn_icon_text_color" type="button"
                                preference="pref_icon_text_color"
-                               onchange="firetray.Messaging.updateMsgCount();"
+                               onchange="firetray.Messaging.updateIcon();"
                                observes="broadcaster-notification-disabled"/>
                 </hbox>
               </hbox>
@@ -203,7 +208,7 @@
                 <hbox id="custom_mail_icon" align="center" flex="1" >
                   <textbox id="custom_mail_icon_filename" preference="pref_custom_mail_icon"
                            observes="broadcaster-notification-disabled"
-                           onchange="firetray.Messaging.updateMsgCount();" flex="1" />
+                           onchange="firetray.Messaging.updateIcon();" flex="1" />
                   <button id="custom_mail_icon_select" label="&choose;"
                           accesskey="&choose.accesskey;"
                           observes="broadcaster-notification-disabled"
@@ -215,38 +220,10 @@
 
           </groupbox>
 
-          <checkbox id="ui_folder_count_recursive"
-                    label="&folder_count_recursive.label;"
-                    accesskey="&folder_count_recursive.accesskey;"
-                    preference="pref_folder_count_recursive"
-                    observes="broadcaster-notification-disabled"/>
-                    
-          <groupbox id="mail_scripts" flex="1">
-          
-            <caption>
-              <label id="ui_mail_scripts_label"
-                     value="&mail_scripts.label;"
-                     observes="broadcaster-notification-disabled" />
-            </caption>
-            
-            <vbox>
-              <label id="ui_new_mail_script_label"
-                     value="&new_mail_script.label;"
-                     observes="broadcaster-notification-disabled" />
-              <textbox id="ui_new_mail_script" size="18"
-                               onchange="firetrayUIOptions.updateNewMailScript();" flex="1" />
-            </vbox>
-                             
-            <vbox>
-              <label id="ui_no_new_mail_script_label"
-                     value="&no_new_mail_script.label;"
-                     observes="broadcaster-notification-disabled" />
-              <textbox id="ui_no_new_mail_script" size="18"
-                               onchange="firetrayUIOptions.updateNoNewMailScript();" flex="1"
-                               label="&no_new_mail_script.label;" />
-            </vbox>
-                             
-          </groupbox>
+          <textbox id="ui_mail_change_trigger" size="18" placeholder="&mail_change_trigger.placeholder;"
+                   onchange="firetrayUIOptions.updateMailTrigger();" flex="1"
+                   tooltiptext="&mail_change_trigger.tooltip;"
+                   observes="broadcaster-notification-disabled" />
 
           <!-- NOTE: groupbox and caption don't have a 'disabled' attribute !! -->
           <groupbox id="unread_count_folder_exceptions" flex="1">
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index e23c6c2..c904d02 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -23,9 +23,6 @@ var firetrayChrome = { // each new window gets a new firetrayChrome !
     F.LOG("ONLOAD"); firetray.Handler.dumpWindows();
     this.winId = firetray.Handler.registerWindow(win);
 
-    if (firetray.Handler.inMailApp && firetray.Messaging.initialized)
-      firetray.Messaging.updateMsgCount();
-
     win.addEventListener('close', firetrayChrome.onClose, true);
     win.addEventListener('resize', firetrayChrome.onResize, true);
 
diff --git a/src/chrome/locale/en-US/options.dtd b/src/chrome/locale/en-US/options.dtd
index 3432619..9dd80d1 100644
--- a/src/chrome/locale/en-US/options.dtd
+++ b/src/chrome/locale/en-US/options.dtd
@@ -41,16 +41,15 @@
 <!ENTITY hide "hide" >
 <!ENTITY restore "restore" >
 
-<!ENTITY mail_scripts.label "Scripts run on new mail / no new mail event" >
-<!ENTITY new_mail_script.label "Script for new mail event:" >
-<!ENTITY no_new_mail_script.label "Script for no new mail event:" >
+<!ENTITY mail_change_trigger.placeholder "mail change trigger">
+<!ENTITY mail_change_trigger.tooltip "Absolute path of the program to run when the message count changes. The first argument is the new message 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 folder_count_recursive.label "Include subfolders">
 <!ENTITY folder_count_recursive.accesskey "f">
+<!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">
diff --git a/src/defaults/preferences/prefs.js b/src/defaults/preferences/prefs.js
index 3e28d02..e02085b 100644
--- a/src/defaults/preferences/prefs.js
+++ b/src/defaults/preferences/prefs.js
@@ -22,13 +22,12 @@ pref("extensions.firetray.scroll_hides", true);
 pref("extensions.firetray.scroll_mode", "down_hides");
 
 pref("extensions.firetray.message_count_type", 0);
-pref("extensions.firetray.folder_count_recursive", true);
 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", "");
-pref("extensions.firetray.new_mail_script", "");
-pref("extensions.firetray.no_new_mail_script", "");
+pref("extensions.firetray.mail_change_trigger", "");
+pref("extensions.firetray.folder_count_recursive", true);
 // Ci.nsMsgFolderFlags.Archive|Drafts|Junk|Queue|SentMail|Trash|Virtual
 pref("extensions.firetray.excluded_folders_flags", 1077956384);
 // exposed in 1 tree, hence 2 branches: serverTypes, excludedAccounts
diff --git a/src/modules/FiretrayMessaging.jsm b/src/modules/FiretrayMessaging.jsm
index ec34131..82bc4b0 100644
--- a/src/modules/FiretrayMessaging.jsm
+++ b/src/modules/FiretrayMessaging.jsm
@@ -25,7 +25,7 @@ const FLDRS_UNINTERESTING = {
 firetray.Messaging = {
   initialized: false,
   cleaningTimer: null,
-  oldMsgCount: 0,
+  currentMsgCount: null,
 
   init: function() {
     if (this.initialized) {
@@ -139,77 +139,69 @@ firetray.Messaging = {
       }
     }
   },
-  
-  runNewMailScript: function() {
-    // create a file for the process
-    var file = Components.classes["@mozilla.org/file/local;1"]  
-                     .createInstance(Components.interfaces.nsILocalFile);  
-    file.initWithPath(firetray.Utils.prefService.getCharPref("new_mail_script"));
-    
-    // create the process
-    var process = Components.classes["@mozilla.org/process/util;1"]  
-                        .createInstance(Components.interfaces.nsIProcess);  
-    process.init(file);
-    
-    var args = [ ];  
-    process.run(false, args, args.length);
-  },
-  
-  runNoNewMailScript: function() {
-    // create a file for the process
-    var file = Components.classes["@mozilla.org/file/local;1"]  
-                     .createInstance(Components.interfaces.nsILocalFile);  
-    file.initWithPath(firetray.Utils.prefService.getCharPref("no_new_mail_script"));
-    
-    // create the process
-    var process = Components.classes["@mozilla.org/process/util;1"]  
-                        .createInstance(Components.interfaces.nsIProcess);  
-    process.init(file);
-    
-    var args = [ ];  
-    process.run(false, args, args.length);
-  },
 
   /**
    * computes and display new msg count
    */
   updateMsgCount: function() {
     F.LOG("updateMsgCount");
+
     if (!this.initialized)
       return;
 
     // initialize
-    let newMsgCount, localizedTooltip;
+    let msgCount;
     let msgCountType = firetray.Utils.prefService.getIntPref("message_count_type");
     F.LOG("msgCountType="+msgCountType);
     if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD) {
-      newMsgCount = this.countMessages(this.unreadMsgCountIterate);
+      msgCount = this.countMessages(this.unreadMsgCountIterate);
+    } else if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW) {
+      msgCount = this.countMessages(this.newMsgCountIterate);
+    } else
+      F.ERROR('unknown message count type');
+
+    if (msgCount !== this.currentMsgCount) {
+
+      this.updateIcon(msgCount);
+
+      let mailChangeTriggerFile = firetray.Utils.prefService.getCharPref("mail_change_trigger");
+      if (mailChangeTriggerFile)
+        this.runProcess(mailChangeTriggerFile, [msgCount.toString()]);
+
+      this.currentMsgCount = msgCount;
+
+    } else {
+      F.LOG("message count unchanged");
+    }
+
+  },
+
+  updateIcon: function(msgCount) {
+    if ("undefined" === typeof(msgCount)) msgCount = this.currentMsgCount;
+
+    let localizedTooltip;
+    let msgCountType = firetray.Utils.prefService.getIntPref("message_count_type");
+    if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD) {
       localizedTooltip = PluralForm.get(
-        newMsgCount,
+        msgCount,
         firetray.Utils.strings.GetStringFromName("tooltip.unread_messages"))
-        .replace("#1", newMsgCount);
+        .replace("#1", msgCount);
       F.LOG(localizedTooltip);
     } else if (msgCountType === FIRETRAY_MESSAGE_COUNT_TYPE_NEW) {
-      newMsgCount = this.countMessages(this.newMsgCountIterate);
       localizedTooltip = firetray.Utils.strings.GetStringFromName("tooltip.new_messages");
     } else
       F.ERROR('unknown message count type');
 
-    // update icon
-    if (newMsgCount == 0) {
+    if (msgCount == 0) {
       firetray.Handler.setIconImageDefault();
       firetray.Handler.setIconTooltipDefault();
-      if (this.oldMsgCount > 0) {
-        this.runNoNewMailScript();
-      }
 
-    } else if (newMsgCount > 0) {
-      this.runNewMailScript();
+    } else if (msgCount > 0) {
       let prefMailNotification = firetray.Utils.prefService.getIntPref('mail_notification_type');
       switch (prefMailNotification) {
       case FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT:
         let prefIconTextColor = firetray.Utils.prefService.getCharPref("icon_text_color");
-        firetray.Handler.setIconText(newMsgCount.toString(), prefIconTextColor);
+        firetray.Handler.setIconText(msgCount.toString(), prefIconTextColor);
         break;
       case FIRETRAY_NOTIFICATION_NEWMAIL_ICON:
         firetray.Handler.setIconImageNewMail();
@@ -227,8 +219,6 @@ firetray.Messaging = {
     } else {
       throw "negative message count"; // should never happen
     }
-    this.oldMsgCount = newMsgCount;
-
   },
 
   /**
@@ -242,7 +232,7 @@ firetray.Messaging = {
     let excludedFoldersFlags = firetray.Utils.prefService
       .getIntPref("excluded_folders_flags");
 
-    let newMsgCount = 0;
+    let msgCount = 0;
     try {
       let accounts = new this.Accounts();
       for (let accountServer in accounts) {
@@ -257,7 +247,7 @@ firetray.Messaging = {
           while(subFolders.hasMoreElements()) {
             let folder = subFolders.getNext().QueryInterface(Ci.nsIMsgFolder);
             if (!(folder.flags & excludedFoldersFlags)) {
-              newMsgCount = folderCountFunction(folder, newMsgCount);
+              msgCount = folderCountFunction(folder, msgCount);
             }
           }
         }
@@ -265,8 +255,8 @@ firetray.Messaging = {
     } catch (x) {
       F.ERROR(x);
     }
-    F.LOG("Total New="+newMsgCount);
-    return newMsgCount;
+    F.LOG("Total New="+msgCount);
+    return msgCount;
   },
 
   unreadMsgCountIterate: function(folder, accumulator) {
@@ -294,6 +284,21 @@ firetray.Messaging = {
       let folderNewMsgCount = folder.hasNewMessages;
       F.LOG(folder.prettyName+" hasNewMessages="+folderNewMsgCount);
       return accumulator || folderNewMsgCount;
+  },
+
+  runProcess: function(filepath, args) {
+    F.LOG("runProcess="+filepath+" args="+args);
+    try {
+      // create a file for the process
+      var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); // TODO: nsILocalFile merged into the nsIFile in Gecko 14
+      file.initWithPath(filepath);
+
+      // create the process
+      var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
+      process.init(file);
+
+      process.run(false, args, args.length);
+    } catch(x) {F.ERROR(x);}
   }
 
 };
diff --git a/src/modules/commons.js b/src/modules/commons.js
index 5edba42..47e7caa 100644
--- a/src/modules/commons.js
+++ b/src/modules/commons.js
@@ -28,7 +28,7 @@ const FIRETRAY_APPLICATION_ICON_TYPE_CUSTOM      = 1;
 
 const FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT = 0;
 const FIRETRAY_NOTIFICATION_NEWMAIL_ICON         = 1;
-const FIRETRAY_NOTIFICATION_CUSTOM_ICON          = 3;
+const FIRETRAY_NOTIFICATION_CUSTOM_ICON          = 2;
 
 const FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS = 500;
 const FIRETRAY_DELAY_NOWAIT_MILLISECONDS          = 0;

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