def _finish_update(self, new_model_medias): if not new_model_medias: self._model.remove_all() self.props.count = 0 return current_models_ids = [ coresong.props.media.get_id() for coresong in self._model ] new_model_ids = [media.get_id() for media in new_model_medias] idx_to_delete = [] for idx, media_id in enumerate(current_models_ids): if media_id not in new_model_ids: idx_to_delete.insert(0, idx) for idx in idx_to_delete: self._model.remove(idx) self.props.count -= 1 for idx, media in enumerate(new_model_medias): if media.get_id() not in current_models_ids: coresong = CoreSong(self._application, media) self._bind_to_main_song(coresong) self._model.append(coresong) self.props.count += 1
def _add_to_model(source, op_id, media, remaining, error): if error: self._log.warning("Error: {}".format(error)) self._notificationmanager.pop_loading() return if not media: self._songs_model.splice(self._songs_model.get_n_items(), 0, songs_added) self._notificationmanager.pop_loading() # Initialize the playlists subwrapper after the initial # songs model fill, the playlists expect a filled songs # hashtable. self._tracker_playlists = GrlTrackerPlaylists( self.props.source, self._application, self._tracker_wrapper, self._hash) return song = CoreSong(self._application, media) songs_added.append(song) self._hash[media.get_id()] = song if len(songs_added) == self._SPLICE_SIZE: self._songs_model.splice(self._songs_model.get_n_items(), 0, songs_added) songs_added.clear()
def _add_to_model(source, op_id, media, remaining, error): if not media: self.props.count = self._model.get_n_items() return coresong = CoreSong(media, self._coreselection, self._grilo) if coresong not in self._songs_todelete: self._model.append(coresong)
def _add_to_model(source, op_id, media, remaining, error): if not media: self.props.count = self._model.get_n_items() return coresong = CoreSong(self._application, media) self._bind_to_main_song(coresong) if coresong not in self._songs_todelete: self._model.append(coresong)
def _add_to_playlist_cb(source, op_id, media, remaining, user_data, error): if not media: self.props.count = self._model.get_n_items() self.emit("playlist-loaded") return coresong = CoreSong(media, self._coreselection, self._grilo) if coresong not in self._songs_todelete: self._model.append(coresong)
def _on_items_changed(model, position, removed, added): songs_list = [] if added > 0: for i in list(range(added)): coresong = model[position + i] song = CoreSong(self._application, coresong.props.media) _bind_song_properties(coresong, song) songs_list.append(song) self._playlist_model.splice(position, removed, songs_list)
def _on_items_changed(model, position, removed, added): if removed > 0: for i in list(range(removed)): self._playlist_model.remove(position) if added > 0: for i in list(range(added)): coresong = model[position + i] song = CoreSong(coresong.props.media, self._coreselection, self.props.grilo) self._playlist_model.insert(position + i, song) song.bind_property("state", coresong, "state", GObject.BindingFlags.SYNC_CREATE) coresong.bind_property( "validation", song, "validation", GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE)
def _add_to_model(source, op_id, media, remaining, error): if error: print("ERROR", error) return if not media: self.props.count = self._model.get_n_items() return coresong = CoreSong(media, self._coreselection, self._grilo) self._model.append(coresong)
def _add_to_model(source, op_id, media, user_data, error): if error: print("ERROR", error) return if not media: return song = CoreSong(media, self._coreselection, self._grilo) self._model.append(song) self._hash[media.get_id()] = song
def _add_to_playlist_cb(source, op_id, media, remaining, user_data, error): if not media: self.props.count = self._model.get_n_items() self.emit("playlist-loaded") self._notificationmanager.pop_loading() return coresong = CoreSong(self._application, media) self._bind_to_main_song(coresong) if coresong not in self._songs_todelete: self._model.append(coresong)
def _search_result_cb(source, op_id, media, remaining, error): if error: print("error") return if media is None: return coresong = CoreSong(media, self._coreselection, self._grilo) coresong.props.title = ( coresong.props.title + " (" + source.props.source_name + ")") self._song_search_store.append(coresong)
def _search_result_cb(source, op_id, media, remaining, error): if error: self._log.warning("Error: {}".format(error)) return if not media: return coresong = CoreSong(self._application, media) coresong.props.title = ( coresong.props.title + " (" + source.props.source_name + ")") self._song_search_store.append(coresong)
def _update_changed_media(source, op_id, media, user_data, error): if error: print("ERROR", error) return if not media: return if media.get_id() not in self._hash: print("Media not in hash", media.get_id()) song = CoreSong(media, self._coreselection, self._grilo) self._model.append(song) self._hash[media.get_id()] = song else: self._hash[media.get_id()].update(media)
def _add_to_model(source, op_id, media, remaining, error): if error: self._log.warning("Error: {}".format(error)) self._notificationmanager.pop_loading() self.emit("playlist-loaded") return if not media: self.props.count = self._model.get_n_items() self._notificationmanager.pop_loading() self.emit("playlist-loaded") return coresong = CoreSong(self._application, media) self._bind_to_main_song(coresong) self._model.append(coresong)
def _update_changed_media(source, op_id, media, remaining, error): if error: self._log.warning("Error: {}".format(error)) return if not media: self._remove_media(media_ids) return media_id = media.get_id() if media_id not in self._hash: song = CoreSong(self._application, media) self._songs_model.append(song) self._hash[media_id] = song self._log.debug("Adding: {}, {}".format( media_id, song.props.title)) else: self._hash[media_id].update(media) media_ids.remove(media_id)
def _set_player_model(self, playlist_type, model): """Set the model for PlayerPlaylist to use This fills playlist model based on the playlist type and model given. This builds a separate model to stay alive and play while the user navigates other views. :param PlaylistType playlist_type: The type of the playlist :param Gio.ListStore model: The base model for the player model """ if model is self._previous_playlist_model: for song in self._playlist_model: if song.props.state == SongWidget.State.PLAYING: song.props.state = SongWidget.State.PLAYED self.emit("playlist-loaded", playlist_type) return def _bind_song_properties(model_song, player_song): model_song.bind_property( "state", player_song, "state", GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE) def _on_items_changed(model, position, removed, added): songs_list = [] if added > 0: for i in list(range(added)): coresong = model[position + i] song = CoreSong(self._application, coresong.props.media) _bind_song_properties(coresong, song) songs_list.append(song) self._playlist_model.splice(position, removed, songs_list) played_states = [SongWidget.State.PLAYING, SongWidget.State.PLAYED] for song in self._playlist_model: if song.props.state in played_states: song.props.state = SongWidget.State.UNPLAYED if self._player_signal_id is not None: self._current_playlist_model.disconnect(self._player_signal_id) self._player_signal_id = None self._current_playlist_model = None songs_added = [] if playlist_type == PlayerPlaylist.Type.ALBUM: proxy_model = Gio.ListStore.new(Gio.ListModel) for disc in model: proxy_model.append(disc.props.model) self._flatten_model = Gfm.FlattenListModel.new( CoreSong, proxy_model) self._current_playlist_model = self._flatten_model for model_song in self._flatten_model: song = CoreSong(self._application, model_song.props.media) _bind_song_properties(model_song, song) songs_added.append(song) elif playlist_type == PlayerPlaylist.Type.ARTIST: proxy_model = Gio.ListStore.new(Gio.ListModel) for artist_album in model: for disc in artist_album.model: proxy_model.append(disc.props.model) self._flatten_model = Gfm.FlattenListModel.new( CoreSong, proxy_model) self._current_playlist_model = self._flatten_model for model_song in self._flatten_model: song = CoreSong(self._application, model_song.props.media) _bind_song_properties(model_song, song) songs_added.append(song) elif playlist_type == PlayerPlaylist.Type.SONGS: self._current_playlist_model = self._songliststore.props.model for song in self._songliststore.props.model: songs_added.append(song) if song.props.state == SongWidget.State.PLAYING: song.props.state = SongWidget.State.PLAYED elif playlist_type == PlayerPlaylist.Type.SEARCH_RESULT: self._current_playlist_model = self._songs_search_flatten for song in self._songs_search_flatten: songs_added.append(song) elif playlist_type == PlayerPlaylist.Type.PLAYLIST: self._current_playlist_model = model for model_song in model: song = CoreSong(self._application, model_song.props.media) _bind_song_properties(model_song, song) songs_added.append(song) self._playlist_model.splice(0, self._playlist_model.get_n_items(), songs_added) if self._current_playlist_model is not None: self._player_signal_id = self._current_playlist_model.connect( "items-changed", _on_items_changed) self._previous_playlist_model = model self.emit("playlist-loaded", playlist_type)
def set_player_model(self, playlist_type, model): if model is self._previous_playlist_model: for song in self._playlist_model: if song.props.state == SongWidget.State.PLAYING: song.props.state = SongWidget.State.PLAYED self.emit("playlist-loaded") return def _on_items_changed(model, position, removed, added): if removed > 0: for i in list(range(removed)): self._playlist_model.remove(position) if added > 0: for i in list(range(added)): coresong = model[position + i] song = CoreSong( coresong.props.media, self._coreselection, self.props.grilo) self._playlist_model.insert(position + i, song) song.bind_property( "state", coresong, "state", GObject.BindingFlags.SYNC_CREATE) coresong.bind_property( "validation", song, "validation", GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE) with model.freeze_notify(): self._playlist_model.remove_all() if playlist_type == PlayerPlaylist.Type.ALBUM: proxy_model = Gio.ListStore.new(Gio.ListModel) for disc in model: proxy_model.append(disc.props.model) self._flatten_model = Gfm.FlattenListModel.new( CoreSong, proxy_model) self._flatten_model.connect("items-changed", _on_items_changed) for model_song in self._flatten_model: song = CoreSong( model_song.props.media, self._coreselection, self.props.grilo) self._playlist_model.append(song) song.bind_property( "state", model_song, "state", GObject.BindingFlags.SYNC_CREATE) model_song.bind_property( "validation", song, "validation", GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE) self.emit("playlist-loaded") elif playlist_type == PlayerPlaylist.Type.ARTIST: proxy_model = Gio.ListStore.new(Gio.ListModel) for artist_album in model: for disc in artist_album.model: proxy_model.append(disc.props.model) self._flatten_model = Gfm.FlattenListModel.new( CoreSong, proxy_model) self._flatten_model.connect("items-changed", _on_items_changed) for model_song in self._flatten_model: song = CoreSong( model_song.props.media, self._coreselection, self.props.grilo) self._playlist_model.append(song) song.bind_property( "state", model_song, "state", GObject.BindingFlags.SYNC_CREATE) model_song.bind_property( "validation", song, "validation", GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE) self.emit("playlist-loaded") elif playlist_type == PlayerPlaylist.Type.SONGS: if self._song_signal_id: self._songliststore.props.model.disconnect( self._song_signal_id) for song in self._songliststore.props.model: self._playlist_model.append(song) if song.props.state == SongWidget.State.PLAYING: song.props.state = SongWidget.State.PLAYED self._song_signal_id = self._songliststore.props.model.connect( "items-changed", _on_items_changed) self.emit("playlist-loaded") elif playlist_type == PlayerPlaylist.Type.SEARCH_RESULT: if self._search_signal_id: self._song_search_flatten.disconnect( self._search_signal_id) for song in self._song_search_flatten: self._playlist_model.append(song) self._search_signal_id = self._song_search_flatten.connect( "items-changed", _on_items_changed) self.emit("playlist-loaded") elif playlist_type == PlayerPlaylist.Type.PLAYLIST: if self._playlist_signal_id: self._previous_playlist_model.disconnect( self._playlist_signal_id) for model_song in model: song = CoreSong( model_song.props.media, self._coreselection, self.props.grilo) self._playlist_model.append(song) song.bind_property( "state", model_song, "state", GObject.BindingFlags.SYNC_CREATE) model_song.bind_property( "validation", song, "validation", GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE) self._playlist_signal_id = model.connect( "items-changed", _on_items_changed) self.emit("playlist-loaded") self._previous_playlist_model = model