From e8e36e8a66620ec69e1c9d7393e8d20c0fde4d01 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 28 Feb 2011 17:03:35 +0100 Subject: [PATCH] statusMenu: change IM presence when needed (#617207) --- js/ui/statusMenu.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/js/ui/statusMenu.js b/js/ui/statusMenu.js index 931f02483..60643e3d0 100644 --- a/js/ui/statusMenu.js +++ b/js/ui/statusMenu.js @@ -5,6 +5,7 @@ const GLib = imports.gi.GLib; const Lang = imports.lang; const Shell = imports.gi.Shell; const St = imports.gi.St; +const Tp = imports.gi.TelepathyGLib; const UPowerGlib = imports.gi.UPowerGlib; const Gettext = imports.gettext.domain('gnome-shell'); const _ = Gettext.gettext; @@ -39,6 +40,8 @@ StatusMenuButton.prototype = { this._presence = new GnomeSession.Presence(); this._presenceItems = {}; + this._account_mgr = Tp.AccountManager.dup() + this._upClient = new UPowerGlib.Client(); this.actor.connect('destroy', Lang.bind(this, this._onDestroy)); @@ -169,6 +172,8 @@ StatusMenuButton.prototype = { _setPresenceStatus: function(item, event, status) { this._presence.setStatus(status); + + this._setIMStatus(status); }, _onMyAccountActivate: function() { @@ -206,5 +211,31 @@ StatusMenuButton.prototype = { } else { Util.spawn(['gnome-session-quit', '--power-off']); } + }, + + _setIMStatus: function(session_status) { + let [presence_type, presence_status, msg] = this._account_mgr.get_most_available_presence(); + let type, status; + + // We change the IM presence only if there are connected accounts + if (presence_type == Tp.ConnectionPresenceType.UNSET || + presence_type == Tp.ConnectionPresenceType.OFFLINE || + presence_type == Tp.ConnectionPresenceType.UNKNOWN || + presence_type == Tp.ConnectionPresenceType.ERROR) + return; + + if (session_status == GnomeSession.PresenceStatus.AVAILABLE) { + type = Tp.ConnectionPresenceType.AVAILABLE; + status = "available"; + } + else if (session_status == GnomeSession.PresenceStatus.BUSY) { + type = Tp.ConnectionPresenceType.BUSY; + status = "busy"; + } + else { + return; + } + + this._account_mgr.set_all_requested_presences(type, status, msg); } };