From 92c98f341c6b5600d4b5fae8753326c866e40860 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 22 Mar 2013 16:24:06 -0400 Subject: Add service that adheres to the new indicator protocol This is the one that gets built now. It doesn't do anything interesting yet, though. --- src/Makefile.am | 8 ++-- src/com.canonical.sound.indicator | 4 ++ src/main.vala | 5 +++ src/service.vala | 84 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 src/com.canonical.sound.indicator create mode 100644 src/main.vala create mode 100644 src/service.vala (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index a56f82a..39ec6bf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,8 @@ glib_marshal_prefix = _sound_service_marshal # Sound service vala ##################### music_bridge_VALASOURCES = \ + service.vala \ + main.vala \ music-player-bridge.vala \ transport-menu-item.vala \ specific-items-manager.vala \ @@ -44,7 +46,9 @@ music_bridge_VALAFLAGS = \ --pkg gio-2.0 \ --pkg gio-unix-2.0 \ --pkg gdk-pixbuf-2.0 \ - --pkg libxml-2.0 + --pkg libxml-2.0 \ + --pkg libpulse \ + --target-glib=2.36 $(MAINTAINER_VALAFLAGS) @@ -60,8 +64,6 @@ music_bridge_vala.stamp $(music_bridge_APIFILES): $(music_bridge_VALASOURCES) ############################### indicator_sound_service_SOURCES = \ common-defs.h \ - sound-service.h \ - sound-service.c \ sound-state.c \ sound-state.h \ pulseaudio-mgr.h \ diff --git a/src/com.canonical.sound.indicator b/src/com.canonical.sound.indicator new file mode 100644 index 0000000..e2f26b0 --- /dev/null +++ b/src/com.canonical.sound.indicator @@ -0,0 +1,4 @@ +[Indicator Service] +Name=indicator-sound +BusName=com.canonical.indicator.sound +ObjectPath=/com/canonical/indicator/sound diff --git a/src/main.vala b/src/main.vala new file mode 100644 index 0000000..1ec7d2c --- /dev/null +++ b/src/main.vala @@ -0,0 +1,5 @@ + +static int main (string[] args) { + var service = new IndicatorSound.Service (); + return service.run (); +} diff --git a/src/service.vala b/src/service.vala new file mode 100644 index 0000000..fc35dd7 --- /dev/null +++ b/src/service.vala @@ -0,0 +1,84 @@ + +public class IndicatorSound.Service { + public Service () { + } + + public int run () { + if (this.loop != null) { + warning ("service is already running"); + return 1; + } + + Bus.own_name (BusType.SESSION, "com.canonical.indicator.sound", BusNameOwnerFlags.NONE, + this.bus_acquired, null, this.name_lost); + + this.loop = new MainLoop (null, false); + this.loop.run (); + + return 0; + } + + const ActionEntry[] action_entries = { + { "root", null, null, "('', 'audio-volume-high-panel', '', true)", null }, + { "mute", activate_mute, null, "false", null }, + { "volume", null, null, "0", volume_changed }, + { "settings", activate_settings, null, null, null } + }; + + MainLoop loop; + SimpleActionGroup actions; + Menu menu; + + void activate_mute (SimpleAction action, Variant? param) { + bool muted = action.get_state ().get_boolean (); + } + + void volume_changed (SimpleAction action, Variant val) { + } + + void activate_settings (SimpleAction action, Variant? param) { + try { + Process.spawn_command_line_async ("gnome-control-center sound"); + } catch (Error e) { + warning ("unable to launch sound settings: %s", e.message); + } + } + + static Menu create_base_menu () { + var submenu = new Menu (); + submenu.append ("Mute", "indicator.mute"); + + var slider = new MenuItem ("null", "indicator.volume"); + slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider"); + submenu.append_item (slider); + + submenu.append ("Sound Settingsā€¦", "indicator.settings"); + + var root = new MenuItem (null, "indicator.root"); + root.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); + root.set_submenu (submenu); + + var menu = new Menu (); + menu.append_item (root); + + return menu; + } + + void bus_acquired (DBusConnection connection, string name) { + this.actions = new SimpleActionGroup (); + this.actions.add_entries (action_entries, this); + + this.menu = create_base_menu (); + + try { + connection.export_action_group ("/com/canonical/indicator/sound", this.actions); + connection.export_menu_model ("/com/canonical/indicator/sound/desktop", this.menu); + } catch (Error e) { + critical ("%s", e.message); + } + } + + void name_lost (DBusConnection connection, string name) { + this.loop.quit (); + } +} -- cgit v1.2.3