From 3cc732f558737acd0004efb013993515845e67d7 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 1 Aug 2013 01:34:47 -0500 Subject: add per-profile icons and initial menus w/settings section --- data/Makefile.am | 6 + data/com.canonical.indicator.bluetooth | 10 + src/Makefile.am | 34 +-- src/desktop.vala | 99 +++++++ src/gnome-bluetooth-1.0.vapi | 82 ------ src/indicator-bluetooth-service.vala | 415 ----------------------------- src/indicator-bluetooth.vala | 142 ---------- src/main.vala | 17 +- src/menu.vala | 53 ++++ src/phone.vala | 76 ++++++ src/service.vala | 470 +++++++++++++++++++++++++++++++++ vapi/gnome-bluetooth-1.0.vapi | 82 ++++++ 12 files changed, 803 insertions(+), 683 deletions(-) create mode 100644 data/com.canonical.indicator.bluetooth create mode 100644 src/desktop.vala delete mode 100644 src/gnome-bluetooth-1.0.vapi delete mode 100644 src/indicator-bluetooth-service.vala delete mode 100644 src/indicator-bluetooth.vala create mode 100644 src/menu.vala create mode 100644 src/phone.vala create mode 100644 src/service.vala create mode 100644 vapi/gnome-bluetooth-1.0.vapi diff --git a/data/Makefile.am b/data/Makefile.am index 6c491f1..d5f40aa 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,3 +1,9 @@ + +# the indicator bus file +indicatorsdir = $(prefix)/share/unity/indicators +dist_indicators_DATA = com.canonical.indicator.datetime + +# the dbus service file dbus_servicesdir = $(datadir)/dbus-1/services dbus_services_DATA = indicator-bluetooth.service diff --git a/data/com.canonical.indicator.bluetooth b/data/com.canonical.indicator.bluetooth new file mode 100644 index 0000000..746157a --- /dev/null +++ b/data/com.canonical.indicator.bluetooth @@ -0,0 +1,10 @@ +[Indicator Service] +Name=indicator-bluetooth +ObjectPath=/com/canonical/indicator/bluetooth +Position=70 + +[desktop] +ObjectPath=/com/canonical/indicator/bluetooth/desktop + +[phone] +ObjectPath=/com/canonical/indicator/bluetooth/phone diff --git a/src/Makefile.am b/src/Makefile.am index 2b92f9b..ed2c976 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,17 +1,18 @@ pkglibexec_PROGRAMS = indicator-bluetooth-service -indicatordir = ${libdir}/indicators3/7 -indicator_LTLIBRARIES = libbluetooth.la indicator_bluetooth_service_SOURCES = \ indicator3-0.4.vapi \ - gnome-bluetooth-1.0.vapi \ + desktop.vala \ main.vala \ - indicator-bluetooth-service.vala + menu.vala \ + phone.vala \ + service.vala indicator_bluetooth_service_VALAFLAGS = \ --ccode \ --vapidir=$(top_srcdir)/vapi/ \ --vapidir=./ \ + --pkg gnome-bluetooth-1.0 \ --pkg config \ --pkg posix \ --pkg glib-2.0 \ @@ -26,31 +27,6 @@ indicator_bluetooth_service_CFLAGS = \ indicator_bluetooth_service_LDADD = \ $(INDICATOR_BLUETOOTH_SERVICE_LIBS) -libbluetooth_la_SOURCES = \ - indicator3-0.4.vapi \ - indicator-bluetooth.vala \ - libido3-0.1.vapi - -libbluetooth_la_VALAFLAGS = \ - --ccode \ - --vapidir=$(top_srcdir)/vapi/ \ - --vapidir=./ \ - --pkg posix \ - --pkg glib-2.0 \ - --pkg gtk+-3.0 \ - --pkg Dbusmenu-0.4 \ - --pkg DbusmenuGtk3-0.4 - -libbluetooth_la_CFLAGS = \ - -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \ - $(INDICATOR_BLUETOOTH_CFLAGS) - -libbluetooth_la_LIBADD = \ - $(INDICATOR_BLUETOOTH_LIBS) - -libbluetooth_la_LDFLAGS = \ - -module -avoid-version - CLEANFILES = \ $(patsubst %.vala,%.c,$(filter %.vala, $(SOURCES))) \ *_vala.stamp diff --git a/src/desktop.vala b/src/desktop.vala new file mode 100644 index 0000000..bd005f5 --- /dev/null +++ b/src/desktop.vala @@ -0,0 +1,99 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +class DesktopMenu: BluetoothMenu +{ + private Settings settings; + + private Action[] actions; + + public override void add_actions_to_group (SimpleActionGroup group) + { + base.add_actions_to_group (group); + + for (var i=0; i { message("visible toggled"); }); + + this.actions = {}; + this.actions += new SimpleAction.stateful ("root-desktop", null, action_state_for_root()); + this.actions += create_settings_action (); + this.actions += create_wizard_action (); + + var section = new Menu (); + section.append (_("Set Up New Device…"), "indicator.desktop-wizard"); + section.append (_("Bluetooth Settings…"), "indicator.desktop-settings"); + this.menu.append_section (null, section); + } + + Action create_wizard_action () + { + var action = new SimpleAction ("desktop-wizard", null); + + action.activate.connect ((action, param) => { + try { + Process.spawn_command_line_async ("bluetooth-wizard"); + } catch (Error e) { + warning ("unable to launch settings: %s", e.message); + } + }); + + return action; + } + + Action create_settings_action () + { + var action = new SimpleAction ("desktop-settings", null); + + action.activate.connect ((action, param) => { + try { + Process.spawn_command_line_async ("gnome-control-center bluetooth"); + } catch (Error e) { + warning ("unable to launch settings: %s", e.message); + } + }); + + return action; + } + + protected Variant action_state_for_root () + { + var label = "Hello"; // FIXME + var a11y = "Hello"; // FIXME + var visible = true; // FIXME + + string icon_name = "bluetooth-active"; // FIXME: enabled, disabled, connected, etc. +//indicator-bluetooth-service.vala: bluetooth_service._icon_name = enabled ? "bluetooth-active" : "bluetooth-disabled"; + var icon = new ThemedIcon.with_default_fallbacks (icon_name); + + var builder = new VariantBuilder (new VariantType ("a{sv}")); + builder.add ("{sv}", "visible", new Variant ("b", visible)); + builder.add ("{sv}", "label", new Variant ("s", label)); + builder.add ("{sv}", "accessible-desc", new Variant ("s", a11y)); + builder.add ("{sv}", "icon", icon.serialize()); + return builder.end (); + } +} diff --git a/src/gnome-bluetooth-1.0.vapi b/src/gnome-bluetooth-1.0.vapi deleted file mode 100644 index 6d6aa09..0000000 --- a/src/gnome-bluetooth-1.0.vapi +++ /dev/null @@ -1,82 +0,0 @@ -[CCode (cprefix = "Bluetooth", lower_case_cprefix = "bluetooth_")] -namespace GnomeBluetooth -{ - -[CCode (cheader_filename = "bluetooth-client.h")] -public class Client : GLib.Object -{ - public Client (); - public Gtk.TreeModel model { get; } - public Gtk.TreeModel adapter_model { get; } - public Gtk.TreeModel device_model { get; } - [CCode (finish_function = "bluetooth_client_connect_service_finish")] - public async bool connect_service (string device, bool connect, GLib.Cancellable? cancellable = null) throws GLib.Error; -} - -[CCode (cheader_filename = "bluetooth-enums.h", cprefix = "BLUETOOTH_COLUMN_")] -public enum Column -{ - PROXY, - ADDRESS, - ALIAS, - NAME, - TYPE, - ICON, - DEFAULT, - PAIRED, - TRUSTED, - CONNECTED, - DISCOVERABLE, - DISCOVERING, - LEGACYPAIRING, - POWERED, - SERVICES, - UUIDS -} - -[CCode (cheader_filename = "bluetooth-enums.h", cprefix = "BLUETOOTH_TYPE_")] -public enum Type -{ - ANY, - PHONE, - MODEM, - COMPUTER, - NETWORK, - HEADSET, - HEADPHONES, - OTHER_AUDIO, - KEYBOARD, - MOUSE, - CAMERA, - PRINTER, - JOYPAD, - TABLET, - VIDEO -} - -[CCode (cheader_filename = "bluetooth-utils.h")] -public void browse_address (GLib.Object? object, string address, uint timestamp, GLib.AsyncReadyCallback? callback); - -[CCode (cheader_filename = "bluetooth-utils.h")] -public void send_to_address (string address, string alias); - -[CCode (cheader_filename = "bluetooth-killswitch.h", cprefix = "BLUETOOTH_KILLSWITCH_STATE_")] -public enum KillswitchState -{ - NO_ADAPTER, - SOFT_BLOCKED, - UNBLOCKED, - HARD_BLOCKED -} - -[CCode (cheader_filename = "bluetooth-killswitch.h")] -public class Killswitch : GLib.Object -{ - public Killswitch (); - public signal void state_changed (KillswitchState state); - public bool has_killswitches (); - public KillswitchState state { get; set; } - public unowned string state_to_string (); -} - -} diff --git a/src/indicator-bluetooth-service.vala b/src/indicator-bluetooth-service.vala deleted file mode 100644 index f65c538..0000000 --- a/src/indicator-bluetooth-service.vala +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (C) 2012-2013 Canonical Ltd. - * Author: Robert Ancell - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 3 of the License. - * See http://www.gnu.org/copyleft/gpl.html the full text of the license. - */ - -public class BluetoothIndicator -{ - private Settings settings; - private DBusConnection bus; - private Indicator.Service indicator_service; - private Dbusmenu.Server menu_server; - private BluetoothService bluetooth_service; - private GnomeBluetooth.Client client; - private GnomeBluetooth.Killswitch killswitch; - private bool updating_killswitch = false; - private Dbusmenu.Menuitem enable_item; - private Dbusmenu.Menuitem visible_item; - private bool updating_visible = false; - private Dbusmenu.Menuitem devices_separator; - private List device_items; - 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"); - menu_server = new Dbusmenu.Server ("/com/canonical/indicator/bluetooth/menu"); - - bluetooth_service = new BluetoothService (); - bus.register_object ("/com/canonical/indicator/bluetooth/service", bluetooth_service); - - killswitch = new GnomeBluetooth.Killswitch (); - killswitch.state_changed.connect (killswitch_state_changed_cb); - - client = new GnomeBluetooth.Client (); - - menu = new Dbusmenu.Menuitem (); - menu_server.set_root (menu); - - enable_item = new Dbusmenu.Menuitem (); - enable_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Bluetooth")); - enable_item.property_set (Dbusmenu.MENUITEM_PROP_TYPE, "x-canonical-switch"); - enable_item.item_activated.connect (() => - { - if (updating_killswitch) - return; - if (killswitch.state == GnomeBluetooth.KillswitchState.UNBLOCKED) - killswitch.state = GnomeBluetooth.KillswitchState.SOFT_BLOCKED; - else - killswitch.state = GnomeBluetooth.KillswitchState.UNBLOCKED; - }); - menu.child_append (enable_item); - - visible_item = new Dbusmenu.Menuitem (); - visible_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Visible")); - visible_item.property_set (Dbusmenu.MENUITEM_PROP_TYPE, "x-canonical-switch"); - bool discoverable; - client.get ("default-adapter-discoverable", out discoverable); - visible_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, discoverable ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); - client.notify["default-adapter-discoverable"].connect (() => - { - updating_visible = true; - bool is_discoverable; - client.get ("default-adapter-discoverable", out is_discoverable); - visible_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, is_discoverable ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); - updating_visible = false; - }); - visible_item.item_activated.connect (() => - { - if (updating_visible) - return; - client.set ("default-adapter-discoverable", visible_item.property_get_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE) != Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED); - }); - menu.child_append (visible_item); - - devices_separator = new Dbusmenu.Menuitem (); - devices_separator.property_set (Dbusmenu.MENUITEM_PROP_TYPE, Dbusmenu.CLIENT_TYPES_SEPARATOR); - menu.child_append (devices_separator); - - device_items = new List (); - - client.model.row_inserted.connect (device_changed_cb); - client.model.row_changed.connect (device_changed_cb); - client.model.row_deleted.connect (device_removed_cb); - Gtk.TreeIter iter; - var have_iter = client.model.get_iter_first (out iter); - while (have_iter) - { - Gtk.TreeIter child_iter; - var have_child_iter = client.model.iter_children (out child_iter, iter); - while (have_child_iter) - { - device_changed_cb (null, child_iter); - have_child_iter = client.model.iter_next (ref child_iter); - } - have_iter = client.model.iter_next (ref iter); - } - - var sep = new Dbusmenu.Menuitem (); - sep.property_set (Dbusmenu.MENUITEM_PROP_TYPE, Dbusmenu.CLIENT_TYPES_SEPARATOR); - menu.child_append (sep); - - 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) - { - foreach (var item in device_items) - if (item.address == address) - return item; - - return null; - } - - private void device_changed_cb (Gtk.TreePath? path, Gtk.TreeIter iter) - { - /* Ignore adapters */ - Gtk.TreeIter parent_iter; - if (!client.model.iter_parent (out parent_iter, iter)) - return; - - DBusProxy proxy; - string address; - string alias; - GnomeBluetooth.Type type; - string icon; - bool connected; - HashTable services; - string[] uuids; - client.model.get (iter, - GnomeBluetooth.Column.PROXY, out proxy, - GnomeBluetooth.Column.ADDRESS, out address, - GnomeBluetooth.Column.ALIAS, out alias, - GnomeBluetooth.Column.TYPE, out type, - GnomeBluetooth.Column.ICON, out icon, - GnomeBluetooth.Column.CONNECTED, out connected, - GnomeBluetooth.Column.SERVICES, out services, - GnomeBluetooth.Column.UUIDS, out uuids); - - /* Skip if haven't actually got any information yet */ - if (proxy == null) - return; - - /* Find or create menu item */ - var item = find_menu_item (address); - if (item == null) - { - item = new BluetoothMenuItem (client, address); - item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, killswitch.state == GnomeBluetooth.KillswitchState.UNBLOCKED); - var last_item = devices_separator as Dbusmenu.Menuitem; - if (device_items != null) - last_item = device_items.last ().data; - device_items.append (item); - menu.child_add_position (item, last_item.get_position (menu) + 1); - } - - 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; - if (!client.model.get_iter (out iter, path)) - return; - - string address; - client.model.get (iter, GnomeBluetooth.Column.ADDRESS, out address); - - var item = find_menu_item (address); - if (item == null) - return; - - device_items.remove (item); - menu.child_delete (item); - } - - private void killswitch_state_changed_cb (GnomeBluetooth.KillswitchState state) - { - updating_killswitch = true; - - var enabled = state == GnomeBluetooth.KillswitchState.UNBLOCKED; - - bluetooth_service._icon_name = enabled ? "bluetooth-active" : "bluetooth-disabled"; - bluetooth_service._accessible_description = enabled ? _("Bluetooth: On") : _("Bluetooth: Off"); - - var builder = new VariantBuilder (VariantType.ARRAY); - builder.add ("{sv}", "IconName", new Variant.string (bluetooth_service._icon_name)); - builder.add ("{sv}", "AccessibleDescription", new Variant.string (bluetooth_service._accessible_description)); - 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); - } - - enable_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, enabled ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); - - /* Disable devices when locked */ - visible_item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, enabled); - devices_separator.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, enabled); - foreach (var item in device_items) - item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, enabled && item.get_children () != null); - - updating_killswitch = false; - } -} - -private class BluetoothMenuItem : Dbusmenu.Menuitem -{ - private GnomeBluetooth.Client client; - public string address; - private Dbusmenu.Menuitem? connect_item = null; - private bool make_submenu = false; - - public BluetoothMenuItem (GnomeBluetooth.Client client, string address) - { - this.client = client; - this.address = address; - } - - public void update (GnomeBluetooth.Type type, DBusProxy proxy, string alias, string icon, bool connected, HashTable? services, string[] uuids) - { - property_set (Dbusmenu.MENUITEM_PROP_LABEL, alias); - property_set (Dbusmenu.MENUITEM_PROP_ICON_NAME, icon); - if (connect_item != null) - connect_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, connected ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); - - /* FIXME: Not sure if the GUI elements below can change over time */ - if (make_submenu) - return; - make_submenu = true; - - if (services != null) - { - connect_item = new Dbusmenu.Menuitem (); - connect_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Connection")); - connect_item.property_set (Dbusmenu.MENUITEM_PROP_TYPE, "x-canonical-switch"); - connect_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, connected ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); - connect_item.item_activated.connect (() => { connect_service (proxy.get_object_path (), connect_item.property_get_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE) != Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED); }); - child_append (connect_item); - } - - var can_send = false; - var can_browse = false; - if (uuids != null) - { - for (var i = 0; uuids[i] != null; i++) - { - if (uuids[i] == "OBEXObjectPush") - can_send = true; - if (uuids[i] == "OBEXFileTransfer") - can_browse = true; - } - } - - if (can_send) - { - var send_item = new Dbusmenu.Menuitem (); - send_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Send files…")); - send_item.item_activated.connect (() => { GnomeBluetooth.send_to_address (address, alias); }); - child_append (send_item); - } - - if (can_browse) - { - var browse_item = new Dbusmenu.Menuitem (); - browse_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Browse files…")); - browse_item.item_activated.connect (() => { GnomeBluetooth.browse_address (null, address, Gdk.CURRENT_TIME, null); }); - child_append (browse_item); - } - - switch (type) - { - case GnomeBluetooth.Type.KEYBOARD: - var keyboard_item = new Dbusmenu.Menuitem (); - keyboard_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Keyboard Settings…")); - keyboard_item.item_activated.connect (() => { show_control_center ("keyboard"); }); - child_append (keyboard_item); - break; - - case GnomeBluetooth.Type.MOUSE: - case GnomeBluetooth.Type.TABLET: - var mouse_item = new Dbusmenu.Menuitem (); - mouse_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Mouse and Touchpad Settings…")); - mouse_item.item_activated.connect (() => { show_control_center ("mouse"); }); - child_append (mouse_item); - break; - - case GnomeBluetooth.Type.HEADSET: - case GnomeBluetooth.Type.HEADPHONES: - case GnomeBluetooth.Type.OTHER_AUDIO: - var sound_item = new Dbusmenu.Menuitem (); - sound_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Sound Settings…")); - sound_item.item_activated.connect (() => { show_control_center ("sound"); }); - child_append (sound_item); - break; - } - - property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, get_children () != null); - } - - private void connect_service (string device, bool connect) - { - client.connect_service.begin (device, connect, null, (object, result) => - { - var connected = false; - try - { - connected = client.connect_service.end (result); - } - catch (Error e) - { - warning ("Failed to connect service: %s", e.message); - } - }); - } -} - -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 - { - Process.spawn_command_line_async ("gnome-control-center %s".printf (panel)); - } - catch (GLib.SpawnError e) - { - warning ("Failed to open control center: %s", e.message); - } -} - -[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 - { - get { return _icon_name; } - } - internal string _accessible_description = _("Bluetooth"); - public string accessible_description - { - get { return _accessible_description; } - } -} diff --git a/src/indicator-bluetooth.vala b/src/indicator-bluetooth.vala deleted file mode 100644 index bfbbc9f..0000000 --- a/src/indicator-bluetooth.vala +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (C) 2012-2013 Canonical Ltd. - * Author: Robert Ancell - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 3 of the License. - * See http://www.gnu.org/copyleft/gpl.html the full text of the license. - */ - -public class BluetoothIndicator : Indicator.Object -{ - private Indicator.ServiceManager service; - private Gtk.Image image; - private DbusmenuGtk.Menu menu; - private BluetoothService proxy; - private string accessible_description = _("Bluetooth: On"); - - construct - { - service = new Indicator.ServiceManager ("com.canonical.indicator.bluetooth"); - service.connection_change.connect (connection_change_cb); - menu = new DbusmenuGtk.Menu ("com.canonical.indicator.bluetooth", "/com/canonical/indicator/bluetooth/menu"); - image = Indicator.image_helper ("bluetooth-active"); - image.visible = true; - - 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) - { - var item = new Switch (newitem); - (client as DbusmenuGtk.Client).newitem_base (newitem, item, parent); - return true; - } - - public override unowned Gtk.Image get_image () - { - return image; - } - - public override unowned Gtk.Menu get_menu () - { - return menu; - } - - public override unowned string get_accessible_desc () - { - return accessible_description; - } - - private void connection_change_cb (bool connected) - { - if (!connected) - return; - - // FIXME: Set proxy to null on disconnect? - // FIXME: Use Cancellable to cancel existing connection - if (proxy == null) - { - Bus.get_proxy.begin (BusType.SESSION, - "com.canonical.indicator.bluetooth", - "/com/canonical/indicator/bluetooth/service", - DBusProxyFlags.NONE, null, (object, result) => - { - try - { - proxy = Bus.get_proxy.end (result); - proxy.g_properties_changed.connect (server_properties_changed_cb); - server_properties_changed_cb (); - } - catch (IOError e) - { - warning ("Failed to connect to bluetooth service: %s", e.message); - } - }); - } - } - - private void server_properties_changed_cb () - { - set_visible (proxy.visible); - Indicator.image_helper_update (image, proxy.icon_name); - accessible_description = proxy.accessible_description; - } -} - -public class Switch : Ido.SwitchMenuItem -{ - public Dbusmenu.Menuitem menuitem; - public new Gtk.Label label; - private bool updating_switch = false; - - public Switch (Dbusmenu.Menuitem menuitem) - { - this.menuitem = menuitem; - label = new Gtk.Label (""); - label.visible = true; - content_area.add (label); - - /* Be the first listener to the activate signal so we can stop it - * emitting when we change the state. Without this you get feedback loops */ - activate.connect (() => - { - if (updating_switch) - Signal.stop_emission_by_name (this, "activate"); - }); - - menuitem.property_changed.connect ((mi, prop, value) => { update (); }); - update (); - } - - private void update () - { - updating_switch = true; - label.label = menuitem.property_get (Dbusmenu.MENUITEM_PROP_LABEL); - active = menuitem.property_get_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE) == Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED; - updating_switch = false; - } -} - -[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; } -} - -public static string get_version () -{ - return Indicator.VERSION; -} - -public static GLib.Type get_type () -{ - return typeof (BluetoothIndicator); -} diff --git a/src/main.vala b/src/main.vala index 79683b2..1df55c3 100644 --- a/src/main.vala +++ b/src/main.vala @@ -7,21 +7,8 @@ main (string[] args) Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.GNOMELOCALEDIR); Intl.textdomain (Config.GETTEXT_PACKAGE); - var loop = new MainLoop (); + var service = new BluetoothIndicator (); + service.run (); - BluetoothIndicator indicator; - try - { - indicator = new BluetoothIndicator (); - } - catch (Error e) - { - warning ("Failed to start bluetooth indicator service: %s", e.message); - return Posix.EXIT_FAILURE; - } - - loop.run (); return Posix.EXIT_SUCCESS; } - //var service = new IndicatorSound.Service (); - //return service.run (); diff --git a/src/menu.vala b/src/menu.vala new file mode 100644 index 0000000..a2c5449 --- /dev/null +++ b/src/menu.vala @@ -0,0 +1,53 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +class BluetoothMenu: Object +{ + protected Menu root; + protected Menu menu; + + public virtual void add_actions_to_group (SimpleActionGroup group) + { + } + + public BluetoothMenu (string profile) + { + this.menu = new Menu (); + + var root_item = new MenuItem (null, "indicator.root-" + profile); + root_item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); + root_item.set_submenu (this.menu); + + this.root = new Menu (); + this.root.append_item (root_item); + } + + public void export (DBusConnection connection, string object_path) + { + try + { + message ("exporting on %s", object_path); + connection.export_menu_model (object_path, this.root); + } + catch (Error e) + { + critical ("%s", e.message); + } + } +} diff --git a/src/phone.vala b/src/phone.vala new file mode 100644 index 0000000..2abcf11 --- /dev/null +++ b/src/phone.vala @@ -0,0 +1,76 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +class PhoneMenu: BluetoothMenu +{ + private Action[] actions; + + public override void add_actions_to_group (SimpleActionGroup group) + { + base.add_actions_to_group (group); + + for (var i=0; i { + try { + Process.spawn_command_line_async ("system-settings bluetooth"); + } catch (Error e) { + warning ("unable to launch settings: %s", e.message); + } + }); + + return action; + } + + protected Variant action_state_for_root () + { + var label = "Hello World"; // FIXME + var a11y = "Hello World"; // FIXME + var visible = true; // FIXME + + string icon_name = "bluetooth"; // FIXME: enabled, disabled, connected, etc. + var icon = new ThemedIcon.with_default_fallbacks (icon_name); + + var builder = new VariantBuilder (new VariantType ("a{sv}")); + builder.add ("{sv}", "visible", new Variant ("b", visible)); + builder.add ("{sv}", "label", new Variant ("s", label)); + builder.add ("{sv}", "accessible-desc", new Variant ("s", a11y)); + builder.add ("{sv}", "icon", icon.serialize()); + return builder.end (); + } +} diff --git a/src/service.vala b/src/service.vala new file mode 100644 index 0000000..b6ae0f3 --- /dev/null +++ b/src/service.vala @@ -0,0 +1,470 @@ +/* + * Copyright (C) 2012-2013 Canonical Ltd. + * Author: Robert Ancell + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3 of the License. + * See http://www.gnu.org/copyleft/gpl.html the full text of the license. + */ + +public class BluetoothIndicator +{ + private MainLoop loop; + private SimpleActionGroup actions; + private HashTable menus; + + private DBusConnection bus; + private Indicator.Service indicator_service; + private Dbusmenu.Server menu_server; + private BluetoothService bluetooth_service; + private GnomeBluetooth.Client client; + private GnomeBluetooth.Killswitch killswitch; + private bool updating_killswitch = false; + private Dbusmenu.Menuitem enable_item; + private Dbusmenu.Menuitem visible_item; + private bool updating_visible = false; + private Dbusmenu.Menuitem devices_separator; + private List device_items; + private Dbusmenu.Menuitem menu; + + public BluetoothIndicator () throws Error + { + var phone = new PhoneMenu (); + var desktop = new DesktopMenu (); + + this.menus = new HashTable (str_hash, str_equal); + this.menus.insert ("phone", phone); + this.menus.insert ("desktop", desktop); + + this.actions = new SimpleActionGroup (); + phone.add_actions_to_group (this.actions); + desktop.add_actions_to_group (this.actions); + } + + private void init_for_bus (DBusConnection bus) + { + this.bus = bus; + + indicator_service = new Indicator.Service ("com.canonical.indicator.bluetooth.old"); + menu_server = new Dbusmenu.Server ("/com/canonical/indicator/bluetooth/menu"); + + bluetooth_service = new BluetoothService (); + bus.register_object ("/com/canonical/indicator/bluetooth/service", bluetooth_service); + + killswitch = new GnomeBluetooth.Killswitch (); + killswitch.state_changed.connect (killswitch_state_changed_cb); + + client = new GnomeBluetooth.Client (); + + menu = new Dbusmenu.Menuitem (); + menu_server.set_root (menu); + + enable_item = new Dbusmenu.Menuitem (); + enable_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Bluetooth")); + enable_item.property_set (Dbusmenu.MENUITEM_PROP_TYPE, "x-canonical-switch"); + enable_item.item_activated.connect (() => + { + if (updating_killswitch) + return; + if (killswitch.state == GnomeBluetooth.KillswitchState.UNBLOCKED) + killswitch.state = GnomeBluetooth.KillswitchState.SOFT_BLOCKED; + else + killswitch.state = GnomeBluetooth.KillswitchState.UNBLOCKED; + }); + menu.child_append (enable_item); + + visible_item = new Dbusmenu.Menuitem (); + visible_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Visible")); + visible_item.property_set (Dbusmenu.MENUITEM_PROP_TYPE, "x-canonical-switch"); + bool discoverable; + client.get ("default-adapter-discoverable", out discoverable); + visible_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, discoverable ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); + client.notify["default-adapter-discoverable"].connect (() => + { + updating_visible = true; + bool is_discoverable; + client.get ("default-adapter-discoverable", out is_discoverable); + visible_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, is_discoverable ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); + updating_visible = false; + }); + visible_item.item_activated.connect (() => + { + if (updating_visible) + return; + client.set ("default-adapter-discoverable", visible_item.property_get_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE) != Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED); + }); + menu.child_append (visible_item); + + devices_separator = new Dbusmenu.Menuitem (); + devices_separator.property_set (Dbusmenu.MENUITEM_PROP_TYPE, Dbusmenu.CLIENT_TYPES_SEPARATOR); + menu.child_append (devices_separator); + + device_items = new List (); + + client.model.row_inserted.connect (device_changed_cb); + client.model.row_changed.connect (device_changed_cb); + client.model.row_deleted.connect (device_removed_cb); + Gtk.TreeIter iter; + var have_iter = client.model.get_iter_first (out iter); + while (have_iter) + { + Gtk.TreeIter child_iter; + var have_child_iter = client.model.iter_children (out child_iter, iter); + while (have_child_iter) + { + device_changed_cb (null, child_iter); + have_child_iter = client.model.iter_next (ref child_iter); + } + have_iter = client.model.iter_next (ref iter); + } + + var sep = new Dbusmenu.Menuitem (); + sep.property_set (Dbusmenu.MENUITEM_PROP_TYPE, Dbusmenu.CLIENT_TYPES_SEPARATOR); + menu.child_append (sep); + + 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 (); + } + + public int run () + { + if (this.loop != null) + { + warning ("service is already running"); + return 1; + } + + Bus.own_name (BusType.SESSION, + "com.canonical.indicator.bluetooth", + BusNameOwnerFlags.NONE, + this.on_bus_acquired, + null, + this.on_name_lost); + + this.loop = new MainLoop (null, false); + this.loop.run (); + return 0; + } + + void on_bus_acquired (DBusConnection connection, string name) + { + stdout.printf ("bus acquired: %s\n", name); + + init_for_bus (connection); + + try + { + connection.export_action_group ("/com/canonical/indicator/bluetooth", this.actions); + } + catch (Error e) + { + critical ("%s", e.message); + } + + this.menus.@foreach ( (profile, menu) => menu.export (connection, @"/com/canonical/indicator/bluetooth/$profile")); + } + + void on_name_lost (DBusConnection connection, string name) + { + stdout.printf ("name lost: %s\n", name); + this.loop.quit (); + } + + + private BluetoothMenuItem? find_menu_item (string address) + { + foreach (var item in device_items) + if (item.address == address) + return item; + + return null; + } + + private void device_changed_cb (Gtk.TreePath? path, Gtk.TreeIter iter) + { + /* Ignore adapters */ + Gtk.TreeIter parent_iter; + if (!client.model.iter_parent (out parent_iter, iter)) + return; + + DBusProxy proxy; + string address; + string alias; + GnomeBluetooth.Type type; + string icon; + bool connected; + HashTable services; + string[] uuids; + client.model.get (iter, + GnomeBluetooth.Column.PROXY, out proxy, + GnomeBluetooth.Column.ADDRESS, out address, + GnomeBluetooth.Column.ALIAS, out alias, + GnomeBluetooth.Column.TYPE, out type, + GnomeBluetooth.Column.ICON, out icon, + GnomeBluetooth.Column.CONNECTED, out connected, + GnomeBluetooth.Column.SERVICES, out services, + GnomeBluetooth.Column.UUIDS, out uuids); + + /* Skip if haven't actually got any information yet */ + if (proxy == null) + return; + + /* Find or create menu item */ + var item = find_menu_item (address); + if (item == null) + { + item = new BluetoothMenuItem (client, address); + item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, killswitch.state == GnomeBluetooth.KillswitchState.UNBLOCKED); + var last_item = devices_separator as Dbusmenu.Menuitem; + if (device_items != null) + last_item = device_items.last ().data; + device_items.append (item); + menu.child_add_position (item, last_item.get_position (menu) + 1); + } + + 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; + if (!client.model.get_iter (out iter, path)) + return; + + string address; + client.model.get (iter, GnomeBluetooth.Column.ADDRESS, out address); + + var item = find_menu_item (address); + if (item == null) + return; + + device_items.remove (item); + menu.child_delete (item); + } + + private void killswitch_state_changed_cb (GnomeBluetooth.KillswitchState state) + { + updating_killswitch = true; + + var enabled = state == GnomeBluetooth.KillswitchState.UNBLOCKED; + + bluetooth_service._icon_name = enabled ? "bluetooth-active" : "bluetooth-disabled"; + bluetooth_service._accessible_description = enabled ? _("Bluetooth: On") : _("Bluetooth: Off"); + + var builder = new VariantBuilder (VariantType.ARRAY); + builder.add ("{sv}", "IconName", new Variant.string (bluetooth_service._icon_name)); + builder.add ("{sv}", "AccessibleDescription", new Variant.string (bluetooth_service._accessible_description)); + 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); + } + + enable_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, enabled ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); + + /* Disable devices when locked */ + visible_item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, enabled); + devices_separator.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, enabled); + foreach (var item in device_items) + item.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, enabled && item.get_children () != null); + + updating_killswitch = false; + } +} + +private class BluetoothMenuItem : Dbusmenu.Menuitem +{ + private GnomeBluetooth.Client client; + public string address; + private Dbusmenu.Menuitem? connect_item = null; + private bool make_submenu = false; + + public BluetoothMenuItem (GnomeBluetooth.Client client, string address) + { + this.client = client; + this.address = address; + } + + public void update (GnomeBluetooth.Type type, DBusProxy proxy, string alias, string icon, bool connected, HashTable? services, string[] uuids) + { + property_set (Dbusmenu.MENUITEM_PROP_LABEL, alias); + property_set (Dbusmenu.MENUITEM_PROP_ICON_NAME, icon); + if (connect_item != null) + connect_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, connected ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); + + /* FIXME: Not sure if the GUI elements below can change over time */ + if (make_submenu) + return; + make_submenu = true; + + if (services != null) + { + connect_item = new Dbusmenu.Menuitem (); + connect_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Connection")); + connect_item.property_set (Dbusmenu.MENUITEM_PROP_TYPE, "x-canonical-switch"); + connect_item.property_set_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE, connected ? Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED : Dbusmenu.MENUITEM_TOGGLE_STATE_UNCHECKED); + connect_item.item_activated.connect (() => { connect_service (proxy.get_object_path (), connect_item.property_get_int (Dbusmenu.MENUITEM_PROP_TOGGLE_STATE) != Dbusmenu.MENUITEM_TOGGLE_STATE_CHECKED); }); + child_append (connect_item); + } + + var can_send = false; + var can_browse = false; + if (uuids != null) + { + for (var i = 0; uuids[i] != null; i++) + { + if (uuids[i] == "OBEXObjectPush") + can_send = true; + if (uuids[i] == "OBEXFileTransfer") + can_browse = true; + } + } + + if (can_send) + { + var send_item = new Dbusmenu.Menuitem (); + send_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Send files…")); + send_item.item_activated.connect (() => { GnomeBluetooth.send_to_address (address, alias); }); + child_append (send_item); + } + + if (can_browse) + { + var browse_item = new Dbusmenu.Menuitem (); + browse_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Browse files…")); + browse_item.item_activated.connect (() => { GnomeBluetooth.browse_address (null, address, Gdk.CURRENT_TIME, null); }); + child_append (browse_item); + } + + switch (type) + { + case GnomeBluetooth.Type.KEYBOARD: + var keyboard_item = new Dbusmenu.Menuitem (); + keyboard_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Keyboard Settings…")); + keyboard_item.item_activated.connect (() => { show_control_center ("keyboard"); }); + child_append (keyboard_item); + break; + + case GnomeBluetooth.Type.MOUSE: + case GnomeBluetooth.Type.TABLET: + var mouse_item = new Dbusmenu.Menuitem (); + mouse_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Mouse and Touchpad Settings…")); + mouse_item.item_activated.connect (() => { show_control_center ("mouse"); }); + child_append (mouse_item); + break; + + case GnomeBluetooth.Type.HEADSET: + case GnomeBluetooth.Type.HEADPHONES: + case GnomeBluetooth.Type.OTHER_AUDIO: + var sound_item = new Dbusmenu.Menuitem (); + sound_item.property_set (Dbusmenu.MENUITEM_PROP_LABEL, _("Sound Settings…")); + sound_item.item_activated.connect (() => { show_control_center ("sound"); }); + child_append (sound_item); + break; + } + + property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, get_children () != null); + } + + private void connect_service (string device, bool connect) + { + client.connect_service.begin (device, connect, null, (object, result) => + { + var connected = false; + try + { + connected = client.connect_service.end (result); + } + catch (Error e) + { + warning ("Failed to connect service: %s", e.message); + } + }); + } +} + +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 + { + Process.spawn_command_line_async ("gnome-control-center %s".printf (panel)); + } + catch (GLib.SpawnError e) + { + warning ("Failed to open control center: %s", e.message); + } +} + +[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 + { + get { return _icon_name; } + } + internal string _accessible_description = _("Bluetooth"); + public string accessible_description + { + get { return _accessible_description; } + } +} diff --git a/vapi/gnome-bluetooth-1.0.vapi b/vapi/gnome-bluetooth-1.0.vapi new file mode 100644 index 0000000..6d6aa09 --- /dev/null +++ b/vapi/gnome-bluetooth-1.0.vapi @@ -0,0 +1,82 @@ +[CCode (cprefix = "Bluetooth", lower_case_cprefix = "bluetooth_")] +namespace GnomeBluetooth +{ + +[CCode (cheader_filename = "bluetooth-client.h")] +public class Client : GLib.Object +{ + public Client (); + public Gtk.TreeModel model { get; } + public Gtk.TreeModel adapter_model { get; } + public Gtk.TreeModel device_model { get; } + [CCode (finish_function = "bluetooth_client_connect_service_finish")] + public async bool connect_service (string device, bool connect, GLib.Cancellable? cancellable = null) throws GLib.Error; +} + +[CCode (cheader_filename = "bluetooth-enums.h", cprefix = "BLUETOOTH_COLUMN_")] +public enum Column +{ + PROXY, + ADDRESS, + ALIAS, + NAME, + TYPE, + ICON, + DEFAULT, + PAIRED, + TRUSTED, + CONNECTED, + DISCOVERABLE, + DISCOVERING, + LEGACYPAIRING, + POWERED, + SERVICES, + UUIDS +} + +[CCode (cheader_filename = "bluetooth-enums.h", cprefix = "BLUETOOTH_TYPE_")] +public enum Type +{ + ANY, + PHONE, + MODEM, + COMPUTER, + NETWORK, + HEADSET, + HEADPHONES, + OTHER_AUDIO, + KEYBOARD, + MOUSE, + CAMERA, + PRINTER, + JOYPAD, + TABLET, + VIDEO +} + +[CCode (cheader_filename = "bluetooth-utils.h")] +public void browse_address (GLib.Object? object, string address, uint timestamp, GLib.AsyncReadyCallback? callback); + +[CCode (cheader_filename = "bluetooth-utils.h")] +public void send_to_address (string address, string alias); + +[CCode (cheader_filename = "bluetooth-killswitch.h", cprefix = "BLUETOOTH_KILLSWITCH_STATE_")] +public enum KillswitchState +{ + NO_ADAPTER, + SOFT_BLOCKED, + UNBLOCKED, + HARD_BLOCKED +} + +[CCode (cheader_filename = "bluetooth-killswitch.h")] +public class Killswitch : GLib.Object +{ + public Killswitch (); + public signal void state_changed (KillswitchState state); + public bool has_killswitches (); + public KillswitchState state { get; set; } + public unowned string state_to_string (); +} + +} -- cgit v1.2.3