aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavi Garcia Mena <xavi.garcia.mena@canonical.com>2016-02-10 14:08:49 +0100
committerXavi Garcia Mena <xavi.garcia.mena@canonical.com>2016-02-10 14:08:49 +0100
commitf1bdb863aea00a03acf9501432e2baa70dd9ee8b (patch)
tree8ab41e0d437047d35464a3c464c33cf037c35438
parentd17217847987bc11f139f2676715beb74e0406ff (diff)
downloadayatana-indicator-sound-f1bdb863aea00a03acf9501432e2baa70dd9ee8b.tar.gz
ayatana-indicator-sound-f1bdb863aea00a03acf9501432e2baa70dd9ee8b.tar.bz2
ayatana-indicator-sound-f1bdb863aea00a03acf9501432e2baa70dd9ee8b.zip
Added persistence for last running player
-rw-r--r--data/com.canonical.indicator.sound.gschema.xml11
-rw-r--r--src/service.vala15
-rw-r--r--src/sound-menu.vala23
-rw-r--r--tests/integration/test-indicator.cpp1
-rw-r--r--tests/sound-menu.cc6
5 files changed, 45 insertions, 11 deletions
diff --git a/data/com.canonical.indicator.sound.gschema.xml b/data/com.canonical.indicator.sound.gschema.xml
index b2ee856..8408883 100644
--- a/data/com.canonical.indicator.sound.gschema.xml
+++ b/data/com.canonical.indicator.sound.gschema.xml
@@ -102,5 +102,16 @@
</description>
</key>
+ <key name="last-running-player" type="s">
+ <default>""</default>
+ <summary>Stores which was the last running music player.</summary>
+ <description>
+ To make the last running player persistent and be able to set its playback controls
+ we store which was the last player running id.
+
+ The default value ("") corresponds to no player.
+ </description>
+ </key>
+
</schema>
</schemalist>
diff --git a/src/service.vala b/src/service.vala
index 2228ba2..cb30820 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -91,11 +91,12 @@ public class IndicatorSound.Service: Object {
this.actions.add_action (this.create_high_volume_action ());
this.actions.add_action (this.create_volume_sync_action ());
+ string last_player = this.settings.get_string ("last-running-player");
this.menus = new HashTable<string, SoundMenu> (str_hash, str_equal);
- this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS));
- this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS));
- this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS_PLAY_CONTROLS));
- this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
+ this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS, last_player));
+ this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS, last_player));
+ this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS_PLAY_CONTROLS | SoundMenu.DisplayFlags.ADD_PLAY_CONTROL_INACTIVE_PLAYER, last_player));
+ this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS, last_player));
this.menus.@foreach ( (profile, menu) => {
this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE);
@@ -109,6 +110,12 @@ public class IndicatorSound.Service: Object {
this.volume_control.active_output_changed.connect (menu.update_volume_slider);
});
+ this.menus.@foreach ( (profile, menu) => {
+ menu.last_player_updated.connect ((player_id) => {
+ this.settings.set_value ("last-running-player", player_id);
+ });
+ });
+
this.sync_preferred_players ();
this.settings.changed["interested-media-players"].connect ( () => {
this.sync_preferred_players ();
diff --git a/src/sound-menu.vala b/src/sound-menu.vala
index 669e83d..630dca0 100644
--- a/src/sound-menu.vala
+++ b/src/sound-menu.vala
@@ -26,7 +26,8 @@ public class SoundMenu: Object
HIDE_PLAYERS = 4,
GREETER_PLAYERS = 8,
SHOW_SILENT_MODE = 16,
- HIDE_INACTIVE_PLAYERS_PLAY_CONTROLS = 32
+ HIDE_INACTIVE_PLAYERS_PLAY_CONTROLS = 32,
+ ADD_PLAY_CONTROL_INACTIVE_PLAYER = 64
}
public enum PlayerSectionPosition {
@@ -37,7 +38,7 @@ public class SoundMenu: Object
const string PLAYBACK_ITEM_TYPE = "com.canonical.unity.playback-item";
- public SoundMenu (string? settings_action, DisplayFlags flags) {
+ public SoundMenu (string? settings_action, DisplayFlags flags, string default_player_id) {
/* 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.
@@ -78,10 +79,13 @@ public class SoundMenu: Object
this.hide_players = (flags & DisplayFlags.HIDE_PLAYERS) != 0;
this.hide_inactive = (flags & DisplayFlags.HIDE_INACTIVE_PLAYERS) != 0;
this.hide_inactive_player_controls = (flags & DisplayFlags.HIDE_INACTIVE_PLAYERS_PLAY_CONTROLS) != 0;
+ this.add_play_button_inactive_player = (flags & DisplayFlags.ADD_PLAY_CONTROL_INACTIVE_PLAYER) != 0;
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 () {
@@ -261,9 +265,11 @@ public class SoundMenu: Object
bool hide_inactive;
bool hide_players = false;
bool hide_inactive_player_controls = false;
+ bool add_play_button_inactive_player = false;
HashTable<MediaPlayer, ulong> notify_handlers;
bool greeter_players = false;
int number_of_running_players = 0;
+ string default_player = "";
/* returns the position in this.menu of the section that's associated with @player */
int find_player_section (MediaPlayer player) {
@@ -309,6 +315,10 @@ public class SoundMenu: Object
if (player.can_do_prev) {
playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id);
}
+ } else {
+ if (this.add_play_button_inactive_player) {
+ playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id);
+ }
}
return playback_item;
}
@@ -336,7 +346,7 @@ public class SoundMenu: Object
player_item.set_attribute_value ("icon", icon.serialize ());
section.append_item (player_item);
- if (player.is_running|| !this.hide_inactive_player_controls) {
+ if (player.is_running|| !this.hide_inactive_player_controls || player.id == this.default_player) {
var playback_item = create_playback_menu_item (player);
section.insert_item (PlayerSectionPosition.PLAYER_CONTROLS, playback_item);
}
@@ -362,6 +372,11 @@ public class SoundMenu: Object
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) {
MenuItem playback_item = create_playback_menu_item (player);
if (play_control_index != -1) {
@@ -432,4 +447,6 @@ public class SoundMenu: Object
return slider;
}
+
+ public signal void last_player_updated (string player_id);
}
diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp
index 050c306..33a27af 100644
--- a/tests/integration/test-indicator.cpp
+++ b/tests/integration/test-indicator.cpp
@@ -1385,7 +1385,6 @@ TEST_F(TestIndicator, DISABLED_PhoneNotificationWarningVolume)
// try again...
notificationsSpy.clear();
- qWarning() << "-----------------------------------------------------------";
// change volume to 1.0... warning should be emitted
setActionValue("volume", QVariant::fromValue(1.0));
EXPECT_TRUE(waitVolumeChangedInIndicator());
diff --git a/tests/sound-menu.cc b/tests/sound-menu.cc
index ca8b426..2576d19 100644
--- a/tests/sound-menu.cc
+++ b/tests/sound-menu.cc
@@ -62,7 +62,7 @@ class SoundMenuTest : public ::testing::Test
void check_player_control_buttons(bool canPlay, bool canNext, bool canPrev)
{
- SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
+ SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE, "");
MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url");
@@ -125,7 +125,7 @@ class SoundMenuTest : public ::testing::Test
};
TEST_F(SoundMenuTest, BasicObject) {
- SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
+ SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE, "");
ASSERT_NE(nullptr, menu);
@@ -134,7 +134,7 @@ TEST_F(SoundMenuTest, BasicObject) {
}
TEST_F(SoundMenuTest, AddRemovePlayer) {
- SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
+ SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE, "");
MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url");