aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2014-10-14 16:03:11 -0500
committerTed Gould <ted@gould.cx>2014-10-14 16:03:11 -0500
commit297a640e325c129a6ecd42210db30e522465078b (patch)
treef4e8b493588f25e3ee10390b4eac2ed0278a4b51
parent2b4342f72a57c6b3d112fd6e923c544be789f6ea (diff)
parenta3de59a992980727e05c58e052be53a8adc5bf08 (diff)
downloadayatana-indicator-sound-297a640e325c129a6ecd42210db30e522465078b.tar.gz
ayatana-indicator-sound-297a640e325c129a6ecd42210db30e522465078b.tar.bz2
ayatana-indicator-sound-297a640e325c129a6ecd42210db30e522465078b.zip
Making the removal of items smarter
-rw-r--r--src/sound-menu.vala27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/sound-menu.vala b/src/sound-menu.vala
index 38c5214..b93c513 100644
--- a/src/sound-menu.vala
+++ b/src/sound-menu.vala
@@ -82,8 +82,10 @@ public class SoundMenu: Object
this.mic_volume_shown = true;
}
else if (!value && this.mic_volume_shown) {
- /* TODO: Make smarter */
- this.volume_section.remove (this.volume_section.get_n_items () -1);
+ int location = -1;
+ while ((location = find_action(this.volume_section, "indicator.mic-volume")) != -1) {
+ this.volume_section.remove (location);
+ }
this.mic_volume_shown = false;
}
}
@@ -95,18 +97,35 @@ public class SoundMenu: Object
}
set {
if (value && !this.high_volume_warning_shown) {
- var item = new MenuItem(_("High volume can damage your hearing."), null);
+ /* NOTE: Action doesn't really exist, just used to find below when removing */
+ var item = new MenuItem(_("High volume can damage your hearing."), "indicator.high-volume-warning-item");
volume_section.append_item (item);
this.high_volume_warning_shown = true;
}
else if (!value && this.high_volume_warning_shown) {
- /* TODO: Make smarter */
+ int location = -1;
+ while ((location = find_action(this.volume_section, "indicator.high-volume-warning-item")) != -1) {
+ this.volume_section.remove (location);
+ }
this.volume_section.remove (this.volume_section.get_n_items () -1);
this.high_volume_warning_shown = false;
}
}
}
+ int find_action (Menu menu, string in_action) {
+ int n = menu.get_n_items ();
+ for (int i = 0; i < n; i++) {
+ string action;
+ menu.get_item_attribute (0, "action", "s", out action);
+ if (in_action == action)
+ return i;
+ }
+
+ return -1;
+ }
+
+
public void add_player (MediaPlayer player) {
if (this.notify_handlers.contains (player))
return;