aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/service.vala17
-rw-r--r--src/volume-control-pulse.vala47
-rw-r--r--src/volume-control.vala3
-rw-r--r--src/volume-warning.vala10
-rw-r--r--tests/notifications-test.cc6
-rw-r--r--tests/volume-control-mock.vala4
6 files changed, 19 insertions, 68 deletions
diff --git a/src/service.vala b/src/service.vala
index 51f5cb6..5f6b00e 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -617,7 +617,7 @@ public class IndicatorSound.Service: Object {
notify_server_caps_checked = true;
}
- var loud = volume_control.high_volume;
+ var loud = _volume_warning.high_volume;
bool ignore_warning_this_time = _volume_warning.ignore_high_volume;
var warn = loud
&& this.notify_server_supports_actions
@@ -821,12 +821,19 @@ public class IndicatorSound.Service: Object {
return mic_volume_action;
}
+ private Variant create_high_volume_action_state() {
+ return new Variant.boolean (_volume_warning.high_volume);
+ }
+ private void update_high_volume_action_state() {
+ high_volume_action.set_state(create_high_volume_action_state());
+ }
+
SimpleAction high_volume_action;
Action create_high_volume_action () {
- high_volume_action = new SimpleAction.stateful("high-volume", null, new Variant.boolean (this.volume_control.high_volume));
+ high_volume_action = new SimpleAction.stateful("high-volume", null, create_high_volume_action_state());
- this.volume_control.notify["high-volume"].connect( () => {
- high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume));
+ _volume_warning.notify["high-volume"].connect( () => {
+ update_high_volume_action_state();
update_notification();
});
@@ -982,7 +989,7 @@ public class IndicatorSound.Service: Object {
private bool clamp_to_high_idle() {
_clamp_to_high_timeout = 0;
- volume_control.clamp_to_high_volume();
+ _volume_warning.clamp_to_high_volume();
return false; // Source.REMOVE;
}
}
diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala
index 8c09a6b..56cfba7 100644
--- a/src/volume-control-pulse.vala
+++ b/src/volume-control-pulse.vala
@@ -102,18 +102,11 @@ public class VolumeControlPulse : VolumeControl
_mute_cancellable = new Cancellable ();
_volume_cancellable = new Cancellable ();
- init_all_properties();
-
setup_accountsservice.begin ();
this.reconnect_to_pulse ();
}
- private void init_all_properties()
- {
- init_high_volume();
- }
-
~VolumeControlPulse ()
{
stop_all_timers();
@@ -252,7 +245,6 @@ public class VolumeControlPulse : VolumeControl
(active_output_now != VolumeControl.ActiveOutput.CALL_MODE &&
active_output_before != VolumeControl.ActiveOutput.CALL_MODE)) {
this.active_output_changed (active_output_now);
- update_high_volume();
}
if (_pulse_use_stream_restore == false &&
@@ -686,45 +678,6 @@ public class VolumeControlPulse : VolumeControl
&& volume_changed) {
start_local_volume_timer();
}
-
- update_high_volume();
- }
- }
-
- /** HIGH VOLUME PROPERTY **/
-
- private bool _high_volume = false;
- public override bool high_volume {
- get { return this._high_volume; }
- private set { this._high_volume = value; }
- }
- private void init_high_volume() {
- _options.loud_changed.connect(() => update_high_volume());
- update_high_volume();
- }
- private void update_high_volume() {
- var new_high_volume = calculate_high_volume();
- if (high_volume != new_high_volume) {
- debug("changing high_volume from %d to %d", (int)high_volume, (int)new_high_volume);
- high_volume = new_high_volume;
- }
- }
- private bool calculate_high_volume() {
- return calculate_high_volume_from_volume(_volume.volume);
- }
- private bool calculate_high_volume_from_volume(double volume) {
- return _active_port_headphone
- && _options.is_loud(_volume)
- && (stream == "multimedia");
- }
-
- public override void clamp_to_high_volume() {
- if (_high_volume && _options.is_loud(_volume)) {
- var vol = new VolumeControl.Volume();
- vol.volume = _volume.volume.clamp(0, volume_to_double(_options.loud_volume()));
- vol.reason = _volume.reason;
- debug("Clamping from %f down to %f", _volume.volume, vol.volume);
- volume = vol;
}
}
diff --git a/src/volume-control.vala b/src/volume-control.vala
index e59997c..53e4336 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -54,7 +54,6 @@ public abstract class VolumeControl : Object
public virtual string stream { get { return ""; } }
public bool ready { get; protected set; default = false; }
public virtual bool active_mic { get { return false; } set { } }
- public virtual bool high_volume { get { return false; } protected set { } }
public virtual bool mute { get { return false; } }
public bool is_playing { get; protected set; default = false; }
public virtual VolumeControl.ActiveOutput active_output { get { return VolumeControl.ActiveOutput.SPEAKERS; } }
@@ -63,8 +62,6 @@ public abstract class VolumeControl : Object
public virtual Volume volume { get { return _volume; } set { } }
public virtual double mic_volume { get { return 0.0; } set { } }
- public virtual void clamp_to_high_volume() { }
-
public abstract void set_mute (bool mute);
public void set_volume_clamp (double unclamped, VolumeControl.VolumeReasons reason) {
diff --git a/src/volume-warning.vala b/src/volume-warning.vala
index 5809f61..423f129 100644
--- a/src/volume-warning.vala
+++ b/src/volume-warning.vala
@@ -30,6 +30,9 @@ public class VolumeWarning : VolumeControl
// true if the warning dialog is currently active
public bool active { get; public set; default = false; }
+ // true iff we're playing unapproved loud multimedia over headphones
+ public bool high_volume { get; protected set; default = false; }
+
// FIXME: this is temporarily necessary while bootstrapping this
// code because VolumeWarning is still subclassed from VolumeControl,
// but TBH we don't need any concept of mute here.
@@ -638,7 +641,6 @@ public class VolumeWarning : VolumeControl
/** HIGH VOLUME PROPERTY **/
- private bool _high_volume = false;
public bool ignore_high_volume {
get {
if (_ignore_warning_this_time) {
@@ -650,10 +652,6 @@ public class VolumeWarning : VolumeControl
}
set { }
}
- public override bool high_volume {
- get { return this._high_volume; }
- private set { this._high_volume = value; }
- }
private void init_high_volume() {
_options.loud_changed.connect(() => update_high_volume());
update_high_volume();
@@ -674,7 +672,7 @@ public class VolumeWarning : VolumeControl
&& (stream == "multimedia");
}
- public override void clamp_to_high_volume() {
+ public void clamp_to_high_volume() {
if (_high_volume && _options.is_loud(_volume)) {
var vol = new VolumeControl.Volume();
vol.volume = _volume.volume.clamp(0, volume_to_double(_options.loud_volume()));
diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc
index ec9d915..19aeac1 100644
--- a/tests/notifications-test.cc
+++ b/tests/notifications-test.cc
@@ -385,7 +385,7 @@ TEST_F(NotificationsTest, HighVolume) {
/* Set high volume with volume change */
notifications->clearNotifications();
- volume_control_mock_set_high_volume(VOLUME_CONTROL_MOCK(volumeControl.get()), true);
+ volume_warning_mock_set_high_volume(VOLUME_WARNING_MOCK(volumeWarning.get()), true);
setMockVolume(volumeControl, 0.90);
loop(50);
notev = notifications->getNotifications();
@@ -395,14 +395,14 @@ TEST_F(NotificationsTest, HighVolume) {
EXPECT_GVARIANT_EQ("@s 'true'", notev[0].hints["x-canonical-value-bar-tint"]);
/* Move it back */
- volume_control_mock_set_high_volume(VOLUME_CONTROL_MOCK(volumeControl.get()), false);
+ volume_warning_mock_set_high_volume(VOLUME_WARNING_MOCK(volumeWarning.get()), false);
setMockVolume(volumeControl, 0.50);
loop(50);
/* Set high volume without level change */
/* NOTE: This can happen if headphones are plugged in */
notifications->clearNotifications();
- volume_control_mock_set_high_volume(VOLUME_CONTROL_MOCK(volumeControl.get()), TRUE);
+ volume_warning_mock_set_high_volume(VOLUME_WARNING_MOCK(volumeWarning.get()), true);
loop(50);
notev = notifications->getNotifications();
ASSERT_EQ(1, notev.size());
diff --git a/tests/volume-control-mock.vala b/tests/volume-control-mock.vala
index f21f5c0..95d6a6a 100644
--- a/tests/volume-control-mock.vala
+++ b/tests/volume-control-mock.vala
@@ -20,10 +20,6 @@
public class VolumeControlMock : VolumeControl
{
- private bool _high_volume = false;
- public override bool high_volume { get { return _high_volume; } protected set { _high_volume = value; } }
- public void set_high_volume(bool b) { high_volume = b; }
-
public string mock_stream { get; set; default = "multimedia"; }
public override string stream { get { return mock_stream; } }
public void mock_set_is_ready(bool b) { ready = b; }