From 040e9977f7b83221c85d8b279d9537ad46303e20 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 28 Jun 2013 15:51:48 -0400 Subject: service.vala: make removing a player from the menu more readable --- src/service.vala | 27 +++++++++++++++++---------- 1 file 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 (); } } -- cgit v1.2.3