Igen
This commit is contained in:
@@ -107,19 +107,35 @@ class LibraryManagerDialog(QDialog):
|
||||
layout.addLayout(btn_row)
|
||||
|
||||
def _load(self):
|
||||
# Ryd eksisterende widgets
|
||||
while self._libs_layout.count():
|
||||
item = self._libs_layout.takeAt(0)
|
||||
if item.widget():
|
||||
item.widget().deleteLater()
|
||||
|
||||
try:
|
||||
from local.local_db import get_libraries, get_db
|
||||
import sqlite3
|
||||
from local.local_db import DB_PATH, get_libraries
|
||||
libs = get_libraries(active_only=True)
|
||||
for lib in libs:
|
||||
self._libs_layout.addWidget(self._make_lib_row(lib))
|
||||
conn = sqlite3.connect(str(DB_PATH))
|
||||
conn.row_factory = sqlite3.Row
|
||||
count = conn.execute(
|
||||
"SELECT COUNT(*) FROM songs WHERE library_id=? AND file_missing=0",
|
||||
(lib["id"],)
|
||||
).fetchone()[0]
|
||||
missing_bpm = conn.execute(
|
||||
"SELECT COUNT(*) FROM songs WHERE library_id=? AND file_missing=0 "
|
||||
"AND (bpm IS NULL OR bpm=0)",
|
||||
(lib["id"],)
|
||||
).fetchone()[0]
|
||||
conn.close()
|
||||
lib_dict = dict(lib)
|
||||
lib_dict["_count"] = count
|
||||
lib_dict["_missing_bpm"] = missing_bpm
|
||||
self._libs_layout.addWidget(self._make_lib_row(lib_dict))
|
||||
except Exception as e:
|
||||
pass
|
||||
lbl = QLabel(f"Fejl: {e}")
|
||||
self._libs_layout.addWidget(lbl)
|
||||
|
||||
def _make_lib_row(self, lib: dict) -> QFrame:
|
||||
from pathlib import Path
|
||||
@@ -137,21 +153,8 @@ class LibraryManagerDialog(QDialog):
|
||||
last_scan = lib.get("last_full_scan") or "aldrig"
|
||||
if isinstance(last_scan, str) and len(last_scan) > 10:
|
||||
last_scan = last_scan[:10]
|
||||
try:
|
||||
from local.local_db import get_db
|
||||
with get_db() as conn:
|
||||
total = conn.execute(
|
||||
"SELECT COUNT(*) FROM songs WHERE library_id=? AND file_missing=0",
|
||||
(lib_id,)
|
||||
).fetchone()[0]
|
||||
missing_bpm = conn.execute(
|
||||
"SELECT COUNT(*) FROM songs WHERE library_id=? AND file_missing=0 "
|
||||
"AND (bpm IS NULL OR bpm=0)",
|
||||
(lib_id,)
|
||||
).fetchone()[0]
|
||||
except Exception:
|
||||
total = 0
|
||||
missing_bpm = 0
|
||||
total = lib.get("_count", 0)
|
||||
missing_bpm = lib.get("_missing_bpm", 0)
|
||||
|
||||
lbl_path = QLabel(("⚠ " if not exists else "") + path)
|
||||
lbl_path.setObjectName("track_title" if exists else "result_count")
|
||||
@@ -175,13 +178,13 @@ class LibraryManagerDialog(QDialog):
|
||||
btn_row.setSpacing(6)
|
||||
|
||||
btn_scan = QPushButton("⟳ Fil-scan")
|
||||
btn_scan.setFixedHeight(24)
|
||||
btn_scan.setFixedHeight(30)
|
||||
btn_scan.setToolTip("Scan for nye og ændrede filer")
|
||||
btn_scan.clicked.connect(lambda _, lid=lib_id, p=path: self._scan_files(lid, p))
|
||||
btn_row.addWidget(btn_scan)
|
||||
|
||||
btn_bpm = QPushButton(f"♩ BPM manglende ({missing_bpm})")
|
||||
btn_bpm.setFixedHeight(24)
|
||||
btn_bpm.setFixedHeight(30)
|
||||
btn_bpm.setToolTip("Analysér BPM på sange der mangler det")
|
||||
btn_bpm.setEnabled(missing_bpm > 0)
|
||||
btn_bpm.clicked.connect(
|
||||
@@ -190,7 +193,7 @@ class LibraryManagerDialog(QDialog):
|
||||
btn_row.addWidget(btn_bpm)
|
||||
|
||||
btn_bpm_all = QPushButton("♩ BPM alle")
|
||||
btn_bpm_all.setFixedHeight(24)
|
||||
btn_bpm_all.setFixedHeight(30)
|
||||
btn_bpm_all.setToolTip("Genanalysér BPM på alle sange (overskriver eksisterende)")
|
||||
btn_bpm_all.clicked.connect(
|
||||
lambda _, lid=lib_id, b=btn_bpm_all, s=lbl_status: self._start_bpm(lid, True, b, s)
|
||||
@@ -200,7 +203,7 @@ class LibraryManagerDialog(QDialog):
|
||||
btn_row.addStretch()
|
||||
|
||||
btn_remove = QPushButton("✕ Fjern")
|
||||
btn_remove.setFixedHeight(24)
|
||||
btn_remove.setFixedHeight(30)
|
||||
btn_remove.clicked.connect(lambda _, l=lib: self._remove_library(l))
|
||||
btn_row.addWidget(btn_remove)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user