[Pkg-mozext-commits] [firetray] 49/399: add pref to exclude mail servers from checking

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 33fd0b47f7a28b29f97e9fbf3ee6aa93138b3f74
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Thu Sep 22 20:13:43 2011 +0200

    add pref to exclude mail servers from checking
---
 src/chrome/content/options.js       |   71 +++++++++++++++++++++++++++++++++--
 src/chrome/content/options.xul      |    7 +++-
 src/chrome/content/overlay.js       |    2 +-
 src/chrome/locale/en-US/options.dtd |    1 +
 src/defaults/preferences/prefs.js   |    7 ++--
 src/modules/MoztHandler.jsm         |    8 ++--
 src/modules/MoztMessaging.jsm       |   16 +++++---
 7 files changed, 95 insertions(+), 17 deletions(-)

diff --git a/src/chrome/content/options.js b/src/chrome/content/options.js
index e2edaa2..5e5dd3b 100644
--- a/src/chrome/content/options.js
+++ b/src/chrome/content/options.js
@@ -1,9 +1,12 @@
 /* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
-Components.utils.import("resource://moztray/commons.js");
-
 const Cc = Components.classes;
 const Ci = Components.interfaces;
+const Cu = Components.utils;
+
+Cu.import("resource:///modules/mailServices.js");
+Cu.import("resource://moztray/MoztHandler.jsm");
+Cu.import("resource://moztray/commons.js");
 
 /**
  * mozt namespace.
@@ -13,7 +16,69 @@ if ("undefined" == typeof(mozt)) {
 };
 
 mozt.UIOptions = {
+  accountBoxId: "accounts_box",
+
+  onLoad: function() {
+    if(mozt.Handler.inMailApp) {
+      Cu.import("resource://moztray/MoztMessaging.jsm");
+      this.insertMailAccountsExcluded(this.accountBoxId);
+    }
+  },
+
+  insertMailAccountsExcluded: function(parentId) {
+    // the DOM parent where we do appendChild
+    let targetNode = document.getElementById(parentId);
+
+    // accounts_to_exclude preference is a stringified Array containing the
+    // keys of the accounts to exclude
+    let accountsExcluded = mozt.Utils.prefService
+      .getCharPref('accounts_to_exclude').split(',');
+
+    // TODO: sort servers by type, name
+    let accounts = MailServices.accounts.accounts;
+    for (let i = 0; i < accounts.Count(); i++) {
+      let account = accounts.QueryElementAt(i, Ci.nsIMsgAccount);
+      let accountServer = account.incomingServer;
+      if (mozt.Messaging.SERVER_TYPES_EXCLUDED.indexOf(accountServer.type) >= 0)
+        continue;
+
+      let nodeAccount = document.createElement("checkbox");
+      let accountServerKey = accountServer.key.toString();
+      nodeAccount.setAttribute('id', accountServerKey);
+      nodeAccount.setAttribute('label', accountServer.rootFolder.name);
+      nodeAccount.setAttribute('checked',
+                               (accountsExcluded.indexOf(accountServerKey) >= 0));
+      nodeAccount.setAttribute(
+        'oncommand',
+        'mozt.UIOptions.updateMailAccountsExcluded(mozt.UIOptions.accountBoxId)');
+      targetNode.appendChild(nodeAccount);
+    }
+
+    // let disable_notify=prefManager.getIntPref("extensions.firetray.show_mail_notification")==0;
+    // this._disableGroup(targetNode,disable_notify);
+  },
+
+  updateMailAccountsExcluded: function(parentId) {
+    let targetNode = document.getElementById(parentId);
+
+    let prefValue = [];
+    for (let i=1; i < targetNode.childNodes.length; i++) {
+      if (targetNode.childNodes[i].checked)
+        prefValue.push(targetNode.childNodes[i].getAttribute('id'));
+    }
+
+    mozt.Utils.prefService.setCharPref('accounts_to_exclude', prefValue.toString());
+
+    mozt.Messaging.updateUnreadMsgCount();
+  },
 
-  onLoad: function() {}
+  _disableGroup: function(group, disableval) {
+    try {
+      for (let i=0; i< group.childNodes.length; i++)
+        group.childNodes[i].disabled = disableval;
+    } catch(e) {
+      ERROR(e);
+    }
+  }
 
 };
diff --git a/src/chrome/content/options.xul b/src/chrome/content/options.xul
index 08865f3..c7afe08 100644
--- a/src/chrome/content/options.xul
+++ b/src/chrome/content/options.xul
@@ -4,7 +4,7 @@
 <prefwindow id="moztray-preferences"
             xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
             title="&prefwindow.title;"
-            onload= "mozt.UIOptions.onLoad()">
+            onload="mozt.UIOptions.onLoad()">
 
   <script type="application/x-javascript" src="options.js" />
 
@@ -21,6 +21,11 @@
                 accesskey="&bool_close_hides.accesskey;"/>
     </groupbox>
 
+    <groupbox id="accounts_box"> <!-- mozt.UIOptions.accountBoxId -->
+      <caption label="&mail_accounts_exclude;"/>
+      <!-- accounts  are dynamically added here with insert_accounts_name() functions, called at the bottom of this file -->
+    </groupbox>
+
   </prefpane>
 
 </prefwindow>
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index c91453e..ce6d219 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -30,7 +30,7 @@ mozt.Main = {
     let init = mozt.Handler.initialized || mozt.Handler.init();
 
     // update unread messages count
-    if (mozt.Handler._inMailApp)
+    if (mozt.Handler.inMailApp)
       mozt.Messaging.updateUnreadMsgCount();
 
     // prevent window closing.
diff --git a/src/chrome/locale/en-US/options.dtd b/src/chrome/locale/en-US/options.dtd
index d538f99..2a48e75 100644
--- a/src/chrome/locale/en-US/options.dtd
+++ b/src/chrome/locale/en-US/options.dtd
@@ -2,3 +2,4 @@
 <!ENTITY pane1.title "MozTray preferences">
 <!ENTITY bool_close_hides.label "Closing windows hides to tray">
 <!ENTITY bool_close_hides.accesskey "C">
+<!ENTITY mail_accounts_exclude "Mail accounts to exclude" >
diff --git a/src/defaults/preferences/prefs.js b/src/defaults/preferences/prefs.js
index e9b0426..721c95b 100644
--- a/src/defaults/preferences/prefs.js
+++ b/src/defaults/preferences/prefs.js
@@ -1,8 +1,9 @@
 // https://developer.mozilla.org/en/Localizing_extension_descriptions
 pref("extensions.moztray at foudil.fr.description", "chrome://moztray/locale/overlay.properties");
 
-// Extension prefs
-pref("extensions.moztray.close_hides", true);
-
 // Global prefs
 pref("browser.tabs.warnOnClose", false);
+
+// Extension prefs
+pref("extensions.moztray.close_hides", true);
+pref("extensions.moztray.accounts_to_exclude", "");
diff --git a/src/modules/MoztHandler.jsm b/src/modules/MoztHandler.jsm
index c95f569..419386a 100644
--- a/src/modules/MoztHandler.jsm
+++ b/src/modules/MoztHandler.jsm
@@ -28,10 +28,10 @@ if ("undefined" == typeof(mozt)) {
 // (https://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management)
 mozt.Handler = {
   initialized: false,
+  inMailApp: false,
 
   _windowsHidden: false,
   _handledDOMWindows: [],
-  _inMailApp: false,
 
   _getBaseOrXULWindowFromDOMWindow: function(win, winType) {
     let winInterface, winOut;
@@ -173,7 +173,7 @@ mozt.Handler = {
     // check if in mail app
     var mozAppId = Services.appinfo.ID;
     if (mozAppId === THUNDERBIRD_ID || mozAppId === SEAMONKEY_ID) {
-      this._inMailApp = true;
+      this.inMailApp = true;
       try {
         Cu.import("resource://moztray/MoztMessaging.jsm");
         mozt.Messaging.enable();
@@ -185,14 +185,14 @@ mozt.Handler = {
       // init unread messages count
       mozt.Messaging.updateUnreadMsgCount();
     }
-    LOG('inMailApp: '+this._inMailApp);
+    LOG('inMailApp: '+this.inMailApp);
 
     this.initialized = true;
     return true;
   },
 
   shutdown: function() {        // NOT USED YET
-    if (this._inMailApp)
+    if (this.inMailApp)
       mozt.Messaging.disable();
 
     mozt.IconLinux.shutdown();
diff --git a/src/modules/MoztMessaging.jsm b/src/modules/MoztMessaging.jsm
index e7dfadf..4b3e2ec 100644
--- a/src/modules/MoztMessaging.jsm
+++ b/src/modules/MoztMessaging.jsm
@@ -29,6 +29,9 @@ if ("undefined" == typeof(mozt)) {
 };
 
 mozt.Messaging = {
+  // TODO: turn into pref
+  SERVER_TYPES_EXCLUDED: ["nntp","rss","movemail"], // keep "pop3","imap","none"
+
   _unreadMsgCount: 0,
 
   enable: function() {
@@ -81,14 +84,17 @@ mozt.Messaging = {
 
     this._unreadMsgCount = 0;   // reset
     try {
+      let accountsExcluded = mozt.Utils.prefService
+        .getCharPref('accounts_to_exclude').split(',');
+
       let accounts = MailServices.accounts.accounts;
       for (let i = 0; i < accounts.Count(); i++) {
         let account = accounts.QueryElementAt(i, Ci.nsIMsgAccount);
-        let accountServerType = account.incomingServer.type;
-        LOG("ACCOUNT: "+account.incomingServer.prettyName+" type: "+accountServerType);
-        if (["pop3","imap","none"].indexOf(accountServerType) == -1)
-          continue; // skip "nntp" "rss" "movemail"
-        // TODO: turn into pref
+        let accountServer = account.incomingServer;
+        LOG("ACCOUNT: "+account.incomingServer.prettyName+" type: "+accountServer.type);
+        if ( (this.SERVER_TYPES_EXCLUDED.indexOf(accountServer.type) >= 0)
+           || (accountsExcluded.indexOf(accountServer.key) >= 0) )
+          continue;
 
         let rootFolder = account.incomingServer.rootFolder; // nsIMsgFolder
         if (rootFolder.hasSubFolders) {

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