v0.100.0: songs a playlist already has are skipped quietly — the status bar says so for ten seconds with an Add Anyway button, instead of a prompt every time (Preferences › General › Playlists brings the prompt back)

This commit is contained in:
2026-11-21 02:15:27 -08:00
parent 6797910d76
commit 5f6f01d91c
9 changed files with 350 additions and 3 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.99.1"
__version__ = "0.100.0"
+99
View File
@@ -0,0 +1,99 @@
"""The status bar's "already in the playlist" notice (Round 132).
Adding songs a playlist already has used to stop everything with a modal
prompt. Now (unless the ``ask_on_duplicates`` preference brings the prompt
back) playlist_ops adds only the new songs and this says so in the status
bar, with an Add Anyway button that adds the rest. It shows for ``SHOW_MS``
and then fades out; the cursor over it holds it, so it never vanishes from
under a click.
"""
from PyQt6.QtCore import QPropertyAnimation, QTimer
from PyQt6.QtWidgets import (
QGraphicsOpacityEffect, QHBoxLayout, QLabel, QPushButton, QWidget)
SHOW_MS = 10_000
FADE_MS = 600
# After the cursor leaves, a little longer to come back to it.
LINGER_MS = 3_000
def message(name: str, skipped: int, added: int) -> str:
songs = "1 song was" if skipped == 1 else f"{skipped} songs were"
if added:
return (f"{songs} already in “{name}” — "
"only the new ones were added")
return f"{songs} already in “{name}” — nothing was added"
class DuplicateNotice(QWidget):
def __init__(self, prefs, parent=None):
super().__init__(parent)
self._prefs = prefs
self._action = None
layout = QHBoxLayout(self)
layout.setContentsMargins(0, 0, 6, 0)
layout.setSpacing(6)
self.label = QLabel()
layout.addWidget(self.label)
self.button = QPushButton("Add Anyway")
# The shared button face, only shrunk to fit the status bar
# (main_window._CancelSyncButton's rule).
self.button.setStyleSheet("QPushButton { padding: 0 6px; "
"min-height: 0; }")
self.button.clicked.connect(self._add_anyway)
layout.addWidget(self.button)
self._effect = QGraphicsOpacityEffect(self)
self._effect.setOpacity(1.0)
self.setGraphicsEffect(self._effect)
self._fade = QPropertyAnimation(self._effect, b"opacity", self)
self._fade.setDuration(FADE_MS)
self._fade.setStartValue(1.0)
self._fade.setEndValue(0.0)
self._fade.finished.connect(self.dismiss)
self._timer = QTimer(self)
self._timer.setSingleShot(True)
self._timer.timeout.connect(self._fade.start)
self.hide()
def quiet(self) -> bool:
"""Whether duplicates are skipped quietly (vs. asked about)."""
return not bool(self._prefs.get("ask_on_duplicates", False))
def show_skipped(self, name: str, skipped: int, added: int, action):
"""Say ``skipped`` songs were left out of ``name``; ``action`` adds
them. A newer add replaces whatever was showing."""
self._fade.stop()
self._effect.setOpacity(1.0)
self._action = action
self.label.setText(message(name, skipped, added))
self.button.setEnabled(True)
self.show()
self._timer.start(SHOW_MS)
def dismiss(self):
self._timer.stop()
self._fade.stop()
self._action = None
self.hide()
self._effect.setOpacity(1.0)
def _add_anyway(self):
action = self._action
self.dismiss()
if action is not None:
action()
def enterEvent(self, event):
if self.isVisible():
self._timer.stop()
self._fade.stop()
self._effect.setOpacity(1.0)
super().enterEvent(event)
def leaveEvent(self, event):
if self.isVisible() and self._action is not None:
self._timer.start(LINGER_MS)
super().leaveEvent(event)
+6
View File
@@ -38,6 +38,7 @@ from lintunes.gui import menu_bar, sounds, titlebar
from lintunes.gui.device_sync_dialog import (
DeviceSyncSettingsDialog, resolve_sync_playlists,
)
from lintunes.gui.duplicate_notice import DuplicateNotice
from lintunes.gui.export_dialog import ExportKindDialog, WebMixDialog
from lintunes.gui.identify_batch_dialog import IdentifyBatchDialog
from lintunes.gui.identify_dialog import IdentifyDialog
@@ -267,6 +268,11 @@ class MainWindow(QMainWindow):
# is added *last* owns the corner and never moves. The cancel button
# goes there deliberately: it is the one widget the user aims at, and
# the label beside it is as wide as the song title of the moment.
# "Already in the playlist — Add Anyway" (gui/duplicate_notice.py),
# found by playlist_ops through window().duplicate_notice. Permanent,
# so a passing showMessage can't hide it before it's read.
self.duplicate_notice = DuplicateNotice(self._prefs)
self.statusBar().addPermanentWidget(self.duplicate_notice)
self._sync_label = _StatusLabel()
self._sync_label.hide()
# A click brings back a hidden link-import progress window.
+68 -1
View File
@@ -1,8 +1,14 @@
"""Shared playlist-add logic with a duplicate-confirmation prompt.
"""Shared playlist-add logic with the duplicate guard.
All GUI paths that add tracks to a playlist (sidebar drop, drop onto an open
playlist's track list, paste) route through here so the duplicate guard is
consistent for single- and multi-track adds.
Since Round 132 the guard is quiet by default: only the songs the playlist
doesn't have yet go in, and the window's status bar says so for a while with
an Add Anyway button (``MainWindow.duplicate_notice``). The old modal prompt
comes back with the ``ask_on_duplicates`` preference, and is what a caller
with no such window (a test passing ``parent=None``) still gets.
"""
from PyQt6.QtWidgets import QMessageBox
@@ -36,6 +42,9 @@ def add_tracks_with_dup_check(manager, parent, pid, track_ids,
existing = playlist.track_ids
if has_duplicates(track_ids, existing):
notice = _quiet_notice(parent)
if notice is not None:
return _add_quietly(manager, notice, pid, track_ids, position)
to_add = _resolve_duplicates(parent, track_ids, existing)
else:
to_add = list(track_ids)
@@ -65,3 +74,61 @@ def _resolve_duplicates(parent, track_ids, existing) -> list[int]:
if clicked is skip:
return filter_for_add(track_ids, existing, add_duplicates=False)
return [] # dialog dismissed (Escape / close) -> add nothing
def _quiet_notice(parent):
"""The window's status-bar notice when duplicates are to be skipped
quietly, else None (ask with the dialog)."""
if parent is None:
return None
notice = getattr(parent.window(), "duplicate_notice", None)
if notice is None or not notice.quiet():
return None
return notice
def full_add(before, track_ids, position):
"""``before`` with every one of ``track_ids`` inserted at ``position``
(None or past the end appends) — what adding them all would make."""
after = list(before)
if position is None or position >= len(after):
after.extend(track_ids)
else:
after[position:position] = track_ids
return after
def _add_quietly(manager, notice, pid, track_ids, position) -> list[int]:
"""Add only the new songs and offer the rest in the status bar."""
playlist = manager.library.playlists[pid]
before = list(playlist.track_ids)
to_add = filter_for_add(track_ids, before, add_duplicates=False)
skipped = len(track_ids) - len(to_add)
if to_add:
manager.add_tracks_to_playlist(pid, to_add, position)
quiet_after = list(playlist.track_ids)
everything = full_add(before, list(track_ids), position)
def add_anyway():
add_skipped(manager, pid, quiet_after, everything,
[tid for tid in track_ids if tid in set(before)])
notice.show_skipped(playlist.name, skipped, len(to_add), add_anyway)
return to_add
def add_skipped(manager, pid, quiet_after, everything, duplicates):
"""Add Anyway: make the playlist what adding everything would have made.
If the playlist is still exactly as the quiet add left it, it becomes
``everything`` (the songs in the order they were dropped, at the drop
position) as one more undo step. If something changed it since, the
duplicates are appended instead, so nothing anyone did since is undone.
"""
playlist = manager.library.playlists.get(pid)
if playlist is None:
return
if list(playlist.track_ids) == quiet_after:
manager.replace_playlist_tracks(pid, everything, "Add to Playlist")
else:
manager.add_tracks_to_playlist(pid, duplicates)
+17
View File
@@ -138,6 +138,7 @@ class PreferencesDialog(QDialog):
self._headings = []
general = [self._build_playback_group(), self._build_import_group(),
self._build_playlists_group(),
self._build_sound_group(), self._build_wrapped_group()]
if self._music_folder is not None:
general.insert(0, self._build_music_group())
@@ -317,6 +318,22 @@ class PreferencesDialog(QDialog):
self._compress_cassette.setEnabled(on)
self._prefs.set("import_compress", on)
def _build_playlists_group(self) -> QGroupBox:
group = QGroupBox("Playlists")
column = QVBoxLayout(group)
self._dup_check = QCheckBox(
"Ask before adding a song a playlist already has")
self._dup_check.setChecked(
bool(self._prefs.get("ask_on_duplicates", False)))
self._dup_check.toggled.connect(
lambda on: self._prefs.set("ask_on_duplicates", on))
column.addWidget(self._dup_check)
column.addWidget(self._note(
"When it's off, only the songs the playlist doesn't have yet are "
"added, and the status bar says so for a few seconds with an "
"Add Anyway button."))
return group
def _build_sound_group(self) -> QGroupBox:
group = QGroupBox("Sound effects")
row = QHBoxLayout(group)
+13
View File
@@ -370,6 +370,19 @@ class LibraryManager(QObject):
if undoable:
self._push_track_ids("Add to Playlist", pid, before, after)
def replace_playlist_tracks(self, pid: str, track_ids: list[int],
label: str):
"""Set a regular playlist's songs to ``track_ids`` as one undo step
(playlist_ops' Add Anyway)."""
playlist = self.library.playlists.get(pid)
if not playlist or playlist.playlist_type == PlaylistType.FOLDER \
or playlist.is_smart:
return
before = list(playlist.track_ids)
after = [tid for tid in track_ids if tid in self.library.tracks]
self._set_track_ids(pid, after)
self._push_track_ids(label, pid, before, after)
def remove_tracks_from_playlist(self, pid: str, rows: list[int]):
playlist = self.library.playlists.get(pid)
if not playlist or playlist.is_smart:
+4
View File
@@ -92,6 +92,10 @@ DEFAULTS = {
"import_compress": False,
"import_compress_kbps": 256,
"import_compress_cassette": False, # ...songs from Cassette friends too
# Adding songs a playlist already has: False = add only the new ones and
# say so in the status bar with Add Anyway (gui/duplicate_notice.py);
# True = the old prompt that asks every time.
"ask_on_duplicates": False,
# The quiet "tink" when a sync, export or URL import finishes.
"sound_effects": True,
# The yearly Wrapped (storage/listen_history.py). Synced on purpose: one