diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-03-28 12:34:35 -0400 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-03-28 12:34:35 -0400 |
commit | 1419ef39b81be9d8a42b915ad9f56e81ab4eb03c (patch) | |
tree | c2265dd76e20dfcdf6bb42fd17915fa63c70dfbb /src/service.vala | |
parent | 0386c87d0176c3d539f6cac6f5d52ba1adf9d761 (diff) | |
download | ayatana-indicator-sound-1419ef39b81be9d8a42b915ad9f56e81ab4eb03c.tar.gz ayatana-indicator-sound-1419ef39b81be9d8a42b915ad9f56e81ab4eb03c.tar.bz2 ayatana-indicator-sound-1419ef39b81be9d8a42b915ad9f56e81ab4eb03c.zip |
Show running media players in the menu
Each player has its own action with a dictionary state. Right now, this state
only contains one key "running", which signifies whether an instance of the
player is currently running.
It does not yet show non-running players on startup, and ignores the blacklist.
Diffstat (limited to 'src/service.vala')
-rw-r--r-- | src/service.vala | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/service.vala b/src/service.vala index aa6664e..4ea4a95 100644 --- a/src/service.vala +++ b/src/service.vala @@ -2,6 +2,9 @@ public class IndicatorSound.Service { public Service () { this.volume_control = new VolumeControl (); + + this.players = new MediaPlayerList (); + this.players.player_added.connect (player_added); } public int run () { @@ -28,6 +31,8 @@ public class IndicatorSound.Service { SimpleActionGroup actions; Menu menu; VolumeControl volume_control; + MediaPlayerList players; + uint player_action_update_id; void activate_settings (SimpleAction action, Variant? param) { try { @@ -41,7 +46,7 @@ public class IndicatorSound.Service { var submenu = new Menu (); submenu.append ("Mute", "indicator.mute"); - var slider = new MenuItem ("null", "indicator.volume"); + var slider = new MenuItem (null, "indicator.volume"); slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider"); submenu.append_item (slider); @@ -111,4 +116,37 @@ public class IndicatorSound.Service { void name_lost (DBusConnection connection, string name) { this.loop.quit (); } + + bool update_player_action (MediaPlayer player) { + var builder = new VariantBuilder (new VariantType ("a{sv}")); + builder.add ("{sv}", "running", new Variant ("b", player.is_running)); + var state = builder.end (); + + SimpleAction? action = this.actions.lookup (player.id) as SimpleAction; + if (action == null) { + action = new SimpleAction.stateful (player.id, null, state); + action.activate.connect ( () => { player.launch (); }); + this.actions.insert (action); + } + else { + action.set_state (state); + } + + this.player_action_update_id = 0; + return false; + } + + void eventually_update_player_action (MediaPlayer player) { + if (player_action_update_id == 0) + this.player_action_update_id = Idle.add ( () => this.update_player_action (player) ); + } + + void player_added (MediaPlayer player) { + var item = new MenuItem (player.name, player.id); + item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.media-player"); + this.menu.insert_item (this.menu.get_n_items () -1, item); + + eventually_update_player_action (player); + player.notify.connect ( () => eventually_update_player_action (player) ); + } } |