From 7ec3795022cbfff0e1c0c094309a4b67d1dd3b04 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 13 Oct 2014 20:51:07 -0500 Subject: Create actions based on the high volume status --- src/service.vala | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 2a65492..92523aa 100644 --- a/src/service.vala +++ b/src/service.vala @@ -49,6 +49,7 @@ public class IndicatorSound.Service: Object { this.actions.add_action (this.create_mute_action ()); this.actions.add_action (this.create_volume_action ()); this.actions.add_action (this.create_mic_volume_action ()); + this.actions.add_action (this.create_high_volume_actions ()); this.menus = new HashTable (str_hash, str_equal); this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); @@ -388,6 +389,36 @@ public class IndicatorSound.Service: Object { return volume_action; } + Action create_high_volume_actions () { + var high_volume_action = new SimpleAction.stateful("high-volume", null, new Variant.boolean (this.volume_control.high_volume)); + + this.volume_control.notify["high_volume"].connect( () => + high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume))); + + /* So this is a bit confusing, putting it here because everywhere else + sucks too. It might create an action and put it into the action group. + Which is sneaky. Better to have the code not duplicated, but no good + place to put code like that. */ + setup_high_volume_menu_action(); + + return high_volume_action; + } + + void setup_high_volume_menu_action () { + this.volume_control.notify["high_volume"].connect(update_high_volume_menu_action); + update_high_volume_menu_action(); + } + + void update_high_volume_menu_action () { + if (this.volume_control.high_volume) { + var menu_action = new SimpleAction("high-volume-menu", null); + menu_action.set_enabled(false); + this.actions.add_action(menu_action); + } else { + this.actions.remove_action("high-volume-menu"); + } + } + void bus_acquired (DBusConnection connection, string name) { try { connection.export_action_group ("/com/canonical/indicator/sound", this.actions); -- cgit v1.2.3