From f14da3cc27e2ec514d2e829fd7281f8c5dc9b252 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 11 Oct 2012 08:42:59 +1300 Subject: First start on bluetooth-indicator --- Makefile.am | 3 + NEWS | 3 + autogen.sh | 8 +++ configure.ac | 34 +++++++++++ po/POTFILES.in | 4 ++ po/POTFILES.skip | 1 + src/Makefile.am | 24 ++++++++ src/config.vapi | 3 + src/indicator-bluetooth.vala | 137 +++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 217 insertions(+) create mode 100644 Makefile.am create mode 100644 NEWS create mode 100755 autogen.sh create mode 100644 configure.ac create mode 100644 po/POTFILES.in create mode 100644 po/POTFILES.skip create mode 100644 src/Makefile.am create mode 100644 src/config.vapi create mode 100644 src/indicator-bluetooth.vala diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..8d48c26 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = po src + +EXTRA_DIST = autogen.sh NEWS diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..5cbc40c --- /dev/null +++ b/NEWS @@ -0,0 +1,3 @@ +Overview of changes in indicator-bluetooth 0.0.1 + + * First release diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..dfd3fb8 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +intltoolize --force +aclocal +automake --add-missing --copy --foreign +autoconf +./configure $@ diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..d7d5b4d --- /dev/null +++ b/configure.ac @@ -0,0 +1,34 @@ +AC_INIT(indicator-bluetooth, 0.0.1) +AM_INIT_AUTOMAKE([1.11 no-dist-gzip dist-xz foreign]) +AM_SILENT_RULES([yes]) +AM_MAINTAINER_MODE + +AM_PROG_VALAC([0.16.0]) +AM_PROG_CC_C_O + +dnl ########################################################################### +dnl Dependencies +dnl ########################################################################### + +PKG_CHECK_MODULES(INDICATOR_BLUETOOTH, [ + glib-2.0 + gtk+-3.0 + appindicator3-0.1 +]) + +dnl ########################################################################### +dnl Internationalization +dnl ########################################################################### + +IT_PROG_INTLTOOL([0.35.0]) +AC_SUBST(GETTEXT_PACKAGE, indicator-bluetooth) + +dnl ########################################################################### +dnl Files to generate +dnl ########################################################################### + +AC_OUTPUT([ +Makefile +po/Makefile.in +src/Makefile +]) diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..b1f140c --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,4 @@ +# List of source files containing translatable strings. +# Please keep this file in alphabetical order. +[encoding: UTF-8] +src/indicator-bluetooth.vala diff --git a/po/POTFILES.skip b/po/POTFILES.skip new file mode 100644 index 0000000..dfa1f6d --- /dev/null +++ b/po/POTFILES.skip @@ -0,0 +1 @@ +src/indicator-bluetooth.c 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 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 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 (BusType.SYSTEM, "org.bluez", "/"); + var path = manager.default_adapter (); + adapter = Bus.get_proxy_sync (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 (BusType.SYSTEM, "org.bluez", path); + var properties = device.get_properties (); + var iter = HashTableIter (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; +} -- cgit v1.2.3