From de247720b4c7261d96dd99edd42f5ea898ab09b5 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 11 Oct 2012 19:07:48 +1300 Subject: Check device class --- src/bluez.vala | 5 +++ src/indicator-bluetooth.vala | 90 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 83 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/bluez.vala b/src/bluez.vala index 976c1ce..c20acc7 100644 --- a/src/bluez.vala +++ b/src/bluez.vala @@ -102,6 +102,9 @@ public class BluezDevice : Object private string _name = null; public string name { get { return _name; } } + private uint32 _class = 0; + public uint32 class { get { return _class; } } + internal string path; private BluezDeviceInterface proxy; @@ -127,6 +130,8 @@ public class BluezDevice : Object stderr.printf ("%s %s=%s\n", path, name, value.print (false)); if (name == "Name" && value.is_of_type (VariantType.STRING)) _name = value.get_string (); + if (name == "Class" && value.is_of_type (VariantType.UINT32)) + _class = value.get_uint32 (); } private void input_property_changed_cb (string name, Variant value) diff --git a/src/indicator-bluetooth.vala b/src/indicator-bluetooth.vala index fd09738..e7ca190 100644 --- a/src/indicator-bluetooth.vala +++ b/src/indicator-bluetooth.vala @@ -74,18 +74,84 @@ public class BluetoothIndicator : AppIndicator.Indicator menu.append (item); item.submenu = new Gtk.Menu (); - var i = new Gtk.MenuItem.with_label (_("Send files...")); - i.visible = true; - i.activate.connect (() => { Process.spawn_command_line_async ("bluetooth-sendto --device=DEVICE --name=NAME"); }); // FIXME - item.submenu.append (i); - - //FIXME - //var i = new Gtk.MenuItem.with_label (_("Keyboard Settings...")); - //i.activate.connect (() => { Process.spawn_command_line_async ("gnome-control-center keyboard"); }); - //var i = new Gtk.MenuItem.with_label (_("Mouse and Touchpad Settings...")); - //i.activate.connect (() => { Process.spawn_command_line_async ("gnome-control-center mouse"); }); - //var i = new Gtk.MenuItem.with_label (_("Sound Settings...")); - //i.activate.connect (() => { Process.spawn_command_line_async ("gnome-control-center sound"); }); + + /* Scan class mask to determine what type of device it is */ + var is_keyboard = false; + var is_pointer = false; + var is_audio = false; + switch ((device.class & 0x1f00) >> 8) + { + case 0x04: + switch ((device.class & 0xfc) >> 2) + { + case 0x0b: + case 0x0c: + case 0x0d: + /* (video devices) */ + break; + default: + is_audio = true; + break; + } + break; + case 0x05: + switch ((device.class & 0xc0) >> 6) + { + case 0x00: + /* (joypads) */ + break; + case 0x01: + is_keyboard = true; + break; + case 0x02: + is_pointer = true; + break; + } + break; + } + + // FIXME: Check by looking at the UUIDs + var can_receive_files = true; + var can_browse_files = true; + + if (can_receive_files) + { + var i = new Gtk.MenuItem.with_label (_("Send files...")); + i.visible = true; + i.activate.connect (() => { Process.spawn_command_line_async ("bluetooth-sendto --device=DEVICE --name=NAME"); }); // FIXME + item.submenu.append (i); + } + if (can_browse_files) + { + var i = new Gtk.MenuItem.with_label (_("Browse files...")); + i.visible = true; + i.activate.connect (() => { Process.spawn_command_line_async ("gnome-open obex://[%s]/"); }); // FIXME + item.submenu.append (i); + } + + if (is_keyboard) + { + var i = new Gtk.MenuItem.with_label (_("Keyboard Settings...")); + i.visible = true; + i.activate.connect (() => { Process.spawn_command_line_async ("gnome-control-center keyboard"); }); + item.submenu.append (i); + } + + if (is_pointer) + { + var i = new Gtk.MenuItem.with_label (_("Mouse and Touchpad Settings...")); + i.visible = true; + i.activate.connect (() => { Process.spawn_command_line_async ("gnome-control-center mouse"); }); + item.submenu.append (i); + } + + if (is_audio) + { + var i = new Gtk.MenuItem.with_label (_("Sound Settings...")); + i.visible = true; + i.activate.connect (() => { Process.spawn_command_line_async ("gnome-control-center sound"); }); + item.submenu.append (i); + } } var sep = new Gtk.SeparatorMenuItem (); -- cgit v1.2.3