aboutsummaryrefslogtreecommitdiff
path: root/src/sound-menu.vala
diff options
context:
space:
mode:
authorXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-09-15 14:16:10 +0200
committerXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-09-15 14:16:10 +0200
commita3b4aa7d5959ed275dd501ae2264e81b00b184b3 (patch)
treebbf439be2344033510ccc1b0e26ab0e25aa3484b /src/sound-menu.vala
parentf76bbdf9eefaffd594078efe534ad1090f5aa41f (diff)
downloadayatana-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/sound-menu.vala')
-rw-r--r--src/sound-menu.vala67
1 files changed, 61 insertions, 6 deletions
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);