aboutsummaryrefslogtreecommitdiff
path: root/src/sound-menu.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound-menu.vala')
-rw-r--r--src/sound-menu.vala58
1 files changed, 52 insertions, 6 deletions
diff --git a/src/sound-menu.vala b/src/sound-menu.vala
index f5e2627..3881faf 100644
--- a/src/sound-menu.vala
+++ b/src/sound-menu.vala
@@ -24,7 +24,8 @@ public class SoundMenu: Object
SHOW_MUTE = 1,
HIDE_INACTIVE_PLAYERS = 2,
HIDE_PLAYERS = 4,
- GREETER_PLAYERS = 8
+ GREETER_PLAYERS = 8,
+ SHOW_SILENT_MODE = 16
}
public SoundMenu (string? settings_action, DisplayFlags flags) {
@@ -34,9 +35,16 @@ public class SoundMenu: Object
*/
this.volume_section = new Menu ();
+
if ((flags & DisplayFlags.SHOW_MUTE) != 0)
volume_section.append (_("Mute"), "indicator.mute");
- volume_section.append_item (this.create_slider_menu_item ("indicator.volume(0)", 0.0, 1.0, 0.01,
+ if ((flags & DisplayFlags.SHOW_SILENT_MODE) != 0) {
+ var item = new MenuItem(_("Silent Mode"), "indicator.silent-mode");
+ item.set_attribute("x-canonical-type", "s", "com.canonical.indicator.switch");
+ volume_section.append_item(item);
+ }
+
+ volume_section.append_item (this.create_slider_menu_item (_("Volume"), "indicator.volume(0)", 0.0, 1.0, 0.01,
"audio-volume-low-zero-panel",
"audio-volume-high-panel"));
@@ -78,19 +86,56 @@ public class SoundMenu: Object
}
set {
if (value && !this.mic_volume_shown) {
- var slider = this.create_slider_menu_item ("indicator.mic-volume", 0.0, 1.0, 0.01,
+ var slider = this.create_slider_menu_item (_("Microphone Volume"), "indicator.mic-volume", 0.0, 1.0, 0.01,
"audio-input-microphone-low-zero-panel",
"audio-input-microphone-high-panel");
volume_section.append_item (slider);
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;
@@ -133,6 +178,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;
@@ -235,11 +281,11 @@ public class SoundMenu: Object
player_section.append_submenu (_("Choose Playlist"), submenu);
}
- MenuItem create_slider_menu_item (string action, double min, double max, double step, string min_icon_name, string max_icon_name) {
+ MenuItem create_slider_menu_item (string label, string action, double min, double max, double step, string min_icon_name, string max_icon_name) {
var min_icon = new ThemedIcon.with_default_fallbacks (min_icon_name);
var max_icon = new ThemedIcon.with_default_fallbacks (max_icon_name);
- var slider = new MenuItem (null, action);
+ var slider = new MenuItem (label, action);
slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider");
slider.set_attribute_value ("min-icon", min_icon.serialize ());
slider.set_attribute_value ("max-icon", max_icon.serialize ());