MusicStorage: Add source
This commit is contained in:
parent
5d35c22238
commit
99d963b99c
|
@ -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<FilesystemMusicStorage>(dir.path, dir.id);
|
||||
storage_ << std::make_shared<FilesystemMusicStorage>(backend_->source(), dir.path, dir.id);
|
||||
appendRow(item);
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include "filesystemmusicstorage.h"
|
||||
|
||||
FilesystemMusicStorage::FilesystemMusicStorage(const QString &root, const std::optional<int> collection_directory_id) : root_(root), collection_directory_id_(collection_directory_id) {}
|
||||
FilesystemMusicStorage::FilesystemMusicStorage(const Song::Source source, const QString &root, const std::optional<int> collection_directory_id) : source_(source), root_(root), collection_directory_id_(collection_directory_id) {}
|
||||
|
||||
bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
|
||||
|
||||
|
|
|
@ -28,12 +28,14 @@
|
|||
|
||||
#include <QString>
|
||||
|
||||
#include "song.h"
|
||||
#include "musicstorage.h"
|
||||
|
||||
class FilesystemMusicStorage : public virtual MusicStorage {
|
||||
public:
|
||||
explicit FilesystemMusicStorage(const QString &root, const std::optional<int> collection_directory_id = std::optional<int>());
|
||||
explicit FilesystemMusicStorage(const Song::Source source, const QString &root, const std::optional<int> collection_directory_id = std::optional<int>());
|
||||
|
||||
Song::Source source() const override { return source_; }
|
||||
QString LocalPath() const override { return root_; }
|
||||
std::optional<int> 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<int> collection_directory_id_;
|
||||
|
||||
|
|
|
@ -3172,7 +3172,7 @@ void MainWindow::PlaylistDelete() {
|
|||
app_->player()->Next();
|
||||
}
|
||||
|
||||
std::shared_ptr<MusicStorage> storage = std::make_shared<FilesystemMusicStorage>("/");
|
||||
std::shared_ptr<MusicStorage> storage = std::make_shared<FilesystemMusicStorage>(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);
|
||||
|
|
|
@ -77,6 +77,7 @@ class MusicStorage {
|
|||
bool use_trash_;
|
||||
};
|
||||
|
||||
virtual Song::Source source() const = 0;
|
||||
virtual QString LocalPath() const { return QString(); }
|
||||
virtual std::optional<int> collection_directory_id() const { return std::optional<int>(); }
|
||||
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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_);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue