aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcharles kerr <charlesk@canonical.com>2015-12-31 11:11:46 -0600
committercharles kerr <charlesk@canonical.com>2015-12-31 11:11:46 -0600
commitd122698e9d07abdb18564852171a8488511f43a0 (patch)
tree30589b0c1b1fff4fcf24ea4ebf458c3df4ab920f
parent3216d99edcec8a8cfe4533983af4a26f2bb9fa36 (diff)
downloadayatana-indicator-sound-d122698e9d07abdb18564852171a8488511f43a0.tar.gz
ayatana-indicator-sound-d122698e9d07abdb18564852171a8488511f43a0.tar.bz2
ayatana-indicator-sound-d122698e9d07abdb18564852171a8488511f43a0.zip
rename VolumeWarning.high_volume_approved as VolumeWarning.approved
After being moved into a class named "VolumeWarning", the high_volume_ prefix was redunant.
-rw-r--r--src/volume-warning.vala134
-rw-r--r--tests/notifications-test.cc2
-rw-r--r--tests/volume-warning-mock.vala4
3 files changed, 70 insertions, 70 deletions
diff --git a/src/volume-warning.vala b/src/volume-warning.vala
index d475570..d7f0e79 100644
--- a/src/volume-warning.vala
+++ b/src/volume-warning.vala
@@ -39,8 +39,8 @@ public abstract class VolumeWarning : Object
public void user_keypress (Key key) {
if ((key == Key.VOLUME_DOWN) && active) {
- _notification.close();
- on_user_response(IndicatorSound.WarnNotification.Response.CANCEL);
+ _notification.close ();
+ on_user_response (IndicatorSound.WarnNotification.Response.CANCEL);
}
}
@@ -48,14 +48,13 @@ public abstract class VolumeWarning : Object
_options = options;
- init_all_properties();
+ init_all_properties ();
- _notification = new IndicatorSound.WarnNotification ();
- _notification.user_responded.connect((n, r) => on_user_response(r));
+ _notification.user_responded.connect ((n, r) => on_user_response (r));
}
~VolumeWarning () {
- stop_all_timers();
+ stop_all_timers ();
}
/***
@@ -63,18 +62,18 @@ public abstract class VolumeWarning : Object
***/
// true if the user has approved high volumes recently
- protected bool high_volume_approved { get; set; default = false; }
+ protected bool approved { get; set; default = false; }
// true if multimedia is currently playing
protected bool multimedia_active { get; set; default = false; }
/* Cached value of the multimedia volume reported by pulse.
Setting this only updates the cache -- to change the volume,
- use sound_system_set_multimedia_volume().
+ use sound_system_set_multimedia_volume.
NB: This PulseAudio.Volume is typed as uint to unconfuse valac. */
protected uint multimedia_volume { get; set; default = PulseAudio.Volume.INVALID; }
- protected abstract void sound_system_set_multimedia_volume(PulseAudio.Volume volume);
+ protected abstract void sound_system_set_multimedia_volume (PulseAudio.Volume volume);
protected void clear_timer (ref uint timer) {
if (timer != 0) {
@@ -89,15 +88,15 @@ public abstract class VolumeWarning : Object
private IndicatorSound.Options _options;
- private void init_all_properties()
+ private void init_all_properties ()
{
- init_high_volume();
- init_high_volume_approved();
+ init_high_volume ();
+ init_approved ();
}
- private void stop_all_timers()
+ private void stop_all_timers ()
{
- stop_high_volume_approved_timer();
+ stop_approved_timer ();
}
/**
@@ -105,13 +104,13 @@ public abstract class VolumeWarning : Object
**/
private void init_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();
+ 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 () {
@@ -119,14 +118,14 @@ public abstract class VolumeWarning : Object
var newval = _options.loud_warning_enabled
&& headphones_active
&& multimedia_active
- && !high_volume_approved
+ && !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);
+ debug ("changing high_volume from %d to %d", (int)high_volume, (int)newval);
if (newval && !active)
- show();
+ activate ();
high_volume = newval;
}
}
@@ -136,84 +135,85 @@ public abstract class VolumeWarning : Object
**/
private Settings _settings = new Settings ("com.canonical.indicator.sound");
- private uint _high_volume_approved_timer = 0;
- private int64 _high_volume_approved_at = 0;
- private int64 _high_volume_approved_ttl_usec = 0;
+ private static const string TTL_KEY = "warning-volume-confirmation-ttl";
+ private uint _approved_timer = 0;
+ private int64 _approved_at = 0;
+ private int64 _approved_ttl_usec = 0;
- private void approve_high_volume() {
- _high_volume_approved_at = GLib.get_monotonic_time();
- update_high_volume_approved();
- update_high_volume_approved_timer();
+ private void approve_high_volume () {
+ _approved_at = GLib.get_monotonic_time ();
+ update_approved ();
+ update_approved_timer ();
}
- private void init_high_volume_approved() {
- _settings.changed["warning-volume-confirmation-ttl"].connect(() => update_high_volume_approved_cache());
- update_high_volume_approved_cache();
+ private void init_approved () {
+ _settings.changed[TTL_KEY].connect (() => update_approved_cache ());
+ update_approved_cache ();
}
- private void update_high_volume_approved_cache() {
- _high_volume_approved_ttl_usec = _settings.get_int("warning-volume-confirmation-ttl");
- _high_volume_approved_ttl_usec *= 1000000;
+ private void update_approved_cache () {
+ _approved_ttl_usec = _settings.get_int (TTL_KEY);
+ _approved_ttl_usec *= 1000000;
- update_high_volume_approved();
- update_high_volume_approved_timer();
+ update_approved ();
+ update_approved_timer ();
}
- private void update_high_volume_approved_timer() {
- stop_high_volume_approved_timer();
- if (_high_volume_approved_at != 0) {
- int64 expires_at = _high_volume_approved_at + _high_volume_approved_ttl_usec;
- int64 now = GLib.get_monotonic_time();
+ private void update_approved_timer () {
+ stop_approved_timer ();
+ if (_approved_at != 0) {
+ int64 expires_at = _approved_at + _approved_ttl_usec;
+ int64 now = GLib.get_monotonic_time ();
if (expires_at > now) {
var seconds_left = 1 + ((expires_at - now) / 1000000);
- _high_volume_approved_timer = Timeout.add_seconds((uint)seconds_left, on_high_volume_approved_timer);
+ _approved_timer = Timeout.add_seconds ((uint)seconds_left, on_approved_timer);
}
}
}
- private void stop_high_volume_approved_timer() {
- clear_timer(ref _high_volume_approved_timer);
+ private void stop_approved_timer () {
+ clear_timer (ref _approved_timer);
}
- private bool on_high_volume_approved_timer() {
- _high_volume_approved_timer = 0;
- update_high_volume_approved();
+ private bool on_approved_timer () {
+ _approved_timer = 0;
+ update_approved ();
return Source.REMOVE;
}
- private void update_high_volume_approved() {
- var new_high_volume_approved = calculate_high_volume_approved();
- if (high_volume_approved != new_high_volume_approved) {
- debug("changing high_volume_approved from %d to %d", (int)high_volume_approved, (int)new_high_volume_approved);
- high_volume_approved = new_high_volume_approved;
+ private void update_approved () {
+ var new_approved = calculate_approved ();
+ if (approved != new_approved) {
+ debug ("changing approved from %d to %d", (int)approved, (int)new_approved);
+ approved = new_approved;
}
}
- private bool calculate_high_volume_approved() {
- int64 now = GLib.get_monotonic_time();
- return (_high_volume_approved_at != 0)
- && (_high_volume_approved_at + _high_volume_approved_ttl_usec >= now);
+ private bool calculate_approved () {
+ int64 now = GLib.get_monotonic_time ();
+ return (_approved_at != 0)
+ && (_approved_at + _approved_ttl_usec >= now);
}
// NOTIFICATION
- private IndicatorSound.WarnNotification _notification = new IndicatorSound.WarnNotification();
+ private IndicatorSound.WarnNotification _notification = new IndicatorSound.WarnNotification ();
private PulseAudio.Volume _ok_volume = PulseAudio.Volume.INVALID;
- protected virtual void preshow() {}
+ protected virtual void preshow () {}
- private void show() {
- preshow();
+ private void activate () {
+ preshow ();
_ok_volume = multimedia_volume;
- _notification.show();
+ _notification.show ();
this.active = true;
// lower the volume to just under the warning level
sound_system_set_multimedia_volume (_options.loud_volume-1);
}
- private void on_user_response(IndicatorSound.WarnNotification.Response response) {
+ private void on_user_response (IndicatorSound.WarnNotification.Response response) {
this.active = false;
if (response == IndicatorSound.WarnNotification.Response.OK) {
- approve_high_volume();
- sound_system_set_multimedia_volume(_ok_volume);
+ approve_high_volume ();
+ sound_system_set_multimedia_volume (_ok_volume);
}
_ok_volume = PulseAudio.Volume.INVALID;
diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc
index 7f8d49a..0206e2b 100644
--- a/tests/notifications-test.cc
+++ b/tests/notifications-test.cc
@@ -520,7 +520,7 @@ TEST_F(NotificationsTest, WarningRequiresHeadphones) {
const pa_volume_t volume = 100;
options_mock_mock_set_loud_volume(OPTIONS_MOCK(options.get()), volume);
options_mock_mock_set_loud_warning_enabled(OPTIONS_MOCK(options.get()), true);
- volume_warning_mock_set_high_volume_approved(VOLUME_WARNING_MOCK(volumeWarning.get()), false);
+ volume_warning_mock_set_approved(VOLUME_WARNING_MOCK(volumeWarning.get()), false);
volume_warning_mock_set_multimedia_volume(VOLUME_WARNING_MOCK(volumeWarning.get()), volume);
volume_warning_mock_set_multimedia_active(VOLUME_WARNING_MOCK(volumeWarning.get()), true);
diff --git a/tests/volume-warning-mock.vala b/tests/volume-warning-mock.vala
index 0dcae50..f69688f 100644
--- a/tests/volume-warning-mock.vala
+++ b/tests/volume-warning-mock.vala
@@ -34,7 +34,7 @@ public class VolumeWarningMock : VolumeWarning
public void set_multimedia_volume(PulseAudio.Volume val) { multimedia_volume = val; }
- public void set_high_volume_approved(bool val) { high_volume_approved = val; }
+ public void set_approved(bool val) { approved = val; }
- public bool is_high_volume_approved() { return high_volume_approved; }
+ public bool is_approved() { return approved; }
}