diff options
author | Ted Gould <ted@gould.cx> | 2014-10-14 16:02:23 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2014-10-14 16:02:23 -0500 |
commit | a3de59a992980727e05c58e052be53a8adc5bf08 (patch) | |
tree | cf80b2c94aa98189057bccac5c23fc8e772c9117 /src | |
parent | 8e7cbaadfed452063b2d659bc679746cad5cbb14 (diff) | |
download | ayatana-indicator-sound-a3de59a992980727e05c58e052be53a8adc5bf08.tar.gz ayatana-indicator-sound-a3de59a992980727e05c58e052be53a8adc5bf08.tar.bz2 ayatana-indicator-sound-a3de59a992980727e05c58e052be53a8adc5bf08.zip |
Making the removal of items smarter
Diffstat (limited to 'src')
-rw-r--r-- | src/sound-menu.vala | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/sound-menu.vala b/src/sound-menu.vala index e1c4e98..a9efd74 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -93,8 +93,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; } } @@ -106,18 +108,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; |