@@ -21,6 +21,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
@@ -43,6 +45,9 @@
|
||||
#include "scrobbler/lastfmimport.h"
|
||||
#include "settings/collectionsettingspage.h"
|
||||
|
||||
using std::make_unique;
|
||||
using std::make_shared;
|
||||
|
||||
const char *SCollection::kSongsTable = "songs";
|
||||
const char *SCollection::kFtsTable = "songs_fts";
|
||||
const char *SCollection::kDirsTable = "directories";
|
||||
@@ -61,9 +66,9 @@ SCollection::SCollection(Application *app, QObject *parent)
|
||||
|
||||
original_thread_ = thread();
|
||||
|
||||
backend_ = new CollectionBackend();
|
||||
backend_ = make_shared<CollectionBackend>();
|
||||
backend()->moveToThread(app->database()->thread());
|
||||
qLog(Debug) << backend_ << "moved to thread" << app->database()->thread();
|
||||
qLog(Debug) << &*backend_ << "moved to thread" << app->database()->thread();
|
||||
|
||||
backend_->Init(app->database(), app->task_manager(), Song::Source::Collection, kSongsTable, kFtsTable, kDirsTable, kSubdirsTable);
|
||||
|
||||
@@ -83,44 +88,43 @@ SCollection::~SCollection() {
|
||||
watcher_thread_->exit();
|
||||
watcher_thread_->wait(5000);
|
||||
}
|
||||
backend_->deleteLater();
|
||||
|
||||
}
|
||||
|
||||
void SCollection::Init() {
|
||||
|
||||
watcher_ = new CollectionWatcher(Song::Source::Collection);
|
||||
watcher_ = make_unique<CollectionWatcher>(Song::Source::Collection);
|
||||
watcher_thread_ = new Thread(this);
|
||||
|
||||
watcher_thread_->SetIoPriority(Utilities::IoPriority::IOPRIO_CLASS_IDLE);
|
||||
|
||||
watcher_->moveToThread(watcher_thread_);
|
||||
|
||||
qLog(Debug) << watcher_ << "moved to thread" << watcher_thread_;
|
||||
qLog(Debug) << &*watcher_ << "moved to thread" << watcher_thread_;
|
||||
|
||||
watcher_thread_->start(QThread::IdlePriority);
|
||||
|
||||
watcher_->set_backend(backend_);
|
||||
watcher_->set_task_manager(app_->task_manager());
|
||||
|
||||
QObject::connect(backend_, &CollectionBackend::Error, this, &SCollection::Error);
|
||||
QObject::connect(backend_, &CollectionBackend::DirectoryDiscovered, watcher_, &CollectionWatcher::AddDirectory);
|
||||
QObject::connect(backend_, &CollectionBackend::DirectoryDeleted, watcher_, &CollectionWatcher::RemoveDirectory);
|
||||
QObject::connect(backend_, &CollectionBackend::SongsRatingChanged, this, &SCollection::SongsRatingChanged);
|
||||
QObject::connect(backend_, &CollectionBackend::SongsStatisticsChanged, this, &SCollection::SongsPlaycountChanged);
|
||||
QObject::connect(&*backend_, &CollectionBackend::Error, this, &SCollection::Error);
|
||||
QObject::connect(&*backend_, &CollectionBackend::DirectoryDiscovered, &*watcher_, &CollectionWatcher::AddDirectory);
|
||||
QObject::connect(&*backend_, &CollectionBackend::DirectoryDeleted, &*watcher_, &CollectionWatcher::RemoveDirectory);
|
||||
QObject::connect(&*backend_, &CollectionBackend::SongsRatingChanged, this, &SCollection::SongsRatingChanged);
|
||||
QObject::connect(&*backend_, &CollectionBackend::SongsStatisticsChanged, this, &SCollection::SongsPlaycountChanged);
|
||||
|
||||
QObject::connect(watcher_, &CollectionWatcher::NewOrUpdatedSongs, backend_, &CollectionBackend::AddOrUpdateSongs);
|
||||
QObject::connect(watcher_, &CollectionWatcher::SongsMTimeUpdated, backend_, &CollectionBackend::UpdateMTimesOnly);
|
||||
QObject::connect(watcher_, &CollectionWatcher::SongsDeleted, backend_, &CollectionBackend::DeleteSongs);
|
||||
QObject::connect(watcher_, &CollectionWatcher::SongsUnavailable, backend_, &CollectionBackend::MarkSongsUnavailable);
|
||||
QObject::connect(watcher_, &CollectionWatcher::SongsReadded, backend_, &CollectionBackend::MarkSongsUnavailable);
|
||||
QObject::connect(watcher_, &CollectionWatcher::SubdirsDiscovered, backend_, &CollectionBackend::AddOrUpdateSubdirs);
|
||||
QObject::connect(watcher_, &CollectionWatcher::SubdirsMTimeUpdated, backend_, &CollectionBackend::AddOrUpdateSubdirs);
|
||||
QObject::connect(watcher_, &CollectionWatcher::CompilationsNeedUpdating, backend_, &CollectionBackend::CompilationsNeedUpdating);
|
||||
QObject::connect(watcher_, &CollectionWatcher::UpdateLastSeen, backend_, &CollectionBackend::UpdateLastSeen);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::NewOrUpdatedSongs, &*backend_, &CollectionBackend::AddOrUpdateSongs);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::SongsMTimeUpdated, &*backend_, &CollectionBackend::UpdateMTimesOnly);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::SongsDeleted, &*backend_, &CollectionBackend::DeleteSongs);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::SongsUnavailable, &*backend_, &CollectionBackend::MarkSongsUnavailable);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::SongsReadded, &*backend_, &CollectionBackend::MarkSongsUnavailable);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::SubdirsDiscovered, &*backend_, &CollectionBackend::AddOrUpdateSubdirs);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::SubdirsMTimeUpdated, &*backend_, &CollectionBackend::AddOrUpdateSubdirs);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::CompilationsNeedUpdating, &*backend_, &CollectionBackend::CompilationsNeedUpdating);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::UpdateLastSeen, &*backend_, &CollectionBackend::UpdateLastSeen);
|
||||
|
||||
QObject::connect(app_->lastfm_import(), &LastFMImport::UpdateLastPlayed, backend_, &CollectionBackend::UpdateLastPlayed);
|
||||
QObject::connect(app_->lastfm_import(), &LastFMImport::UpdatePlayCount, backend_, &CollectionBackend::UpdatePlayCount);
|
||||
QObject::connect(&*app_->lastfm_import(), &LastFMImport::UpdateLastPlayed, &*backend_, &CollectionBackend::UpdateLastPlayed);
|
||||
QObject::connect(&*app_->lastfm_import(), &LastFMImport::UpdatePlayCount, &*backend_, &CollectionBackend::UpdatePlayCount);
|
||||
|
||||
// This will start the watcher checking for updates
|
||||
backend_->LoadDirectoriesAsync();
|
||||
@@ -129,13 +133,13 @@ void SCollection::Init() {
|
||||
|
||||
void SCollection::Exit() {
|
||||
|
||||
wait_for_exit_ << backend_ << watcher_;
|
||||
wait_for_exit_ << &*backend_ << &*watcher_;
|
||||
|
||||
QObject::disconnect(backend_, nullptr, watcher_, nullptr);
|
||||
QObject::disconnect(watcher_, nullptr, backend_, nullptr);
|
||||
QObject::disconnect(&*backend_, nullptr, &*watcher_, nullptr);
|
||||
QObject::disconnect(&*watcher_, nullptr, &*backend_, nullptr);
|
||||
|
||||
QObject::connect(backend_, &CollectionBackend::ExitFinished, this, &SCollection::ExitReceived);
|
||||
QObject::connect(watcher_, &CollectionWatcher::ExitFinished, this, &SCollection::ExitReceived);
|
||||
QObject::connect(&*backend_, &CollectionBackend::ExitFinished, this, &SCollection::ExitReceived);
|
||||
QObject::connect(&*watcher_, &CollectionWatcher::ExitFinished, this, &SCollection::ExitReceived);
|
||||
backend_->ExitAsync();
|
||||
watcher_->Abort();
|
||||
watcher_->ExitAsync();
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
|
||||
#include "core/scoped_ptr.h"
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
|
||||
class QThread;
|
||||
@@ -42,7 +44,7 @@ class SCollection : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SCollection(Application *app, QObject *parent);
|
||||
explicit SCollection(Application *app, QObject *parent = nullptr);
|
||||
~SCollection() override;
|
||||
|
||||
static const char *kSongsTable;
|
||||
@@ -53,7 +55,7 @@ class SCollection : public QObject {
|
||||
void Init();
|
||||
void Exit();
|
||||
|
||||
CollectionBackend *backend() const { return backend_; }
|
||||
SharedPtr<CollectionBackend> backend() const { return backend_; }
|
||||
CollectionModel *model() const { return model_; }
|
||||
|
||||
QString full_rescan_reason(int schema_version) const { return full_rescan_revisions_.value(schema_version, QString()); }
|
||||
@@ -86,10 +88,10 @@ class SCollection : public QObject {
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
CollectionBackend *backend_;
|
||||
SharedPtr<CollectionBackend> backend_;
|
||||
CollectionModel *model_;
|
||||
|
||||
CollectionWatcher *watcher_;
|
||||
ScopedPtr<CollectionWatcher> watcher_;
|
||||
Thread *watcher_thread_;
|
||||
QThread *original_thread_;
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/database.h"
|
||||
#include "core/scopedtransaction.h"
|
||||
@@ -67,7 +68,13 @@ CollectionBackend::CollectionBackend(QObject *parent)
|
||||
|
||||
}
|
||||
|
||||
void CollectionBackend::Init(Database *db, TaskManager *task_manager, const Song::Source source, const QString &songs_table, const QString &fts_table, const QString &dirs_table, const QString &subdirs_table) {
|
||||
CollectionBackend::~CollectionBackend() {
|
||||
|
||||
qLog(Debug) << "Collection backend" << this << "for" << Song::TextForSource(source_) << "deleted";
|
||||
|
||||
}
|
||||
|
||||
void CollectionBackend::Init(SharedPtr<Database> db, SharedPtr<TaskManager> task_manager, const Song::Source source, const QString &songs_table, const QString &fts_table, const QString &dirs_table, const QString &subdirs_table) {
|
||||
|
||||
db_ = db;
|
||||
task_manager_ = task_manager;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
@@ -35,6 +36,7 @@
|
||||
#include <QUrl>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "collectionfilteroptions.h"
|
||||
#include "collectionquery.h"
|
||||
@@ -82,7 +84,7 @@ class CollectionBackendInterface : public QObject {
|
||||
|
||||
virtual Song::Source source() const = 0;
|
||||
|
||||
virtual Database *db() const = 0;
|
||||
virtual SharedPtr<Database> db() const = 0;
|
||||
|
||||
// Get a list of directories in the collection. Emits DirectoriesDiscovered.
|
||||
virtual void LoadDirectoriesAsync() = 0;
|
||||
@@ -140,7 +142,9 @@ class CollectionBackend : public CollectionBackendInterface {
|
||||
|
||||
Q_INVOKABLE explicit CollectionBackend(QObject *parent = nullptr);
|
||||
|
||||
void Init(Database *db, TaskManager *task_manager, const Song::Source source, const QString &songs_table, const QString &fts_table, const QString &dirs_table = QString(), const QString &subdirs_table = QString());
|
||||
~CollectionBackend();
|
||||
|
||||
void Init(SharedPtr<Database> db, SharedPtr<TaskManager> task_manager, const Song::Source source, const QString &songs_table, const QString &fts_table, const QString &dirs_table = QString(), const QString &subdirs_table = QString());
|
||||
void Close();
|
||||
|
||||
void ExitAsync();
|
||||
@@ -149,7 +153,7 @@ class CollectionBackend : public CollectionBackendInterface {
|
||||
|
||||
Song::Source source() const override { return source_; }
|
||||
|
||||
Database *db() const override { return db_; }
|
||||
SharedPtr<Database> db() const override { return db_; }
|
||||
|
||||
QString songs_table() const override { return songs_table_; }
|
||||
QString fts_table() const override { return fts_table_; }
|
||||
@@ -305,8 +309,8 @@ class CollectionBackend : public CollectionBackendInterface {
|
||||
SongList GetSongsBySongId(const QStringList &song_ids, QSqlDatabase &db);
|
||||
|
||||
private:
|
||||
Database *db_;
|
||||
TaskManager *task_manager_;
|
||||
SharedPtr<Database> db_;
|
||||
SharedPtr<TaskManager> task_manager_;
|
||||
Song::Source source_;
|
||||
QString songs_table_;
|
||||
QString dirs_table_;
|
||||
|
||||
@@ -20,12 +20,15 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QObject>
|
||||
#include <QStandardItemModel>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/filesystemmusicstorage.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/musicstorage.h"
|
||||
@@ -34,24 +37,24 @@
|
||||
#include "collectionbackend.h"
|
||||
#include "collectiondirectorymodel.h"
|
||||
|
||||
CollectionDirectoryModel::CollectionDirectoryModel(CollectionBackend *backend, QObject *parent)
|
||||
using std::make_shared;
|
||||
|
||||
CollectionDirectoryModel::CollectionDirectoryModel(SharedPtr<CollectionBackend> backend, QObject *parent)
|
||||
: QStandardItemModel(parent),
|
||||
dir_icon_(IconLoader::Load("document-open-folder")),
|
||||
backend_(backend) {
|
||||
|
||||
QObject::connect(backend_, &CollectionBackend::DirectoryDiscovered, this, &CollectionDirectoryModel::DirectoryDiscovered);
|
||||
QObject::connect(backend_, &CollectionBackend::DirectoryDeleted, this, &CollectionDirectoryModel::DirectoryDeleted);
|
||||
QObject::connect(&*backend_, &CollectionBackend::DirectoryDiscovered, this, &CollectionDirectoryModel::DirectoryDiscovered);
|
||||
QObject::connect(&*backend_, &CollectionBackend::DirectoryDeleted, this, &CollectionDirectoryModel::DirectoryDeleted);
|
||||
|
||||
}
|
||||
|
||||
CollectionDirectoryModel::~CollectionDirectoryModel() = default;
|
||||
|
||||
void CollectionDirectoryModel::DirectoryDiscovered(const CollectionDirectory &dir) {
|
||||
|
||||
QStandardItem *item = new QStandardItem(dir.path);
|
||||
item->setData(dir.id, kIdRole);
|
||||
item->setIcon(dir_icon_);
|
||||
storage_ << std::make_shared<FilesystemMusicStorage>(backend_->source(), dir.path, dir.id);
|
||||
storage_ << make_shared<FilesystemMusicStorage>(backend_->source(), dir.path, dir.id);
|
||||
appendRow(item);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QObject>
|
||||
#include <QStandardItemModel>
|
||||
#include <QList>
|
||||
@@ -32,6 +30,8 @@
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
|
||||
class QModelIndex;
|
||||
|
||||
struct CollectionDirectory;
|
||||
@@ -42,8 +42,7 @@ class CollectionDirectoryModel : public QStandardItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CollectionDirectoryModel(CollectionBackend *backend, QObject *parent = nullptr);
|
||||
~CollectionDirectoryModel() override;
|
||||
explicit CollectionDirectoryModel(SharedPtr<CollectionBackend> collection_backend, QObject *parent = nullptr);
|
||||
|
||||
// To be called by GUIs
|
||||
void AddDirectory(const QString &path);
|
||||
@@ -60,8 +59,8 @@ class CollectionDirectoryModel : public QStandardItemModel {
|
||||
static const int kIdRole = Qt::UserRole + 1;
|
||||
|
||||
QIcon dir_icon_;
|
||||
CollectionBackend *backend_;
|
||||
QList<std::shared_ptr<MusicStorage>> storage_;
|
||||
SharedPtr<CollectionBackend> backend_;
|
||||
QList<SharedPtr<MusicStorage>> storage_;
|
||||
};
|
||||
|
||||
#endif // COLLECTIONDIRECTORYMODEL_H
|
||||
|
||||
@@ -53,6 +53,8 @@
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "core/scoped_ptr.h"
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/application.h"
|
||||
#include "core/database.h"
|
||||
#include "core/iconloader.h"
|
||||
@@ -78,7 +80,7 @@ const char *CollectionModel::kPixmapDiskCacheDir = "pixmapcache";
|
||||
|
||||
QNetworkDiskCache *CollectionModel::sIconCache = nullptr;
|
||||
|
||||
CollectionModel::CollectionModel(CollectionBackend *backend, Application *app, QObject *parent)
|
||||
CollectionModel::CollectionModel(SharedPtr<CollectionBackend> backend, Application *app, QObject *parent)
|
||||
: SimpleTreeModel<CollectionItem>(new CollectionItem(this), parent),
|
||||
backend_(backend),
|
||||
app_(app),
|
||||
@@ -103,7 +105,7 @@ CollectionModel::CollectionModel(CollectionBackend *backend, Application *app, Q
|
||||
group_by_[2] = GroupBy::None;
|
||||
|
||||
if (app_) {
|
||||
QObject::connect(app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &CollectionModel::AlbumCoverLoaded);
|
||||
QObject::connect(&*app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &CollectionModel::AlbumCoverLoaded);
|
||||
}
|
||||
|
||||
QIcon nocover = IconLoader::Load("cdcase");
|
||||
@@ -118,14 +120,14 @@ CollectionModel::CollectionModel(CollectionBackend *backend, Application *app, Q
|
||||
QObject::connect(app_, &Application::ClearPixmapDiskCache, this, &CollectionModel::ClearDiskCache);
|
||||
}
|
||||
|
||||
QObject::connect(backend_, &CollectionBackend::SongsDiscovered, this, &CollectionModel::SongsDiscovered);
|
||||
QObject::connect(backend_, &CollectionBackend::SongsDeleted, this, &CollectionModel::SongsDeleted);
|
||||
QObject::connect(backend_, &CollectionBackend::DatabaseReset, this, &CollectionModel::Reset);
|
||||
QObject::connect(backend_, &CollectionBackend::TotalSongCountUpdated, this, &CollectionModel::TotalSongCountUpdatedSlot);
|
||||
QObject::connect(backend_, &CollectionBackend::TotalArtistCountUpdated, this, &CollectionModel::TotalArtistCountUpdatedSlot);
|
||||
QObject::connect(backend_, &CollectionBackend::TotalAlbumCountUpdated, this, &CollectionModel::TotalAlbumCountUpdatedSlot);
|
||||
QObject::connect(backend_, &CollectionBackend::SongsStatisticsChanged, this, &CollectionModel::SongsSlightlyChanged);
|
||||
QObject::connect(backend_, &CollectionBackend::SongsRatingChanged, this, &CollectionModel::SongsSlightlyChanged);
|
||||
QObject::connect(&*backend_, &CollectionBackend::SongsDiscovered, this, &CollectionModel::SongsDiscovered);
|
||||
QObject::connect(&*backend_, &CollectionBackend::SongsDeleted, this, &CollectionModel::SongsDeleted);
|
||||
QObject::connect(&*backend_, &CollectionBackend::DatabaseReset, this, &CollectionModel::Reset);
|
||||
QObject::connect(&*backend_, &CollectionBackend::TotalSongCountUpdated, this, &CollectionModel::TotalSongCountUpdatedSlot);
|
||||
QObject::connect(&*backend_, &CollectionBackend::TotalArtistCountUpdated, this, &CollectionModel::TotalArtistCountUpdatedSlot);
|
||||
QObject::connect(&*backend_, &CollectionBackend::TotalAlbumCountUpdated, this, &CollectionModel::TotalAlbumCountUpdatedSlot);
|
||||
QObject::connect(&*backend_, &CollectionBackend::SongsStatisticsChanged, this, &CollectionModel::SongsSlightlyChanged);
|
||||
QObject::connect(&*backend_, &CollectionBackend::SongsRatingChanged, this, &CollectionModel::SongsSlightlyChanged);
|
||||
|
||||
backend_->UpdateTotalSongCountAsync();
|
||||
backend_->UpdateTotalArtistCountAsync();
|
||||
@@ -136,7 +138,11 @@ CollectionModel::CollectionModel(CollectionBackend *backend, Application *app, Q
|
||||
}
|
||||
|
||||
CollectionModel::~CollectionModel() {
|
||||
|
||||
qLog(Debug) << "Collection model" << this << "for" << Song::TextForSource(backend_->source()) << "deleted";
|
||||
|
||||
delete root_;
|
||||
|
||||
}
|
||||
|
||||
void CollectionModel::set_pretty_covers(const bool use_pretty_covers) {
|
||||
@@ -632,10 +638,10 @@ QVariant CollectionModel::AlbumIcon(const QModelIndex &idx) {
|
||||
|
||||
// Try to load it from the disk cache
|
||||
if (use_disk_cache_ && sIconCache) {
|
||||
std::unique_ptr<QIODevice> disk_cache_img(sIconCache->data(AlbumIconPixmapDiskCacheKey(cache_key)));
|
||||
ScopedPtr<QIODevice> disk_cache_img(sIconCache->data(AlbumIconPixmapDiskCacheKey(cache_key)));
|
||||
if (disk_cache_img) {
|
||||
QImage cached_image;
|
||||
if (cached_image.load(disk_cache_img.get(), "XPM")) {
|
||||
if (cached_image.load(&*disk_cache_img, "XPM")) {
|
||||
QPixmapCache::insert(cache_key, QPixmap::fromImage(cached_image));
|
||||
return QPixmap::fromImage(cached_image);
|
||||
}
|
||||
@@ -688,7 +694,7 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderR
|
||||
// If we have a valid cover not already in the disk cache
|
||||
if (use_disk_cache_ && sIconCache && result.success && !result.image_scaled.isNull()) {
|
||||
const QUrl disk_cache_key = AlbumIconPixmapDiskCacheKey(cache_key);
|
||||
std::unique_ptr<QIODevice> disk_cache_img(sIconCache->data(disk_cache_key));
|
||||
ScopedPtr<QIODevice> disk_cache_img(sIconCache->data(disk_cache_key));
|
||||
if (!disk_cache_img) {
|
||||
QNetworkCacheMetaData disk_cache_metadata;
|
||||
disk_cache_metadata.setSaveToDisk(true);
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <QPixmap>
|
||||
#include <QNetworkDiskCache>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/simpletreemodel.h"
|
||||
#include "core/song.h"
|
||||
#include "core/sqlrow.h"
|
||||
@@ -64,7 +65,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CollectionModel(CollectionBackend *backend, Application *app, QObject *parent = nullptr);
|
||||
explicit CollectionModel(SharedPtr<CollectionBackend> backend, Application *app, QObject *parent = nullptr);
|
||||
~CollectionModel() override;
|
||||
|
||||
static const int kPrettyCoverSize;
|
||||
@@ -131,7 +132,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
|
||||
bool create_va;
|
||||
};
|
||||
|
||||
CollectionBackend *backend() const { return backend_; }
|
||||
SharedPtr<CollectionBackend> backend() const { return backend_; }
|
||||
CollectionDirectoryModel *directory_model() const { return dir_model_; }
|
||||
|
||||
// Call before Init()
|
||||
@@ -273,7 +274,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
|
||||
static qint64 MaximumCacheSize(QSettings *s, const char *size_id, const char *size_unit_id, const qint64 cache_size_default);
|
||||
|
||||
private:
|
||||
CollectionBackend *backend_;
|
||||
SharedPtr<CollectionBackend> backend_;
|
||||
Application *app_;
|
||||
CollectionDirectoryModel *dir_model_;
|
||||
bool show_various_artists_;
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/taskmanager.h"
|
||||
#include "collectiontask.h"
|
||||
|
||||
CollectionTask::CollectionTask(TaskManager *task_manager, const QString &message) : task_manager_(task_manager), task_id_(-1) {
|
||||
CollectionTask::CollectionTask(SharedPtr<TaskManager> task_manager, const QString &message) : task_manager_(task_manager), task_id_(-1) {
|
||||
|
||||
if (task_manager_) task_id_ = task_manager_->StartTask(message);
|
||||
|
||||
|
||||
@@ -23,15 +23,17 @@
|
||||
#include <QtGlobal>
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
|
||||
class TaskManager;
|
||||
|
||||
class CollectionTask {
|
||||
public:
|
||||
explicit CollectionTask(TaskManager *task_manager, const QString &message);
|
||||
explicit CollectionTask(SharedPtr<TaskManager> task_manager, const QString &message);
|
||||
~CollectionTask();
|
||||
|
||||
private:
|
||||
TaskManager *task_manager_;
|
||||
SharedPtr<TaskManager> task_manager_;
|
||||
int task_id_;
|
||||
|
||||
Q_DISABLE_COPY(CollectionTask)
|
||||
|
||||
@@ -71,6 +71,8 @@
|
||||
#include "organize/organizeerrordialog.h"
|
||||
#include "settings/collectionsettingspage.h"
|
||||
|
||||
using std::make_unique;
|
||||
|
||||
CollectionView::CollectionView(QWidget *parent)
|
||||
: AutoExpandingTreeView(parent),
|
||||
app_(nullptr),
|
||||
@@ -573,7 +575,7 @@ SongList CollectionView::GetSelectedSongs() const {
|
||||
void CollectionView::Organize() {
|
||||
|
||||
if (!organize_dialog_) {
|
||||
organize_dialog_ = std::make_unique<OrganizeDialog>(app_->task_manager(), app_->collection_backend(), this);
|
||||
organize_dialog_ = make_unique<OrganizeDialog>(app_->task_manager(), app_->collection_backend(), this);
|
||||
}
|
||||
|
||||
organize_dialog_->SetDestinationModel(app_->collection_model()->directory_model());
|
||||
@@ -591,8 +593,8 @@ void CollectionView::Organize() {
|
||||
void CollectionView::EditTracks() {
|
||||
|
||||
if (!edit_tag_dialog_) {
|
||||
edit_tag_dialog_ = std::make_unique<EditTagDialog>(app_, this);
|
||||
QObject::connect(edit_tag_dialog_.get(), &EditTagDialog::Error, this, &CollectionView::EditTagError);
|
||||
edit_tag_dialog_ = make_unique<EditTagDialog>(app_, this);
|
||||
QObject::connect(&*edit_tag_dialog_, &EditTagDialog::Error, this, &CollectionView::EditTagError);
|
||||
}
|
||||
const SongList songs = GetSelectedSongs();
|
||||
edit_tag_dialog_->SetSongs(songs);
|
||||
@@ -614,7 +616,7 @@ void CollectionView::CopyToDevice() {
|
||||
|
||||
#ifndef Q_OS_WIN
|
||||
if (!organize_dialog_) {
|
||||
organize_dialog_ = std::make_unique<OrganizeDialog>(app_->task_manager(), nullptr, this);
|
||||
organize_dialog_ = make_unique<OrganizeDialog>(app_->task_manager(), nullptr, this);
|
||||
}
|
||||
|
||||
organize_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true);
|
||||
@@ -686,7 +688,7 @@ void CollectionView::Delete() {
|
||||
if (DeleteConfirmationDialog::warning(files) != QDialogButtonBox::Yes) return;
|
||||
|
||||
// We can cheat and always take the storage of the first directory, since they'll all be FilesystemMusicStorage in a collection and deleting doesn't check the actual directory.
|
||||
std::shared_ptr<MusicStorage> storage = app_->collection_model()->directory_model()->index(0, 0).data(MusicStorage::Role_Storage).value<std::shared_ptr<MusicStorage>>();
|
||||
SharedPtr<MusicStorage> storage = app_->collection_model()->directory_model()->index(0, 0).data(MusicStorage::Role_Storage).value<SharedPtr<MusicStorage>>();
|
||||
|
||||
DeleteFiles *delete_files = new DeleteFiles(app_->task_manager(), storage, true);
|
||||
QObject::connect(delete_files, &DeleteFiles::Finished, this, &CollectionView::DeleteFilesFinished);
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QAbstractItemView>
|
||||
@@ -33,6 +31,7 @@
|
||||
#include <QPixmap>
|
||||
#include <QSet>
|
||||
|
||||
#include "core/scoped_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "widgets/autoexpandingtreeview.h"
|
||||
|
||||
@@ -148,8 +147,8 @@ class CollectionView : public AutoExpandingTreeView {
|
||||
QAction *action_no_show_in_various_;
|
||||
QAction *action_delete_files_;
|
||||
|
||||
std::unique_ptr<OrganizeDialog> organize_dialog_;
|
||||
std::unique_ptr<EditTagDialog> edit_tag_dialog_;
|
||||
ScopedPtr<OrganizeDialog> organize_dialog_;
|
||||
ScopedPtr<EditTagDialog> edit_tag_dialog_;
|
||||
|
||||
bool is_in_keyboard_search_;
|
||||
bool delete_files_;
|
||||
|
||||
@@ -119,6 +119,12 @@ CollectionWatcher::CollectionWatcher(Song::Source source, QObject *parent)
|
||||
|
||||
}
|
||||
|
||||
CollectionWatcher::~CollectionWatcher() {
|
||||
|
||||
qLog(Debug) << "Collection watcher" << this << "for" << Song::TextForSource(source_) << "deleted.";
|
||||
|
||||
}
|
||||
|
||||
void CollectionWatcher::ExitAsync() {
|
||||
QMetaObject::invokeMethod(this, &CollectionWatcher::Exit, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <QUrl>
|
||||
|
||||
#include "collectiondirectory.h"
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
|
||||
class QThread;
|
||||
@@ -50,11 +51,12 @@ class CollectionWatcher : public QObject {
|
||||
|
||||
public:
|
||||
explicit CollectionWatcher(Song::Source source, QObject *parent = nullptr);
|
||||
~CollectionWatcher();
|
||||
|
||||
Song::Source source() { return source_; }
|
||||
|
||||
void set_backend(CollectionBackend *backend) { backend_ = backend; }
|
||||
void set_task_manager(TaskManager *task_manager) { task_manager_ = task_manager; }
|
||||
void set_backend(SharedPtr<CollectionBackend> backend) { backend_ = backend; }
|
||||
void set_task_manager(SharedPtr<TaskManager> task_manager) { task_manager_ = task_manager; }
|
||||
void set_device_name(const QString &device_name) { device_name_ = device_name; }
|
||||
|
||||
void IncrementalScanAsync();
|
||||
@@ -208,8 +210,8 @@ class CollectionWatcher : public QObject {
|
||||
|
||||
private:
|
||||
Song::Source source_;
|
||||
CollectionBackend *backend_;
|
||||
TaskManager *task_manager_;
|
||||
SharedPtr<CollectionBackend> backend_;
|
||||
SharedPtr<TaskManager> task_manager_;
|
||||
QString device_name_;
|
||||
|
||||
FileSystemWatcherInterface *fs_watcher_;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include <QDialog>
|
||||
#include <QWidget>
|
||||
@@ -41,6 +41,8 @@
|
||||
#include <boost/multi_index_container_fwd.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
using std::make_unique;
|
||||
|
||||
using boost::multi_index_container;
|
||||
using boost::multi_index::indexed_by;
|
||||
using boost::multi_index::ordered_unique;
|
||||
@@ -69,7 +71,7 @@ class GroupByDialogPrivate {
|
||||
MappingContainer mapping_;
|
||||
};
|
||||
|
||||
GroupByDialog::GroupByDialog(QWidget *parent) : QDialog(parent), ui_(new Ui_GroupByDialog), p_(new GroupByDialogPrivate) {
|
||||
GroupByDialog::GroupByDialog(QWidget *parent) : QDialog(parent), ui_(make_unique<Ui_GroupByDialog>()), p_(make_unique<GroupByDialogPrivate>()) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
Reset();
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QDialog>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include "core/scoped_ptr.h"
|
||||
#include "collectionmodel.h"
|
||||
#include "ui_groupbydialog.h"
|
||||
|
||||
@@ -55,8 +54,8 @@ class GroupByDialog : public QDialog {
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_GroupByDialog> ui_;
|
||||
std::unique_ptr<GroupByDialogPrivate> p_;
|
||||
ScopedPtr<Ui_GroupByDialog> ui_;
|
||||
ScopedPtr<GroupByDialogPrivate> p_;
|
||||
};
|
||||
|
||||
#endif // GROUPBYDIALOG_H
|
||||
|
||||
Reference in New Issue
Block a user