aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2012-10-11 08:42:59 +1300
committerRobert Ancell <robert.ancell@canonical.com>2012-10-11 08:42:59 +1300
commitf14da3cc27e2ec514d2e829fd7281f8c5dc9b252 (patch)
tree4efc31d56123a9059d309b41fd3192710409a2bf /src
downloadayatana-indicator-bluetooth-f14da3cc27e2ec514d2e829fd7281f8c5dc9b252.tar.gz
ayatana-indicator-bluetooth-f14da3cc27e2ec514d2e829fd7281f8c5dc9b252.tar.bz2
ayatana-indicator-bluetooth-f14da3cc27e2ec514d2e829fd7281f8c5dc9b252.zip
First start on bluetooth-indicator
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am24
-rw-r--r--src/config.vapi3
-rw-r--r--src/indicator-bluetooth.vala137
3 files changed, 164 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..101f8f1
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,24 @@
+bin_PROGRAMS = indicator-bluetooth
+
+indicator_bluetooth_SOURCES = \
+ config.vapi \
+ indicator-bluetooth.vala
+
+indicator_bluetooth_VALAFLAGS = \
+ --pkg posix \
+ --pkg glib-2.0 \
+ --pkg gtk+-3.0 \
+ --pkg appindicator3-0.1
+
+indicator_bluetooth_CFLAGS = \
+ -DVERSION=\"$(VERSION)\" \
+ -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
+ -DLOCALE_DIR=\"$(datadir)/locale\" \
+ $(INDICATOR_BLUETOOTH_CFLAGS)
+
+indicator_bluetooth_LDADD = \
+ $(INDICATOR_BLUETOOTH_LIBS)
+
+CLEANFILES = \
+ $(patsubst %.vala,%.c,$(filter %.vala, $(SOURCES))) \
+ *_vala.stamp
diff --git a/src/config.vapi b/src/config.vapi
new file mode 100644
index 0000000..a1bb094
--- /dev/null
+++ b/src/config.vapi
@@ -0,0 +1,3 @@
+public const string VERSION;
+public const string GETTEXT_PACKAGE;
+public const string LOCALE_DIR;
diff --git a/src/indicator-bluetooth.vala b/src/indicator-bluetooth.vala
new file mode 100644
index 0000000..88cb175
--- /dev/null
+++ b/src/indicator-bluetooth.vala
@@ -0,0 +1,137 @@
+[DBus (name = "org.bluez.Manager")]
+interface BluezManager : Object
+{
+ public abstract string default_adapter () throws IOError;
+}
+
+[DBus (name = "org.bluez.Adapter")]
+interface BluezAdapter : Object
+{
+ public abstract string[] list_devices () throws IOError;
+ public abstract HashTable<string, Variant> get_properties () throws IOError;
+ public abstract void set_property (string name, Variant value) throws IOError;
+}
+
+[DBus (name = "org.bluez.Device")]
+interface BluezDevice : Object
+{
+ public abstract HashTable<string, Variant> get_properties () throws IOError;
+}
+
+[DBus (name = "org.bluez.Audio")]
+interface BluezAudio : Object
+{
+ public abstract void connect () throws IOError;
+}
+
+[DBus (name = "org.bluez.Input")]
+interface BluezInput : Object
+{
+ public abstract void connect () throws IOError;
+}
+
+int main (string[] args)
+{
+ Intl.setlocale (LocaleCategory.ALL, "");
+ Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
+ Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ Intl.textdomain (GETTEXT_PACKAGE);
+
+ Gtk.init (ref args);
+
+ BluezAdapter adapter;
+ try
+ {
+ var manager = Bus.get_proxy_sync<BluezManager> (BusType.SYSTEM, "org.bluez", "/");
+ var path = manager.default_adapter ();
+ adapter = Bus.get_proxy_sync<BluezAdapter> (BusType.SYSTEM, "org.bluez", path);
+ }
+ catch (IOError e)
+ {
+ return Posix.EXIT_FAILURE;
+ }
+
+ var indicator = new AppIndicator.Indicator ("indicator-bluetooth", "bluetooth-active", AppIndicator.IndicatorCategory.HARDWARE);
+ indicator.set_status (AppIndicator.IndicatorStatus.ACTIVE);
+
+ var menu = new Gtk.Menu ();
+ indicator.set_menu (menu);
+
+ var item = new Gtk.MenuItem.with_label ("Bluetooth: On");
+ item.sensitive = false;
+ item.show ();
+ menu.append (item);
+
+ item = new Gtk.MenuItem.with_label ("Turn off Bluetooth");
+ item.show ();
+ menu.append (item);
+
+ item = new Gtk.CheckMenuItem.with_label (_("Visible"));
+ item.activate.connect (() => { adapter.set_property ("Discoverable", new Variant.boolean (true)); });
+ item.show ();
+ menu.append (item);
+
+ var sep = new Gtk.SeparatorMenuItem ();
+ sep.show ();
+ menu.append (sep);
+
+ item = new Gtk.MenuItem.with_label (_("Devices"));
+ item.sensitive = false;
+ item.show ();
+ menu.append (item);
+
+ try
+ {
+ var devices = adapter.list_devices ();
+ foreach (var path in devices)
+ {
+ var device = Bus.get_proxy_sync<BluezDevice> (BusType.SYSTEM, "org.bluez", path);
+ var properties = device.get_properties ();
+ var iter = HashTableIter<string, Variant> (properties);
+ string name;
+ Variant value;
+ //stderr.printf ("%s\n", path);
+ while (iter.next (out name, out value))
+ {
+ //stderr.printf (" %s=%s\n", name, value.print (false));
+ if (name == "Name" && value.is_of_type (VariantType.STRING))
+ {
+ item = new Gtk.MenuItem.with_label (value.get_string ());
+ item.show ();
+ menu.append (item);
+
+ item.submenu = new Gtk.Menu ();
+ var i = new Gtk.MenuItem.with_label (_("Send files..."));
+ i.show ();
+ i.activate.connect (() => { Process.spawn_command_line_async ("bluetooth-sendto --device=DEVICE --name=NAME"); });
+ item.submenu.append (i);
+
+ //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"); });
+ }
+ }
+ }
+ }
+ catch (IOError e)
+ {
+ stderr.printf ("%s\n", e.message);
+ return Posix.EXIT_FAILURE;
+ }
+
+ sep = new Gtk.SeparatorMenuItem ();
+ sep.show ();
+ menu.append (sep);
+
+ item = new Gtk.MenuItem.with_label (_("Bluetooth Settings..."));
+ item.activate.connect (() => { Process.spawn_command_line_async ("gnome-control-center bluetooth"); });
+ item.show ();
+ menu.append (item);
+
+ Gtk.main ();
+
+ return 0;
+}