aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/service.vala2
-rw-r--r--src/volume-control.vala25
2 files changed, 13 insertions, 14 deletions
diff --git a/src/service.vala b/src/service.vala
index cdb5b15..aa6664e 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -86,6 +86,8 @@ public class IndicatorSound.Service {
volume_action.set_state (volume);
});
+ this.volume_control.bind_property ("ready", volume_action, "enabled", BindingFlags.SYNC_CREATE);
+
return volume_action;
}
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);