From e8d9cf8f0096bad39e47c5d79786c7580d6f1200 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Fri, 26 Sep 2025 00:38:44 +0100 Subject: [PATCH] Ensure track marked as played in playlist Fixes #295 --- app/playlistmodel.py | 59 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/app/playlistmodel.py b/app/playlistmodel.py index e930884..e9c7e63 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -288,7 +288,6 @@ class PlaylistModel(QAbstractTableModel): # Update Playdates in database log.debug(f"{self}: update playdates {track_id=}") Playdates(session, track_id) - session.commit() # Mark track as played in playlist log.debug(f"{self}: Mark track as played") @@ -298,39 +297,41 @@ class PlaylistModel(QAbstractTableModel): self.refresh_row(session, plr.row_number) else: log.error( - f"{self}: Can't retrieve plr, {track_sequence.current.playlistrow_id=}" + f"{self}: Can't retrieve plr, " + f"{track_sequence.current.playlistrow_id=}" ) + session.commit() - # Update colour and times for current row + # Update colour and times for current row + # only invalidate required roles + roles = [ + Qt.ItemDataRole.DisplayRole + ] + self.invalidate_row(row_number, roles) + + # Update previous row in case we're hiding played rows + if track_sequence.previous and track_sequence.previous.row_number: # only invalidate required roles - roles = [ - Qt.ItemDataRole.DisplayRole - ] - self.invalidate_row(row_number, roles) + self.invalidate_row(track_sequence.previous.row_number, roles) - # Update previous row in case we're hiding played rows - if track_sequence.previous and track_sequence.previous.row_number: - # only invalidate required roles - self.invalidate_row(track_sequence.previous.row_number, roles) + # Update all other track times + self.update_track_times() - # Update all other track times - self.update_track_times() - - # Find next track - next_row = None - unplayed_rows = [ - a - for a in self.get_unplayed_rows() - if not self.is_header_row(a) - and not file_is_unreadable(self.playlist_rows[a].path) - ] - if unplayed_rows: - try: - next_row = min([a for a in unplayed_rows if a > row_number]) - except ValueError: - next_row = min(unplayed_rows) - if next_row is not None: - self.set_next_row(next_row) + # Find next track + next_row = None + unplayed_rows = [ + a + for a in self.get_unplayed_rows() + if not self.is_header_row(a) + and not file_is_unreadable(self.playlist_rows[a].path) + ] + if unplayed_rows: + try: + next_row = min([a for a in unplayed_rows if a > row_number]) + except ValueError: + next_row = min(unplayed_rows) + if next_row is not None: + self.set_next_row(next_row) def data( self, index: QModelIndex, role: int = Qt.ItemDataRole.DisplayRole