From e0eac1c9d9a050dc44d0883f556753f6f8d1a7b6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 2 Dec 2014 18:55:00 -0600 Subject: Moving the notification into the service --- src/volume-control.vala | 105 ++++++++++-------------------------------------- 1 file changed, 22 insertions(+), 83 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index 6f22dc5..d9a734c 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -68,7 +68,6 @@ public class VolumeControl : Object private uint _accountservice_volume_timer = 0; private bool _send_next_local_volume = false; private double _account_service_volume = 0.0; - private Notify.Notification _notification; private bool _active_port_headphone = false; public signal void volume_changed (double v); @@ -91,12 +90,6 @@ public class VolumeControl : Object _mute_cancellable = new Cancellable (); _volume_cancellable = new Cancellable (); - Notify.init ("Volume"); - _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"); - setup_accountsservice.begin (); this.reconnect_to_pulse (); @@ -594,74 +587,15 @@ public class VolumeControl : Object set_volume_active_role.begin (); else context.get_server_info (server_info_cb_for_set_volume); + + high_volume = volume > 0.75 && _active_port_headphone; + return true; } else { return false; } } - public void set_volume (double volume) - { - /* Using this to detect whether we're on the phone or not */ - if (_pulse_use_stream_restore) { - /* Watch for extreme */ - if (volume > 0.75 && _active_port_headphone) - high_volume = true; - else - high_volume = false; - - /* Determine Label */ - string volume_label = ""; - if (high_volume) - volume_label = _("High volume"); - - /* Choose an icon */ - string icon = "audio-volume-muted"; - if (volume <= 0.0) - icon = "audio-volume-muted"; - else if (volume <= 0.3) - icon = "audio-volume-low"; - else if (volume <= 0.7) - icon = "audio-volume-medium"; - else - icon = "audio-volume-high"; - - /* Choose a sound */ - string? sound = null; - if (!((_active_sink_input >= 0) && (_active_sink_input < _valid_roles.length) - && (_valid_roles[_active_sink_input] == "multimedia"))) - sound = "/usr/share/sounds/ubuntu/stereo/message.ogg"; - - /* Check tint */ - string tint = "false"; - if (high_volume) - tint = "true"; - - /* Put it all into the notification */ - _notification.clear_hints (); - _notification.update (_("Volume"), volume_label, icon); - _notification.set_hint ("value", (int32)(volume * 100.0)); - /* TODO: Removing sound until we can get all the roles cleaned up for - when to play it. We expect this to come back, but in another landing. - _notification.set_hint ("sound-file", sound); - */ - _notification.set_hint ("x-canonical-value-bar-tint", tint); - _notification.set_hint ("x-canonical-private-synchronous", "true"); - _notification.set_hint ("x-canonical-non-shaped-icon", "true"); - - /* Show it */ - try { - _notification.show (); - } catch (GLib.Error e) { - warning("Unable to send volume change notification: %s", e.message); - } - } - - if (set_volume_internal (volume)) { - start_local_volume_timer(); - } - } - void set_mic_volume_success_cb (Context c, int success) { if ((bool)success) @@ -676,23 +610,28 @@ public class VolumeControl : Object } } - public void set_mic_volume (double volume) - { - return_if_fail (context.get_state () == Context.State.READY); - - _mic_volume = volume; - - context.get_server_info (set_mic_volume_get_server_info_cb); + public double volume { + get { + return _volume; + } + set { + if (set_volume_internal (value)) { + start_local_volume_timer(); + } + } } - public double get_volume () - { - return _volume; - } + public double mic_volume { + get { + return _mic_volume; + } + set { + return_if_fail (context.get_state () == Context.State.READY); - public double get_mic_volume () - { - return _mic_volume; + _mic_volume = value; + + context.get_server_info (set_mic_volume_get_server_info_cb); + } } /* PulseAudio Dbus (Stream Restore) logic */ -- cgit v1.2.3 From 66cd2203d5fcee99d3264bc6f23c8d4683c299bf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 16:30:23 -0600 Subject: Switch from having custom signals for volume changing to using the property change signals. --- src/volume-control.vala | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index d9a734c..22212d5 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -70,9 +70,6 @@ public class VolumeControl : Object private double _account_service_volume = 0.0; private bool _active_port_headphone = false; - public signal void volume_changed (double v); - public signal void mic_volume_changed (double v); - /** true when connected to the pulse server */ public bool ready { get; set; } @@ -190,10 +187,10 @@ public class VolumeControl : Object _volume != volume_to_double (i.volume.max ())) { _volume = volume_to_double (i.volume.max ()); - volume_changed (_volume); + this.notify_property("volume"); start_local_volume_timer(); } else if (this._active_port_headphone != old_active_port_headphone) { - volume_changed (_volume); + this.notify_property("volume"); } } @@ -205,7 +202,7 @@ public class VolumeControl : Object if (_mic_volume != volume_to_double (i.volume.values[0])) { _mic_volume = volume_to_double (i.volume.values[0]); - mic_volume_changed (_mic_volume); + this.notify_property ("mic-volume"); } } @@ -261,7 +258,7 @@ public class VolumeControl : Object if (volume != cvolume) { /* Someone else changed the volume for this role, reflect on the indicator */ _volume = volume_to_double (volume); - volume_changed (_volume); + this.notify_property("volume"); start_local_volume_timer(); } } @@ -304,7 +301,7 @@ public class VolumeControl : Object iter.next ("(uu)", &type, &volume); _volume = volume_to_double (volume); - volume_changed (_volume); + this.notify_property("volume"); start_local_volume_timer(); } catch (GLib.Error e) { warning ("unable to get volume for active role %s (%s)", sink_input_objp, e.message); @@ -521,7 +518,7 @@ public class VolumeControl : Object private void set_volume_success_cb (Context c, int success) { if ((bool)success) - volume_changed (_volume); + this.notify_property("volume"); } private void sink_info_set_volume_cb (Context c, SinkInfo? i, int eol) @@ -567,7 +564,7 @@ public class VolumeControl : Object new Variant ("(ssv)", "org.PulseAudio.Ext.StreamRestore1.RestoreEntry", "Volume", volume), null, DBusCallFlags.NONE, -1); - volume_changed (_volume); + this.notify_property("volume"); } catch (GLib.Error e) { lock (_pa_volume_sig_count) { _pa_volume_sig_count--; @@ -599,7 +596,7 @@ public class VolumeControl : Object void set_mic_volume_success_cb (Context c, int success) { if ((bool)success) - mic_volume_changed (_mic_volume); + this.notify_property ("mic-volume"); } void set_mic_volume_get_server_info_cb (PulseAudio.Context c, PulseAudio.ServerInfo? i) { -- cgit v1.2.3 From 91b54a8a59cd51813d750efbe01203b7fe1d0e3c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Dec 2014 11:24:48 -0600 Subject: Encapsulate high volume better --- src/volume-control.vala | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/volume-control.vala') diff --git a/src/volume-control.vala b/src/volume-control.vala index 22212d5..193e621 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -77,7 +77,11 @@ public class VolumeControl : Object public bool active_mic { get; private set; default = false; } /** true when high volume warnings should be shown */ - public bool high_volume { get; set; } + public bool high_volume { + get { + return this._volume > 0.75 && _active_port_headphone; + } + } public VolumeControl () { @@ -152,7 +156,7 @@ 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; + bool old_high_volume = this.high_volume; if (i == null) return; @@ -189,8 +193,10 @@ public class VolumeControl : Object _volume = volume_to_double (i.volume.max ()); this.notify_property("volume"); start_local_volume_timer(); - } else if (this._active_port_headphone != old_active_port_headphone) { - this.notify_property("volume"); + } + + if (this.high_volume != old_high_volume) { + this.notify_property("high-volume"); } } @@ -579,13 +585,18 @@ public class VolumeControl : Object return false; if (_volume != volume) { + var old_high_volume = this.high_volume; + _volume = volume; if (_pulse_use_stream_restore) set_volume_active_role.begin (); else context.get_server_info (server_info_cb_for_set_volume); - high_volume = volume > 0.75 && _active_port_headphone; + this.notify_property("volume"); + + if (this.high_volume != old_high_volume) + this.notify_property("high-volume"); return true; } else { -- cgit v1.2.3