From c3d504bc66bbd360ca6c8d5742a121441dacbfe2 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 27 Mar 2013 13:06:26 -0400 Subject: Add VolumeControl and hook up mute and volume actions to it The VolumeControl class originated in the phablet branch of this indicator. --- src/service.vala | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index fc35dd7..cdb5b15 100644 --- a/src/service.vala +++ b/src/service.vala @@ -1,6 +1,7 @@ public class IndicatorSound.Service { public Service () { + this.volume_control = new VolumeControl (); } public int run () { @@ -20,21 +21,13 @@ public class IndicatorSound.Service { const ActionEntry[] action_entries = { { "root", null, null, "('', 'audio-volume-high-panel', '', true)", null }, - { "mute", activate_mute, null, "false", null }, - { "volume", null, null, "0", volume_changed }, { "settings", activate_settings, null, null, null } }; MainLoop loop; SimpleActionGroup actions; Menu menu; - - void activate_mute (SimpleAction action, Variant? param) { - bool muted = action.get_state ().get_boolean (); - } - - void volume_changed (SimpleAction action, Variant val) { - } + VolumeControl volume_control; void activate_settings (SimpleAction action, Variant? param) { try { @@ -64,10 +57,45 @@ public class IndicatorSound.Service { return menu; } + Action create_mute_action () { + var mute_action = new SimpleAction.stateful ("mute", null, this.volume_control.mute); + + mute_action.activate.connect ( (action, param) => { + action.change_state (!action.get_state ().get_boolean ()); + }); + + mute_action.change_state.connect ( (action, val) => { + volume_control.set_mute (val.get_boolean ()); + }); + + this.volume_control.notify["mute"].connect ( () => { + mute_action.set_state (this.volume_control.mute); + }); + + return mute_action; + } + + Action create_volume_action () { + var volume_action = new SimpleAction.stateful ("volume", null, this.volume_control.get_volume ()); + + volume_action.change_state.connect ( (action, val) => { + volume_control.set_volume (val.get_double ()); + }); + + this.volume_control.volume_changed.connect ( (volume) => { + volume_action.set_state (volume); + }); + + return volume_action; + } + void bus_acquired (DBusConnection connection, string name) { this.actions = new SimpleActionGroup (); this.actions.add_entries (action_entries, this); + this.actions.add_action (this.create_mute_action ()); + this.actions.add_action (this.create_volume_action ()); + this.menu = create_base_menu (); try { -- cgit v1.2.3