From 99d963b99c4271de78a81e8c535cbc9c1b891ee7 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 19 Oct 2022 18:36:33 +0200 Subject: [PATCH] MusicStorage: Add source --- src/collection/collectiondirectorymodel.cpp | 2 +- src/core/filesystemmusicstorage.cpp | 2 +- src/core/filesystemmusicstorage.h | 5 ++++- src/core/mainwindow.cpp | 2 +- src/core/musicstorage.h | 1 + src/device/connecteddevice.h | 2 ++ src/device/filesystemdevice.cpp | 2 +- src/device/filesystemdevice.h | 2 ++ src/organize/organize.cpp | 2 +- src/widgets/fileview.cpp | 2 +- 10 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/collection/collectiondirectorymodel.cpp b/src/collection/collectiondirectorymodel.cpp index dbd150a93..eceb709c1 100644 --- a/src/collection/collectiondirectorymodel.cpp +++ b/src/collection/collectiondirectorymodel.cpp @@ -51,7 +51,7 @@ void CollectionDirectoryModel::DirectoryDiscovered(const Directory &dir) { QStandardItem *item = new QStandardItem(dir.path); item->setData(dir.id, kIdRole); item->setIcon(dir_icon_); - storage_ << std::make_shared(dir.path, dir.id); + storage_ << std::make_shared(backend_->source(), dir.path, dir.id); appendRow(item); } diff --git a/src/core/filesystemmusicstorage.cpp b/src/core/filesystemmusicstorage.cpp index 230b676b9..69ae26638 100644 --- a/src/core/filesystemmusicstorage.cpp +++ b/src/core/filesystemmusicstorage.cpp @@ -34,7 +34,7 @@ #include "filesystemmusicstorage.h" -FilesystemMusicStorage::FilesystemMusicStorage(const QString &root, const std::optional collection_directory_id) : root_(root), collection_directory_id_(collection_directory_id) {} +FilesystemMusicStorage::FilesystemMusicStorage(const Song::Source source, const QString &root, const std::optional collection_directory_id) : source_(source), root_(root), collection_directory_id_(collection_directory_id) {} bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) { diff --git a/src/core/filesystemmusicstorage.h b/src/core/filesystemmusicstorage.h index 6a5766eee..a4cfc29f5 100644 --- a/src/core/filesystemmusicstorage.h +++ b/src/core/filesystemmusicstorage.h @@ -28,12 +28,14 @@ #include +#include "song.h" #include "musicstorage.h" class FilesystemMusicStorage : public virtual MusicStorage { public: - explicit FilesystemMusicStorage(const QString &root, const std::optional collection_directory_id = std::optional()); + explicit FilesystemMusicStorage(const Song::Source source, const QString &root, const std::optional collection_directory_id = std::optional()); + Song::Source source() const override { return source_; } QString LocalPath() const override { return root_; } std::optional collection_directory_id() const override { return collection_directory_id_; } @@ -41,6 +43,7 @@ class FilesystemMusicStorage : public virtual MusicStorage { bool DeleteFromStorage(const DeleteJob &job) override; private: + Song::Source source_; QString root_; std::optional collection_directory_id_; diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 1be8ebda8..c19828d70 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -3172,7 +3172,7 @@ void MainWindow::PlaylistDelete() { app_->player()->Next(); } - std::shared_ptr storage = std::make_shared("/"); + std::shared_ptr storage = std::make_shared(Song::Source_LocalFile, "/"); DeleteFiles *delete_files = new DeleteFiles(app_->task_manager(), storage, true); //QObject::connect(delete_files, &DeleteFiles::Finished, this, &MainWindow::DeleteFinished); delete_files->Start(selected_songs); diff --git a/src/core/musicstorage.h b/src/core/musicstorage.h index 75742f4bc..97b824995 100644 --- a/src/core/musicstorage.h +++ b/src/core/musicstorage.h @@ -77,6 +77,7 @@ class MusicStorage { bool use_trash_; }; + virtual Song::Source source() const = 0; virtual QString LocalPath() const { return QString(); } virtual std::optional collection_directory_id() const { return std::optional(); } diff --git a/src/device/connecteddevice.h b/src/device/connecteddevice.h index b57208e06..cba039a60 100644 --- a/src/device/connecteddevice.h +++ b/src/device/connecteddevice.h @@ -46,6 +46,8 @@ class ConnectedDevice : public QObject, public virtual MusicStorage, public std: explicit ConnectedDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr); ~ConnectedDevice() override; + Song::Source source() const override { return Song::Source_Device; } + virtual bool Init() = 0; virtual bool IsLoading() { return false; } virtual void NewConnection() {} diff --git a/src/device/filesystemdevice.cpp b/src/device/filesystemdevice.cpp index 53557e1e1..880326963 100644 --- a/src/device/filesystemdevice.cpp +++ b/src/device/filesystemdevice.cpp @@ -39,7 +39,7 @@ class DeviceLister; FilesystemDevice::FilesystemDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, const int database_id, const bool first_time, QObject *parent) - : FilesystemMusicStorage(url.toLocalFile()), + : FilesystemMusicStorage(Song::Source_Device, url.toLocalFile()), ConnectedDevice(url, lister, unique_id, manager, app, database_id, first_time, parent), watcher_(new CollectionWatcher(Song::Source_Device)), watcher_thread_(new QThread(this)) { diff --git a/src/device/filesystemdevice.h b/src/device/filesystemdevice.h index 4035a414b..80eb1c3d2 100644 --- a/src/device/filesystemdevice.h +++ b/src/device/filesystemdevice.h @@ -46,6 +46,8 @@ class FilesystemDevice : public ConnectedDevice, public virtual FilesystemMusicS Q_INVOKABLE FilesystemDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr); ~FilesystemDevice() override; + Song::Source source() const final { return Song::Source_Device; } + bool Init() override; void CloseAsync(); diff --git a/src/organize/organize.cpp b/src/organize/organize.cpp index 69491c2e5..d11bd1c2a 100644 --- a/src/organize/organize.cpp +++ b/src/organize/organize.cpp @@ -249,7 +249,7 @@ void Organize::ProcessSomeFiles() { job.progress_ = std::bind(&Organize::SetSongProgress, this, std::placeholders::_1, !task.transcoded_filename_.isEmpty()); if (destination_->CopyToStorage(job)) { - if (job.remove_original_ && (song.is_collection_song() || song.source() == Song::Source_Device)) { + if (job.remove_original_ && (destination_->source() == Song::Source_Collection || destination_->source() == Song::Source_Device)) { // Notify other aspects of system that song has been invalidated QString root = destination_->LocalPath(); QFileInfo new_file = QFileInfo(root + "/" + task.song_info_.new_filename_); diff --git a/src/widgets/fileview.cpp b/src/widgets/fileview.cpp index b064a9bc6..361910886 100644 --- a/src/widgets/fileview.cpp +++ b/src/widgets/fileview.cpp @@ -60,7 +60,7 @@ FileView::FileView(QWidget *parent) model_(nullptr), undo_stack_(new QUndoStack(this)), task_manager_(nullptr), - storage_(new FilesystemMusicStorage("/")) { + storage_(new FilesystemMusicStorage(Song::Source_LocalFile, "/")) { ui_->setupUi(this);