mirror of
https://github.com/moparisthebest/FireTray
synced 2024-12-22 05:48:49 -05:00
IM icon changes according to IM global status
This commit is contained in:
parent
82fae974d1
commit
866bbc1a2e
@ -1,14 +1,16 @@
|
||||
/* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
var EXPORTED_SYMBOLS = [ "firetray", "FLDRS_UNINTERESTING" ];
|
||||
var EXPORTED_SYMBOLS = [ "firetray" ];
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource:///modules/imServices.jsm");
|
||||
Cu.import("resource://firetray/commons.js");
|
||||
Cu.import("resource://firetray/linux/FiretrayIMStatusIcon.jsm");
|
||||
|
||||
// FIXME: rename to firetray.Chat
|
||||
firetray.InstantMessaging = {
|
||||
initialized: false,
|
||||
observedTopics: {},
|
||||
@ -22,11 +24,10 @@ firetray.InstantMessaging = {
|
||||
|
||||
firetray.Utils.addObservers(firetray.InstantMessaging, [
|
||||
// "*" // debugging
|
||||
"idle-time-changed", "new-directed-incoming-message", "new-text",
|
||||
"new-ui-conversation", "status-changed", "unread-im-count-changed",
|
||||
"visited-status-resolution"
|
||||
"account-connected", "account-disconnected", "idle-time-changed",
|
||||
"new-directed-incoming-message", "new-text", "new-ui-conversation",
|
||||
"status-changed", "unread-im-count-changed", "visited-status-resolution"
|
||||
]);
|
||||
|
||||
firetray.IMStatusIcon.init();
|
||||
|
||||
this.initialized = true;
|
||||
@ -37,7 +38,6 @@ firetray.InstantMessaging = {
|
||||
F.LOG("Disabling InstantMessaging");
|
||||
|
||||
firetray.IMStatusIcon.shutdown();
|
||||
|
||||
firetray.Utils.removeAllObservers(firetray.InstantMessaging);
|
||||
|
||||
this.initialized = false;
|
||||
@ -46,18 +46,54 @@ firetray.InstantMessaging = {
|
||||
observe: function(subject, topic, data) {
|
||||
F.LOG("RECEIVED InstantMessaging: "+topic+" subject="+subject+" data="+data);
|
||||
switch (topic) {
|
||||
case "account-connected":
|
||||
case "account-disconnected":
|
||||
case "idle-time-changed":
|
||||
case "status-changed":
|
||||
// case "visited-status-resolution":
|
||||
this.updateIcon();
|
||||
break;
|
||||
|
||||
case "unread-im-count-changed":
|
||||
break;
|
||||
|
||||
case "new-directed-incoming-message": // when PM or cited in channel: new-directed-incoming-message: [xpconnect wrapped (nsISupports, nsIClassInfo, prplIMessage)] null
|
||||
break;
|
||||
case "visited-status-resolution":
|
||||
break;
|
||||
case "status-changed":
|
||||
case "idle-time-changed":
|
||||
break;
|
||||
|
||||
default:
|
||||
F.WARN("unhandled topic: "+topic);
|
||||
}
|
||||
},
|
||||
|
||||
updateIcon: function() {
|
||||
let userStatus = Services.core.globalUserStatus.statusType;
|
||||
F.LOG("IM status="+userStatus);
|
||||
|
||||
let iconName;
|
||||
switch (userStatus) {
|
||||
case Ci.imIStatusInfo.STATUS_OFFLINE:
|
||||
iconName = FIRETRAY_IM_STATUS_OFFLINE;
|
||||
break;
|
||||
case Ci.imIStatusInfo.STATUS_IDLE:
|
||||
case Ci.imIStatusInfo.STATUS_AWAY:
|
||||
iconName = FIRETRAY_IM_STATUS_AWAY;
|
||||
break;
|
||||
case Ci.imIStatusInfo.STATUS_AVAILABLE:
|
||||
iconName = FIRETRAY_IM_STATUS_AVAILABLE;
|
||||
break;
|
||||
case Ci.imIStatusInfo.STATUS_UNAVAILABLE:
|
||||
iconName = FIRETRAY_IM_STATUS_BUSY;
|
||||
break;
|
||||
case Ci.imIStatusInfo.STATUS_UNKNOWN:
|
||||
case Ci.imIStatusInfo.STATUS_INVISIBLE:
|
||||
case Ci.imIStatusInfo.STATUS_MOBILE:
|
||||
default:
|
||||
// ignore
|
||||
}
|
||||
|
||||
F.LOG("IM status changed="+iconName);
|
||||
if (iconName)
|
||||
firetray.IMStatusIcon.setIconImage(iconName);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -62,6 +62,11 @@ firetray.Messaging = {
|
||||
this.initialized = false;
|
||||
},
|
||||
|
||||
// FIXME: this should definetely be done in InstantMessaging, 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...
|
||||
existsIMAccount: function() {
|
||||
let accounts = new this.Accounts();
|
||||
for (let accountServer in accounts)
|
||||
@ -80,10 +85,12 @@ firetray.Messaging = {
|
||||
this.cleanExcludedAccounts();
|
||||
if (subject.QueryInterface(Ci.imIAccount) && !this.existsIMAccount())
|
||||
firetray.InstantMessaging.shutdown();
|
||||
// FIXME: clean InstantMessaging.accounts or just update (?)
|
||||
break;
|
||||
case "account-added":
|
||||
if (subject.QueryInterface(Ci.imIAccount) && !firetray.InstantMessaging.initialized)
|
||||
firetray.InstantMessaging.init();
|
||||
// FIXME: clean InstantMessaging.accounts or just update (?)
|
||||
break;
|
||||
default:
|
||||
F.WARN("unhandled topic: "+topic);
|
||||
|
@ -9,6 +9,8 @@ var EXPORTED_SYMBOLS =
|
||||
"FIRETRAY_APPLICATION_ICON_TYPE_CUSTOM",
|
||||
"FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT",
|
||||
"FIRETRAY_NOTIFICATION_NEWMAIL_ICON", "FIRETRAY_NOTIFICATION_CUSTOM_ICON",
|
||||
"FIRETRAY_IM_STATUS_AVAILABLE", "FIRETRAY_IM_STATUS_AWAY",
|
||||
"FIRETRAY_IM_STATUS_BUSY", "FIRETRAY_IM_STATUS_OFFLINE",
|
||||
"FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS",
|
||||
"FIRETRAY_DELAY_NOWAIT_MILLISECONDS",
|
||||
"FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS",
|
||||
@ -36,6 +38,11 @@ const FIRETRAY_NOTIFICATION_UNREAD_MESSAGE_COUNT = 0;
|
||||
const FIRETRAY_NOTIFICATION_NEWMAIL_ICON = 1;
|
||||
const FIRETRAY_NOTIFICATION_CUSTOM_ICON = 2;
|
||||
|
||||
const FIRETRAY_IM_STATUS_AVAILABLE = "user-available";
|
||||
const FIRETRAY_IM_STATUS_AWAY = "user-away";
|
||||
const FIRETRAY_IM_STATUS_BUSY = "user-busy";
|
||||
const FIRETRAY_IM_STATUS_OFFLINE = "user-offline";
|
||||
|
||||
const FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS = 500;
|
||||
const FIRETRAY_DELAY_NOWAIT_MILLISECONDS = 0;
|
||||
const FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS = 15*60*1000;
|
||||
|
@ -24,12 +24,14 @@ firetray.IMStatusIcon = {
|
||||
|
||||
initialized: false,
|
||||
trayIcon: null,
|
||||
themedIcons: {
|
||||
"user-available": null,
|
||||
"user-away": null,
|
||||
"user-busy": null,
|
||||
"user-offline": null
|
||||
},
|
||||
appId: (function(){return Services.appinfo.ID;})(),
|
||||
themedIcons: (function(){let o = {};
|
||||
o[FIRETRAY_IM_STATUS_AVAILABLE] = null;
|
||||
o[FIRETRAY_IM_STATUS_AWAY] = null;
|
||||
o[FIRETRAY_IM_STATUS_BUSY] = null;
|
||||
o[FIRETRAY_IM_STATUS_OFFLINE] = null;
|
||||
return o;
|
||||
})(),
|
||||
|
||||
init: function() {
|
||||
if (!firetray.Handler.inMailApp) throw "IMStatusIcon for mail app only";
|
||||
@ -37,7 +39,7 @@ firetray.IMStatusIcon = {
|
||||
|
||||
this.trayIcon = gtk.gtk_status_icon_new();
|
||||
this.loadThemedIcons();
|
||||
this.setIconImageFromGIcon(this.themedIcons["user-offline"]);
|
||||
this.setIconImage(FIRETRAY_IM_STATUS_OFFLINE);
|
||||
|
||||
this.initialized = true;
|
||||
return true;
|
||||
@ -66,6 +68,10 @@ firetray.IMStatusIcon = {
|
||||
F.ERROR("Icon missing");
|
||||
F.LOG(gicon);
|
||||
gtk.gtk_status_icon_set_from_gicon(firetray.IMStatusIcon.trayIcon, gicon);
|
||||
},
|
||||
|
||||
setIconImage: function(name) {
|
||||
this.setIconImageFromGIcon(this.themedIcons[name]);
|
||||
}
|
||||
|
||||
}; // firetray.IMStatusIcon
|
||||
|
Loading…
Reference in New Issue
Block a user