~josharenson/indicator-sound/fix_mute_notifications

« back to all changes in this revision

Viewing changes to src/service.vala

  • Committer: CI bot
  • Author(s): Ted Gould
  • Date: 2014-10-09 13:32:42 UTC
  • mfrom: (446.6.13 silent-mode)
  • Revision ID: ps-jenkins@lists.canonical.com-20141009133242-jcvoplk3q98qxs2p
Show a silent mode checkbox Fixes: 1342151, 1367818
Approved by: PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
                this.volume_control = new VolumeControl ();
29
29
 
 
30
                /* If we're on the greeter, don't export */
 
31
                if (GLib.Environment.get_user_name() != "lightdm") {
 
32
                        this.accounts_service = new AccountsServiceUser();
 
33
 
 
34
                        this.accounts_service.notify["showDataOnGreeter"].connect(() => {
 
35
                                this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
 
36
                                eventually_update_player_actions();
 
37
                        });
 
38
 
 
39
                        this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
 
40
                }
 
41
 
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);
33
45
 
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 ());
39
52
 
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));
45
58
 
46
59
                this.menus.@foreach ( (profile, menu) => {
47
60
                        this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE);
48
61
                });
49
62
 
50
 
                /* Setup handling for the greeter-export setting */
51
 
                this.settings.changed["greeter-export"].connect( () => this.build_accountsservice() );
52
 
                build_accountsservice();
53
 
 
54
63
                this.sync_preferred_players ();
55
64
                this.settings.changed["interested-media-players"].connect ( () => {
56
65
                        this.sync_preferred_players ();
74
83
                }
75
84
        }
76
85
 
77
 
        void build_accountsservice () {
78
 
                clear_acts_player();
79
 
                this.accounts_service = null;
80
 
 
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");
84
 
                        return;
85
 
                }
86
 
 
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");
90
 
                        return;
91
 
                }
92
 
 
93
 
                this.accounts_service = new AccountsServiceUser();
94
 
 
95
 
                this.eventually_update_player_actions();
 
86
        bool greeter_show_track () {
 
87
                return export_to_accounts_service;
96
88
        }
97
89
 
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;
170
163
 
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());
266
259
        }
267
260
 
 
261
        Action create_silent_mode_action () {
 
262
                bool silentNow = false;
 
263
                if (this.accounts_service != null) {
 
264
                        silentNow = this.accounts_service.silentMode;
 
265
                }
 
266
 
 
267
                var silent_action = new SimpleAction.stateful ("silent-mode", null, new Variant.boolean (silentNow));
 
268
 
 
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;
 
273
                }
 
274
 
 
275
                this.accounts_service.notify["silentMode"].connect(() => {
 
276
                        silent_action.set_state(new Variant.boolean(this.accounts_service.silentMode));
 
277
                        this.update_root_icon ();
 
278
                });
 
279
 
 
280
                silent_action.activate.connect ((action, param) => {
 
281
                        action.change_state (new Variant.boolean (!action.get_state().get_boolean()));
 
282
                });
 
283
 
 
284
                silent_action.change_state.connect ((action, val) => {
 
285
                        this.accounts_service.silentMode = val.get_boolean();
 
286
                });
 
287
 
 
288
                return silent_action;
 
289
        }
 
290
 
268
291
        Action create_mute_action () {
269
292
                var mute_action = new SimpleAction.stateful ("mute", null, new Variant.boolean (this.volume_control.mute));
270
293
 
379
402
                this.loop.quit ();
380
403
        }
381
404
 
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);
403
426
                        }
404
427
                        
 
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);
 
432
                        }
 
433
                        
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;
409
438
                        }
446
475
                action.activate.connect ( () => { player.activate (); });
447
476
                this.actions.add_action (action);
448
477
 
 
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);
 
482
 
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);