From 03a879f644d27ec45a97caa7681e4428f7b341fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 8 Oct 2014 13:40:04 -0500 Subject: Make volume string translatable --- src/volume-control.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index 5a8bbe2..a4c97b6 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -578,13 +578,13 @@ public class VolumeControl : Object public void set_volume (double volume) { if (_volume == 0.0) - _notification.update ("Volume", "", "audio-volume-muted"); + _notification.update (_("Volume"), "", "audio-volume-muted"); if (_volume > 0.0 && _volume <= 0.33) - _notification.update ("Volume", "", "audio-volume-low"); + _notification.update (_("Volume"), "", "audio-volume-low"); if (_volume > 0.33 && _volume <= 0.66) - _notification.update ("Volume", "", "audio-volume-medium"); + _notification.update (_("Volume"), "", "audio-volume-medium"); if (_volume > 0.66 && _volume <= 1.0) - _notification.update ("Volume", "", "audio-volume-high"); + _notification.update (_("Volume"), "", "audio-volume-high"); _notification.set_hint ("value", _volume * 100.0); _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); _notification.show (); -- cgit v1.2.3 From 27e2a3618ac09e9ca3dbbc30ed4d8ebec71feba9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 09:47:01 -0500 Subject: No audio ping if we're doing multimedia, and no notification if we're not on phone --- src/volume-control.vala | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index a4c97b6..17367e8 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -577,17 +577,22 @@ public class VolumeControl : Object public void set_volume (double volume) { - if (_volume == 0.0) - _notification.update (_("Volume"), "", "audio-volume-muted"); - if (_volume > 0.0 && _volume <= 0.33) - _notification.update (_("Volume"), "", "audio-volume-low"); - if (_volume > 0.33 && _volume <= 0.66) - _notification.update (_("Volume"), "", "audio-volume-medium"); - if (_volume > 0.66 && _volume <= 1.0) - _notification.update (_("Volume"), "", "audio-volume-high"); - _notification.set_hint ("value", _volume * 100.0); - _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); - _notification.show (); + /* Using this to detect whether we're on the phone or not */ + if (_pulse_use_stream_restore) { + if (_volume == 0.0) + _notification.update (_("Volume"), "", "audio-volume-muted"); + if (_volume > 0.0 && _volume <= 0.33) + _notification.update (_("Volume"), "", "audio-volume-low"); + if (_volume > 0.33 && _volume <= 0.66) + _notification.update (_("Volume"), "", "audio-volume-medium"); + if (_volume > 0.66 && _volume <= 1.0) + _notification.update (_("Volume"), "", "audio-volume-high"); + _notification.set_hint ("value", _volume * 100.0); + if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") + /* No audio ping if we're playing multimedia */ + _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); + _notification.show (); + } if (set_volume_internal (volume)) { start_local_volume_timer(); -- cgit v1.2.3 From 228153f72649485111052f5f13a84fd73f290b94 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 21:52:03 -0500 Subject: Make sure to clear the sound hint --- src/volume-control.vala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index 17367e8..86b976e 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -588,9 +588,12 @@ public class VolumeControl : Object if (_volume > 0.66 && _volume <= 1.0) _notification.update (_("Volume"), "", "audio-volume-high"); _notification.set_hint ("value", _volume * 100.0); - if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") + if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") { /* No audio ping if we're playing multimedia */ _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); + } else { + _notification.set_hint ("sound-file", null); + } _notification.show (); } -- cgit v1.2.3 From 365f0a5af2b6327531f49a0fa3754359063dfea1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 21:54:40 -0500 Subject: Catch the error that show can throw and present a warning --- src/volume-control.vala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index 86b976e..dbc1797 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -594,7 +594,12 @@ public class VolumeControl : Object } else { _notification.set_hint ("sound-file", null); } - _notification.show (); + + try { + _notification.show (); + } catch (GLib.Error e) { + warning("Unable to send volume change notification: %s", e.message); + } } if (set_volume_internal (volume)) { -- cgit v1.2.3 From 70601ef284279d6db7b8add3c50cd0350fdfb707 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 21:58:20 -0500 Subject: Make sure to use the passed parameter for the volume. --- src/volume-control.vala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index dbc1797..e35b3e5 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -579,15 +579,15 @@ public class VolumeControl : Object { /* Using this to detect whether we're on the phone or not */ if (_pulse_use_stream_restore) { - if (_volume == 0.0) + if (volume == 0.0) _notification.update (_("Volume"), "", "audio-volume-muted"); - if (_volume > 0.0 && _volume <= 0.33) + if (volume > 0.0 && volume <= 0.33) _notification.update (_("Volume"), "", "audio-volume-low"); - if (_volume > 0.33 && _volume <= 0.66) + if (volume > 0.33 && volume <= 0.66) _notification.update (_("Volume"), "", "audio-volume-medium"); - if (_volume > 0.66 && _volume <= 1.0) + if (volume > 0.66 && volume <= 1.0) _notification.update (_("Volume"), "", "audio-volume-high"); - _notification.set_hint ("value", _volume * 100.0); + _notification.set_hint ("value", volume * 100.0); if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") { /* No audio ping if we're playing multimedia */ _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); -- cgit v1.2.3 From a0dc1f66614ac40bc527ccad537ff607a4bef642 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 22:06:15 -0500 Subject: Didn't make initial string translated --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index e35b3e5..aee670e 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -88,7 +88,7 @@ public class VolumeControl : Object _volume_cancellable = new Cancellable (); Notify.init ("Volume"); - _notification = new Notify.Notification("Volume", "", "audio-volume-muted"); + _notification = new Notify.Notification(_("Volume"), "", "audio-volume-muted"); _notification.set_hint ("value", 0); _notification.set_hint ("x-canonical-private-synchronous", "true"); _notification.set_hint ("x-canonical-non-shaped-icon", "true"); -- cgit v1.2.3 From 4da707591f393735ed3306421e2c1518eff4d3e5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 22:15:35 -0500 Subject: Ensure we send an integer to the notification service --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index aee670e..0541397 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -587,7 +587,7 @@ public class VolumeControl : Object _notification.update (_("Volume"), "", "audio-volume-medium"); if (volume > 0.66 && volume <= 1.0) _notification.update (_("Volume"), "", "audio-volume-high"); - _notification.set_hint ("value", volume * 100.0); + _notification.set_hint ("value", (int32)(volume * 100.0)); if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") { /* No audio ping if we're playing multimedia */ _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); -- cgit v1.2.3 From f079f5a27a70a377b8787610f1bef62d8af7fe7c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Oct 2014 12:43:29 -0500 Subject: Make notifications check for high volumes and change based on that --- src/volume-control.vala | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index f9db556..0e5abbb 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -580,22 +580,42 @@ public class VolumeControl : Object { /* Using this to detect whether we're on the phone or not */ if (_pulse_use_stream_restore) { - if (volume == 0.0) - _notification.update (_("Volume"), "", "audio-volume-muted"); + /* Watch for extreme */ + bool extreme_volume = false; + if (volume > 0.75) /* TODO: Also if headphones */ + extreme_volume = true; + + /* Determine Label */ + string volume_label = _("Volume"); + if (extreme_volume) + volume_label = _("High volume"); + + /* Choose an icon */ + string icon = "audio-volume-muted"; if (volume > 0.0 && volume <= 0.33) - _notification.update (_("Volume"), "", "audio-volume-low"); + icon = "audio-volume-low"; if (volume > 0.33 && volume <= 0.66) - _notification.update (_("Volume"), "", "audio-volume-medium"); + icon = "audio-volume-medium"; if (volume > 0.66 && volume <= 1.0) - _notification.update (_("Volume"), "", "audio-volume-high"); + icon = "audio-volume-high"; + + /* Choose a sound */ + string? sound = null; + if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") + sound = "/usr/share/sounds/ubuntu/stereo/message.ogg"; + + /* Check tint */ + string tint = "false"; + if (extreme_volume) + tint = "true"; + + /* Put it all into the notification */ + _notification.update (volume_label, "", icon); _notification.set_hint ("value", (int32)(volume * 100.0)); - if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") { - /* No audio ping if we're playing multimedia */ - _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); - } else { - _notification.set_hint ("sound-file", null); - } + _notification.set_hint ("sound-file", sound); + _notification.set_hint ("x-canonical-value-bar-tint", tint); + /* Show it */ try { _notification.show (); } catch (GLib.Error e) { -- cgit v1.2.3 From 53edccc48b6b1999457aaa4241bfc8eee413f16c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Oct 2014 16:10:15 -0500 Subject: Turn high volume into a property --- src/volume-control.vala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index 0e5abbb..e09f212 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -79,6 +79,9 @@ public class VolumeControl : Object /** true when a microphone is active **/ public bool active_mic { get; private set; default = false; } + /** true when high volume warnings should be shown */ + public bool high_volume { get; set; } + public VolumeControl () { if (loop == null) @@ -581,13 +584,14 @@ public class VolumeControl : Object /* Using this to detect whether we're on the phone or not */ if (_pulse_use_stream_restore) { /* Watch for extreme */ - bool extreme_volume = false; if (volume > 0.75) /* TODO: Also if headphones */ - extreme_volume = true; + high_volume = true; + else + high_volume = false; /* Determine Label */ string volume_label = _("Volume"); - if (extreme_volume) + if (high_volume) volume_label = _("High volume"); /* Choose an icon */ @@ -606,7 +610,7 @@ public class VolumeControl : Object /* Check tint */ string tint = "false"; - if (extreme_volume) + if (high_volume) tint = "true"; /* Put it all into the notification */ -- cgit v1.2.3 From 88956a3657cc0f0f8f76b2935a7ae46033d5c200 Mon Sep 17 00:00:00 2001 From: Ricardo Salveti Date: Mon, 13 Oct 2014 20:48:06 -0500 Subject: Headphone detection --- src/volume-control.vala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index e09f212..c9ba42c 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -70,6 +70,8 @@ public class VolumeControl : Object private double _account_service_volume = 0.0; private Notify.Notification _notification; + private bool _active_port_headphone = false; + public signal void volume_changed (double v); public signal void mic_volume_changed (double v); @@ -177,6 +179,19 @@ public class VolumeControl : Object this.notify_property ("is-playing"); } + /* Check if the current active port is headset/headphone */ + /* There is not easy way to check if the port is a headset/headphone besides + * checking for the port name. On touch (with the pulseaudio droid element) + * the headset/headphone port is called 'output-headset' and 'output-headphone'. + * On the desktop this is usually called 'analog-output-headphones' */ + if (i.active_port.name == "output-wired_headset" || + i.active_port.name == "output-wired_headphone" || + i.active_port.name == "analog-output-headphones") { + _active_port_headphone = true; + } else { + _active_port_headphone = false; + } + if (_pulse_use_stream_restore == false && _volume != volume_to_double (i.volume.max ())) { -- cgit v1.2.3 From 9c8f845b511cf8a8a02cb90df5546ff852978ed6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 13 Oct 2014 20:49:19 -0500 Subject: Use the headphone detection --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index c9ba42c..b32146f 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -599,7 +599,7 @@ public class VolumeControl : Object /* Using this to detect whether we're on the phone or not */ if (_pulse_use_stream_restore) { /* Watch for extreme */ - if (volume > 0.75) /* TODO: Also if headphones */ + if (volume > 0.75 && _active_port_headphone) high_volume = true; else high_volume = false; -- cgit v1.2.3 From 7ec3795022cbfff0e1c0c094309a4b67d1dd3b04 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 13 Oct 2014 20:51:07 -0500 Subject: Create actions based on the high volume status --- src/service.vala | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 2a65492..92523aa 100644 --- a/src/service.vala +++ b/src/service.vala @@ -49,6 +49,7 @@ public class IndicatorSound.Service: Object { this.actions.add_action (this.create_mute_action ()); this.actions.add_action (this.create_volume_action ()); this.actions.add_action (this.create_mic_volume_action ()); + this.actions.add_action (this.create_high_volume_actions ()); this.menus = new HashTable (str_hash, str_equal); this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); @@ -388,6 +389,36 @@ public class IndicatorSound.Service: Object { return volume_action; } + Action create_high_volume_actions () { + var high_volume_action = new SimpleAction.stateful("high-volume", null, new Variant.boolean (this.volume_control.high_volume)); + + this.volume_control.notify["high_volume"].connect( () => + high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume))); + + /* So this is a bit confusing, putting it here because everywhere else + sucks too. It might create an action and put it into the action group. + Which is sneaky. Better to have the code not duplicated, but no good + place to put code like that. */ + setup_high_volume_menu_action(); + + return high_volume_action; + } + + void setup_high_volume_menu_action () { + this.volume_control.notify["high_volume"].connect(update_high_volume_menu_action); + update_high_volume_menu_action(); + } + + void update_high_volume_menu_action () { + if (this.volume_control.high_volume) { + var menu_action = new SimpleAction("high-volume-menu", null); + menu_action.set_enabled(false); + this.actions.add_action(menu_action); + } else { + this.actions.remove_action("high-volume-menu"); + } + } + void bus_acquired (DBusConnection connection, string name) { try { connection.export_action_group ("/com/canonical/indicator/sound", this.actions); -- cgit v1.2.3 From 9e39fba127c95aee79b26d2b88cb80dc279a5011 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 13 Oct 2014 21:32:30 -0500 Subject: Ensure we reevaluate the high volume warning when we switch from headphones or not --- src/volume-control.vala | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index b32146f..ea8e3ac 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -163,6 +163,8 @@ public class VolumeControl : Object private void sink_info_cb_for_props (Context c, SinkInfo? i, int eol) { + bool old_active_port_headphone = this._active_port_headphone; + if (i == null) return; @@ -197,6 +199,8 @@ public class VolumeControl : Object { _volume = volume_to_double (i.volume.max ()); volume_changed (_volume); + } else if (this._active_port_headphone != old_active_port_headphone) { + volume_changed (_volume); } } -- cgit v1.2.3 From 973b4eb057f466ad88e62d25f733ed1700e1ac38 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 07:59:43 -0500 Subject: Use title for the a11y info and the body for the message on sync notifications --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index ea8e3ac..b65cbc8 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -633,7 +633,7 @@ public class VolumeControl : Object tint = "true"; /* Put it all into the notification */ - _notification.update (volume_label, "", icon); + _notification.update (_("Volume"), volume_label, icon); _notification.set_hint ("value", (int32)(volume * 100.0)); _notification.set_hint ("sound-file", sound); _notification.set_hint ("x-canonical-value-bar-tint", tint); -- cgit v1.2.3 From 29576aceb257c868e5871972a1440b8602f2880b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 08:06:55 -0500 Subject: Adding a high volume warning menu item --- src/sound-menu.vala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sound-menu.vala b/src/sound-menu.vala index f245a1f..0094c22 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -25,7 +25,9 @@ public class SoundMenu: Object HIDE_INACTIVE_PLAYERS = 2, HIDE_PLAYERS = 4, GREETER_PLAYERS = 8, - SHOW_SILENT_MODE = 16 + SHOW_SILENT_MODE = 16, + HIGH_VOLUME_WARNING = 32 /* Everyone should get this eventually, but we don't + want it in the desktop initially because of freezes */ } public SoundMenu (string? settings_action, DisplayFlags flags) { @@ -48,6 +50,9 @@ public class SoundMenu: Object "audio-volume-low-zero-panel", "audio-volume-high-panel")); + if ((flags & DisplayFlags.HIGH_VOLUME_WARNING) != 0) + volume_section.append (_("High volume can damage your hearing."), "indicator.high-volume-menu"); + this.menu = new Menu (); this.menu.append_section (null, volume_section); -- cgit v1.2.3 From a2de8d1b337113ced7854683aad0183a841917f1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 08:12:58 -0500 Subject: Add high volume warnings to the phone menu --- src/service.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 92523aa..3edcba0 100644 --- a/src/service.vala +++ b/src/service.vala @@ -53,9 +53,9 @@ public class IndicatorSound.Service: Object { this.menus = new HashTable (str_hash, str_equal); this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); - this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); + this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS | SoundMenu.DisplayFlags.HIGH_VOLUME_WARNING)); this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE)); - this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS)); + this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.HIGH_VOLUME_WARNING)); this.menus.@foreach ( (profile, menu) => { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); -- cgit v1.2.3 From 52e2c2d3dce6ded517f9666d5d0412d56054d9d9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 09:45:40 -0500 Subject: Ensure that we're always getting a vlue in the list --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/volume-control.vala b/src/volume-control.vala index b65cbc8..cf2dacf 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -624,7 +624,7 @@ public class VolumeControl : Object /* Choose a sound */ string? sound = null; - if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") + if (!((_active_sink_input in _sink_input_list) && (_valid_roles[_active_sink_input] == "multimedia"))) sound = "/usr/share/sounds/ubuntu/stereo/message.ogg"; /* Check tint */ -- cgit v1.2.3 From 23b3fd431a312f2b02504b998c697241c30caa0b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 10:00:32 -0500 Subject: Drop the high volume menu action as that wasn't working --- src/service.vala | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 3edcba0..93e6a51 100644 --- a/src/service.vala +++ b/src/service.vala @@ -395,30 +395,9 @@ public class IndicatorSound.Service: Object { this.volume_control.notify["high_volume"].connect( () => high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume))); - /* So this is a bit confusing, putting it here because everywhere else - sucks too. It might create an action and put it into the action group. - Which is sneaky. Better to have the code not duplicated, but no good - place to put code like that. */ - setup_high_volume_menu_action(); - return high_volume_action; } - void setup_high_volume_menu_action () { - this.volume_control.notify["high_volume"].connect(update_high_volume_menu_action); - update_high_volume_menu_action(); - } - - void update_high_volume_menu_action () { - if (this.volume_control.high_volume) { - var menu_action = new SimpleAction("high-volume-menu", null); - menu_action.set_enabled(false); - this.actions.add_action(menu_action); - } else { - this.actions.remove_action("high-volume-menu"); - } - } - void bus_acquired (DBusConnection connection, string name) { try { connection.export_action_group ("/com/canonical/indicator/sound", this.actions); -- cgit v1.2.3 From 16828d0102efae82bf760097988474e434b884fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 10:07:30 -0500 Subject: Changing tact to change the menu when we want to show the warning --- src/service.vala | 4 ++-- src/sound-menu.vala | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 93e6a51..51060d4 100644 --- a/src/service.vala +++ b/src/service.vala @@ -53,9 +53,9 @@ public class IndicatorSound.Service: Object { this.menus = new HashTable (str_hash, str_equal); this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); - this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS | SoundMenu.DisplayFlags.HIGH_VOLUME_WARNING)); + this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE)); - this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.HIGH_VOLUME_WARNING)); + this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS)); this.menus.@foreach ( (profile, menu) => { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); diff --git a/src/sound-menu.vala b/src/sound-menu.vala index 0094c22..e1c4e98 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -25,9 +25,7 @@ public class SoundMenu: Object HIDE_INACTIVE_PLAYERS = 2, HIDE_PLAYERS = 4, GREETER_PLAYERS = 8, - SHOW_SILENT_MODE = 16, - HIGH_VOLUME_WARNING = 32 /* Everyone should get this eventually, but we don't - want it in the desktop initially because of freezes */ + SHOW_SILENT_MODE = 16 } public SoundMenu (string? settings_action, DisplayFlags flags) { @@ -50,9 +48,6 @@ public class SoundMenu: Object "audio-volume-low-zero-panel", "audio-volume-high-panel")); - if ((flags & DisplayFlags.HIGH_VOLUME_WARNING) != 0) - volume_section.append (_("High volume can damage your hearing."), "indicator.high-volume-menu"); - this.menu = new Menu (); this.menu.append_section (null, volume_section); @@ -98,12 +93,31 @@ 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); 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) { + var item = new MenuItem(_("High volume can damage your hearing."), null); + volume_section.append_item (item); + this.high_volume_warning_shown = true; + } + else if (!value && this.high_volume_warning_shown) { + /* TODO: Make smarter */ + this.volume_section.remove (this.volume_section.get_n_items () -1); + this.high_volume_warning_shown = false; + } + } + } + public void add_player (MediaPlayer player) { if (this.notify_handlers.contains (player)) return; @@ -146,6 +160,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 notify_handlers; -- cgit v1.2.3 From 8e7cbaadfed452063b2d659bc679746cad5cbb14 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 10:16:15 -0500 Subject: Linking volume control and the menu visibility --- src/service.vala | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 51060d4..8f58110 100644 --- a/src/service.vala +++ b/src/service.vala @@ -61,6 +61,10 @@ public class IndicatorSound.Service: Object { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); }); + this.menus.@foreach ( (profile, menu) => { + this.volume_control.bind_property ("high-volume", menu, "show-high-volume-warning", BindingFlags.SYNC_CREATE); + }); + this.sync_preferred_players (); this.settings.changed["interested-media-players"].connect ( () => { this.sync_preferred_players (); -- cgit v1.2.3