Fix library remove: delete files from disk, not just from UI
- _on_library_remove_selected now removes files from disk with confirmation - Shows count, file names, sizes, and total size in dialog - Cleans up empty parent directories after deletion - Re-scans library after deletion to refresh the UI
This commit is contained in:
parent
c68bc3a09a
commit
ea5f9d038b
50
src/main.py
50
src/main.py
@ -631,10 +631,52 @@ class MainWindow(QMainWindow):
|
|||||||
self._scan_library()
|
self._scan_library()
|
||||||
|
|
||||||
def _on_library_remove_selected(self):
|
def _on_library_remove_selected(self):
|
||||||
for item in self.library_ready_list.selectedItems():
|
"""Delete selected files from disk and clean up empty directories."""
|
||||||
self.library_ready_list.takeItem(self.library_ready_list.row(item))
|
files_to_delete = []
|
||||||
for item in self.library_source_list.selectedItems():
|
for lst in (self.library_ready_list, self.library_source_list):
|
||||||
self.library_source_list.takeItem(self.library_source_list.row(item))
|
for item in lst.selectedItems():
|
||||||
|
data = item.data(Qt.ItemDataRole.UserRole)
|
||||||
|
if data and os.path.exists(data.get("path", "")):
|
||||||
|
files_to_delete.append(data)
|
||||||
|
|
||||||
|
if not files_to_delete:
|
||||||
|
QMessageBox.information(self, "Info", "No files selected")
|
||||||
|
return
|
||||||
|
|
||||||
|
total_size = sum(f.get("size", 0) for f in files_to_delete)
|
||||||
|
details = ""
|
||||||
|
for f in files_to_delete[:15]:
|
||||||
|
details += f" {f.get('artist', 'Unknown')} {f['title']} ({self._format_size(f.get('size', 0))})\n"
|
||||||
|
if len(files_to_delete) > 15:
|
||||||
|
details += f" ... and {len(files_to_delete) - 15} more\n"
|
||||||
|
|
||||||
|
reply = QMessageBox.question(
|
||||||
|
self, "Delete Files",
|
||||||
|
f"Delete {len(files_to_delete)} file(s) from disk?\n\n{details}\n"
|
||||||
|
f"Total: {self._format_size(total_size)}\n\n"
|
||||||
|
f"This action cannot be undone.",
|
||||||
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||||
|
)
|
||||||
|
if reply != QMessageBox.StandardButton.Yes:
|
||||||
|
return
|
||||||
|
|
||||||
|
deleted = 0
|
||||||
|
for f in files_to_delete:
|
||||||
|
path = f["path"]
|
||||||
|
try:
|
||||||
|
os.remove(path)
|
||||||
|
deleted += 1
|
||||||
|
parent = os.path.dirname(path)
|
||||||
|
while parent != os.path.dirname(parent):
|
||||||
|
if os.listdir(parent):
|
||||||
|
break
|
||||||
|
os.rmdir(parent)
|
||||||
|
parent = os.path.dirname(parent)
|
||||||
|
except OSError as e:
|
||||||
|
logger.error(f"Failed to delete {path}: {e}")
|
||||||
|
|
||||||
|
self._scan_library()
|
||||||
|
QMessageBox.information(self, "Done", f"Deleted {deleted} file(s)")
|
||||||
|
|
||||||
def _on_download_clicked(self):
|
def _on_download_clicked(self):
|
||||||
url = self.url_input.text().strip()
|
url = self.url_input.text().strip()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user