28
28
this.volume_control = new VolumeControl ();
30
/* If we're on the greeter, don't export */
31
if (GLib.Environment.get_user_name() != "lightdm") {
32
this.accounts_service = new AccountsServiceUser();
34
this.accounts_service.notify["showDataOnGreeter"].connect(() => {
35
this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
36
eventually_update_player_actions();
39
this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
30
42
this.players = playerlist;
31
43
this.players.player_added.connect (this.player_added);
32
44
this.players.player_removed.connect (this.player_removed);
34
46
this.actions = new SimpleActionGroup ();
35
47
this.actions.add_action_entries (action_entries, this);
48
this.actions.add_action (this.create_silent_mode_action ());
36
49
this.actions.add_action (this.create_mute_action ());
37
50
this.actions.add_action (this.create_volume_action ());
38
51
this.actions.add_action (this.create_mic_volume_action ());
40
53
this.menus = new HashTable<string, SoundMenu> (str_hash, str_equal);
41
this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS));
42
this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
54
this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS));
55
this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS));
43
56
this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE));
44
this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
57
this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
46
59
this.menus.@foreach ( (profile, menu) => {
47
60
this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE);
50
/* Setup handling for the greeter-export setting */
51
this.settings.changed["greeter-export"].connect( () => this.build_accountsservice() );
52
build_accountsservice();
54
63
this.sync_preferred_players ();
55
64
this.settings.changed["interested-media-players"].connect ( () => {
56
65
this.sync_preferred_players ();
77
void build_accountsservice () {
79
this.accounts_service = null;
81
/* If we're not exporting, don't build anything */
82
if (!this.settings.get_boolean("greeter-export")) {
83
debug("Accounts service export disabled due to user setting");
87
/* If we're on the greeter, don't export */
88
if (GLib.Environment.get_user_name() == "lightdm") {
89
debug("Accounts service export disabled due to being used on the greeter");
93
this.accounts_service = new AccountsServiceUser();
95
this.eventually_update_player_actions();
86
bool greeter_show_track () {
87
return export_to_accounts_service;
98
90
void clear_acts_player () {
167
159
Notify.Notification notification;
168
160
bool syncing_preferred_players = false;
169
161
AccountsServiceUser? accounts_service = null;
162
bool export_to_accounts_service = false;
171
164
/* Maximum volume as a scaling factor between the volume action's state and the value in
172
165
* this.volume_control. See create_volume_action().
265
258
root_action.set_state (builder.end());
261
Action create_silent_mode_action () {
262
bool silentNow = false;
263
if (this.accounts_service != null) {
264
silentNow = this.accounts_service.silentMode;
267
var silent_action = new SimpleAction.stateful ("silent-mode", null, new Variant.boolean (silentNow));
269
/* If we're not dealing with accounts service, we'll just always be out
270
of silent mode and that's cool. */
271
if (this.accounts_service == null) {
272
return silent_action;
275
this.accounts_service.notify["silentMode"].connect(() => {
276
silent_action.set_state(new Variant.boolean(this.accounts_service.silentMode));
277
this.update_root_icon ();
280
silent_action.activate.connect ((action, param) => {
281
action.change_state (new Variant.boolean (!action.get_state().get_boolean()));
284
silent_action.change_state.connect ((action, val) => {
285
this.accounts_service.silentMode = val.get_boolean();
288
return silent_action;
268
291
Action create_mute_action () {
269
292
var mute_action = new SimpleAction.stateful ("mute", null, new Variant.boolean (this.volume_control.mute));
379
402
this.loop.quit ();
382
Variant action_state_for_player (MediaPlayer player) {
405
Variant action_state_for_player (MediaPlayer player, bool show_track = true) {
383
406
var builder = new VariantBuilder (new VariantType ("a{sv}"));
384
407
builder.add ("{sv}", "running", new Variant ("b", player.is_running));
385
408
builder.add ("{sv}", "state", new Variant ("s", player.state));
386
if (player.current_track != null) {
409
if (player.current_track != null && show_track) {
387
410
builder.add ("{sv}", "title", new Variant ("s", player.current_track.title));
388
411
builder.add ("{sv}", "artist", new Variant ("s", player.current_track.artist));
389
412
builder.add ("{sv}", "album", new Variant ("s", player.current_track.album));
402
425
action.set_enabled (player.can_raise);
428
SimpleAction? greeter_action = this.actions.lookup_action (player.id + ".greeter") as SimpleAction;
429
if (greeter_action != null) {
430
greeter_action.set_state (this.action_state_for_player (player, greeter_show_track()));
431
greeter_action.set_enabled (player.can_raise);
405
434
/* If we're playing then put that data in accounts service */
406
if (player.is_running && accounts_service != null) {
435
if (player.is_running && export_to_accounts_service && accounts_service != null) {
407
436
accounts_service.player = player;
408
437
clear_accounts_player = false;
446
475
action.activate.connect ( () => { player.activate (); });
447
476
this.actions.add_action (action);
478
SimpleAction greeter_action = new SimpleAction.stateful (player.id + ".greeter", null, this.action_state_for_player (player, greeter_show_track()));
479
greeter_action.set_enabled (player.can_raise);
480
greeter_action.activate.connect ( () => { player.activate (); });
481
this.actions.add_action (greeter_action);
449
483
var play_action = new SimpleAction.stateful ("play." + player.id, null, player.state);
450
484
play_action.activate.connect ( () => player.play_pause () );
451
485
this.actions.add_action (play_action);