File drops from the file manager insert at the drop position
The table already computed and emitted the drop row for external URL drops, but PlaylistView._on_files_dropped threw it away, so imported files always appended. Thread it through: playlist_view.files_dropped gains a row slot (None = append), MainWindow.import_files and file_importer.import_paths take an optional position and hand it to add_tracks_to_playlist, which already supported positional insert. Files already in the library dedup to the existing track and insert at the drop position without duplicating the library entry.
This commit is contained in:
@@ -99,3 +99,75 @@ class TestVisualizerGrayColor:
|
||||
def test_visualizer_row_in_preferences_dialog(self, qapp):
|
||||
from lintunes.gui.preferences_dialog import _COLOR_ROWS
|
||||
assert "color_visualizer_gray" in [key for key, _label in _COLOR_ROWS]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# 2. External file drops insert at the drop position
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def _seeded_manager(tmp_path, track_ids=(1, 2, 3)):
|
||||
from lintunes.models import Library, Track
|
||||
from lintunes.library_manager import LibraryManager
|
||||
tracks = {tid: Track(track_id=tid, name=f"T{tid}") for tid in track_ids}
|
||||
return LibraryManager(Library(tracks=tracks), tmp_path / "data")
|
||||
|
||||
|
||||
class TestFileDropPosition:
|
||||
def test_import_paths_inserts_at_position(self, qapp, tmp_path, mp3_file):
|
||||
from lintunes.importers import file_importer
|
||||
manager = _seeded_manager(tmp_path)
|
||||
playlist = manager.create_playlist("Drops")
|
||||
manager.add_tracks_to_playlist(playlist.persistent_id, [1, 2, 3])
|
||||
|
||||
imported = file_importer.import_paths(
|
||||
[mp3_file], tmp_path / "music", manager,
|
||||
playlist.persistent_id, position=1)
|
||||
|
||||
assert len(imported) == 1
|
||||
new_id = imported[0].track_id
|
||||
assert playlist.track_ids == [1, new_id, 2, 3]
|
||||
|
||||
def test_import_paths_default_appends(self, qapp, tmp_path, mp3_file):
|
||||
from lintunes.importers import file_importer
|
||||
manager = _seeded_manager(tmp_path)
|
||||
playlist = manager.create_playlist("Drops")
|
||||
manager.add_tracks_to_playlist(playlist.persistent_id, [1, 2])
|
||||
|
||||
imported = file_importer.import_paths(
|
||||
[mp3_file], tmp_path / "music", manager, playlist.persistent_id)
|
||||
|
||||
assert playlist.track_ids == [1, 2, imported[0].track_id]
|
||||
|
||||
def test_duplicate_file_inserts_without_new_track(self, qapp, tmp_path,
|
||||
mp3_file):
|
||||
from lintunes.importers import file_importer
|
||||
manager = _seeded_manager(tmp_path)
|
||||
existing = file_importer.import_file(
|
||||
mp3_file, tmp_path / "music", manager)
|
||||
playlist = manager.create_playlist("Drops")
|
||||
manager.add_tracks_to_playlist(playlist.persistent_id, [1, 2])
|
||||
count_before = len(manager.library.tracks)
|
||||
|
||||
imported = file_importer.import_paths(
|
||||
[mp3_file], tmp_path / "music", manager,
|
||||
playlist.persistent_id, position=0)
|
||||
|
||||
assert imported[0].track_id == existing.track_id
|
||||
assert playlist.track_ids == [existing.track_id, 1, 2]
|
||||
assert len(manager.library.tracks) == count_before
|
||||
|
||||
def test_playlist_view_relays_drop_row(self, qapp, tmp_path):
|
||||
from lintunes.gui.playlist_view import PlaylistView
|
||||
manager = _seeded_manager(tmp_path)
|
||||
playlist = manager.create_playlist("Drops")
|
||||
view = PlaylistView(manager)
|
||||
view.show_playlist(playlist)
|
||||
received = []
|
||||
view.files_dropped.connect(
|
||||
lambda paths, pid, row: received.append((paths, pid, row)))
|
||||
|
||||
view._on_files_dropped(["/x.mp3"], 2)
|
||||
view._on_files_dropped(["/y.mp3"], None)
|
||||
|
||||
assert received == [(["/x.mp3"], playlist.persistent_id, 2),
|
||||
(["/y.mp3"], playlist.persistent_id, None)]
|
||||
|
||||
Reference in New Issue
Block a user