forked from trav/lintunes
v0.10.0: a first launch that welcomes you
Three things that only ever hurt new users.
The startup font modal is gone. _ensure_now_playing_font ran before
MainWindow existed, so on a machine without Century Gothic the very first
thing LinTunes did was open a parentless dialog demanding a font decision.
theme.NOW_PLAYING_FALLBACKS now picks the closest geometric sans installed
(URW Gothic, the Avant Garde clone CG derives from, leads the chain), and
the choice moved to Preferences ▸ Now-playing font. An uninstalled saved
family falls back to automatic instead of the app default.
A non-iTunes user can finally set their music folder. library.music_folder
was written in exactly one place — the iTunes importer — and with it unset
_music_import_dir fell back to a *relative* Path("Music"), resolved against
a working directory GNOME's dash does not set predictably (see
packaging/install-desktop.sh). Music scattered somewhere unfindable. Now
the first launch asks one plain-language question, Preferences can change
it later, and an import with no folder set refuses rather than guessing.
Picking ~/Music files into ~/Music, not ~/Music/Music.
music_folder is portable at last. It was the only path in the library
stored raw absolute in the *synced* metadata, so machine 2 inherited
machine 1's paths. It is now also stored relative to the data dir, the
same trick Track.location has used all along. The absolute key stays
forever as the shared floor between versions: old code reads it and
behaves exactly as before, and old code that writes the file just drops
the new keys, so no version combination hard-fails.
Two traps worth naming. set_music_folder must call
mark_library_settings_dirty() or reload_from_disk reverts the change on
the next sync tick. And the dirty flag only guards until flush, so a
music_folder_set_at stamp decides adoption semantically — _merge_metadata
picks the whole file by mtime, which moves when someone resizes a column
(the Round 39 lesson, applied to metadata).
Also: correct CLAUDE.md's claim that the importer skips smart playlists —
it imports them; system playlists are what's skipped. README gains a
"never used a terminal?" on-ramp and loses the instruction to hand-write
library_metadata.json before first launch.
Verified against the live 21,490-track library: still resolves (via the
legacy key), metadata untouched, 646 tests pass.
Claude-Session: https://claude.ai/code/session_01G4Z46BMQYS57bcbxWbSS3C
This commit is contained in:
+111
-9
@@ -9,7 +9,7 @@ from PyQt6.QtWidgets import (
|
||||
from PyQt6.QtCore import Qt, QEvent, QTimer
|
||||
from PyQt6.QtGui import QAction, QKeySequence
|
||||
|
||||
from lintunes import device_sync, mpris, tagging, theme
|
||||
from lintunes import device_sync, mpris, music_folder, tagging, theme
|
||||
from lintunes.art_search import AlbumArtFetcher
|
||||
from lintunes.cast.controller import CastController
|
||||
from lintunes.eventlog import log_control
|
||||
@@ -25,6 +25,7 @@ from lintunes.gui.library_view import LibraryView
|
||||
from lintunes.gui.playlist_view import PlaylistView
|
||||
from lintunes.gui.transport import TransportBar
|
||||
from lintunes.gui.info_dialog import InfoDialog
|
||||
from lintunes.gui.music_folder_dialog import MusicFolderDialog
|
||||
from lintunes.gui.preferences_dialog import PreferencesDialog
|
||||
from lintunes.gui.track_table import format_total_time
|
||||
from lintunes.gui.version_button import VersionButton
|
||||
@@ -126,6 +127,7 @@ class MainWindow(QMainWindow):
|
||||
# stretch would squeeze the message area to zero width and swallow
|
||||
# every message.
|
||||
self.restart_requested = False # run_gui re-execs when True on quit
|
||||
self._missing_folder_prompted = False
|
||||
self._updater = Updater(self)
|
||||
self._version_button = VersionButton(self._updater)
|
||||
self.statusBar().addWidget(self._version_button)
|
||||
@@ -261,7 +263,12 @@ class MainWindow(QMainWindow):
|
||||
|
||||
def _show_preferences(self):
|
||||
if self._prefs_dialog is None:
|
||||
self._prefs_dialog = PreferencesDialog(self._prefs, self._lastfm, self)
|
||||
self._prefs_dialog = PreferencesDialog(
|
||||
self._prefs, self._lastfm, self,
|
||||
music_folder=self._music_folder_summary,
|
||||
on_music_folder_change=self._change_music_folder)
|
||||
else:
|
||||
self._prefs_dialog.refresh_music_folder()
|
||||
self._prefs_dialog.show()
|
||||
self._prefs_dialog.raise_()
|
||||
self._prefs_dialog.activateWindow()
|
||||
@@ -554,8 +561,10 @@ class MainWindow(QMainWindow):
|
||||
return
|
||||
details = web_dialog.values()
|
||||
|
||||
start_dir = self._music_import_dir()
|
||||
parent_dir = QFileDialog.getExistingDirectory(
|
||||
self, "Export To", str(self._music_import_dir().parent))
|
||||
self, "Export To",
|
||||
str(start_dir.parent) if start_dir else str(Path.home()))
|
||||
if not parent_dir:
|
||||
return
|
||||
|
||||
@@ -777,12 +786,94 @@ class MainWindow(QMainWindow):
|
||||
ids = view.table.selected_track_ids()
|
||||
self._show_info(ids)
|
||||
|
||||
# ---- music folder ----
|
||||
|
||||
def check_music_folder(self):
|
||||
"""Ask where the music goes, if we don't already know.
|
||||
|
||||
Called once shortly after the window appears, and again lazily if an
|
||||
import happens while no folder is set. Never blocks startup: by the
|
||||
time this runs the main window is already up, so the dialog is a normal
|
||||
child dialog rather than a popup in front of an empty screen.
|
||||
"""
|
||||
state = self._manager.music_folder_state()
|
||||
if state.path is not None:
|
||||
return
|
||||
if state.source == "unset":
|
||||
if music_folder.prompt_seen():
|
||||
return
|
||||
elif self._missing_folder_prompted:
|
||||
return # asked once this session; don't nag on every import
|
||||
|
||||
dialog = MusicFolderDialog(
|
||||
self, missing_path=state.stored if state.source == "missing" else "")
|
||||
dialog.exec()
|
||||
chosen = dialog.chosen_folder()
|
||||
|
||||
# Remember we asked, whatever the answer — including "Not Now".
|
||||
music_folder.mark_prompt_seen()
|
||||
self._missing_folder_prompted = True
|
||||
|
||||
if chosen is not None:
|
||||
# A folder that exists elsewhere but not here is this machine's own
|
||||
# problem to solve; don't overwrite what the other machine set.
|
||||
self._manager.set_music_folder(
|
||||
chosen, machine_only=(state.source == "missing"))
|
||||
self.statusBar().showMessage(
|
||||
f"Music folder set to {self._manager.organize_root()}", 6000)
|
||||
|
||||
def _change_music_folder(self):
|
||||
"""Preferences ▸ Music folder ▸ Change… — pick a new one."""
|
||||
state = self._manager.music_folder_state()
|
||||
start = str(state.path) if state.path else str(Path.home())
|
||||
chosen = QFileDialog.getExistingDirectory(
|
||||
self, "Choose Music Folder", start)
|
||||
if not chosen:
|
||||
return
|
||||
|
||||
media = music_folder.normalize_media_folder(chosen)
|
||||
old_root = self._manager.organize_root()
|
||||
if old_root is not None and old_root.exists() and \
|
||||
media != Path(state.path or ""):
|
||||
# Say the quiet part out loud: nothing moves, and from here on only
|
||||
# new music goes to the new place. Otherwise the change looks total
|
||||
# but silently applies to future additions only.
|
||||
answer = QMessageBox.question(
|
||||
self, "Change music folder?",
|
||||
f"Your existing songs will stay where they are:\n{old_root}\n\n"
|
||||
f"Only music you add from now on will go to:\n"
|
||||
f"{music_folder.organize_root_for(media)}\n\n"
|
||||
"Change the folder?",
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||
QMessageBox.StandardButton.No)
|
||||
if answer != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
|
||||
self._manager.set_music_folder(
|
||||
media, machine_only=state.is_machine_local)
|
||||
self.statusBar().showMessage(
|
||||
f"Music folder set to {self._manager.organize_root()}", 6000)
|
||||
|
||||
def _music_folder_summary(self) -> tuple[str, str]:
|
||||
"""(folder, note) for the Preferences row."""
|
||||
state = self._manager.music_folder_state()
|
||||
if state.path is None:
|
||||
return ("", "Not set yet — pick a folder to start adding music.")
|
||||
if state.is_machine_local:
|
||||
return (str(state.path), "Used on this computer only.")
|
||||
return (str(state.path), "Shared with your other computers.")
|
||||
|
||||
# ---- file import ----
|
||||
|
||||
def _music_import_dir(self) -> Path:
|
||||
# Fall back to ./Music when no music folder is set (fresh library),
|
||||
# matching the pre-organize_root behavior.
|
||||
return self._manager.organize_root() or Path("Music")
|
||||
def _music_import_dir(self) -> Path | None:
|
||||
"""Where imports are filed, or None when no music folder is usable.
|
||||
|
||||
Deliberately no fallback. The old `or Path("Music")` was *relative*, so
|
||||
it resolved against the process working directory — which GNOME's dash
|
||||
does not set predictably (see packaging/install-desktop.sh), scattering
|
||||
a new user's music somewhere they'd never find it.
|
||||
"""
|
||||
return self._manager.organize_root()
|
||||
|
||||
def _open_files_dialog(self):
|
||||
paths, _filter = QFileDialog.getOpenFileNames(
|
||||
@@ -793,9 +884,20 @@ class MainWindow(QMainWindow):
|
||||
|
||||
def import_files(self, paths, playlist_pid: str = "",
|
||||
position: int | None = None):
|
||||
music_dir = self._music_import_dir()
|
||||
if music_dir is None:
|
||||
# Ask rather than guess — better one question than music copied
|
||||
# somewhere unfindable.
|
||||
self.check_music_folder()
|
||||
music_dir = self._music_import_dir()
|
||||
if music_dir is None:
|
||||
self.statusBar().showMessage(
|
||||
"Choose where to keep your music first — Edit ▸ Preferences.",
|
||||
8000)
|
||||
return []
|
||||
self.statusBar().showMessage(f"Importing {len(paths)} item(s)…")
|
||||
imported = file_importer.import_paths(
|
||||
paths, self._music_import_dir(), self._manager, playlist_pid,
|
||||
paths, music_dir, self._manager, playlist_pid,
|
||||
position)
|
||||
self.statusBar().showMessage(f"Imported {len(imported)} track(s)", 5000)
|
||||
if imported:
|
||||
@@ -981,7 +1083,7 @@ class MainWindow(QMainWindow):
|
||||
if p.exists():
|
||||
return str(p)
|
||||
music = self._music_import_dir()
|
||||
return str(music) if music.exists() else str(Path.home())
|
||||
return str(music) if music and music.exists() else str(Path.home())
|
||||
|
||||
def _on_track_missing(self, track):
|
||||
"""A track's file is gone (moved/renamed outside lintunes). Offer to
|
||||
|
||||
Reference in New Issue
Block a user