diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-bluetooth-service.vala | 63 | ||||
-rw-r--r-- | src/indicator-bluetooth.vala | 5 |
2 files changed, 63 insertions, 5 deletions
diff --git a/src/indicator-bluetooth-service.vala b/src/indicator-bluetooth-service.vala index 63e634d..ac84f33 100644 --- a/src/indicator-bluetooth-service.vala +++ b/src/indicator-bluetooth-service.vala @@ -10,6 +10,7 @@ public class BluetoothIndicator { + private Settings settings; private DBusConnection bus; private Indicator.Service indicator_service; private Dbusmenu.Server menu_server; @@ -22,11 +23,17 @@ public class BluetoothIndicator private bool updating_visible = false; private Dbusmenu.Menuitem devices_separator; private List<BluetoothMenuItem> device_items; - private Dbusmenu.Menuitem settings_item; private Dbusmenu.Menuitem menu; public BluetoothIndicator () throws Error { + settings = new Settings ("com.canonical.indicator.bluetooth"); + settings.changed.connect ((key) => + { + if (key == "visible") + update_visible (); + }); + bus = Bus.get_sync (BusType.SESSION); indicator_service = new Indicator.Service ("com.canonical.indicator.bluetooth"); @@ -106,12 +113,21 @@ public class BluetoothIndicator sep.property_set (Dbusmenu.MENUITEM_PROP_TYPE, Dbusmenu.CLIENT_TYPES_SEPARATOR); menu.child_append (sep); - settings_item = new Dbusmenu.Menuitem (); - settings_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Bluetooth Settings…")); - settings_item.item_activated.connect (() => { show_control_center ("bluetooth"); }); - menu.child_append (settings_item); + var item = new Dbusmenu.Menuitem (); + item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Set Up New Device…")); + item.item_activated.connect (() => { set_up_new_device (); }); + menu.child_append (item); + + item = new Dbusmenu.Menuitem (); + item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Bluetooth Settings…")); + item.item_activated.connect (() => { show_control_center ("bluetooth"); }); + menu.child_append (item); killswitch_state_changed_cb (killswitch.state); + + client.adapter_model.row_inserted.connect (update_visible); + client.adapter_model.row_deleted.connect (update_visible); + update_visible (); } private BluetoothMenuItem? find_menu_item (string address) @@ -168,6 +184,26 @@ public class BluetoothIndicator item.update (type, proxy, alias, icon, connected, services, uuids); } + private void update_visible () + { + bluetooth_service._visible = client.adapter_model.iter_n_children (null) > 0 && settings.get_boolean ("visible"); + 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; @@ -334,6 +370,18 @@ private class BluetoothMenuItem : Dbusmenu.Menuitem } } +private void set_up_new_device () +{ + try + { + Process.spawn_command_line_async ("bluetooth-wizard"); + } + catch (GLib.SpawnError e) + { + warning ("Failed to open bluetooth-wizard: %s", e.message); + } +} + private void show_control_center (string panel) { try @@ -377,6 +425,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; } } |