diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-10-24 19:33:47 +0000 |
---|---|---|
committer | Tarmac <Unknown> | 2013-10-24 19:33:47 +0000 |
commit | 39890de138edeb70c68b72bb5686f557c3ab74aa (patch) | |
tree | 8be534d4cc61f60ab1879b84d9bb0818a2f093cf /src | |
parent | d12eb5690956a3e5fb35e56a151822bd8a819358 (diff) | |
parent | a66beb0805404bdf8f138fd3a683372487e6e35b (diff) | |
download | ayatana-indicator-sound-39890de138edeb70c68b72bb5686f557c3ab74aa.tar.gz ayatana-indicator-sound-39890de138edeb70c68b72bb5686f557c3ab74aa.tar.bz2 ayatana-indicator-sound-39890de138edeb70c68b72bb5686f557c3ab74aa.zip |
Only display running players in the phone's sound menu
The design says to only display the _one_ running player. This will have that effect, as there's only one player allowed to run at a time on the phone.
Approved by PS Jenkins bot, Ted Gould.
Diffstat (limited to 'src')
-rw-r--r-- | src/service.vala | 6 | ||||
-rw-r--r-- | src/sound-menu.vala | 84 |
2 files changed, 62 insertions, 28 deletions
diff --git a/src/service.vala b/src/service.vala index e69bca8..393a1ea 100644 --- a/src/service.vala +++ b/src/service.vala @@ -34,9 +34,9 @@ public class IndicatorSound.Service { this.actions.add_action (this.create_mic_volume_action ()); this.menus = new HashTable<string, SoundMenu> (str_hash, str_equal); - this.menus.insert ("desktop_greeter", new SoundMenu (true, null)); - this.menus.insert ("desktop", new SoundMenu (true, "indicator.desktop-settings")); - this.menus.insert ("phone", new SoundMenu (false, "indicator.phone-settings")); + this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE)); + this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE)); + this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS)); this.menus.@foreach ( (profile, menu) => { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); diff --git a/src/sound-menu.vala b/src/sound-menu.vala index 1641219..e1c5c1f 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -22,14 +22,20 @@ extern Variant? g_icon_serialize (Icon icon); class SoundMenu: Object { - public SoundMenu (bool show_mute, string? settings_action) { + public enum DisplayFlags { + NONE = 0, + SHOW_MUTE = 1, + HIDE_INACTIVE_PLAYERS = 2 + } + + public SoundMenu (string? settings_action, DisplayFlags flags) { /* A sound menu always has at least two sections: the volume section (this.volume_section) * at the start of the menu, and the settings section at the end. Between those two, * it has a dynamic amount of player sections, one for each registered player. */ this.volume_section = new Menu (); - if (show_mute) + if ((flags & DisplayFlags.SHOW_MUTE) != 0) volume_section.append (_("Mute"), "indicator.mute"); volume_section.append_item (this.create_slider_menu_item ("indicator.volume(0)", 0.0, 1.0, 0.01, "audio-volume-low-zero-panel", @@ -51,6 +57,9 @@ class SoundMenu: Object this.root = new Menu (); root.append_item (root_item); + + this.hide_inactive = (flags & DisplayFlags.HIDE_INACTIVE_PLAYERS) != 0; + this.notify_handlers = new HashTable<MediaPlayer, ulong> (direct_hash, direct_equal); } public void export (DBusConnection connection, string object_path) { @@ -81,36 +90,30 @@ class SoundMenu: Object } public void add_player (MediaPlayer player) { - /* Add new players to the end of the player sections, just before the settings */ - var player_item = new MenuItem (player.name, "indicator." + player.id); - player_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.media-player"); - player_item.set_attribute_value ("icon", g_icon_serialize (player.icon)); + if (this.notify_handlers.contains (player)) + return; - var playback_item = new MenuItem (null, null); - playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item"); - playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id); - playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id); - playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id); + if (player.is_running || !this.hide_inactive) + this.insert_player_section (player); + this.update_playlists (player); - var section = new Menu (); - section.append_item (player_item); - section.append_item (playback_item); + var handler_id = player.notify["is-running"].connect ( () => { + if (this.hide_inactive) { + if (player.is_running) + this.insert_player_section (player); + else + this.remove_player_section (player); + } + this.update_playlists (player); + }); + this.notify_handlers.insert (player, handler_id); player.playlists_changed.connect (this.update_playlists); - player.notify["is-running"].connect ( () => this.update_playlists (player) ); - update_playlists (player); - - if (settings_shown) { - this.menu.insert_section (this.menu.get_n_items () -1, null, section); - } else { - this.menu.append_section (null, section); - } } public void remove_player (MediaPlayer player) { - int index = this.find_player_section (player); - if (index >= 0) - this.menu.remove (index); + this.remove_player_section (player); + this.notify_handlers.remove (player); } Menu root; @@ -118,6 +121,8 @@ class SoundMenu: Object Menu volume_section; bool mic_volume_shown; bool settings_shown = false; + bool hide_inactive; + HashTable<MediaPlayer, ulong> notify_handlers; /* returns the position in this.menu of the section that's associated with @player */ int find_player_section (MediaPlayer player) { @@ -134,6 +139,35 @@ class SoundMenu: Object return -1; } + void insert_player_section (MediaPlayer player) { + var section = new Menu (); + + var player_item = new MenuItem (player.name, "indicator." + player.id); + player_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.media-player"); + player_item.set_attribute_value ("icon", g_icon_serialize (player.icon)); + section.append_item (player_item); + + var playback_item = new MenuItem (null, null); + playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item"); + playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id); + playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id); + playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id); + section.append_item (playback_item); + + /* Add new players to the end of the player sections, just before the settings */ + if (settings_shown) { + this.menu.insert_section (this.menu.get_n_items () -1, null, section); + } else { + this.menu.append_section (null, section); + } + } + + void remove_player_section (MediaPlayer player) { + int index = this.find_player_section (player); + if (index >= 0) + this.menu.remove (index); + } + void update_playlists (MediaPlayer player) { int index = find_player_section (player); if (index < 0) |