diff options
author | Xavi Garcia Mena <xavi.garcia.mena@canonical.com> | 2015-09-15 14:16:10 +0200 |
---|---|---|
committer | Xavi Garcia Mena <xavi.garcia.mena@canonical.com> | 2015-09-15 14:16:10 +0200 |
commit | a3b4aa7d5959ed275dd501ae2264e81b00b184b3 (patch) | |
tree | bbf439be2344033510ccc1b0e26ab0e25aa3484b /src | |
parent | f76bbdf9eefaffd594078efe534ad1090f5aa41f (diff) | |
download | ayatana-indicator-sound-a3b4aa7d5959ed275dd501ae2264e81b00b184b3.tar.gz ayatana-indicator-sound-a3b4aa7d5959ed275dd501ae2264e81b00b184b3.tar.bz2 ayatana-indicator-sound-a3b4aa7d5959ed275dd501ae2264e81b00b184b3.zip |
Added changed to reflect the state of the player control buttons
Diffstat (limited to 'src')
-rw-r--r-- | src/media-player-mpris.vala | 21 | ||||
-rw-r--r-- | src/media-player.vala | 4 | ||||
-rw-r--r-- | src/mpris2-interfaces.vala | 5 | ||||
-rw-r--r-- | src/sound-menu.vala | 67 |
4 files changed, 90 insertions, 7 deletions
diff --git a/src/media-player-mpris.vala b/src/media-player-mpris.vala index 741d887..8bc2884 100644 --- a/src/media-player-mpris.vala +++ b/src/media-player-mpris.vala @@ -79,6 +79,24 @@ public class MediaPlayerMpris: MediaPlayer { } } + public override bool can_do_play { + get { + return this.proxy.CanPlay; + } + } + + public override bool can_do_prev { + get { + return this.proxy.CanGoPrevious; + } + } + + public override bool can_do_next { + get { + return this.proxy.CanGoNext; + } + } + /** * Attach this object to a process of the associated media player. The player must own @dbus_name and * implement the org.mpris.MediaPlayer2.Player interface. @@ -272,6 +290,9 @@ public class MediaPlayerMpris: MediaPlayer { if (changed_properties.lookup ("PlaybackStatus", "s", null)) { this.state = this.proxy.PlaybackStatus != null ? this.proxy.PlaybackStatus : "Unknown"; } + if (changed_properties.lookup ("CanGoNext", "b", null) || changed_properties.lookup ("CanGoPrev", "b", null)) { + this.playbackstatus_changed (); + } var metadata = changed_properties.lookup_value ("Metadata", new VariantType ("a{sv}")); if (metadata != null) diff --git a/src/media-player.vala b/src/media-player.vala index 4d4aef3..04d1426 100644 --- a/src/media-player.vala +++ b/src/media-player.vala @@ -26,6 +26,9 @@ public abstract class MediaPlayer : Object { public virtual bool is_running { get { not_implemented(); return false; } } public virtual bool can_raise { get { not_implemented(); return false; } } + public virtual bool can_do_next { get { not_implemented(); return false; } } + public virtual bool can_do_prev { get { not_implemented(); return false; } } + public virtual bool can_do_play { get { not_implemented(); return false; } } public class Track : Object { public string artist { get; construct; } @@ -44,6 +47,7 @@ public abstract class MediaPlayer : Object { } public signal void playlists_changed (); + public signal void playbackstatus_changed (); public abstract void activate (); public abstract void play_pause (); diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index a472d5c..0ed8719 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -37,7 +37,10 @@ public interface MprisPlayer : Object { // properties public abstract HashTable<string, Variant?> Metadata{owned get; set;} public abstract int32 Position{owned get; set;} - public abstract string? PlaybackStatus{owned get; set;} + public abstract string? PlaybackStatus{owned get; set;} + public abstract bool CanPlay{owned get; set;} + public abstract bool CanGoNext{owned get; set;} + public abstract bool CanGoPrevious{owned get; set;} // methods public abstract async void PlayPause() throws IOError; public abstract async void Next() throws IOError; diff --git a/src/sound-menu.vala b/src/sound-menu.vala index 8718162..7a6044b 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -157,18 +157,26 @@ public class SoundMenu: Object this.update_playlists (player); var handler_id = player.notify["is-running"].connect ( () => { - if (player.is_running) - if (this.find_player_section(player) == -1) + if (player.is_running) { + int index = this.find_player_section(player); + if (index == -1) { this.insert_player_section (player); - else + } + else { + update_player_section (player, index); + } + } + else { if (this.hide_inactive) this.remove_player_section (player); + } this.update_playlists (player); }); this.notify_handlers.insert (player, handler_id); player.playlists_changed.connect (this.update_playlists); + player.playbackstatus_changed.connect (this.update_playbackstatus); } public void remove_player (MediaPlayer player) { @@ -215,6 +223,23 @@ public class SoundMenu: Object return -1; } + MenuItem create_playback_menu_item (MediaPlayer player) { + var playback_item = new MenuItem (null, null); + playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item"); + if (player.is_running) { + if (player.can_do_play) { + playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id); + } + if (player.can_do_next) { + playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id); + } + if (player.can_do_prev) { + playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id); + } + } + return playback_item; + } + void insert_player_section (MediaPlayer player) { if (this.hide_players) return; @@ -240,9 +265,21 @@ public class SoundMenu: Object 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); + playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id + ".disabled"); + playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id + ".disabled"); + playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id + ".disabled"); + + if (player.is_running) { + if (player.can_do_play) { + playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id); + } + if (player.can_do_next) { + playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id); + } + if (player.can_do_prev) { + 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 */ @@ -262,6 +299,17 @@ public class SoundMenu: Object this.menu.remove (index); } + void update_player_section (MediaPlayer player, int index) { + var player_section = this.menu.get_item_link(index, Menu.LINK_SECTION) as Menu; + if (player_section.get_n_items () == 2) { + // we have 2 items, the second one is the playback item + // remove it first + player_section.remove (1); + MenuItem playback_item = create_playback_menu_item (player); + player_section.append_item (playback_item); + } + } + void update_playlists (MediaPlayer player) { int index = find_player_section (player); if (index < 0) @@ -292,6 +340,13 @@ public class SoundMenu: Object submenu.append_section (null, playlists_section); player_section.append_submenu (_("Choose Playlist"), submenu); } + + void update_playbackstatus (MediaPlayer player) { + int index = find_player_section (player); + if (index != -1) { + update_player_section (player, index); + } + } MenuItem create_slider_menu_item (string label, string action, double min, double max, double step, string min_icon_name, string max_icon_name) { var min_icon = new ThemedIcon.with_default_fallbacks (min_icon_name); |