aboutsummaryrefslogtreecommitdiff
path: root/src/volume-control.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/volume-control.vala')
-rw-r--r--src/volume-control.vala25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 8c88c92..5ce5a05 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -31,9 +31,11 @@ public class VolumeControl : Object
private bool _mute = true;
private double _volume = 0.0;
- public signal void ready ();
public signal void volume_changed (double v);
+ /** true when connected to the pulse server */
+ public bool ready { get; set; }
+
public VolumeControl ()
{
if (loop == null)
@@ -47,7 +49,7 @@ public class VolumeControl : Object
context = new PulseAudio.Context (loop.get_api(), null, props);
- context.set_state_callback (notify_cb);
+ context.set_state_callback (context_state_callback);
if (context.connect(null, Context.Flags.NOFAIL, null) < 0)
{
@@ -95,25 +97,23 @@ public class VolumeControl : Object
context.get_server_info (server_info_cb_for_props);
}
- private void notify_cb (Context c)
+ private void context_state_callback (Context c)
{
if (c.get_state () == Context.State.READY)
{
c.subscribe (PulseAudio.Context.SubscriptionMask.SINK);
c.set_subscribe_callback (context_events_cb);
get_properties ();
- ready ();
+ this.ready = true;
}
+ else
+ this.ready = false;
}
/* Mute operations */
public void set_mute (bool mute)
{
- if (context.get_state () != Context.State.READY)
- {
- warning ("Could not mute: PulseAudio server connection is not ready.");
- return;
- }
+ return_if_fail (context.get_state () == Context.State.READY);
context.get_sink_info_list ((context, sink, eol) => {
if (sink != null)
@@ -175,11 +175,8 @@ public class VolumeControl : Object
public void set_volume (double volume)
{
- if (context.get_state () != Context.State.READY)
- {
- warning ("Could not change volume: PulseAudio server connection is not ready.");
- return;
- }
+ return_if_fail (context.get_state () == Context.State.READY);
+
_volume = volume;
context.get_server_info (server_info_cb_for_set_volume);