diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 17 | ||||
-rw-r--r-- | src/main.c | 7 | ||||
-rw-r--r-- | src/service.vala | 14 | ||||
-rw-r--r-- | src/volume-control-pulse.vala | 34 | ||||
-rw-r--r-- | src/volume-control.vala | 9 | ||||
-rw-r--r-- | src/volume-warning.vala | 30 |
6 files changed, 46 insertions, 65 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 51f474b..4ff5646 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,22 +45,38 @@ vala_add(indicator-sound-service volume-control volume-control-pulse volume-warning + options + options-gsettings media-player media-player-list mpris2-interfaces accounts-service-user ) vala_add(indicator-sound-service + options.vala +) +vala_add(indicator-sound-service + options-gsettings.vala + DEPENDS + options + volume-control + volume-control-pulse +) +vala_add(indicator-sound-service volume-control.vala + DEPENDS + options ) vala_add(indicator-sound-service volume-control-pulse.vala DEPENDS + options volume-control ) vala_add(indicator-sound-service volume-warning.vala DEPENDS + options volume-control ) vala_add(indicator-sound-service @@ -110,6 +126,7 @@ vala_add(indicator-sound-service DEPENDS media-player volume-control + options ) vala_add(indicator-sound-service accounts-service-user.vala @@ -46,6 +46,7 @@ on_bus_acquired(GDBusConnection *connection, gpointer user_data) { MediaPlayerList * playerlist = NULL; + IndicatorSoundOptions * options = NULL; VolumeControlPulse * volume = NULL; AccountsServiceUser * accounts = NULL; @@ -57,11 +58,13 @@ on_bus_acquired(GDBusConnection *connection, accounts = accounts_service_user_new(); } - volume = volume_control_pulse_new(); + options = indicator_sound_options_gsettings_new(); + volume = volume_control_pulse_new(options); - service = indicator_sound_service_new (playerlist, volume, accounts); + service = indicator_sound_service_new (playerlist, volume, accounts, options); g_clear_object(&playerlist); + g_clear_object(&options); g_clear_object(&volume); g_clear_object(&accounts); } diff --git a/src/service.vala b/src/service.vala index 0a7e108..3ff7ffb 100644 --- a/src/service.vala +++ b/src/service.vala @@ -27,7 +27,10 @@ public class IndicatorSound.Service: Object { */ VolumeControl.Volume _pre_warn_volume = null; - public Service (MediaPlayerList playerlist, VolumeControl volume, AccountsServiceUser? accounts) { + public Service (MediaPlayerList playerlist, VolumeControl volume, AccountsServiceUser? accounts, Options options) { + + _options = options; + try { bus = Bus.get_sync(GLib.BusType.SESSION); } catch (GLib.Error e) { @@ -205,6 +208,7 @@ public class IndicatorSound.Service: Object { bool export_to_accounts_service = false; private Notify.Notification info_notification; private Notify.Notification warn_notification; + private Options _options = null; const double volume_step_percentage = 0.06; @@ -750,10 +754,10 @@ public class IndicatorSound.Service: Object { /* return the current volume in the range of [0.0, 1.0] */ private double get_volume_percent() { - return volume_control.volume.volume / this.volume_control.max_volume; + return volume_control.volume.volume / _options.max_volume; } - /* volume control's range can vary depending on its max_volume property, + /* volume control's range can vary depending on options.max_volume, * but the action always needs to be in [0.0, 1.0]... */ private Variant create_volume_action_state() { return new Variant.double (get_volume_percent()); @@ -768,14 +772,14 @@ public class IndicatorSound.Service: Object { volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, create_volume_action_state()); volume_action.change_state.connect ( (action, val) => { - double v = val.get_double () * this.volume_control.max_volume; + double v = val.get_double () * _options.max_volume; volume_control.set_volume_clamp (v, VolumeControl.VolumeReasons.USER_KEYPRESS); }); /* activating this action changes the volume by the amount given in the parameter */ volume_action.activate.connect ((a,p) => activate_scroll_action(a,p)); - this.volume_control.notify["max-volume"].connect(() => { + _options.notify["max_volume"].connect(() => { update_volume_action_state(); }); diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala index 4bd3076..6c3ef17 100644 --- a/src/volume-control-pulse.vala +++ b/src/volume-control-pulse.vala @@ -46,7 +46,6 @@ public class VolumeControlPulse : VolumeControl private VolumeControl.Volume _volume = new VolumeControl.Volume(); private double _mic_volume = 0.0; private Settings _settings = new Settings ("com.canonical.indicator.sound"); - private Settings _shared_settings = new Settings ("com.ubuntu.sound"); /* Used by the pulseaudio stream restore extension */ private DBusConnection _pconn; @@ -96,8 +95,10 @@ public class VolumeControlPulse : VolumeControl /** true when a microphone is active **/ public override bool active_mic { get; private set; default = false; } - public VolumeControlPulse () + public VolumeControlPulse (IndicatorSound.Options options) { + base(options); + _volume.volume = 0.0; _volume.reason = VolumeControl.VolumeReasons.PULSE_CHANGE; @@ -116,7 +117,6 @@ public class VolumeControlPulse : VolumeControl private void init_all_properties() { - init_max_volume(); init_high_volume(); init_high_volume_approved(); } @@ -607,13 +607,13 @@ public class VolumeControlPulse : VolumeControl } /* Volume operations */ - private static PulseAudio.Volume double_to_volume (double vol) + public static PulseAudio.Volume double_to_volume (double vol) { double tmp = (double)(PulseAudio.Volume.NORM - PulseAudio.Volume.MUTED) * vol; return (PulseAudio.Volume)tmp + PulseAudio.Volume.MUTED; } - private static double volume_to_double (PulseAudio.Volume vol) + public static double volume_to_double (PulseAudio.Volume vol) { double tmp = (double)(vol - PulseAudio.Volume.MUTED); return tmp / (double)(PulseAudio.Volume.NORM - PulseAudio.Volume.MUTED); @@ -721,30 +721,6 @@ public class VolumeControlPulse : VolumeControl } } - /** MAX VOLUME PROPERTY **/ - - private void init_max_volume() { - _settings.changed["normal-volume-decibels"].connect(() => update_max_volume()); - _settings.changed["amplified-volume-decibels"].connect(() => update_max_volume()); - _shared_settings.changed["allow-amplified-volume"].connect(() => update_max_volume()); - update_max_volume(); - } - private void update_max_volume () { - var new_max_volume = calculate_max_volume(); - if (max_volume != new_max_volume) { - debug("changing max_volume from %f to %f", this.max_volume, new_max_volume); - max_volume = calculate_max_volume(); - } - } - private double calculate_max_volume () { - unowned string decibel_key = _shared_settings.get_boolean("allow-amplified-volume") - ? "amplified-volume-decibels" - : "normal-volume-decibels"; - var volume_dB = _settings.get_double(decibel_key); - var volume_sw = PulseAudio.Volume.sw_from_dB (volume_dB); - return volume_to_double (volume_sw); - } - /** HIGH VOLUME PROPERTY **/ private bool _warning_volume_enabled; diff --git a/src/volume-control.vala b/src/volume-control.vala index 90fc325..f33ae18 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -45,6 +45,12 @@ public abstract class VolumeControl : Object public VolumeReasons reason; } + private IndicatorSound.Options _options = null; + + public VolumeControl(IndicatorSound.Options options) { + _options = options; + } + public virtual string stream { get { return ""; } } public virtual bool ready { get { return false; } set { } } public virtual bool active_mic { get { return false; } set { } } @@ -58,7 +64,6 @@ public abstract class VolumeControl : Object private double _pre_clamp_volume; public virtual Volume volume { get { return _volume; } set { } } public virtual double mic_volume { get { return 0.0; } set { } } - public virtual double max_volume { get { return 1.0; } protected set { } } public virtual bool high_volume_approved { get { return false; } protected set { } } public virtual void approve_high_volume() { } @@ -69,7 +74,7 @@ public abstract class VolumeControl : Object public void set_volume_clamp (double unclamped, VolumeControl.VolumeReasons reason) { var v = new VolumeControl.Volume(); - v.volume = unclamped.clamp (0.0, this.max_volume); + v.volume = unclamped.clamp (0.0, _options.max_volume); v.reason = reason; this.volume = v; _pre_clamp_volume = unclamped; diff --git a/src/volume-warning.vala b/src/volume-warning.vala index 73a8ade..b511856 100644 --- a/src/volume-warning.vala +++ b/src/volume-warning.vala @@ -45,7 +45,6 @@ public class VolumeWarning : VolumeControl private VolumeControl.Volume _volume = new VolumeControl.Volume(); private double _mic_volume = 0.0; private Settings _settings = new Settings ("com.canonical.indicator.sound"); - private Settings _shared_settings = new Settings ("com.ubuntu.sound"); /* Used by the pulseaudio stream restore extension */ private DBusConnection _pconn; @@ -87,8 +86,10 @@ public class VolumeWarning : VolumeControl /** true when a microphone is active **/ public override bool active_mic { get; private set; default = false; } - public VolumeWarning () + public VolumeWarning (IndicatorSound.Options options) { + base(options); + _volume.volume = 0.0; _volume.reason = VolumeControl.VolumeReasons.PULSE_CHANGE; @@ -102,7 +103,6 @@ public class VolumeWarning : VolumeControl private void init_all_properties() { - init_max_volume(); init_high_volume(); init_high_volume_approved(); } @@ -648,30 +648,6 @@ public class VolumeWarning : VolumeControl } } - /** MAX VOLUME PROPERTY **/ - - private void init_max_volume() { - _settings.changed["normal-volume-decibels"].connect(() => update_max_volume()); - _settings.changed["amplified-volume-decibels"].connect(() => update_max_volume()); - _shared_settings.changed["allow-amplified-volume"].connect(() => update_max_volume()); - update_max_volume(); - } - private void update_max_volume () { - var new_max_volume = calculate_max_volume(); - if (max_volume != new_max_volume) { - debug("changing max_volume from %f to %f", this.max_volume, new_max_volume); - max_volume = calculate_max_volume(); - } - } - private double calculate_max_volume () { - unowned string decibel_key = _shared_settings.get_boolean("allow-amplified-volume") - ? "amplified-volume-decibels" - : "normal-volume-decibels"; - var volume_dB = _settings.get_double(decibel_key); - var volume_sw = PulseAudio.Volume.sw_from_dB (volume_dB); - return volume_to_double (volume_sw); - } - /** HIGH VOLUME PROPERTY **/ private bool _warning_volume_enabled; |