From abc3e28dc72d9641e2ce07d0d99a23ac23e4f3b6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 6 Dec 2013 15:36:47 +0000 Subject: add a 'connected' property as a simple hook to whether or not we have any connected bluetooth devices --- src/bluetooth.vala | 3 +++ src/bluez.vala | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/bluetooth.vala b/src/bluetooth.vala index b268701..c711e19 100644 --- a/src/bluetooth.vala +++ b/src/bluetooth.vala @@ -32,6 +32,9 @@ public interface Bluetooth: Object eg by a laptop's network killswitch */ public abstract bool enabled { get; protected set; } + /* True if we have a connected device. */ + public abstract bool connected { get; protected set; } + /* Try to enable/disable bluetooth. This can fail if it's overridden by the system, eg by a laptop's network killswitch */ public abstract void try_set_enabled (bool b); diff --git a/src/bluez.vala b/src/bluez.vala index 1a1f837..adbd4c4 100644 --- a/src/bluez.vala +++ b/src/bluez.vala @@ -414,6 +414,7 @@ public class Bluez: Bluetooth, Object supports_file_transfer)); devices_changed (); + update_connected (); } /* update the 'enabled' property by looking at the killswitch state @@ -424,7 +425,22 @@ public class Bluez: Bluetooth, Object debug (@"in upate_enabled, powered is $powered, blocked is $blocked"); enabled = powered && !blocked; } - + + private bool have_connected_device () + { + var devices = get_devices(); + + foreach (var device in devices) + if (device.is_connected) + return true; + + return false; + } + + private void update_connected () + { + connected = have_connected_device (); + } //// //// Public API @@ -444,6 +460,8 @@ public class Bluez: Bluetooth, Object device_connect (proxy); else device_disconnect (proxy); + + update_connected (); } } @@ -463,6 +481,7 @@ public class Bluez: Bluetooth, Object public bool supported { get; protected set; default = false; } public bool discoverable { get; protected set; default = false; } public bool enabled { get; protected set; default = false; } + public bool connected { get; protected set; default = false; } public void try_set_enabled (bool b) { -- cgit v1.2.3