From 4643e1008371882190c7dcc3dfcec12d6008152b Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Feb 2013 11:38:17 +1300 Subject: Only show indicator if Bluetooth adapter present --- src/indicator-bluetooth-service.vala | 29 +++++++++++++++++++++++++++++ src/indicator-bluetooth.vala | 5 +++++ 2 files changed, 34 insertions(+) (limited to 'src') diff --git a/src/indicator-bluetooth-service.vala b/src/indicator-bluetooth-service.vala index 0348876..21ac4e5 100644 --- a/src/indicator-bluetooth-service.vala +++ b/src/indicator-bluetooth-service.vala @@ -116,6 +116,10 @@ public class BluetoothIndicator menu.child_append (item); killswitch_state_changed_cb (killswitch.state); + + client.adapter_model.row_inserted.connect (adapters_changed_cb); + client.adapter_model.row_deleted.connect (adapters_changed_cb); + adapters_changed_cb (); } private BluetoothMenuItem? find_menu_item (string address) @@ -172,6 +176,26 @@ public class BluetoothIndicator item.update (type, proxy, alias, icon, connected, services, uuids); } + private void adapters_changed_cb () + { + bluetooth_service._visible = client.adapter_model.iter_n_children (null) > 0; + var builder = new VariantBuilder (VariantType.ARRAY); + builder.add ("{sv}", "Visible", new Variant.boolean (bluetooth_service._visible)); + try + { + var properties = new Variant ("(sa{sv}as)", "com.canonical.indicator.bluetooth.service", builder, null); + bus.emit_signal (null, + "/com/canonical/indicator/bluetooth/service", + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + properties); + } + catch (Error e) + { + warning ("Failed to emit signal: %s", e.message); + } + } + private void device_removed_cb (Gtk.TreePath path) { Gtk.TreeIter iter; @@ -393,6 +417,11 @@ public static int main (string[] args) [DBus (name = "com.canonical.indicator.bluetooth.service")] private class BluetoothService : Object { + internal bool _visible = false; + public bool visible + { + get { return _visible; } + } internal string _icon_name = "bluetooth-active"; public string icon_name { diff --git a/src/indicator-bluetooth.vala b/src/indicator-bluetooth.vala index 4f3aef8..bfbbc9f 100644 --- a/src/indicator-bluetooth.vala +++ b/src/indicator-bluetooth.vala @@ -26,6 +26,9 @@ public class BluetoothIndicator : Indicator.Object var menu_client = menu.get_client (); menu_client.add_type_handler_full ("x-canonical-switch", new_switch_cb); + + /* Hide until ready */ + set_visible (false); } private bool new_switch_cb (Dbusmenu.Menuitem newitem, Dbusmenu.Menuitem parent, Dbusmenu.Client client) @@ -80,6 +83,7 @@ public class BluetoothIndicator : Indicator.Object private void server_properties_changed_cb () { + set_visible (proxy.visible); Indicator.image_helper_update (image, proxy.icon_name); accessible_description = proxy.accessible_description; } @@ -122,6 +126,7 @@ public class Switch : Ido.SwitchMenuItem [DBus (name = "com.canonical.indicator.bluetooth.service")] public interface BluetoothService : DBusProxy { + public abstract bool visible { owned get; } public abstract string icon_name { owned get; } public abstract string accessible_description { owned get; } } -- cgit v1.2.3