From 693611c9942756432e4335a69e4b3ae79b32059f Mon Sep 17 00:00:00 2001 From: foudfou Date: Sat, 25 Aug 2012 21:45:00 +0200 Subject: [PATCH] * add chat_icon_enable pref * fix globaluserStatus with all IM accounts disconnected * cleaning --- src/chrome/content/options.js | 9 ++++++ src/chrome/content/options.xul | 45 +++++++++++++++++++---------- src/chrome/locale/en-US/options.dtd | 36 +++++++++++++---------- src/defaults/preferences/prefs.js | 1 + src/modules/FiretrayChat.jsm | 36 ++++++++++++++++------- src/modules/FiretrayMessaging.jsm | 9 +++--- 6 files changed, 90 insertions(+), 46 deletions(-) diff --git a/src/chrome/content/options.js b/src/chrome/content/options.js index 96402cd..2239b53 100644 --- a/src/chrome/content/options.js +++ b/src/chrome/content/options.js @@ -5,6 +5,7 @@ const Ci = Components.interfaces; const Cu = Components.utils; Cu.import("resource://firetray/FiretrayHandler.jsm"); +Cu.import("resource://firetray/FiretrayChat.jsm"); Cu.import("resource://firetray/commons.js"); const TREEROW_ACCOUNT_OR_SERVER_TYPE_NAME = 0; @@ -592,6 +593,14 @@ var firetrayUIOptions = { if (!/\d/.test(charStr)) event.preventDefault(); } + }, + + toggleChat: function(enabled) { + F.LOG("Chat icon enable="+enabled); + if (enabled) + firetray.Chat.init(); + else + firetray.Chat.shutdown(); } }; diff --git a/src/chrome/content/options.xul b/src/chrome/content/options.xul index c42002a..3fea56b 100644 --- a/src/chrome/content/options.xul +++ b/src/chrome/content/options.xul @@ -30,6 +30,7 @@ + @@ -44,6 +45,7 @@ + @@ -51,27 +53,27 @@ + label="&hides_single_window.label;" + accesskey="&hides_single_window.accesskey;" + tooltiptext="&hides_single_window.tooltip;"/> + label="&start_hidden.label;" + accesskey="&start_hidden.accesskey;"/> + label="&show_activates.label;" + accesskey="&show_activates.accesskey;" + tooltiptext="&show_activates.tooltip;"/> + label="&remember_desktop.label;" + accesskey="&remember_desktop.accesskey;"/> @@ -113,8 +115,8 @@ + label="&show_icon_on_hide.label;" + accesskey="&show_icon_on_hide.accesskey;"/> + + + + + + + + diff --git a/src/chrome/locale/en-US/options.dtd b/src/chrome/locale/en-US/options.dtd index 9dd80d1..6087848 100644 --- a/src/chrome/locale/en-US/options.dtd +++ b/src/chrome/locale/en-US/options.dtd @@ -7,24 +7,25 @@ + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - + + @@ -77,3 +78,6 @@ + + + diff --git a/src/defaults/preferences/prefs.js b/src/defaults/preferences/prefs.js index e02085b..bdce715 100644 --- a/src/defaults/preferences/prefs.js +++ b/src/defaults/preferences/prefs.js @@ -20,6 +20,7 @@ pref("extensions.firetray.new_mail_icon_names", '["indicator-messages-new", "mai pref("extensions.firetray.show_icon_on_hide", false); pref("extensions.firetray.scroll_hides", true); pref("extensions.firetray.scroll_mode", "down_hides"); +pref("extensions.firetray.chat_icon_enable", true); pref("extensions.firetray.message_count_type", 0); pref("extensions.firetray.mail_notification_enabled", true); diff --git a/src/modules/FiretrayChat.jsm b/src/modules/FiretrayChat.jsm index fd00b31..0f7d756 100644 --- a/src/modules/FiretrayChat.jsm +++ b/src/modules/FiretrayChat.jsm @@ -10,7 +10,6 @@ Cu.import("resource:///modules/imServices.jsm"); Cu.import("resource://firetray/commons.js"); Cu.import("resource://firetray/linux/FiretrayChatStatusIcon.jsm"); -// FIXME: rename to firetray.Chat firetray.Chat = { initialized: false, observedTopics: {}, @@ -118,27 +117,32 @@ firetray.Chat = { }, updateIcon: function() { - let userStatus = Services.core.globalUserStatus.statusType; + let globalConnectedStatus = this.globalConnectedStatus(); + let userStatus; + if (globalConnectedStatus) + userStatus = Services.core.globalUserStatus.statusType; + else + userStatus = Ci.imIStatusInfo.STATUS_OFFLINE; F.LOG("IM status="+userStatus); let iconName; switch (userStatus) { - case Ci.imIStatusInfo.STATUS_OFFLINE: + case Ci.imIStatusInfo.STATUS_OFFLINE: // 1 iconName = FIRETRAY_IM_STATUS_OFFLINE; break; - case Ci.imIStatusInfo.STATUS_IDLE: - case Ci.imIStatusInfo.STATUS_AWAY: + case Ci.imIStatusInfo.STATUS_IDLE: // 4 + case Ci.imIStatusInfo.STATUS_AWAY: // 5 iconName = FIRETRAY_IM_STATUS_AWAY; break; - case Ci.imIStatusInfo.STATUS_AVAILABLE: + case Ci.imIStatusInfo.STATUS_AVAILABLE: // 7 iconName = FIRETRAY_IM_STATUS_AVAILABLE; break; - case Ci.imIStatusInfo.STATUS_UNAVAILABLE: + case Ci.imIStatusInfo.STATUS_UNAVAILABLE: // 6 iconName = FIRETRAY_IM_STATUS_BUSY; break; - case Ci.imIStatusInfo.STATUS_UNKNOWN: - case Ci.imIStatusInfo.STATUS_INVISIBLE: - case Ci.imIStatusInfo.STATUS_MOBILE: + case Ci.imIStatusInfo.STATUS_UNKNOWN: // 0 + case Ci.imIStatusInfo.STATUS_INVISIBLE: // 2 + case Ci.imIStatusInfo.STATUS_MOBILE: // 3 default: // ignore } @@ -146,6 +150,18 @@ firetray.Chat = { F.LOG("IM status changed="+iconName); if (iconName) firetray.ChatStatusIcon.setIconImage(iconName); + }, + + globalConnectedStatus: function() { + let accounts = Services.accounts.getAccounts(); + let globalConnected = false; + while (accounts.hasMoreElements()) { + let account = accounts.getNext().QueryInterface(Ci.imIAccount); + F.LOG("account="+account+" STATUS="+account.statusInfo.statusType+" connected="+account.connected); + globalConnected = globalConnected || account.connected; + } + F.LOG("globalConnected="+globalConnected); + return globalConnected; } }; diff --git a/src/modules/FiretrayMessaging.jsm b/src/modules/FiretrayMessaging.jsm index a9f4012..8938090 100644 --- a/src/modules/FiretrayMessaging.jsm +++ b/src/modules/FiretrayMessaging.jsm @@ -43,8 +43,9 @@ firetray.Messaging = { MailServices.mailSession.AddFolderListener(that.mailSessionListener, that.mailSessionListener.notificationFlags); - // FIXME: add im-icon pref - if (Services.prefs.getBoolPref("mail.chat.enabled") && this.existsIMAccount()) + if (Services.prefs.getBoolPref("mail.chat.enabled") && + firetray.Utils.prefService.getBoolPref("chat_icon_enable") && + this.existsChatAccount()) firetray.Chat.init(); this.initialized = true; @@ -68,7 +69,7 @@ firetray.Messaging = { // this._items is undefined' when calling method: // [nsISimpleEnumerator::hasMoreElements]"), and we're unsure if we should // initAccounts() ourselves... - existsIMAccount: function() { + existsChatAccount: function() { let accounts = new this.Accounts(); for (let accountServer in accounts) if (accountServer.type === 'im') { @@ -84,7 +85,7 @@ firetray.Messaging = { switch (topic) { case "account-removed": this.cleanExcludedAccounts(); - if (subject.QueryInterface(Ci.imIAccount) && !this.existsIMAccount()) + if (subject.QueryInterface(Ci.imIAccount) && !this.existsChatAccount()) firetray.Chat.shutdown(); break; case "account-added":