aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcharles kerr <charlesk@canonical.com>2015-12-30 16:03:02 -0600
committercharles kerr <charlesk@canonical.com>2015-12-30 16:03:02 -0600
commit521915475eb73ae22e2c270c687f1f4d5c7c0465 (patch)
tree7cdb4c2a75f06ef6b1558c12557800684b55d0fe
parent812e71f004272f635ba9217ef2f16aa9567196b3 (diff)
downloadayatana-indicator-sound-521915475eb73ae22e2c270c687f1f4d5c7c0465.tar.gz
ayatana-indicator-sound-521915475eb73ae22e2c270c687f1f4d5c7c0465.tar.bz2
ayatana-indicator-sound-521915475eb73ae22e2c270c687f1f4d5c7c0465.zip
simplify the Options class' properties
-rw-r--r--src/options-gsettings.vala33
-rw-r--r--src/options.vala16
-rw-r--r--src/service.vala2
-rw-r--r--src/volume-warning.vala28
-rw-r--r--tests/options-mock.vala25
5 files changed, 27 insertions, 77 deletions
diff --git a/src/options-gsettings.vala b/src/options-gsettings.vala
index a524390..e3bba91 100644
--- a/src/options-gsettings.vala
+++ b/src/options-gsettings.vala
@@ -62,18 +62,6 @@ public class IndicatorSound.OptionsGSettings : Options
/** LOUD VOLUME **/
- private PulseAudio.Volume _loud_volume;
-
- public override PulseAudio.Volume loud_volume() {
- return _loud_volume;
- }
-
- private bool _loud_volume_warning_enabled;
-
- public override bool loud_volume_warning_enabled() {
- return _loud_volume_warning_enabled;
- }
-
private string loud_enabled_key = "warning-volume-enabled";
private string loud_decibel_key = "warning-volume-decibels";
@@ -83,22 +71,13 @@ public class IndicatorSound.OptionsGSettings : Options
update_loud_volume();
}
private void update_loud_volume() {
- var changed = false;
- var vol = PulseAudio.Volume.sw_from_dB (_settings.get_double (loud_decibel_key));
- var enabled = _settings.get_boolean(loud_enabled_key);
- if (_loud_volume != vol) {
- debug("updating loud_volume_sw to %d", (int)vol);
- _loud_volume = vol;
- changed = true;
- }
- if (_loud_volume_warning_enabled != enabled) {
- debug("updating loud_volume_warning_enabled to %d", (int)enabled);
- _loud_volume_warning_enabled = enabled;
- changed = true;
- }
+ var vol = PulseAudio.Volume.sw_from_dB (_settings.get_double (loud_decibel_key));
+ if (loud_volume != vol)
+ loud_volume = vol;
- if (changed)
- loud_changed();
+ var enabled = _settings.get_boolean(loud_enabled_key);
+ if (loud_warning_enabled != enabled)
+ loud_warning_enabled = enabled;
}
}
diff --git a/src/options.vala b/src/options.vala
index 3005cf5..1aab852 100644
--- a/src/options.vala
+++ b/src/options.vala
@@ -20,21 +20,9 @@
public abstract class IndicatorSound.Options : Object
{
- // MAX VOLUME
-
public double max_volume { get; protected set; default = 1.0; }
- // LOUD
-
- public signal void loud_changed();
- public abstract PulseAudio.Volume loud_volume();
- public abstract bool loud_volume_warning_enabled();
-
- public bool is_loud_pulse (PulseAudio.Volume volume) {
- return loud_volume_warning_enabled() && (volume >= loud_volume());
- }
+ public uint loud_volume { get; protected set; default = PulseAudio.Volume.sw_from_dB(8); }
- public bool is_loud (VolumeControl.Volume volume) {
- return is_loud_pulse(VolumeControlPulse.double_to_volume(volume.volume));
- }
+ public bool loud_warning_enabled { get; protected set; default = true; }
}
diff --git a/src/service.vala b/src/service.vala
index b7bc518..692b88d 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -544,7 +544,7 @@ public class IndicatorSound.Service: Object {
/* activating this action changes the volume by the amount given in the parameter */
volume_action.activate.connect ((a,p) => activate_scroll_action(a,p));
- _options.notify["max_volume"].connect(() => {
+ _options.notify["max-volume"].connect(() => {
update_volume_action_state();
});
diff --git a/src/volume-warning.vala b/src/volume-warning.vala
index 49ed3a8..d475570 100644
--- a/src/volume-warning.vala
+++ b/src/volume-warning.vala
@@ -105,27 +105,29 @@ public abstract class VolumeWarning : Object
**/
private void init_high_volume () {
- _options.loud_changed.connect(() => update_high_volume());
this.notify["multimedia-volume"].connect(() => update_high_volume());
this.notify["multimedia-active"].connect(() => update_high_volume());
this.notify["headphones-active"].connect(() => update_high_volume());
this.notify["high-volume-approved"].connect(() => update_high_volume());
+ _options.notify["loud-volume"].connect(() => update_high_volume());
+ _options.notify["loud-warning-enabled"].connect(() => update_high_volume());
update_high_volume();
}
private void update_high_volume () {
- PulseAudio.Volume mm_vol = multimedia_volume;
- var approved = high_volume_approved;
- var hp_active = headphones_active;
- var mm_active = multimedia_active;
- GLib.message("calculating high volume... headphones_active %d high_volume_approved %d multimedia_active %d multimedia_volume %d is_invalid %d, is_loud %d", (int)hp_active, (int)approved, (int)mm_active, (int)mm_vol, (int)(mm_vol == PulseAudio.Volume.INVALID), (int)_options.is_loud_pulse(mm_vol));
- var new_high_volume = hp_active && !approved && mm_active && (mm_vol != PulseAudio.Volume.INVALID) && _options.is_loud_pulse(mm_vol);
- GLib.message("so the new high_volume is %d, was %d", (int)new_high_volume, (int)high_volume);
- if (high_volume != new_high_volume) {
- debug("changing high_volume from %d to %d", (int)high_volume, (int)new_high_volume);
- if (new_high_volume && !active)
+
+ var newval = _options.loud_warning_enabled
+ && headphones_active
+ && multimedia_active
+ && !high_volume_approved
+ && (multimedia_volume != PulseAudio.Volume.INVALID)
+ && (multimedia_volume >= _options.loud_volume);
+
+ if (high_volume != newval) {
+ debug("changing high_volume from %d to %d", (int)high_volume, (int)newval);
+ if (newval && !active)
show();
- high_volume = new_high_volume;
+ high_volume = newval;
}
}
@@ -202,7 +204,7 @@ public abstract class VolumeWarning : Object
this.active = true;
// lower the volume to just under the warning level
- sound_system_set_multimedia_volume (_options.loud_volume()-1);
+ sound_system_set_multimedia_volume (_options.loud_volume-1);
}
private void on_user_response(IndicatorSound.WarnNotification.Response response) {
diff --git a/tests/options-mock.vala b/tests/options-mock.vala
index 4136a0c..cda9e24 100644
--- a/tests/options-mock.vala
+++ b/tests/options-mock.vala
@@ -20,28 +20,9 @@
public class OptionsMock : IndicatorSound.Options
{
- // MAX VOLUME
+ public void mock_set_max_volume (double val) { max_volume = val; }
- public void mock_set_max_volume(double val) { max_volume = val; }
+ public void mock_set_loud_volume (PulseAudio.Volume val) { loud_volume = val; }
- // LOUD
-
- private bool _loud_enabled = true;
- private PulseAudio.Volume _loud_volume;
-
- public override PulseAudio.Volume loud_volume() {
- return _loud_volume;
- }
- public override bool loud_volume_warning_enabled() {
- return _loud_enabled;
- }
-
- public void set_loud_enabled(bool v) {
- _loud_enabled = v;
- loud_changed();
- }
- public void set_loud_volume(PulseAudio.Volume v) {
- _loud_volume = v;
- loud_changed();
- }
+ public void mock_set_loud_warning_enabled (bool val) { loud_warning_enabled = val; }
}