diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-03-27 13:06:26 -0400 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-03-27 13:06:26 -0400 |
commit | c3d504bc66bbd360ca6c8d5742a121441dacbfe2 (patch) | |
tree | 0435c45826c757ba125515933e9a11a927d45eb3 /src/service.vala | |
parent | 5cd2cc805d012b0e019a4d30f3666cb60707ca76 (diff) | |
download | ayatana-indicator-sound-c3d504bc66bbd360ca6c8d5742a121441dacbfe2.tar.gz ayatana-indicator-sound-c3d504bc66bbd360ca6c8d5742a121441dacbfe2.tar.bz2 ayatana-indicator-sound-c3d504bc66bbd360ca6c8d5742a121441dacbfe2.zip |
Add VolumeControl and hook up mute and volume actions to it
The VolumeControl class originated in the phablet branch of this indicator.
Diffstat (limited to 'src/service.vala')
-rw-r--r-- | src/service.vala | 46 |
1 files changed, 37 insertions, 9 deletions
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 { |