Rework track hiding logic

Fixes #248
This commit is contained in:
Keith Edmunds 2024-07-19 15:58:58 +01:00
parent a51dd3a998
commit 30d8b0d5c8

View File

@ -1516,59 +1516,52 @@ class PlaylistProxyModel(QSortFilterProxyModel):
def filterAcceptsRow(self, source_row: int, source_parent: QModelIndex) -> bool:
"""
Subclass to filter by played status
Subclass to filter by played status. Return True to show this row, False to hide it.
"""
if self.source_model.played_tracks_hidden:
if self.source_model.is_played_row(source_row):
# Don't hide current or next track
with db.Session() as session:
if track_sequence.next:
next_plr = session.get(PlaylistRows, track_sequence.next.plr_id)
if (
next_plr
and next_plr.plr_rownum == source_row
and next_plr.playlist_id == self.source_model.playlist_id
):
return True
if track_sequence.current:
now_plr = session.get(
PlaylistRows, track_sequence.current.plr_id
)
if (
now_plr
and now_plr.plr_rownum == source_row
and now_plr.playlist_id == self.source_model.playlist_id
):
return True
# Don't hide previous track until
# HIDE_AFTER_PLAYING_OFFSET milliseconds after
# current track has started
if track_sequence.previous:
previous_plr = session.get(
PlaylistRows, track_sequence.previous.plr_id
)
# Don't hide current track
if (
track_sequence.current
and previous_plr
and previous_plr.plr_rownum == source_row
and previous_plr.playlist_id
== self.source_model.playlist_id
and track_sequence.current.playlist_id == self.source_model.playlist_id
and track_sequence.current.row_number == source_row
):
if track_sequence.current.start_time:
if dt.datetime.now() > (
return True
# Don't hide next track
if (
track_sequence.next
and track_sequence.next.playlist_id == self.source_model.playlist_id
and track_sequence.next.row_number == source_row
):
return True
# Handle previous track
if track_sequence.previous:
if (
track_sequence.previous.playlist_id != self.source_model.playlist_id
or track_sequence.previous.row_number != source_row
):
# This row isn't our previous track: hide it
return False
if track_sequence.current and track_sequence.current.start_time:
# This row is our previous track. Don't hide it
# until HIDE_AFTER_PLAYING_OFFSET milliseconds
# after current track has started
if (
track_sequence.current.start_time
+ dt.timedelta(
milliseconds=Config.HIDE_AFTER_PLAYING_OFFSET
and dt.datetime.now() > (
track_sequence.current.start_time
+ dt.timedelta(milliseconds=Config.HIDE_AFTER_PLAYING_OFFSET)
)
):
return False
else:
# Invalidate this row in
# HIDE_AFTER_PLAYING_OFFSET and a
# bit milliseconds
# so that it hides then - add 100mS
# on so that it if clause above it
# HIDE_AFTER_PLAYING_OFFSET and a bit
# milliseconds so that it hides then. We add
# 100mS on so that the if clause above is
# true next time through.
QTimer.singleShot(
Config.HIDE_AFTER_PLAYING_OFFSET + 100,
@ -1577,10 +1570,13 @@ class PlaylistProxyModel(QSortFilterProxyModel):
),
)
return True
# Next track not playing yet so don't hide previous
else:
return True
# No previous track so hide this played track immediately
return False
return super().filterAcceptsRow(source_row, source_parent)
def set_incremental_search(self, search_string: str) -> None: