[gnome-shell] user-menu: Restore previous IM presence on startup



commit 39c5d23a871fb2b3e2a7860162ff56284c2f2226
Author: Florian MÃllner <fmuellner gnome org>
Date:   Fri Sep 30 18:54:45 2011 +0200

    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

 data/org.gnome.shell.gschema.xml.in |    4 ++++
 js/ui/userMenu.js                   |   26 +++++++++++++++++++-------
 2 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/data/org.gnome.shell.gschema.xml.in b/data/org.gnome.shell.gschema.xml.in
index 55db42a..a848818 100644
--- a/data/org.gnome.shell.gschema.xml.in
+++ b/data/org.gnome.shell.gschema.xml.in
@@ -50,6 +50,10 @@
       <default>[]</default>
       <_summary>History for the looking glass dialog</_summary>
     </key>
+    <key name="saved-im-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"/>
diff --git a/js/ui/userMenu.js b/js/ui/userMenu.js
index 22988fa..85d9802 100644
--- a/js/ui/userMenu.js
+++ b/js/ui/userMenu.js
@@ -163,17 +163,23 @@ IMStatusChooserItem.prototype = {
                                Lang.bind(this, this._sessionStatusChanged));
 
         this._currentPresence = undefined;
-        this._previousPresence = undefined;
 
         this._accountMgr = Tp.AccountManager.dup()
         this._accountMgr.connect('most-available-presence-changed',
                                  Lang.bind(this, this._IMStatusChanged));
         this._accountMgr.prepare_async(null, Lang.bind(this,
             function(mgr) {
-                let [presence, s, msg] = mgr.get_most_available_presence();
-
-                this._previousPresence = presence;
-                this._IMStatusChanged(mgr, presence, s, msg);
+                let [presence, status, msg] = mgr.get_most_available_presence();
+
+                let savedPresence = global.settings.get_int('saved-im-presence');
+                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();
@@ -265,15 +271,18 @@ IMStatusChooserItem.prototype = {
             return;
 
         this._currentPresence = presence;
+        this._setComboboxPresence(presence);
 
         if (presence == Tp.ConnectionPresenceType.AVAILABLE)
             this._presence.setStatus(GnomeSession.PresenceStatus.AVAILABLE);
 
         if (!this._expectedPresence || presence != this._expectedPresence)
-            this._previousPresence = presence;
+            global.settings.set_int('saved-im-presence', presence);
         else
             this._expectedPresence = undefined;
+    },
 
+    _setComboboxPresence: function(presence) {
         let activatedItem;
 
         if (presence == Tp.ConnectionPresenceType.AVAILABLE)
@@ -315,8 +324,11 @@ IMStatusChooserItem.prototype = {
     },
 
     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)
-            return this._previousPresence;
+            return global.settings.get_int('saved-im-presence');
 
         if (sessionStatus == GnomeSession.PresenceStatus.BUSY) {
             // Only change presence if the current one is "more present" than



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]