def __on_insert_track(self, row, new_track_id, down): """ Insert a new row at position @param row as PlaylistRow @param new_track_id as int @param down as bool """ new_track = Track(new_track_id) children = self._box.get_children() position = children.index(row) lenght = len(children) if down: position += 1 # Append track to current/next album if position < lenght and\ children[position].album.id == new_track.album.id: new_track.set_album(children[position].album) children[position].prepend_rows([new_track]) children[position].album.insert_track(new_track, 0) # Append track to previous/current album elif position - 1 < lenght and\ children[position - 1].album.id == new_track.album.id: new_track.set_album(children[position - 1].album) children[position - 1].append_rows([new_track]) children[position - 1].album.insert_track(new_track) # Add a new album else: album = Album(new_track.album.id) album.set_tracks([new_track]) new_row = self.__row_for_album(album) new_row.populate() new_row.show() self._box.insert(new_row, position) App().player.add_album(album, position) if row.previous_row is not None and\ row.previous_row.album.id ==\ App().player.current_track.album.id: App().player.set_next() App().player.set_prev()
def __on_insert_track(self, row, new_track_id, down): """ Insert a new row at position @param row as PlaylistRow @param new_track_id as int @param down as bool """ track = Track(new_track_id) # If same album, add track to album if track.album.id == row.track.album.id: position = self.children.index(row) new_row = TrackRow(track, track.album.artist_ids, self._view_type) new_row.connect("destroy", self.__on_row_destroy) new_row.connect("insert-track", self.__on_insert_track) new_row.connect("insert-album", self.__on_insert_album) new_row.connect("remove-track", self.__on_remove_track) new_row.connect("do-selection", self.__on_do_selection) new_row.show() if down: position += 1 new_row.set_previous_row(row) new_row.set_next_row(row.next_row) if row.next_row is not None: row.next_row.set_previous_row(new_row) row.set_next_row(new_row) else: new_row.set_previous_row(row.previous_row) new_row.set_next_row(row) if row.previous_row is not None: row.previous_row.set_next_row(new_row) row.set_previous_row(new_row) new_row.update_number(position + 1) row.get_parent().insert(new_row, position) row.track.album.insert_track(track, position) if new_row.previous_row is not None and\ new_row.previous_row.track.id ==\ App().player.current_track.id: App().player.set_next() App().player.set_prev() # Else, we need to insert a new album with the track else: # Backup album as __destroy_split() will unset it album = row.track.album split_album = Album(album.id) split_tracks = self.__get_split_tracks(row, down) # Create new album track.album.set_tracks([track]) # We use DNDRow because we know that if tracks are DND # we are DND. Little hack if len(self.children) == len(split_tracks): if self.previous_row is not None: album = self.previous_row.album else: album = Album() elif not split_tracks: if self.next_row is not None: album = self.next_row.album else: album = Album() if album.id == track.album.id: track.set_album(album) if down: self.next_row.prepend_rows([track]) else: self.previous_row.append_rows([track]) else: self.emit("insert-album-after", album, track.album) # Create split album if split_tracks: split_album.set_tracks(split_tracks) if album.id == track.album.id: self.emit("insert-album-after", album, split_album) else: self.emit("insert-album-after", track.album, split_album) self.__destroy_split(row, down)