[polari] Store the last active (selected) room



commit 6df5f3dde2ca9bbff1b78c6ec55d50f1f786f1ff
Author: raresv <rares visalom gmail com>
Date:   Sat Feb 27 21:28:31 2016 +0200

    Store the last active (selected) room
    
    The last active (selected) room is stored as a setting in order
    for it to be set as active the next time the user
    launches polari.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=759812

 data/org.gnome.Polari.gschema.xml |    5 +++++
 src/chatroomManager.js            |   37 +++++++++++++++++++++++++++++++++++--
 2 files changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.Polari.gschema.xml b/data/org.gnome.Polari.gschema.xml
index 0704c1e..39907c1 100644
--- a/data/org.gnome.Polari.gschema.xml
+++ b/data/org.gnome.Polari.gschema.xml
@@ -16,5 +16,10 @@
       <summary>Window maximized</summary>
       <description>Window maximized state</description>
     </key>
+    <key type="a{sv}" name="last-selected-channel">
+      <default>{}</default>
+      <summary>Last active channel</summary>
+      <description>Last active (selected) channel</description>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 9891294..c1561fc 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -155,6 +155,13 @@ const _ChatroomManager = new Lang.Class({
         this._accountsMonitor.connect('account-manager-prepared',
                                       Lang.bind(this, this._onPrepared));
         this._amIsPrepared = false;
+
+        this._app.connect('prepare-shutdown',
+                          Lang.bind(this, this._onPrepareShutdown));
+
+        this._settings = new Gio.Settings({ schema_id: 'org.gnome.Polari' });
+
+        this._lastActiveRoom = null;
     },
 
     _onPrepared: function(mon, am) {
@@ -220,6 +227,15 @@ const _ChatroomManager = new Lang.Class({
             if (account.connection_status == Tp.ConnectionStatus.CONNECTED)
                 this._restoreSavedChannels(account);
         }));
+
+        let selectedChannel = this._settings.get_value('last-selected-channel').deep_unpack();
+
+        for (let prop in selectedChannel)
+            selectedChannel[prop] = selectedChannel[prop].deep_unpack();
+
+        if (selectedChannel.account && selectedChannel.channel)
+             this._restoreChannel(selectedChannel);
+
         this._restoreSavedChannels(null);
 
         this._networkMonitor.connect('notify::network-available', Lang.bind(this,
@@ -242,8 +258,7 @@ const _ChatroomManager = new Lang.Class({
     },
 
     _restoreSavedChannels: function(account) {
-        let settings = new Gio.Settings({ schema_id: 'org.gnome.Polari' });
-        let savedChannels = settings.get_value('saved-channel-list').deep_unpack();
+        let savedChannels = this._settings.get_value('saved-channel-list').deep_unpack();
         for (let i = 0; i < savedChannels.length; i++) {
             let serializedChannel = savedChannels[i];
             for (let prop in serializedChannel)
@@ -444,16 +459,34 @@ const _ChatroomManager = new Lang.Class({
     _removeRoom: function(room) {
         if (!this._rooms[room.id])
             return;
+
+        if (room == this._lastActiveRoom)
+            this._lastActiveRoom = null;
+
         room.disconnect(room._channelChangedId);
         delete room._channelChangedId;
         delete this._rooms[room.id];
         this.emit('room-removed', room);
     },
 
+    _onPrepareShutdown: function() {
+        if (this._lastActiveRoom) {
+            let serializedChannel = { account: GLib.Variant.new('s', 
this._lastActiveRoom.account.get_object_path()),
+                                      channel: GLib.Variant.new('s', this._lastActiveRoom.channel_name) };
+
+            this._settings.set_value('last-selected-channel', GLib.Variant.new('a{sv}', serializedChannel));
+        } else {
+            this._settings.reset('last-selected-channel');
+        }
+    },
+
     setActiveRoom: function(room) {
         if (room == this._activeRoom)
             return;
 
+        if (room && room.type == Tp.HandleType.ROOM)
+            this._lastActiveRoom = room;
+
         this._activeRoom = room;
         this.emit('active-changed', room);
         this.emit('active-state-changed');


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