[Pkg-mozext-commits] [firetray] 301/399: * isolate Chat from Messaging * fix icon update when changing icon preferences * prevent double observer registration * add keyboard shortcut for debugging preference window

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:24:03 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 23975110a55b57e4e095403c955d82773c6e6c9a
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Thu Sep 6 16:07:12 2012 +0200

    * isolate Chat from Messaging
    * fix icon update when changing icon preferences
    * prevent double observer registration
    * add keyboard shortcut for debugging preference window
---
 src/chrome/content/overlay.xul           |    6 ++++
 src/modules/FiretrayHandler.jsm          |   55 ++++++++++++++++++++++++++++--
 src/modules/FiretrayMessaging.jsm        |   36 +------------------
 src/modules/commons.js                   |    5 +++
 src/modules/linux/FiretrayStatusIcon.jsm |    1 +
 5 files changed, 65 insertions(+), 38 deletions(-)

diff --git a/src/chrome/content/overlay.xul b/src/chrome/content/overlay.xul
index cbae84a..1b7251c 100644
--- a/src/chrome/content/overlay.xul
+++ b/src/chrome/content/overlay.xul
@@ -8,4 +8,10 @@
     <stringbundle id="firetray-strings" src="chrome://firetray/locale/overlay.properties"/>
   </stringbundleset>
 
+  <keyset>
+    <key id="key_debug" key="P" modifiers="control alt shift"
+         oncommand="window.openDialog('chrome://firetray/content/options.xul',
+                    '', 'chrome,titlebar,toolbar,centerscreen', 'pane3');" />
+  </keyset>
+
 </overlay>
diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm
index c3e5071..caa0c04 100644
--- a/src/modules/FiretrayHandler.jsm
+++ b/src/modules/FiretrayHandler.jsm
@@ -107,6 +107,17 @@ firetray.Handler = {
       }
     }
 
+    if (this.appHasChat && Services.prefs.getBoolPref("mail.chat.enabled") &&
+        firetray.Utils.prefService.getBoolPref("chat_icon_enable")) {
+      Cu.import("resource://firetray/FiretrayMessaging.jsm"); // needed for existsChatAccount
+      if (this.existsChatAccount()) {
+        Cu.import("resource://firetray/FiretrayChat.jsm");
+        firetray.Chat.init();
+        firetray.Utils.addObservers(firetray.Handler, [
+          "account-added", "account-removed"]);
+      }
+    }
+
     firetray.Utils.addObservers(firetray.Handler, [ this.appStartupTopic,
       "xpcom-will-shutdown", "profile-change-teardown" ]);
 
@@ -120,6 +131,8 @@ firetray.Handler = {
     log.debug("Disabling Handler");
     firetray.PrefListener.unregister();
 
+    if (firetray.Handler.appHasChat) firetray.Chat.shutdown();
+
     if (this.inMailApp)
       firetray.Messaging.shutdown();
     firetray.StatusIcon.shutdown();
@@ -151,6 +164,22 @@ firetray.Handler = {
     }
   },
 
+  // FIXME: this should definetely be done in Chat, but IM accounts
+  // seem not be initialized at this stage (Exception... "'TypeError:
+  // this._items is undefined' when calling method:
+  // [nsISimpleEnumerator::hasMoreElements]"), and we're unsure if we should
+  // initAccounts() ourselves...
+  existsChatAccount: function() {
+    let accounts = new firetray.Messaging.Accounts();
+    for (let accountServer in accounts)
+      if (accountServer.type === 'im')  {
+        log.debug("found im server: "+accountServer.prettyName);
+        return true;
+      }
+
+    return false;
+  },
+
   observe: function(subject, topic, data) {
     switch (topic) {
     case "sessionstore-windows-restored":
@@ -172,7 +201,18 @@ firetray.Handler = {
       if (data === 'shutdown-persist')
         this.restoreWarnOnClose();
       break;
+
+    case "account-removed":
+      if (!this.existsChatAccount())
+        firetray.Chat.shutdown();
+      break;
+    case "account-added":
+      if (!firetray.Chat.initialized)
+        firetray.Chat.init();
+      break;
+
     default:
+      log.warn("unhandled topic: "+topic);
     }
   },
 
@@ -343,6 +383,15 @@ firetray.PrefListener = new PrefListener(
     case 'show_icon_on_hide':
       firetray.Handler.showHideIcon();
       break;
+    case 'mail_notification_enabled':
+      if (firetray.Utils.prefService.getBoolPref('mail_notification_enabled')) {
+        firetray.Messaging.init();
+        firetray.Messaging.updateMsgCountWithCb();
+      } else {
+        firetray.Messaging.shutdown();
+        firetray.Handler.setIconImageDefault();
+      }
+      break;
     case 'new_mail_icon_names':
       firetray.StatusIcon.loadThemedIcons();
     case 'only_favorite_folders':
@@ -353,12 +402,12 @@ firetray.PrefListener = new PrefListener(
     case 'app_mail_icon_names':
     case 'app_browser_icon_names':
     case 'app_default_icon_names':
-      firetray.StatusIcon.loadThemedIcons();
     case 'app_icon_type':
+      firetray.StatusIcon.loadThemedIcons();
+    case 'app_icon_filename':
+      firetray.Handler.setIconImageDefault();
       if (firetray.Handler.inMailApp)
         firetray.Messaging.updateMsgCountWithCb();
-      else
-        firetray.Handler.setIconImageDefault();
       break;
     default:
     }
diff --git a/src/modules/FiretrayMessaging.jsm b/src/modules/FiretrayMessaging.jsm
index 848e2b2..3502165 100644
--- a/src/modules/FiretrayMessaging.jsm
+++ b/src/modules/FiretrayMessaging.jsm
@@ -39,21 +39,12 @@ firetray.Messaging = {
     }
     log.debug("Enabling Messaging");
 
-    firetray.Utils.addObservers(firetray.Messaging, [ "account-added",
-      "account-removed"]);
+    firetray.Utils.addObservers(firetray.Messaging, ["account-removed"]);
 
     let that = this;
     MailServices.mailSession.AddFolderListener(that.mailSessionListener,
                                                that.mailSessionListener.notificationFlags);
 
-    if (firetray.Handler.appHasChat &&
-        Services.prefs.getBoolPref("mail.chat.enabled") &&
-        firetray.Utils.prefService.getBoolPref("chat_icon_enable") &&
-        this.existsChatAccount()) {
-      Cu.import("resource://firetray/FiretrayChat.jsm");
-      firetray.Chat.init();
-    }
-
     this.initialized = true;
   },
 
@@ -61,8 +52,6 @@ firetray.Messaging = {
     if (!this.initialized) return;
     log.debug("Disabling Messaging");
 
-    if (firetray.Handler.appHasChat) firetray.Chat.shutdown();
-
     MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
 
     firetray.Utils.removeAllObservers(firetray.Messaging);
@@ -70,34 +59,11 @@ firetray.Messaging = {
     this.initialized = false;
   },
 
-  // FIXME: this should definetely be done in Chat, but IM accounts
-  // seem not be initialized at this stage (Exception... "'TypeError:
-  // this._items is undefined' when calling method:
-  // [nsISimpleEnumerator::hasMoreElements]"), and we're unsure if we should
-  // initAccounts() ourselves...
-  existsChatAccount: function() {
-    let accounts = new this.Accounts();
-    for (let accountServer in accounts)
-      if (accountServer.type === 'im')  {
-        log.debug("found im server: "+accountServer.prettyName);
-        return true;
-      }
-
-    return false;
-  },
-
   observe: function(subject, topic, data) {
     log.debug("RECEIVED Messaging: "+topic+" subject="+subject+" data="+data);
     switch (topic) {
     case "account-removed":
       this.cleanExcludedAccounts();
-      if (subject.QueryInterface(Ci.imIAccount) && !this.existsChatAccount())
-        firetray.Chat.shutdown();
-      break;
-    case "account-added":
-      if (subject.QueryInterface(Ci.imIAccount) && !firetray.Chat.initialized)
-        firetray.Chat.init();
-      break;
     default:
       log.warn("unhandled topic: "+topic);
     }
diff --git a/src/modules/commons.js b/src/modules/commons.js
index 12fd71b..69b2a5e 100644
--- a/src/modules/commons.js
+++ b/src/modules/commons.js
@@ -70,6 +70,11 @@ firetray.Utils = {
 
   addObservers: function(handler, topics){
     topics.forEach(function(topic){
+      if (this.observedTopics[topic]) {
+        log.warn(topic+" already registred for "+handler);
+        return;
+      }
+
       Services.obs.addObserver(this, topic, false);
       this.observedTopics[topic] = true;
       log.debug("registred "+topic+" for "+handler);
diff --git a/src/modules/linux/FiretrayStatusIcon.jsm b/src/modules/linux/FiretrayStatusIcon.jsm
index e5f1870..10395ec 100644
--- a/src/modules/linux/FiretrayStatusIcon.jsm
+++ b/src/modules/linux/FiretrayStatusIcon.jsm
@@ -193,6 +193,7 @@ firetray.StatusIcon = {
 }; // firetray.StatusIcon
 
 firetray.Handler.setIconImageDefault = function() {
+  log.debug("setIconImageDefault");
   if (!firetray.StatusIcon.themedIconApp)
     throw "Default application themed icon not set";
   let appIconType = firetray.Utils.prefService.getIntPref("app_icon_type");

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