aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-12-06 15:36:47 +0000
committerCharles Kerr <charles.kerr@canonical.com>2013-12-06 15:36:47 +0000
commitabc3e28dc72d9641e2ce07d0d99a23ac23e4f3b6 (patch)
treeda0d8236889c02482c9eeaa832ae2d93b9663737 /src
parent9d183eb66446fb0995f2fe98fd279625281a14ed (diff)
downloadayatana-indicator-bluetooth-abc3e28dc72d9641e2ce07d0d99a23ac23e4f3b6.tar.gz
ayatana-indicator-bluetooth-abc3e28dc72d9641e2ce07d0d99a23ac23e4f3b6.tar.bz2
ayatana-indicator-bluetooth-abc3e28dc72d9641e2ce07d0d99a23ac23e4f3b6.zip
add a 'connected' property as a simple hook to whether or not we have any connected bluetooth devices
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth.vala3
-rw-r--r--src/bluez.vala21
2 files changed, 23 insertions, 1 deletions
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)
{