aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2014-12-02 18:55:00 -0600
committerTed Gould <ted@gould.cx>2014-12-02 18:55:00 -0600
commite0eac1c9d9a050dc44d0883f556753f6f8d1a7b6 (patch)
tree27f2e48e529890d4aba5c6af12b6ea3346a5ced6
parent2f0aba374502b7ea660fce49f70e3ea972725685 (diff)
downloadayatana-indicator-sound-e0eac1c9d9a050dc44d0883f556753f6f8d1a7b6.tar.gz
ayatana-indicator-sound-e0eac1c9d9a050dc44d0883f556753f6f8d1a7b6.tar.bz2
ayatana-indicator-sound-e0eac1c9d9a050dc44d0883f556753f6f8d1a7b6.zip
Moving the notification into the service
-rw-r--r--src/service.vala62
-rw-r--r--src/volume-control.vala105
2 files changed, 74 insertions, 93 deletions
diff --git a/src/service.vala b/src/service.vala
index fd0c08d..1a9034b 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -19,6 +19,8 @@
public class IndicatorSound.Service: Object {
public Service (MediaPlayerList playerlist) {
+ sync_notification = new Notify.Notification(_("Volume"), "", "audio-volume-muted");
+
this.settings = new Settings ("com.canonical.indicator.sound");
this.sharedsettings = new Settings ("com.ubuntu.sound");
@@ -143,7 +145,7 @@ public class IndicatorSound.Service: Object {
}
/* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */
- this.actions.change_action_state ("volume", this.volume_control.get_volume () / this.max_volume);
+ this.actions.change_action_state ("volume", this.volume_control.volume / this.max_volume);
}
}
@@ -168,6 +170,7 @@ public class IndicatorSound.Service: Object {
bool syncing_preferred_players = false;
AccountsServiceUser? accounts_service = null;
bool export_to_accounts_service = false;
+ private Notify.Notification sync_notification;
/* Maximum volume as a scaling factor between the volume action's state and the value in
* this.volume_control. See create_volume_action().
@@ -179,8 +182,8 @@ public class IndicatorSound.Service: Object {
void activate_scroll_action (SimpleAction action, Variant? param) {
int delta = param.get_int32(); /* positive for up, negative for down */
- double v = this.volume_control.get_volume () + volume_step_percentage * delta;
- this.volume_control.set_volume (v.clamp (0.0, this.max_volume));
+ double v = this.volume_control.volume + volume_step_percentage * delta;
+ this.volume_control.volume = v.clamp (0.0, this.max_volume);
/* TODO: Don't want to mess up the desktop today, but we should remove this
scrolling change and merge that into volume control's notification */
@@ -238,7 +241,7 @@ public class IndicatorSound.Service: Object {
}
void update_root_icon () {
- double volume = this.volume_control.get_volume ();
+ double volume = this.volume_control.volume;
string icon;
if (this.volume_control.mute)
icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
@@ -268,6 +271,44 @@ public class IndicatorSound.Service: Object {
root_action.set_state (builder.end());
}
+ void update_sync_notification () {
+ /* Determine Label */
+ string volume_label = "";
+ if (volume_control.high_volume)
+ volume_label = _("High volume");
+
+ /* Choose an icon */
+ string icon = "audio-volume-muted";
+ if (volume_control.volume <= 0.0)
+ icon = "audio-volume-muted";
+ else if (volume_control.volume <= 0.3)
+ icon = "audio-volume-low";
+ else if (volume_control.volume <= 0.7)
+ icon = "audio-volume-medium";
+ else
+ icon = "audio-volume-high";
+
+ /* Check tint */
+ string tint = "false";
+ if (volume_control.high_volume)
+ tint = "true";
+
+ /* Put it all into the notification */
+ sync_notification.clear_hints ();
+ sync_notification.update (_("Volume"), volume_label, icon);
+ sync_notification.set_hint ("value", (int32)(volume_control.volume * 100.0));
+ sync_notification.set_hint ("x-canonical-value-bar-tint", tint);
+ sync_notification.set_hint ("x-canonical-private-synchronous", "true");
+ sync_notification.set_hint ("x-canonical-non-shaped-icon", "true");
+
+ /* Show it */
+ try {
+ sync_notification.show ();
+ } catch (GLib.Error e) {
+ warning("Unable to send volume change notification: %s", e.message);
+ }
+ }
+
Action create_silent_mode_action () {
bool silentNow = false;
if (this.accounts_service != null) {
@@ -349,6 +390,7 @@ public class IndicatorSound.Service: Object {
volume_action.set_state (new Variant.double (volume / this.max_volume));
this.update_root_icon ();
+ this.update_sync_notification ();
}
Action create_volume_action () {
@@ -359,20 +401,20 @@ public class IndicatorSound.Service: Object {
* volume_control.set_volume().
*/
- double volume = this.volume_control.get_volume () / this.max_volume;
+ double volume = this.volume_control.volume / this.max_volume;
var volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, new Variant.double (volume));
volume_action.change_state.connect ( (action, val) => {
double v = val.get_double () * this.max_volume;
- volume_control.set_volume (v.clamp (0.0, this.max_volume));
+ volume_control.volume = v.clamp (0.0, this.max_volume);
});
/* activating this action changes the volume by the amount given in the parameter */
volume_action.activate.connect ( (action, param) => {
int delta = param.get_int32 ();
- double v = volume_control.get_volume () + volume_step_percentage * delta;
- volume_control.set_volume (v.clamp (0.0, this.max_volume));
+ double v = volume_control.volume + volume_step_percentage * delta;
+ volume_control.volume = v.clamp (0.0, this.max_volume);
});
this.volume_control.volume_changed.connect (volume_changed);
@@ -383,10 +425,10 @@ public class IndicatorSound.Service: Object {
}
Action create_mic_volume_action () {
- var volume_action = new SimpleAction.stateful ("mic-volume", null, new Variant.double (this.volume_control.get_mic_volume ()));
+ var volume_action = new SimpleAction.stateful ("mic-volume", null, new Variant.double (this.volume_control.mic_volume));
volume_action.change_state.connect ( (action, val) => {
- volume_control.set_mic_volume (val.get_double ());
+ volume_control.mic_volume = val.get_double ();
});
this.volume_control.mic_volume_changed.connect ( (volume) => {
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 */