user-menu: Restore previous IM presence on startup

Move the saved user-set presence to GSettings, so it is preserved
between logins.

https://bugzilla.gnome.org/show_bug.cgi?id=659021
This commit is contained in:
Florian Müllner 2011-09-30 18:54:45 +02:00
parent d839670f54
commit 39c5d23a87
2 changed files with 22 additions and 6 deletions

View File

@ -50,6 +50,10 @@
<default>[]</default> <default>[]</default>
<_summary>History for the looking glass dialog</_summary> <_summary>History for the looking glass dialog</_summary>
</key> </key>
<key name="saved-im-presence" type="i">
<default>0</default>
<_summary></_summary>
</key>
<child name="clock" schema="org.gnome.shell.clock"/> <child name="clock" schema="org.gnome.shell.clock"/>
<child name="calendar" schema="org.gnome.shell.calendar"/> <child name="calendar" schema="org.gnome.shell.calendar"/>
<child name="recorder" schema="org.gnome.shell.recorder"/> <child name="recorder" schema="org.gnome.shell.recorder"/>

View File

@ -163,17 +163,23 @@ IMStatusChooserItem.prototype = {
Lang.bind(this, this._sessionStatusChanged)); Lang.bind(this, this._sessionStatusChanged));
this._currentPresence = undefined; this._currentPresence = undefined;
this._previousPresence = undefined;
this._accountMgr = Tp.AccountManager.dup() this._accountMgr = Tp.AccountManager.dup()
this._accountMgr.connect('most-available-presence-changed', this._accountMgr.connect('most-available-presence-changed',
Lang.bind(this, this._IMStatusChanged)); Lang.bind(this, this._IMStatusChanged));
this._accountMgr.prepare_async(null, Lang.bind(this, this._accountMgr.prepare_async(null, Lang.bind(this,
function(mgr) { function(mgr) {
let [presence, s, msg] = mgr.get_most_available_presence(); let [presence, status, msg] = mgr.get_most_available_presence();
this._previousPresence = presence; let savedPresence = global.settings.get_int('saved-im-presence');
this._IMStatusChanged(mgr, presence, s, msg); if (savedPresence == presence) {
this._IMStatusChanged(mgr, presence, status, msg);
} else {
this._setComboboxPresence(savedPresence);
status = this._statusForPresence(savedPresence);
msg = msg ? msg : '';
mgr.set_all_requested_presences(savedPresence, status, msg);
}
})); }));
this._userManager = AccountsService.UserManager.get_default(); this._userManager = AccountsService.UserManager.get_default();
@ -265,15 +271,18 @@ IMStatusChooserItem.prototype = {
return; return;
this._currentPresence = presence; this._currentPresence = presence;
this._setComboboxPresence(presence);
if (presence == Tp.ConnectionPresenceType.AVAILABLE) if (presence == Tp.ConnectionPresenceType.AVAILABLE)
this._presence.setStatus(GnomeSession.PresenceStatus.AVAILABLE); this._presence.setStatus(GnomeSession.PresenceStatus.AVAILABLE);
if (!this._expectedPresence || presence != this._expectedPresence) if (!this._expectedPresence || presence != this._expectedPresence)
this._previousPresence = presence; global.settings.set_int('saved-im-presence', presence);
else else
this._expectedPresence = undefined; this._expectedPresence = undefined;
},
_setComboboxPresence: function(presence) {
let activatedItem; let activatedItem;
if (presence == Tp.ConnectionPresenceType.AVAILABLE) if (presence == Tp.ConnectionPresenceType.AVAILABLE)
@ -315,8 +324,11 @@ IMStatusChooserItem.prototype = {
}, },
getIMPresenceForSessionStatus: function(sessionStatus) { getIMPresenceForSessionStatus: function(sessionStatus) {
// Restore the last user-set presence when coming back from
// BUSY/IDLE (otherwise the last user-set presence matches
// the current one)
if (sessionStatus == GnomeSession.PresenceStatus.AVAILABLE) if (sessionStatus == GnomeSession.PresenceStatus.AVAILABLE)
return this._previousPresence; return global.settings.get_int('saved-im-presence');
if (sessionStatus == GnomeSession.PresenceStatus.BUSY) { if (sessionStatus == GnomeSession.PresenceStatus.BUSY) {
// Only change presence if the current one is "more present" than // Only change presence if the current one is "more present" than