diff options
author | Ted Gould <ted@gould.cx> | 2014-10-02 11:12:39 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2014-10-02 11:12:39 -0500 |
commit | dab455206972c36d086ae97da776ddd00795899a (patch) | |
tree | 68c4c4bdb037148a980339b6f4a81c8995da03da | |
parent | 1feb02e715bcb4f201e85c012acfe6196c657930 (diff) | |
download | ayatana-indicator-sound-dab455206972c36d086ae97da776ddd00795899a.tar.gz ayatana-indicator-sound-dab455206972c36d086ae97da776ddd00795899a.tar.bz2 ayatana-indicator-sound-dab455206972c36d086ae97da776ddd00795899a.zip |
Create a silent mode action
-rw-r--r-- | src/service.vala | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/src/service.vala b/src/service.vala index 280c12d..d869053 100644 --- a/src/service.vala +++ b/src/service.vala @@ -25,6 +25,18 @@ public class IndicatorSound.Service: Object { this.settings.bind ("visible", this, "visible", SettingsBindFlags.GET); this.notify["visible"].connect ( () => this.update_root_icon () ); + /* If we're on the greeter, don't export */ + if (GLib.Environment.get_user_name() != "lightdm") { + this.accounts_service = new AccountsServiceUser(); + + this.accounts_service.notify["showDataOnGreeter"].connect(() => { + this.export_to_accounts_service = this.accounts_service.showDataOnGreeter; + eventually_update_player_actions(); + }); + + this.export_to_accounts_service = this.accounts_service.showDataOnGreeter; + } + this.volume_control = new VolumeControl (); this.players = playerlist; @@ -33,6 +45,7 @@ public class IndicatorSound.Service: Object { this.actions = new SimpleActionGroup (); this.actions.add_action_entries (action_entries, this); + this.actions.add_action (this.create_silent_mode_action ()); 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 ()); @@ -47,18 +60,6 @@ public class IndicatorSound.Service: Object { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); }); - /* If we're on the greeter, don't export */ - if (GLib.Environment.get_user_name() != "lightdm") { - this.accounts_service = new AccountsServiceUser(); - - this.accounts_service.notify["showDataOnGreeter"].connect(() => { - this.export_to_accounts_service = this.accounts_service.showDataOnGreeter; - eventually_update_player_actions(); - }); - - this.export_to_accounts_service = this.accounts_service.showDataOnGreeter; - } - this.sync_preferred_players (); this.settings.changed["interested-media-players"].connect ( () => { this.sync_preferred_players (); @@ -257,6 +258,35 @@ public class IndicatorSound.Service: Object { root_action.set_state (builder.end()); } + Action create_silent_mode_action () { + bool silentNow = false; + if (this.accounts_service != null) { + silentNow = this.accounts_service.silentMode; + } + + var silent_action = new SimpleAction.stateful ("silent-mode", null, new Variant.boolean (silentNow)); + + /* If we're not dealing with accounts service, we'll just always be out + of silent mode and that's cool. */ + if (this.accounts_service == null) { + return silent_action; + } + + this.accounts_service.notify["silentMode"].connect(() => { + silent_action.set_state(new Variant.boolean(this.accounts_service.silentMode)); + }); + + silent_action.activate.connect ((action, param) => { + action.change_state (new Variant.boolean (!action.get_state().get_boolean())); + }); + + silent_action.change_state.connect ((action, val) => { + this.accounts_service.silentMode = val.get_boolean(); + }); + + return silent_action; + } + Action create_mute_action () { var mute_action = new SimpleAction.stateful ("mute", null, new Variant.boolean (this.volume_control.mute)); |