~ci-train-bot/indicator-sound/indicator-sound-ubuntu-zesty-2138

« back to all changes in this revision

Viewing changes to src/sound-menu.vala

  • Committer: CI Train Bot
  • Author(s): Xavi Garcia Mena
  • Date: 2016-03-07 10:13:38 UTC
  • mfrom: (529.1.8 last-runnin-player-charles)
  • Revision ID: ci-train-bot@canonical.com-20160307101338-x2wynmsb4sch7jag
This branch sets the last running player using accounts service instead of gsettings.
It also includes a new class AccountsServiceAccess, to centralize all accesses to account service properties.
Approved by: PS Jenkins bot, Charles Kerr

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
        const string PLAYBACK_ITEM_TYPE = "com.canonical.unity.playback-item";
40
40
 
41
 
        public SoundMenu (string? settings_action, DisplayFlags flags, string default_player_id) {
 
41
        public SoundMenu (string? settings_action, DisplayFlags flags) {
42
42
                /* A sound menu always has at least two sections: the volume section (this.volume_section)
43
43
                 * at the start of the menu, and the settings section at the end. Between those two,
44
44
                 * it has a dynamic amount of player sections, one for each registered player.
83
83
                this.notify_handlers = new HashTable<MediaPlayer, ulong> (direct_hash, direct_equal);
84
84
 
85
85
                this.greeter_players = (flags & DisplayFlags.GREETER_PLAYERS) != 0;
86
 
 
87
 
                this.default_player = default_player_id;
88
 
 
89
86
        }
90
87
 
91
88
        ~SoundMenu () {
95
92
                }
96
93
        }
97
94
 
 
95
        public void set_default_player (string default_player_id) {
 
96
                this.default_player = default_player_id;
 
97
                foreach (var player_stored in notify_handlers.get_keys ()) {
 
98
                        int index = this.find_player_section(player_stored);
 
99
                        if (index != -1 && player_stored.id == this.default_player) {
 
100
                                add_player_playback_controls (player_stored, index, true);
 
101
                        }
 
102
                }
 
103
        }
 
104
 
98
105
        DBusConnection? bus = null;
99
106
        uint export_id = 0;
100
107
 
171
178
                        }
172
179
                }
173
180
        }
174
 
 
 
181
 
 
182
        private void check_last_running_player () {
 
183
                foreach (var player in notify_handlers.get_keys ()) {
 
184
                        if (player.is_running && number_of_running_players == 1) {
 
185
                                // this is the first or the last player running...
 
186
                                // store its id
 
187
                                this.last_player_updated (player.id);
 
188
                        }
 
189
                }
 
190
        }
 
191
        
175
192
        public void add_player (MediaPlayer player) {
176
193
                if (this.notify_handlers.contains (player))
177
194
                        return;
198
215
                        // we need to update the rest of players, because we might have
199
216
                        // a non running player still showing the playback controls
200
217
                        update_all_players_play_section();
 
218
 
 
219
                        check_last_running_player ();
201
220
                });
202
221
                this.notify_handlers.insert (player, handler_id);
203
222
 
204
223
                player.playlists_changed.connect (this.update_playlists);
205
224
                player.playbackstatus_changed.connect (this.update_playbackstatus);
 
225
 
 
226
                check_last_running_player ();
206
227
        }
207
228
 
208
229
        public void remove_player (MediaPlayer player) {
217
238
 
218
239
                /* this'll drop our ref to it */
219
240
                this.notify_handlers.remove (player);
 
241
 
 
242
                check_last_running_player ();
220
243
        }
221
244
 
222
245
        public void update_volume_slider (VolumeControl.ActiveOutput active_output) {
368
391
                        this.menu.remove (index);
369
392
        }
370
393
 
371
 
        void update_player_section (MediaPlayer player, int index) {
 
394
        void add_player_playback_controls (MediaPlayer player, int index, bool adding_default_player) {
372
395
                var player_section = this.menu.get_item_link(index, Menu.LINK_SECTION) as Menu;
373
396
 
374
397
                int play_control_index = find_player_playback_controls_section (player_section);
375
 
                if (player.is_running && number_of_running_players == 1) {
376
 
                        // this is the first or the last player running...
377
 
                        // store its id
378
 
                        this.last_player_updated (player.id);
379
 
                }
380
 
                if (player.is_running || !this.hide_inactive_player_controls) {
 
398
                if (player.is_running || !this.hide_inactive_player_controls || (number_of_running_players == 0 && adding_default_player) ) {
381
399
                        MenuItem playback_item = create_playback_menu_item (player);
382
400
                        if (play_control_index != -1) {
383
401
                                player_section.remove (PlayerSectionPosition.PLAYER_CONTROLS);  
389
407
                                player_section.remove (PlayerSectionPosition.PLAYLIST);
390
408
                                player_section.remove (PlayerSectionPosition.PLAYER_CONTROLS);  
391
409
                        }
392
 
                }
 
410
                }       
 
411
        }
 
412
 
 
413
        void update_player_section (MediaPlayer player, int index) {
 
414
                add_player_playback_controls (player, index, false);
393
415
        }
394
416
 
395
417
        void update_playlists (MediaPlayer player) {