aboutsummaryrefslogtreecommitdiff
path: root/src/sound-menu.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound-menu.vala')
-rw-r--r--src/sound-menu.vala48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/sound-menu.vala b/src/sound-menu.vala
index 630dca0..2ef089a 100644
--- a/src/sound-menu.vala
+++ b/src/sound-menu.vala
@@ -38,7 +38,7 @@ public class SoundMenu: Object
const string PLAYBACK_ITEM_TYPE = "com.canonical.unity.playback-item";
- public SoundMenu (string? settings_action, DisplayFlags flags, string default_player_id) {
+ 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.
@@ -83,9 +83,6 @@ public class SoundMenu: Object
this.notify_handlers = new HashTable<MediaPlayer, ulong> (direct_hash, direct_equal);
this.greeter_players = (flags & DisplayFlags.GREETER_PLAYERS) != 0;
-
- this.default_player = default_player_id;
-
}
~SoundMenu () {
@@ -95,6 +92,16 @@ public class SoundMenu: Object
}
}
+ public void set_default_player (string default_player_id) {
+ this.default_player = default_player_id;
+ foreach (var player_stored in notify_handlers.get_keys ()) {
+ int index = this.find_player_section(player_stored);
+ if (index != -1 && player_stored.id == this.default_player) {
+ add_player_playback_controls (player_stored, index, true);
+ }
+ }
+ }
+
DBusConnection? bus = null;
uint export_id = 0;
@@ -171,7 +178,17 @@ public class SoundMenu: Object
}
}
}
-
+
+ private void check_last_running_player () {
+ foreach (var player in notify_handlers.get_keys ()) {
+ if (player.is_running && number_of_running_players == 1) {
+ // this is the first or the last player running...
+ // store its id
+ this.last_player_updated (player.id);
+ }
+ }
+ }
+
public void add_player (MediaPlayer player) {
if (this.notify_handlers.contains (player))
return;
@@ -198,11 +215,15 @@ public class SoundMenu: Object
// we need to update the rest of players, because we might have
// a non running player still showing the playback controls
update_all_players_play_section();
+
+ check_last_running_player ();
});
this.notify_handlers.insert (player, handler_id);
player.playlists_changed.connect (this.update_playlists);
player.playbackstatus_changed.connect (this.update_playbackstatus);
+
+ check_last_running_player ();
}
public void remove_player (MediaPlayer player) {
@@ -217,6 +238,8 @@ public class SoundMenu: Object
/* this'll drop our ref to it */
this.notify_handlers.remove (player);
+
+ check_last_running_player ();
}
public void update_volume_slider (VolumeControl.ActiveOutput active_output) {
@@ -368,16 +391,11 @@ public class SoundMenu: Object
this.menu.remove (index);
}
- void update_player_section (MediaPlayer player, int index) {
+ void add_player_playback_controls (MediaPlayer player, int index, bool adding_default_player) {
var player_section = this.menu.get_item_link(index, Menu.LINK_SECTION) as Menu;
int play_control_index = find_player_playback_controls_section (player_section);
- if (player.is_running && number_of_running_players == 1) {
- // this is the first or the last player running...
- // store its id
- this.last_player_updated (player.id);
- }
- if (player.is_running || !this.hide_inactive_player_controls) {
+ if (player.is_running || !this.hide_inactive_player_controls || (number_of_running_players == 0 && adding_default_player) ) {
MenuItem playback_item = create_playback_menu_item (player);
if (play_control_index != -1) {
player_section.remove (PlayerSectionPosition.PLAYER_CONTROLS);
@@ -389,7 +407,11 @@ public class SoundMenu: Object
player_section.remove (PlayerSectionPosition.PLAYLIST);
player_section.remove (PlayerSectionPosition.PLAYER_CONTROLS);
}
- }
+ }
+ }
+
+ void update_player_section (MediaPlayer player, int index) {
+ add_player_playback_controls (player, index, false);
}
void update_playlists (MediaPlayer player) {