Compare commits

...

2 Commits

Author SHA1 Message Date
Keith Edmunds
8fa98a2207 Have model check for adding existing track 2025-04-15 21:22:07 +01:00
Keith Edmunds
e7af25ad6e Restore last open playlists in correct order 2025-04-15 18:24:56 +01:00
5 changed files with 44 additions and 44 deletions

View File

@ -140,9 +140,9 @@ class TrackInsertDialog(QDialog):
insert_track_data = InsertTrack(self.playlist_id, track_id, note_text) insert_track_data = InsertTrack(self.playlist_id, track_id, note_text)
self.title_edit.clear() self.title_edit.selectAll()
self.title_edit.setFocus()
self.note_edit.clear() self.note_edit.clear()
self.track_list.clear()
self.title_edit.setFocus() self.title_edit.setFocus()
if self.add_to_header: if self.add_to_header:

View File

@ -529,7 +529,7 @@ def _playlists_where(
Playlists.id.label("playlist_id"), Playlists.id.label("playlist_id"),
Playlists.name, Playlists.name,
Playlists.open, Playlists.open,
).where(query) ).where(query).order_by(Playlists.tab)
results: list[PlaylistDTO] = [] results: list[PlaylistDTO] = []
@ -681,7 +681,7 @@ def playlist_mark_status(playlist_id: int, open: bool) -> None:
.values(open=open) .values(open=open)
) )
session.commit() session.commit()
# @log_call # @log_call
@ -796,7 +796,7 @@ def playlist_rename(playlist_id: int, new_name: str) -> None:
.values(name=new_name) .values(name=new_name)
) )
session.commit() session.commit()
def playlist_row_count(playlist_id: int) -> int: def playlist_row_count(playlist_id: int) -> int:

View File

@ -766,8 +766,9 @@ class PreviewManager:
class QueryDialog(QDialog): class QueryDialog(QDialog):
"""Dialog box to handle selecting track from a query""" """Dialog box to handle selecting track from a query"""
def __init__(self, default: int = 0) -> None: def __init__(self, playlist_id: int, default: int = 0) -> None:
super().__init__() super().__init__()
self.playlist_id = playlist_id
self.default = default self.default = default
# Build a list of (query-name, playlist-id) tuples # Build a list of (query-name, playlist-id) tuples
@ -858,6 +859,13 @@ class QueryDialog(QDialog):
def add_tracks_clicked(self): def add_tracks_clicked(self):
self.selected_tracks = self.table_view.model().get_selected_track_ids() self.selected_tracks = self.table_view.model().get_selected_track_ids()
# new_row_number = self.current_row_or_end()
# base_model = self.current.base_model
for track_id in self.query_dialog.selected_tracks:
insert_track_data = InsertTrack(self.playlist_id, track_id, note="")
self.signals.signal_insert_track.emit(InsertTrack(insert_track_data))
self.accept() self.accept()
def cancel_clicked(self): def cancel_clicked(self):
@ -1553,35 +1561,8 @@ class Window(QMainWindow):
""" """
# Keep a reference else it will be gc'd # Keep a reference else it will be gc'd
self.query_dialog = QueryDialog(query_id) self.query_dialog = QueryDialog(self.current.playlist_id, query_id)
if self.query_dialog.exec(): self.query_dialog.exec()
new_row_number = self.current_row_or_end()
base_model = self.current.base_model
for track_id in self.query_dialog.selected_tracks:
# Check whether track is already in playlist
move_existing = False
existing_prd = base_model.is_track_in_playlist(track_id)
if existing_prd is not None:
if ask_yes_no(
"Duplicate row",
"Track already in playlist. " "Move to new location?",
default_yes=True,
):
move_existing = True
if move_existing and existing_prd:
base_model.move_track_add_note(
new_row_number, existing_prd, note=""
)
else:
self.signals.signal_insert_track.emit(
InsertTrack(
playlist_id=base_model.playlist_id,
track_id=track_id,
note="",
)
)
new_row_number += 1
# # # # # # # # # # Miscellaneous functions # # # # # # # # # # # # # # # # # # # # Miscellaneous functions # # # # # # # # # #

View File

@ -692,14 +692,31 @@ class PlaylistModel(QAbstractTableModel):
new_row_number = self._get_new_row_number() new_row_number = self._get_new_row_number()
super().beginInsertRows(QModelIndex(), new_row_number, new_row_number) # Check whether track is already in playlist
move_existing = False
if row_data.track_id:
existing_plr = self.is_track_in_playlist(row_data.track_id)
if existing_plr is not None:
if ask_yes_no(
"Duplicate row",
"Track already in playlist. " "Move to new location?",
default_yes=True,
):
move_existing = True
_ = ds.playlist_insert_row( if move_existing and existing_plr:
playlist_id=self.playlist_id, self.move_track_add_note(
row_number=new_row_number, new_row_number, existing_plr, note=""
track_id=row_data.track_id, )
note=row_data.note, else:
) super().beginInsertRows(QModelIndex(), new_row_number, new_row_number)
_ = ds.playlist_insert_row(
playlist_id=self.playlist_id,
row_number=new_row_number,
track_id=row_data.track_id,
note=row_data.note,
)
# Need to refresh self.playlist_rows because row numbers will have # Need to refresh self.playlist_rows because row numbers will have
# changed # changed
self.refresh_data() self.refresh_data()

View File

@ -214,8 +214,10 @@ class PlaylistRow:
@row_number.setter @row_number.setter
def row_number(self, value: int) -> None: def row_number(self, value: int) -> None:
# This does not update the database which must take place # This does not update the database. The only times the row
# elsewhere # number changes are 1) in ds._playlist_check_playlist and
# ds.playlist_move_rows, and in both those places ds saves
# the change to the database.
self.dto.row_number = value self.dto.row_number = value
def check_for_end_of_track(self) -> None: def check_for_end_of_track(self) -> None: