user-menu: Restore previous session presence at startup

Save the session presence in GSettings and restore it on startup.

https://bugzilla.gnome.org/show_bug.cgi?id=659021
This commit is contained in:
Florian Müllner 2011-10-06 02:47:18 +02:00
parent 39c5d23a87
commit 2947b92148
2 changed files with 28 additions and 1 deletions

View File

@ -54,6 +54,10 @@
<default>0</default>
<_summary></_summary>
</key>
<key name="saved-session-presence" type="i">
<default>0</default>
<_summary></_summary>
</key>
<child name="clock" schema="org.gnome.shell.clock"/>
<child name="calendar" schema="org.gnome.shell.calendar"/>
<child name="recorder" schema="org.gnome.shell.recorder"/>

View File

@ -158,10 +158,11 @@ IMStatusChooserItem.prototype = {
Lang.bind(this, this._changeIMStatus));
this._presence = new GnomeSession.Presence();
this._presence.getStatus(Lang.bind(this, this._sessionStatusChanged));
this._presence.connect('StatusChanged',
Lang.bind(this, this._sessionStatusChanged));
this._sessionPresenceRestored = false;
this._imPresenceRestored = false;
this._currentPresence = undefined;
this._accountMgr = Tp.AccountManager.dup()
@ -267,12 +268,20 @@ IMStatusChooserItem.prototype = {
},
_IMStatusChanged: function(accountMgr, presence, status, message) {
if (!this._imPresenceRestored)
this._imPresenceRestored = true;
if (presence == this._currentPresence)
return;
this._currentPresence = presence;
this._setComboboxPresence(presence);
if (!this._sessionPresenceRestored) {
this._presence.getStatus(Lang.bind(this, this._sessionStatusChanged));
return;
}
if (presence == Tp.ConnectionPresenceType.AVAILABLE)
this._presence.setStatus(GnomeSession.PresenceStatus.AVAILABLE);
@ -349,6 +358,20 @@ IMStatusChooserItem.prototype = {
},
_sessionStatusChanged: function(sessionPresence, sessionStatus) {
if (!this._imPresenceRestored)
return;
if (!this._sessionPresenceRestored) {
let savedStatus = global.settings.get_int('saved-session-presence');
if (sessionStatus != savedStatus) {
this._presence.setStatus(savedStatus);
return;
}
this._sessionPresenceRestored = true;
}
global.settings.set_int('saved-session-presence', sessionStatus);
let [presence, s, msg] = this._accountMgr.get_most_available_presence();
let newPresence, status;