From 0166a12eefbd48e40ffe3354994462eea45461f0 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Feb 2013 11:20:53 +1300 Subject: Add "Set Up New Device" menu item --- src/indicator-bluetooth-service.vala | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/indicator-bluetooth-service.vala') diff --git a/src/indicator-bluetooth-service.vala b/src/indicator-bluetooth-service.vala index 63e634d..0348876 100644 --- a/src/indicator-bluetooth-service.vala +++ b/src/indicator-bluetooth-service.vala @@ -22,7 +22,6 @@ public class BluetoothIndicator private bool updating_visible = false; private Dbusmenu.Menuitem devices_separator; private List device_items; - private Dbusmenu.Menuitem settings_item; private Dbusmenu.Menuitem menu; public BluetoothIndicator () throws Error @@ -106,10 +105,15 @@ 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); } @@ -334,6 +338,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 -- cgit v1.2.3 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 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/indicator-bluetooth-service.vala') 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 { -- cgit v1.2.3 From 5ab20c16591d13dff5cf3b41f98ae46bfd6e2fa2 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Feb 2013 11:57:39 +1300 Subject: Support existing gsettings key to disable indicator --- src/indicator-bluetooth-service.vala | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/indicator-bluetooth-service.vala') diff --git a/src/indicator-bluetooth-service.vala b/src/indicator-bluetooth-service.vala index 21ac4e5..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; @@ -26,6 +27,13 @@ public class BluetoothIndicator 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"); @@ -117,9 +125,9 @@ public class BluetoothIndicator 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 (); + 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) @@ -176,9 +184,9 @@ public class BluetoothIndicator item.update (type, proxy, alias, icon, connected, services, uuids); } - private void adapters_changed_cb () + private void update_visible () { - bluetooth_service._visible = client.adapter_model.iter_n_children (null) > 0; + 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 -- cgit v1.2.3