From 9d183eb66446fb0995f2fe98fd279625281a14ed Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 6 Dec 2013 14:25:40 +0000 Subject: on the desktop, show a bluetooth indicator if the hardware supports bluetooth and if the user has chosen for the indicator to be visible. --- src/desktop.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/desktop.vala b/src/desktop.vala index 3c21124..198101a 100644 --- a/src/desktop.vala +++ b/src/desktop.vala @@ -66,7 +66,7 @@ class Desktop: Profile // know when to show the indicator & when to hide it settings.changed["visible"].connect (()=> update_visibility()); - bluetooth.notify["enabled"].connect (() => update_visibility()); + bluetooth.notify["supported"].connect (() => update_visibility()); update_visibility (); // when devices change, rebuild our device section @@ -82,7 +82,7 @@ class Desktop: Profile void update_visibility () { - visible = bluetooth.enabled && settings.get_boolean("visible"); + visible = bluetooth.supported && settings.get_boolean("visible"); } /// -- cgit v1.2.3 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(-) 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 From a3b7b1c7db28b8e89fe5e1dbd671ed73e85feb05 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 6 Dec 2013 15:36:56 +0000 Subject: support header icon states as per the spec -- different icons for disabled, enabled, and enabled-with-connected-devices --- src/profile.vala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/profile.vala b/src/profile.vala index 6aedec3..96ec780 100644 --- a/src/profile.vala +++ b/src/profile.vala @@ -37,7 +37,8 @@ class Profile: Object null, action_state_for_root()); notify["visible"].connect (() => update_root_action_state()); - + bluetooth.notify["enabled"].connect (() => update_root_action_state()); + bluetooth.notify["connected"].connect (() => update_root_action_state()); menu = new Menu (); var item = create_root_menuitem (); @@ -146,7 +147,13 @@ class Profile: Object { string a11y; string icon_name; - if (bluetooth.enabled) + + if (bluetooth.connected) + { + a11y = "Bluetooth (connections)"; + icon_name = "bluetooth-paired"; + } + else if (bluetooth.enabled) { a11y = "Bluetooth (on)"; icon_name = "bluetooth-active"; @@ -158,7 +165,6 @@ class Profile: Object } var icon = new ThemedIcon.with_default_fallbacks (icon_name); - var builder = new VariantBuilder (new VariantType ("a{sv}")); builder.add ("{sv}", "visible", new Variant.boolean (visible)); builder.add ("{sv}", "accessible-desc", new Variant.string (a11y)); -- cgit v1.2.3 From 1ada398d932a25db4b6ead5dc4615f745a3ca418 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 6 Dec 2013 16:08:49 +0000 Subject: change the bluetooth.supported property whenever bluez' default adapter changes its object path. --- src/bluez.vala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bluez.vala b/src/bluez.vala index adbd4c4..a189a16 100644 --- a/src/bluez.vala +++ b/src/bluez.vala @@ -157,6 +157,8 @@ public class Bluez: Bluetooth, Object critical (@"$(e.message)"); } + supported = object_path != null; + on_default_adapter_properties_changed (); } -- cgit v1.2.3 From f1ebedfa17339bc9903a347900cf2753535a5e86 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 6 Dec 2013 16:13:00 +0000 Subject: mark the 'Bluetooth' menuitem for translation --- src/profile.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/profile.vala b/src/profile.vala index 96ec780..4320ac8 100644 --- a/src/profile.vala +++ b/src/profile.vala @@ -86,7 +86,7 @@ class Profile: Object protected MenuItem create_enabled_menuitem () { - var item = new MenuItem ("Bluetooth", "indicator.bluetooth-enabled"); + var item = new MenuItem (_("Bluetooth"), "indicator.bluetooth-enabled"); item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.switch"); -- cgit v1.2.3