From 997864b9fc62596e8cc238f4c4b77d780651ffb4 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 25 Jul 2013 16:21:44 +0200 Subject: service.vala: store menus in a hash table, keyed by profile name --- src/service.vala | 14 ++++++++------ src/sound-menu.vala | 8 ++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/service.vala b/src/service.vala index eeb0a30..c1c6306 100644 --- a/src/service.vala +++ b/src/service.vala @@ -36,8 +36,9 @@ public class IndicatorSound.Service { this.actions.add_action (this.create_volume_action ()); this.actions.add_action (this.create_mic_volume_action ()); - this.menu = new SoundMenu (); - this.volume_control.bind_property ("active-mic", this.menu, "show-mic-volume", BindingFlags.SYNC_CREATE); + this.menus = new HashTable (str_hash, str_equal); + this.menus.insert ("desktop", new SoundMenu ()); + this.volume_control.bind_property ("active-mic", this.menus.get("desktop"), "show-mic-volume", BindingFlags.SYNC_CREATE); this.players.sync (settings.get_strv ("interested-media-players")); this.settings.changed["interested-media-players"].connect ( () => { @@ -67,7 +68,7 @@ public class IndicatorSound.Service { MainLoop loop; SimpleActionGroup actions; - SoundMenu menu; + HashTable menus; Settings settings; VolumeControl volume_control; MediaPlayerList players; @@ -174,10 +175,11 @@ public class IndicatorSound.Service { void bus_acquired (DBusConnection connection, string name) { try { connection.export_action_group ("/com/canonical/indicator/sound", this.actions); - this.menu.export (connection, "/com/canonical/indicator/sound/desktop"); } catch (Error e) { critical ("%s", e.message); } + + this.menus.@foreach ( (profile, menu) => menu.export (connection, @"/com/canonical/indicator/sound/$profile")); } void name_lost (DBusConnection connection, string name) { @@ -221,7 +223,7 @@ public class IndicatorSound.Service { } void player_added (MediaPlayer player) { - this.menu.add_player (player); + this.menus.@foreach ( (profile, menu) => menu.add_player (player)); SimpleAction action = new SimpleAction.stateful (player.id, null, this.action_state_for_player (player)); action.activate.connect ( () => { player.launch (); }); @@ -259,7 +261,7 @@ public class IndicatorSound.Service { this.actions.remove ("previous." + player.id); this.actions.remove ("play-playlist." + player.id); - this.menu.remove_player (player); + this.menus.@foreach ( (profile, menu) => menu.remove_player (player)); this.update_preferred_players (); } diff --git a/src/sound-menu.vala b/src/sound-menu.vala index acb9adf..376ef15 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -43,8 +43,12 @@ class SoundMenu: Object root.append_item (root_item); } - public void export (DBusConnection connection, string object_path) throws Error { - connection.export_menu_model (object_path, this.root); + public void export (DBusConnection connection, string object_path) { + try { + connection.export_menu_model (object_path, this.root); + } catch (Error e) { + critical ("%s", e.message); + } } public bool show_mic_volume { -- cgit v1.2.3