From 5ae0320911e0d72583732746019773bd32124f8e Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 8 Mar 2025 21:46:27 +0100 Subject: [PATCH] CollectionBackend: Add delete songs by URLs function --- src/collection/collectionbackend.cpp | 24 +++++++++++++++++++++++- src/collection/collectionbackend.h | 6 +++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/collection/collectionbackend.cpp b/src/collection/collectionbackend.cpp index 4c783c514..e509f743b 100644 --- a/src/collection/collectionbackend.cpp +++ b/src/collection/collectionbackend.cpp @@ -2,7 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome - * Copyright 2018-2024, Jonas Kvinge + * Copyright 2018-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -853,6 +853,10 @@ void CollectionBackend::UpdateMTimesOnly(const SongList &songs) { } +void CollectionBackend::DeleteSongsAsync(const SongList &songs) { + QMetaObject::invokeMethod(this, "DeleteSongs", Qt::QueuedConnection, Q_ARG(SongList, songs)); +} + void CollectionBackend::DeleteSongs(const SongList &songs) { QMutexLocker l(db_->Mutex()); @@ -879,6 +883,24 @@ void CollectionBackend::DeleteSongs(const SongList &songs) { } +void CollectionBackend::DeleteSongsByUrlsAsync(const QList &urls) { + QMetaObject::invokeMethod(this, "DeleteSongsByUrl", Qt::QueuedConnection, Q_ARG(QList, urls)); +} + +void CollectionBackend::DeleteSongsByUrls(const QList &urls) { + + SongList songs; + songs.reserve(urls.count()); + for (const QUrl &url : urls) { + songs << GetSongsByUrl(url); + } + + if (!songs.isEmpty()) { + DeleteSongs(songs); + } + +} + void CollectionBackend::MarkSongsUnavailable(const SongList &songs, const bool unavailable) { QMutexLocker l(db_->Mutex()); diff --git a/src/collection/collectionbackend.h b/src/collection/collectionbackend.h index 0e996cf08..ed769f8a1 100644 --- a/src/collection/collectionbackend.h +++ b/src/collection/collectionbackend.h @@ -2,7 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome - * Copyright 2018-2024, Jonas Kvinge + * Copyright 2018-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -234,6 +234,9 @@ class CollectionBackend : public CollectionBackendInterface { void UpdateSongRatingAsync(const int id, const float rating, const bool save_tags = false); void UpdateSongsRatingAsync(const QList &ids, const float rating, const bool save_tags = false); + void DeleteSongsAsync(const SongList &songs); + void DeleteSongsByUrlsAsync(const QList &url); + public Q_SLOTS: void Exit(); void GetAllSongs(const int id); @@ -247,6 +250,7 @@ class CollectionBackend : public CollectionBackendInterface { void UpdateSongsBySongID(const SongMap &new_songs); void UpdateMTimesOnly(const SongList &songs); void DeleteSongs(const SongList &songs); + void DeleteSongsByUrls(const QList &url); void MarkSongsUnavailable(const SongList &songs, const bool unavailable = true); void AddOrUpdateSubdirs(const CollectionSubdirectoryList &subdirs); void CompilationsNeedUpdating();