aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-06-28 15:51:48 -0400
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-06-28 15:51:48 -0400
commit040e9977f7b83221c85d8b279d9537ad46303e20 (patch)
treea0c06944bb671c4dc02cf7841310cce06a9bb276
parent9d78a433b18fd14af4d3cfa01684c32b93f91966 (diff)
downloadayatana-indicator-sound-040e9977f7b83221c85d8b279d9537ad46303e20.tar.gz
ayatana-indicator-sound-040e9977f7b83221c85d8b279d9537ad46303e20.tar.bz2
ayatana-indicator-sound-040e9977f7b83221c85d8b279d9537ad46303e20.zip
service.vala: make removing a player from the menu more readable
-rw-r--r--src/service.vala27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/service.vala b/src/service.vala
index d638b10..7f89c66 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -308,23 +308,30 @@ public class IndicatorSound.Service {
this.update_preferred_players ();
}
- void player_removed (MediaPlayer player) {
- this.actions.remove (player.id);
- this.actions.remove ("play." + player.id);
- this.actions.remove ("next." + player.id);
- this.actions.remove ("previous." + player.id);
-
+ /* returns the position in this.menu of the section that's associated with @player */
+ int find_player_section (MediaPlayer player) {
int n = this.menu.get_n_items ();
for (int i = 0; i < n; i++) {
var section = this.menu.get_item_link (i, Menu.LINK_SECTION);
string action;
section.get_item_attribute (0, "action", "s", out action);
- if (action == player.id) {
- this.menu.remove (i);
- break;
- }
+ if (action == player.id)
+ return i;
}
+ return -1;
+ }
+
+ void player_removed (MediaPlayer player) {
+ this.actions.remove (player.id);
+ this.actions.remove ("play." + player.id);
+ this.actions.remove ("next." + player.id);
+ this.actions.remove ("previous." + player.id);
+
+ int index = this.find_player_section (player);
+ if (index >= 0)
+ this.menu.remove (index);
+
this.update_preferred_players ();
}
}