[polari/wip/fmuellner/disconnect-accounts: 25/25] roomList: Add "Disconnect" to network context popover



commit 17312e1b67785a9e910ffa4df28800518acafcaa
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Nov 8 21:19:05 2017 +0100

    roomList: Add "Disconnect" to network context popover
    
    It can be useful to temporarily disable an account - for instance
    a work network while being on vacation - but we lost the ability
    to do so from Polari itself when dropping the separate connections
    dialog in commit 263ff952a3.
    
    Re-expose the option by adding a "Disconnect" action to the network
    context popover that mirrors the existing "Connect" one, and let
    the actions control the account's :enabled property to preserve the
    connection state over restarts.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771889

 data/resources/room-list-header.ui |  8 ++++++++
 src/application.js                 |  3 +++
 src/roomList.js                    |  3 +++
 src/telepathyClient.js             | 15 ++++++++++++++-
 4 files changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/data/resources/room-list-header.ui b/data/resources/room-list-header.ui
index 9b42d30..b235c04 100644
--- a/data/resources/room-list-header.ui
+++ b/data/resources/room-list-header.ui
@@ -154,6 +154,14 @@
             <property name="text" translatable="yes">Reconnect</property>
           </object>
         </child>
+        <child>
+          <object class="GtkModelButton" id="popoverDisconnect">
+            <property name="xalign">0</property>
+            <property name="visible">True</property>
+            <property name="action-name">app.disconnect-account</property>
+            <property name="text" translatable="yes">Disconnect</property>
+          </object>
+        </child>
         <child>
           <object class="GtkModelButton" id="popoverRemove">
             <property name="xalign">0</property>
diff --git a/src/application.js b/src/application.js
index f7f3576..9b80cba 100644
--- a/src/application.js
+++ b/src/application.js
@@ -169,6 +169,9 @@ var Application = GObject.registerClass({
           { name: 'connect-account',
             activate: this._onConnectAccount.bind(this),
             parameter_type: GLib.VariantType.new('o') },
+          { name: 'disconnect-account',
+            activate: this._onConnectAccount.bind(this),
+            parameter_type: GLib.VariantType.new('o') },
           { name: 'reconnect-account',
             activate: this._onConnectAccount.bind(this),
             parameter_type: GLib.VariantType.new('o') },
diff --git a/src/roomList.js b/src/roomList.js
index e5d0229..53a21c3 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -208,6 +208,7 @@ var RoomListHeader = GObject.registerClass({
                        'popoverTitle',
                        'popoverPassword',
                        'popoverConnect',
+                       'popoverDisconnect',
                        'popoverReconnect',
                        'popoverRemove',
                        'popoverProperties',
@@ -233,6 +234,7 @@ var RoomListHeader = GObject.registerClass({
 
         let target = new GLib.Variant('o', this._account.get_object_path());
         this._popoverConnect.action_target = target;
+        this._popoverDisconnect.action_target = target;
         this._popoverReconnect.action_target = target;
         this._popoverRemove.action_target = target;
         this._popoverProperties.action_target = target;
@@ -370,6 +372,7 @@ var RoomListHeader = GObject.registerClass({
         let presence = this._account.requested_presence_type;
         let offline = presence == Tp.ConnectionPresenceType.OFFLINE;
         this._popoverConnect.visible = offline;
+        this._popoverDisconnect.visible = !offline;
         this._popoverReconnect.visible = !offline;
         this._onConnectionStatusChanged();
     }
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index 1f0f020..07d793e 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -143,6 +143,8 @@ class TelepathyClient extends Tp.BaseClient {
               handler: this._onLeaveActivated.bind(this) },
             { name: 'connect-account',
               handler: this._onConnectAccountActivated.bind(this) },
+            { name: 'disconnect-account',
+              handler: this._onDisconnectAccountActivated.bind(this) },
             { name: 'reconnect-account',
               handler: this._onReconnectAccountActivated.bind(this) },
             { name: 'authenticate-account',
@@ -340,7 +342,18 @@ class TelepathyClient extends Tp.BaseClient {
     _onConnectAccountActivated(action, parameter) {
         let accountPath = parameter.deep_unpack();
         let account = this._accountsMonitor.lookupAccount(accountPath);
-        this._connectAccount(account);
+        if (account.enabled)
+            this._connectAccount(account);
+        else
+            account.set_enabled_async(true, () => {});
+    }
+
+    _onDisconnectAccountActivated(action, parameter) {
+        let accountPath = parameter.deep_unpack();
+        let account = this._accountsMonitor.lookupAccount(accountPath);
+        account.set_enabled_async(false, () => {
+            this._setAccountPresence(account, Tp.ConnectionPresenceType.OFFLINE);
+        });
     }
 
     _onReconnectAccountActivated(action, parameter) {


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