[Pkg-mozext-commits] [firetray] 52/399: sort mail servers in accounts_to_exclude option

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:12 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 dccc716af32ab88c78332fadc00b8cba33c1ab2e
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Fri Sep 23 16:18:44 2011 +0200

    sort mail servers in accounts_to_exclude option
---
 src/chrome/content/options.js |    3 +--
 src/modules/MoztMessaging.jsm |   50 ++++++++++++++++++++++++++++++++---------
 2 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/src/chrome/content/options.js b/src/chrome/content/options.js
index 6d1c0b4..ebe6582 100644
--- a/src/chrome/content/options.js
+++ b/src/chrome/content/options.js
@@ -29,8 +29,7 @@ mozt.UIOptions = {
     // the DOM parent where we do appendChild
     let targetNode = document.getElementById(parentId);
 
-    // TODO: sort servers by type, name
-    let accounts = new mozt.Messaging.Accounts();
+    let accounts = new mozt.Messaging.Accounts(true);
     for (let accountServer in accounts) {
       if (mozt.Messaging.SERVER_TYPES_EXCLUDED.indexOf(accountServer.type) >= 0)
         continue;
diff --git a/src/modules/MoztMessaging.jsm b/src/modules/MoztMessaging.jsm
index a4b1970..e12a81d 100644
--- a/src/modules/MoztMessaging.jsm
+++ b/src/modules/MoztMessaging.jsm
@@ -66,7 +66,6 @@ mozt.Messaging = {
      * @param oldFlag: Old header flag (long).
      * @param newFlag: New header flag (long).
      */
-    // TODO: check if count correctly updated if folder/account creation/deletion
     OnItemIntPropertyChanged: function(folder, property, oldValue, newValue) {
       if (property.toString() === "TotalUnreadMessages" &&
           !(folder.flags & FLDR_UNINTERESTING)) {
@@ -131,25 +130,54 @@ mozt.Messaging = {
       throw "negative message count"; // should never happen
     }
 
-  },
-
-  /**
-   * Accounts constructor for iterating over account servers
-   */
-  Accounts: function() {
   }
 
 };
 
+
 /**
- * make Accounts a Iterator/Generator
+ * Accounts Iterator/Generator for iterating over account servers
+ * @param sortByTypeAndName: boolean
  */
+mozt.Messaging.Accounts = function(sortByTypeAndName) {
+  if (typeof(sortByTypeAndName) == "undefined") {
+    this.sortByTypeAndName = false;
+    return;
+  }
+  if (typeof(sortByTypeAndName) !== "boolean")
+    throw "sort arg must be a boolean";
+
+  this.sortByTypeAndName = sortByTypeAndName;
+};
 mozt.Messaging.Accounts.prototype.__iterator__ = function() {
   let accounts = MailServices.accounts.accounts;
+  LOG("sortByTypeAndName="+this.sortByTypeAndName);
+
+  // NOTE: sort() not provided by nsIMsgAccountManager.accounts
+  // (nsISupportsArray?). Should be OK to re-build a JS-Array for few accounts
+  let accountServers = [];
   for (let i = 0; i < accounts.Count(); i++) {
     let account = accounts.QueryElementAt(i, Ci.nsIMsgAccount);
     let accountServer = account.incomingServer;
-    LOG("ACCOUNT: "+accountServer.prettyName+" type: "+accountServer.type);
-    yield accountServer;
+    accountServers[i] = accountServer;
+  }
+
+  if (this.sortByTypeAndName) {
+    accountServers.sort(function(a,b) {
+      if (a.type < b.type)
+        return -1;
+      if (a.type > b.type)
+        return 1;
+      if (a.name < b.name)
+        return -1;
+      if (a.name > b.name)
+        return 1;
+      return 0; // no sorting
+    });
   }
-}
+
+  for (i = 0; i < accountServers.length; i++) {
+    LOG("ACCOUNT: "+accountServers[i].prettyName+" type: "+accountServers[i].type);
+    yield accountServers[i];
+  }
+};

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