diff options
Diffstat (limited to 'src/service.vala')
-rw-r--r-- | src/service.vala | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/src/service.vala b/src/service.vala index 4e02769..8287b7f 100644 --- a/src/service.vala +++ b/src/service.vala @@ -38,8 +38,8 @@ public class IndicatorSound.Service: Object { this.actions.add_action (this.create_mic_volume_action ()); this.menus = new HashTable<string, SoundMenu> (str_hash, str_equal); - this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS)); - this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS)); + this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); + this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE)); this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS)); @@ -47,9 +47,17 @@ public class IndicatorSound.Service: Object { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); }); - /* Setup handling for the greeter-export setting */ - this.settings.changed["greeter-export"].connect( () => this.build_accountsservice() ); - build_accountsservice(); + /* 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 ( () => { @@ -74,25 +82,8 @@ public class IndicatorSound.Service: Object { } } - void build_accountsservice () { - clear_acts_player(); - this.accounts_service = null; - - /* If we're not exporting, don't build anything */ - if (!this.settings.get_boolean("greeter-export")) { - debug("Accounts service export disabled due to user setting"); - return; - } - - /* If we're on the greeter, don't export */ - if (GLib.Environment.get_user_name() == "lightdm") { - debug("Accounts service export disabled due to being used on the greeter"); - return; - } - - this.accounts_service = new AccountsServiceUser(); - - this.eventually_update_player_actions(); + bool greeter_show_track () { + return export_to_accounts_service; } void clear_acts_player () { @@ -167,6 +158,7 @@ public class IndicatorSound.Service: Object { Notify.Notification notification; bool syncing_preferred_players = false; AccountsServiceUser? accounts_service = null; + bool export_to_accounts_service = false; /* Maximum volume as a scaling factor between the volume action's state and the value in * this.volume_control. See create_volume_action(). @@ -379,11 +371,11 @@ public class IndicatorSound.Service: Object { this.loop.quit (); } - Variant action_state_for_player (MediaPlayer player) { + Variant action_state_for_player (MediaPlayer player, bool show_track = true) { var builder = new VariantBuilder (new VariantType ("a{sv}")); builder.add ("{sv}", "running", new Variant ("b", player.is_running)); builder.add ("{sv}", "state", new Variant ("s", player.state)); - if (player.current_track != null) { + if (player.current_track != null && show_track) { builder.add ("{sv}", "title", new Variant ("s", player.current_track.title)); builder.add ("{sv}", "artist", new Variant ("s", player.current_track.artist)); builder.add ("{sv}", "album", new Variant ("s", player.current_track.album)); @@ -402,8 +394,14 @@ public class IndicatorSound.Service: Object { action.set_enabled (player.can_raise); } + SimpleAction? greeter_action = this.actions.lookup_action (player.id + ".greeter") as SimpleAction; + if (greeter_action != null) { + greeter_action.set_state (this.action_state_for_player (player, greeter_show_track())); + greeter_action.set_enabled (player.can_raise); + } + /* If we're playing then put that data in accounts service */ - if (player.is_running && accounts_service != null) { + if (player.is_running && export_to_accounts_service && accounts_service != null) { accounts_service.player = player; clear_accounts_player = false; } @@ -446,6 +444,11 @@ public class IndicatorSound.Service: Object { action.activate.connect ( () => { player.activate (); }); this.actions.add_action (action); + SimpleAction greeter_action = new SimpleAction.stateful (player.id + ".greeter", null, this.action_state_for_player (player, greeter_show_track())); + greeter_action.set_enabled (player.can_raise); + greeter_action.activate.connect ( () => { player.activate (); }); + this.actions.add_action (greeter_action); + var play_action = new SimpleAction.stateful ("play." + player.id, null, player.state); play_action.activate.connect ( () => player.play_pause () ); this.actions.add_action (play_action); |