[Pkg-mozext-commits] [firetray] 33/399: add unread messages counting facility (messaging-related)

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:09 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 8986ca9cf7ccd7def584c3a9ad27815520435348
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Wed Sep 7 16:24:14 2011 +0200

    add unread messages counting facility (messaging-related)
---
 README.md                     |   11 +++-
 TODO                          |    2 +
 src/modules/MoztHandler.jsm   |   30 ++++++++--
 src/modules/MoztMessaging.jsm |  125 +++++++++++++++++++++++++++++++++++++++++
 src/modules/commons.js        |    4 +-
 5 files changed, 166 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 85b965a..97b6b32 100644
--- a/README.md
+++ b/README.md
@@ -12,9 +12,18 @@ Notes
 * Moztray unsets the `tabs.warnOnClose` built-in preference, which otherwise disrupts the handeling of the close event.
 * Experimental non-customizable keyboard shortcut for hiding all windows set to: `accel-shift-w`
 
+References
+----------
+
 * if you're looking for other mozilla-desktop integration:
   * Paul Neulinger's [Gnome-shell-Thunderbird integration](https://github.com/tanwald/gnome-shell-extension-thunderbird-integration "gnome-shell-thunderbird integration")
-  * Mike Conley's [Unity-Thunderbird integration](http://mozillalabs.com/messaging/messaging-menu/ "Unity-Thunderbird integration")
+  * Mike Conley's
+    [Unity-Thunderbird integration](http://mozillalabs.com/messaging/messaging-menu/
+    "Unity-Thunderbird integration")
+  * discontinued [Mozilla New Mail Icon (Biff)](http://moztraybiff.mozdev.org/)
+
+* [Alltray](http://alltray.trausch.us/ "alltray") launches any applications
+  into tray
 
 KNOWN BUGS
 ----------
diff --git a/TODO b/TODO
index c56d9d0..3b38c85 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
+* change tray icon according to unreadMsgCount
+
 * make multi-platform. At least have js-ctypes library call dependant on OS detection. (best would be to have the OS-dependant modules loaded at startup) 
 
 * convert to a https://developer.mozilla.org/en/Extensions/Bootstrapped_extensions
diff --git a/src/modules/MoztHandler.jsm b/src/modules/MoztHandler.jsm
index 33eb354..6cfbdeb 100644
--- a/src/modules/MoztHandler.jsm
+++ b/src/modules/MoztHandler.jsm
@@ -39,6 +39,7 @@ mozt.Handler = {
   initialized: false,
   _windowsHidden: false,
   _handledDOMWindows: [],
+  _inMailApp: false,
 
   _getBaseOrXULWindowFromDOMWindow: function(win, winType) {
     let winInterface, winOut;
@@ -174,7 +175,7 @@ mozt.Handler = {
     }
   },
 
-  /*
+  /**
    * @param strings l10n Strings passed from the XUL overlay
    */
   init: function() {            // creates icon
@@ -202,14 +203,14 @@ mozt.Handler = {
       // instanciate tray icon
       LibGtkStatusIcon.init();
       this.trayIcon  = LibGtkStatusIcon.gtk_status_icon_new();
-      var mozApp = Services.appinfo.name.toLowerCase();
-      var iconFilename = MOZT_ICON_DIR + mozApp + MOZT_ICON_SUFFIX;
+      let mozApp = Services.appinfo.name.toLowerCase();
+      let iconFilename = MOZT_ICON_DIR + mozApp + MOZT_ICON_SUFFIX;
       LibGtkStatusIcon.gtk_status_icon_set_from_file(this.trayIcon,
                                                      iconFilename);
 
       // build icon popup menu
       this.menu = LibGtkStatusIcon.gtk_menu_new();
-      // shouldn't need to g_utf16_to_utf8() thank to js-ctypes
+      // shouldn't need to convert to utf8 thank to js-ctypes
 		  var menuItemQuitLabel = this.strings.GetStringFromName("popupMenu.itemLabel.Quit");
       var menuItemQuit = LibGtkStatusIcon.gtk_image_menu_item_new_with_label(
         menuItemQuitLabel);
@@ -256,8 +257,29 @@ mozt.Handler = {
       return false;
     }
 
+    // check if in mail app
+    var mozAppId = Services.appinfo.ID;
+    if (mozAppId === THUNDERBIRD_ID || mozAppId === SEAMONKEY_ID) {
+      this._inMailApp = true;
+      try {
+        Cu.import("resource://moztray/MoztMessaging.jsm");
+        mozt.Messaging.enable();
+      } catch (x) {
+        ERROR(x);
+        return false;
+      }
+
+      // init unread messages count
+      mozt.Messaging.updateUnreadMsgCount();
+    }
+
     this.initialized = true;
     return true;
   },
 
+  shutdown: function() {        // NOT USED YET
+      if (this._inMailApp)
+        mozt.Messaging.disable();
+  }
+
 }; // mozt.Handler
diff --git a/src/modules/MoztMessaging.jsm b/src/modules/MoztMessaging.jsm
new file mode 100644
index 0000000..799d232
--- /dev/null
+++ b/src/modules/MoztMessaging.jsm
@@ -0,0 +1,125 @@
+/* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+var EXPORTED_SYMBOLS = [ "mozt" ];
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+
+Cu.import("resource:///modules/mailServices.js");
+Cu.import("resource://moztray/commons.js");
+
+const FLDR_UNINTERESTING =
+  Ci.nsMsgFolderFlags.Archive |
+  Ci.nsMsgFolderFlags.Drafts |
+  Ci.nsMsgFolderFlags.Junk |
+  Ci.nsMsgFolderFlags.Queue |
+  Ci.nsMsgFolderFlags.SentMail |
+  Ci.nsMsgFolderFlags.Templates |
+  Ci.nsMsgFolderFlags.Trash;
+
+/**
+ * mozt namespace.
+ */
+if ("undefined" == typeof(mozt)) {
+  var mozt = {};
+};
+
+mozt.Messaging = {
+  _unreadMsgCount: 0,
+
+  enable: function() {
+    if (this.enabled) {
+      WARN("Trying to enable more than once");
+      return;
+    }
+
+    LOG("Enabling Messaging");
+    let that = this;
+    let mailSessionNotificationFlags = Ci.nsIFolderListener.intPropertyChanged;
+    MailServices.mailSession.AddFolderListener(that.mailSessionListener,
+                                               mailSessionNotificationFlags);
+    // doesn't seem like we also needed a
+    // MailServices.mfn.addListener(that.notificationServiceListener,
+    // msgFolderNotificationFlags);
+
+    this.enabled = true;
+  },
+
+  disable: function() {
+    if (!this.enabled)
+      return;
+
+    MailServices.mailSession.RemoveFolderListener(this);
+
+    this.enabled = false;
+  },
+
+  mailSessionListener: {
+    /**
+     * @param folder: nsIMsgFolder
+     * @param property: nsIAtom
+     * @param oldFlag: Old header flag (long).
+     * @param newFlag: New header flag (long).
+     */
+    // TODO: check count correctly updated if folder/account creation/deletion
+    OnItemIntPropertyChanged: function(folder, property, oldValue, newValue) {
+      LOG("OnItemIntPropertyChanged fired with property: "+property);
+
+      switch (property.toString())  {
+      case "TotalUnreadMessages":
+        if (!(folder.flags & FLDR_UNINTERESTING)) {
+          LOG("Unread msgs for folder "+folder.prettyName+" was "+oldValue+" became "+newValue);
+          mozt.Messaging.updateUnreadMsgCount();
+        }
+        break;
+      default:
+      }
+    }
+  },
+
+  /**
+   * computes total unread message count
+   * TODO: check news accounts shouldn't be considered
+   */
+  updateUnreadMsgCount: function() {
+    LOG("unreadMsgCount");
+    this._unreadMsgCount = 0;   // reset
+    try {
+      let accounts = MailServices.accounts.accounts;
+      for (let i = 0; i < accounts.Count(); i++) {
+        let account = accounts.QueryElementAt(i, Ci.nsIMsgAccount);
+        LOG("ACCOUNT: "+account.incomingServer.prettyName+" type: "+account.incomingServer.type);
+        let rootFolder = account.incomingServer.rootFolder; // nsIMsgFolder
+        if (rootFolder.hasSubFolders) {
+          let subFolders = rootFolder.subFolders; // nsIMsgFolder
+          while(subFolders.hasMoreElements()) {
+            let folder = subFolders.getNext().QueryInterface(Ci.nsIMsgFolder);
+            if (!(folder.flags & FLDR_UNINTERESTING))
+              LOG(folder.prettyName+" unread="+folder.getNumUnread(true)); // include subfolders
+            this._unreadMsgCount += folder.getNumUnread(true);   // reset
+          }
+        }
+      }
+    } catch (x) {
+      ERROR(x);
+    }
+    LOG("TotalUnread="+this._unreadMsgCount);
+  }
+
+};
+
+
+function hasMultipleAccounts() {
+  let count = 0;
+  // We don't want to just call Count() on the account nsISupportsArray, as we
+  // want to filter out accounts with "none" as the incoming server type
+  // (eg, for Local Folders)
+  for (let account in fixIterator(MailServices.accounts.accounts, Ci.nsIMsgAccount)) {
+    if (account.incomingServer.type != "none") {
+      count++
+    }
+  }
+
+  return count > 1;
+}
diff --git a/src/modules/commons.js b/src/modules/commons.js
index 87a140e..9f31578 100644
--- a/src/modules/commons.js
+++ b/src/modules/commons.js
@@ -1,6 +1,8 @@
 /* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
-var EXPORTED_SYMBOLS = [ "mozt", "Cc", "Ci", "Cu", "LOG", "WARN", "ERROR" ];
+var EXPORTED_SYMBOLS =
+  [ "mozt", "Cc", "Ci", "Cu", "LOG", "WARN", "ERROR",
+    "FIREFOX_ID", "THUNDERBIRD_ID", "SEAMONKEY_ID" ];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;

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