* isolate Chat from Messaging

* fix icon update when changing icon preferences
* prevent double observer registration
* add keyboard shortcut for debugging preference window
This commit is contained in:
foudfou 2012-09-06 16:07:12 +02:00
parent aa6b8a9080
commit 23975110a5
5 changed files with 65 additions and 38 deletions

View File

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

View File

@ -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:
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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");