From 9312067d29cc1d767d30176a0f2f77766965b11a Mon Sep 17 00:00:00 2001
From: gyan000 <gyan000@ijaz.fr>
Date: Fri, 23 Nov 2018 15:55:25 +0100
Subject: [PATCH] GH-3 - Stop auto-pairing.

* Now we have to use the main switch button to start a pairing.
* If device is unpaired from mobile device, switch button now turn off.
* If device was unpaired when EOSConnect was not active, switch button
is off.
---
 src/EOSConnect/Views/DeviceSettingsView.vala |  4 ++++
 src/MConnect/Device.vala                     | 12 ++++++++----
 src/MConnect/DeviceManager.vala              |  2 +-
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/EOSConnect/Views/DeviceSettingsView.vala b/src/EOSConnect/Views/DeviceSettingsView.vala
index c7ea26c..416f7cb 100644
--- a/src/EOSConnect/Views/DeviceSettingsView.vala
+++ b/src/EOSConnect/Views/DeviceSettingsView.vala
@@ -82,8 +82,10 @@ namespace EOSConnect.Views {
             status_switch.notify["active"].connect (() => {
                 if (status_switch.active) {
                     // ClientIface.get_instance ().allow_device.begin (device.id);
+                        device.pair_device ();
                 } else {
                     // ClientIface.get_instance ().disallow_device.begin (device.id);
+
                 }
             });
 
@@ -97,6 +99,8 @@ namespace EOSConnect.Views {
         public void update_ui () {
             if(device.is_paired) {
                 status_switch.active = true;
+            } else {
+                status_switch.active = false;
             }
         }
     }
diff --git a/src/MConnect/Device.vala b/src/MConnect/Device.vala
index 2862b35..b9af4e5 100644
--- a/src/MConnect/Device.vala
+++ b/src/MConnect/Device.vala
@@ -241,6 +241,10 @@ namespace MConnect {
             }
         }
 
+        public void pair_device () {
+            pair.begin ();
+        }
+
         /**
          * maybe_pair:
          *
@@ -248,8 +252,8 @@ namespace MConnect {
          */
         public void maybe_pair () {
             if (is_paired == false) {
-                if (_pair_in_progress == false)
-                    pair.begin ();
+                //if (_pair_in_progress == false)
+                    //pair.begin ();
             } else {
                 // We are already paired.
                 handle_pair (true);
@@ -369,7 +373,7 @@ namespace MConnect {
                 capability_removed (c);
                 // Remove capability handlers
                 unregister_capability_handler (c);
-                // update_capabilities_status_available (c, false);
+                // Update_capabilities_status_available (c, false);
             }
 
             if (host != null && host.to_string () != other_dev.host.to_string ()) {
@@ -383,7 +387,7 @@ namespace MConnect {
         }
 
         public void send (Packet pkt) {
-            // @TODO: queue messages
+            // TODO: queue messages
             if (_channel != null) {
                 _channel.send.begin (pkt);
             } else {
diff --git a/src/MConnect/DeviceManager.vala b/src/MConnect/DeviceManager.vala
index 5ad292b..4fe537f 100644
--- a/src/MConnect/DeviceManager.vala
+++ b/src/MConnect/DeviceManager.vala
@@ -104,7 +104,7 @@ namespace MConnect {
                 if (is_new) {
                     // Make sure that this happens before we update device data so that
                     // all subscribeds of found_new_device() signal have a chance to
-                    // setup eveything they need
+                    // setup eveything they need.
                     this.found_new_device (dev);
                     dev.capability_added.connect (this.device_capability_added_cb);
                     dev.capability_removed.connect (this.device_capability_removed_cb);
-- 
GitLab