diff options
author | Ted Gould <ted@gould.cx> | 2015-01-28 16:43:18 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2015-01-28 16:43:18 -0600 |
commit | af63886e47b8262189d54712dbb34383ecf83669 (patch) | |
tree | 4be682091795d3477cc4792d8a4d6b618f0b827c /src/sound-menu.vala | |
parent | 8210778317cd8f8be803f4afa0200bd9cad0f68e (diff) | |
parent | 8fc91cb9823afc3b4dcaa03422c3dc4611ab034f (diff) | |
download | ayatana-indicator-sound-af63886e47b8262189d54712dbb34383ecf83669.tar.gz ayatana-indicator-sound-af63886e47b8262189d54712dbb34383ecf83669.tar.bz2 ayatana-indicator-sound-af63886e47b8262189d54712dbb34383ecf83669.zip |
Bring in the PA Mock
Diffstat (limited to 'src/sound-menu.vala')
-rw-r--r-- | src/sound-menu.vala | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/sound-menu.vala b/src/sound-menu.vala index f245a1f..96dd143 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -60,6 +60,7 @@ public class SoundMenu: Object root_item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); root_item.set_attribute ("x-canonical-scroll-action", "s", "indicator.scroll"); root_item.set_attribute ("x-canonical-secondary-action", "s", "indicator.mute"); + root_item.set_attribute ("submenu-action", "s", "indicator.indicator-shown"); root_item.set_submenu (this.menu); this.root = new Menu (); @@ -93,12 +94,49 @@ public class SoundMenu: Object this.mic_volume_shown = true; } else if (!value && this.mic_volume_shown) { - 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; } } } + public bool show_high_volume_warning { + get { + return this.high_volume_warning_shown; + } + set { + if (value && !this.high_volume_warning_shown) { + /* 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) { + int location = -1; + while ((location = find_action(this.volume_section, "indicator.high-volume-warning-item")) != -1) { + this.volume_section.remove (location); + } + 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 (i, "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; @@ -141,6 +179,7 @@ public class SoundMenu: Object Menu volume_section; bool mic_volume_shown; bool settings_shown = false; + bool high_volume_warning_shown = false; bool hide_inactive; bool hide_players = false; HashTable<MediaPlayer, ulong> notify_handlers; |