Application: Use shared pointers

Fixes #1239
This commit is contained in:
Jonas Kvinge
2023-07-21 05:55:24 +02:00
parent d6b53f78ab
commit 2e61235403
316 changed files with 2170 additions and 1643 deletions

View File

@@ -24,6 +24,7 @@
#include <QString>
#include <QUrl>
#include "core/shared_ptr.h"
#include "collection/collectionmodel.h"
#include "cddasongloader.h"
#include "connecteddevice.h"
@@ -33,7 +34,7 @@ class Application;
class DeviceLister;
class DeviceManager;
CddaDevice::CddaDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, int database_id, bool first_time, QObject *parent)
CddaDevice::CddaDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, int database_id, bool first_time, QObject *parent)
: ConnectedDevice(url, lister, unique_id, manager, app, database_id, first_time, parent),
cdda_song_loader_(url) {

View File

@@ -33,6 +33,7 @@
#include <cdio/cdio.h>
#include <gst/audio/gstaudiocdsrc.h>
#include "core/shared_ptr.h"
#include "core/song.h"
#include "core/musicstorage.h"
#include "cddasongloader.h"
@@ -46,7 +47,7 @@ class CddaDevice : public ConnectedDevice {
Q_OBJECT
public:
Q_INVOKABLE explicit CddaDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr);
Q_INVOKABLE explicit CddaDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr);
bool Init() override;
void Refresh() override;

View File

@@ -21,6 +21,8 @@
#include "config.h"
#include <memory>
#include <cstddef>
#include <glib.h>
#include <glib/gtypes.h>
@@ -39,13 +41,16 @@
#include "cddasongloader.h"
#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/networkaccessmanager.h"
#include "utilities/timeconstants.h"
using std::make_shared;
CddaSongLoader::CddaSongLoader(const QUrl &url, QObject *parent)
: QObject(parent),
url_(url),
network_(new NetworkAccessManager(this)),
network_(make_shared<NetworkAccessManager>()),
cdda_(nullptr),
cdio_(nullptr) {}

View File

@@ -35,6 +35,7 @@
#include <gst/gstelement.h>
#include <gst/audio/gstaudiocdsrc.h>
#include "core/shared_ptr.h"
#include "core/song.h"
#ifdef HAVE_MUSICBRAINZ
# include "musicbrainz/musicbrainzclient.h"
@@ -71,7 +72,7 @@ class CddaSongLoader : public QObject {
private:
const QUrl url_;
NetworkAccessManager *network_;
SharedPtr<NetworkAccessManager> network_;
GstElement *cdda_;
CdIo_t *cdio_;
QMutex mutex_load_;

View File

@@ -19,12 +19,15 @@
*
*/
#include <memory>
#include <QObject>
#include <QAbstractItemModel>
#include <QString>
#include <QUrl>
#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/application.h"
#include "core/database.h"
#include "collection/collectionbackend.h"
@@ -35,7 +38,9 @@
#include "devicemanager.h"
#include "deviceinfo.h"
ConnectedDevice::ConnectedDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, const int database_id, const bool first_time, QObject *parent)
using std::make_shared;
ConnectedDevice::ConnectedDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, const int database_id, const bool first_time, QObject *parent)
: QObject(parent),
app_(app),
url_(url),
@@ -51,12 +56,12 @@ ConnectedDevice::ConnectedDevice(const QUrl &url, DeviceLister *lister, const QS
qLog(Info) << "Connected" << url << unique_id << first_time;
// Create the backend in the database thread.
backend_ = new CollectionBackend();
backend_ = make_shared<CollectionBackend>();
backend_->moveToThread(app_->database()->thread());
qLog(Debug) << backend_ << "for device" << unique_id_ << "moved to thread" << app_->database()->thread();
qLog(Debug) << &*backend_ << "for device" << unique_id_ << "moved to thread" << app_->database()->thread();
if (url_.scheme() != "cdda") {
QObject::connect(backend_, &CollectionBackend::TotalSongCountUpdated, this, &ConnectedDevice::BackendTotalSongCountUpdated);
QObject::connect(&*backend_, &CollectionBackend::TotalSongCountUpdated, this, &ConnectedDevice::BackendTotalSongCountUpdated);
}
backend_->Init(app_->database(),
@@ -72,10 +77,6 @@ ConnectedDevice::ConnectedDevice(const QUrl &url, DeviceLister *lister, const QS
}
ConnectedDevice::~ConnectedDevice() {
backend_->deleteLater();
}
void ConnectedDevice::InitBackendDirectory(const QString &mount_point, const bool first_time, const bool rewrite_path) {
QList<CollectionDirectory> directories = backend_->GetAllDirectories();
@@ -108,7 +109,7 @@ void ConnectedDevice::ConnectAsync() { emit DeviceConnectFinished(unique_id_, tr
void ConnectedDevice::Close() {
QObject::connect(backend_, &CollectionBackend::ExitFinished, this, &ConnectedDevice::BackendCloseFinished);
QObject::connect(&*backend_, &CollectionBackend::ExitFinished, this, &ConnectedDevice::BackendCloseFinished);
backend_->ExitAsync();
}

View File

@@ -30,6 +30,7 @@
#include <QString>
#include <QUrl>
#include "core/shared_ptr.h"
#include "core/musicstorage.h"
#include "core/song.h"
@@ -39,12 +40,13 @@ class CollectionModel;
class DeviceLister;
class DeviceManager;
class ConnectedDevice : public QObject, public virtual MusicStorage, public std::enable_shared_from_this<ConnectedDevice> {
using std::enable_shared_from_this;
class ConnectedDevice : public QObject, public virtual MusicStorage, public enable_shared_from_this<ConnectedDevice> {
Q_OBJECT
public:
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;
explicit ConnectedDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr);
Song::Source source() const override { return Song::Source::Device; }
@@ -91,9 +93,9 @@ class ConnectedDevice : public QObject, public virtual MusicStorage, public std:
DeviceLister *lister_;
QString unique_id_;
int database_id_;
DeviceManager *manager_;
SharedPtr<DeviceManager> manager_;
CollectionBackend *backend_;
SharedPtr<CollectionBackend> backend_;
CollectionModel *model_;
qint64 song_count_;

View File

@@ -30,6 +30,7 @@
#include <QString>
#include <QSqlDatabase>
#include "core/shared_ptr.h"
#include "core/database.h"
#include "core/sqlquery.h"
#include "core/scopedtransaction.h"
@@ -46,7 +47,7 @@ DeviceDatabaseBackend::DeviceDatabaseBackend(QObject *parent)
}
void DeviceDatabaseBackend::Init(Database *db) { db_ = db; }
void DeviceDatabaseBackend::Init(SharedPtr<Database> db) { db_ = db; }
void DeviceDatabaseBackend::Close() {

View File

@@ -30,6 +30,7 @@
#include <QList>
#include <QString>
#include "core/shared_ptr.h"
#include "core/song.h"
#include "core/musicstorage.h"
@@ -57,11 +58,11 @@ class DeviceDatabaseBackend : public QObject {
static const int kDeviceSchemaVersion;
void Init(Database *db);
void Init(SharedPtr<Database> db);
void Close();
void ExitAsync();
Database *db() const { return db_; }
SharedPtr<Database> db() const { return db_; }
DeviceList GetAllDevices();
int AddDevice(const Device &device);
@@ -76,7 +77,7 @@ class DeviceDatabaseBackend : public QObject {
void ExitFinished();
private:
Database *db_;
SharedPtr<Database> db_;
QThread *original_thread_;
};

View File

@@ -102,7 +102,7 @@ class DeviceInfo : public SimpleTreeItem<DeviceInfo> {
const Backend *BestBackend() const;
int database_id_; // -1 if not remembered in the database
std::shared_ptr<ConnectedDevice> device_; // nullptr if not connected
SharedPtr<ConnectedDevice> device_; // nullptr if not connected
QList<Backend> backends_;
QString friendly_name_;

View File

@@ -21,8 +21,8 @@
#include "config.h"
#include <memory>
#include <functional>
#include <memory>
#include <QtGlobal>
#include <QApplication>
@@ -45,6 +45,8 @@
#include "devicemanager.h"
#include "core/logging.h"
#include "core/scoped_ptr.h"
#include "core/shared_ptr.h"
#include "core/application.h"
#include "core/database.h"
#include "core/iconloader.h"
@@ -81,6 +83,8 @@
# include "giolister.h" // Needs to be last because of #undef signals.
#endif
using std::make_unique;
const int DeviceManager::kDeviceIconSize = 32;
const int DeviceManager::kDeviceIconOverlaySize = 16;
@@ -90,10 +94,10 @@ DeviceManager::DeviceManager(Application *app, QObject *parent)
not_connected_overlay_(IconLoader::Load("edit-delete")) {
thread_pool_.setMaxThreadCount(1);
QObject::connect(app_->task_manager(), &TaskManager::TasksChanged, this, &DeviceManager::TasksChanged);
QObject::connect(&*app_->task_manager(), &TaskManager::TasksChanged, this, &DeviceManager::TasksChanged);
// Create the backend in the database thread
backend_ = new DeviceDatabaseBackend;
backend_ = make_unique<DeviceDatabaseBackend>();
backend_->moveToThread(app_->database()->thread());
backend_->Init(app_->database());
@@ -151,9 +155,6 @@ DeviceManager::~DeviceManager() {
delete root_;
root_ = nullptr;
backend_->deleteLater();
backend_ = nullptr;
}
void DeviceManager::Exit() {
@@ -164,9 +165,9 @@ void DeviceManager::CloseDevices() {
for (DeviceInfo *info : devices_) {
if (!info->device_) continue;
if (wait_for_exit_.contains(info->device_.get())) continue;
wait_for_exit_ << info->device_.get();
QObject::connect(info->device_.get(), &ConnectedDevice::destroyed, this, &DeviceManager::DeviceDestroyed);
if (wait_for_exit_.contains(&*info->device_)) continue;
wait_for_exit_ << &*info->device_;
QObject::connect(&*info->device_, &ConnectedDevice::destroyed, this, &DeviceManager::DeviceDestroyed);
info->device_->Close();
}
if (wait_for_exit_.isEmpty()) CloseListers();
@@ -187,9 +188,9 @@ void DeviceManager::CloseListers() {
void DeviceManager::CloseBackend() {
if (!backend_ || wait_for_exit_.contains(backend_)) return;
wait_for_exit_ << backend_;
QObject::connect(backend_, &DeviceDatabaseBackend::ExitFinished, this, &DeviceManager::BackendClosed);
if (!backend_ || wait_for_exit_.contains(&*backend_)) return;
wait_for_exit_ << &*backend_;
QObject::connect(&*backend_, &DeviceDatabaseBackend::ExitFinished, this, &DeviceManager::BackendClosed);
backend_->ExitAsync();
}
@@ -290,7 +291,7 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
if (info->size_ > 0) {
text = text + QString(" (%1)").arg(Utilities::PrettySize(info->size_));
}
if (info->device_.get()) info->device_->Refresh();
if (&*info->device_) info->device_->Refresh();
return text;
}
@@ -341,14 +342,14 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
const_cast<DeviceManager*>(this)->Connect(info);
}
if (!info->device_) return QVariant();
return QVariant::fromValue<std::shared_ptr<MusicStorage>>(info->device_);
return QVariant::fromValue<SharedPtr<MusicStorage>>(info->device_);
case MusicStorage::Role_StorageForceConnect:
if (!info->BestBackend()) return QVariant();
if (!info->device_) {
if (info->database_id_ == -1 && !info->BestBackend()->lister_->DeviceNeedsMount(info->BestBackend()->unique_id_)) {
if (info->BestBackend()->lister_->AskForScan(info->BestBackend()->unique_id_)) {
std::unique_ptr<QMessageBox> dialog(new QMessageBox(QMessageBox::Information, tr("Connect device"), tr("This is the first time you have connected this device. Strawberry will now scan the device to find music files - this may take some time."), QMessageBox::Cancel));
ScopedPtr<QMessageBox> dialog(new QMessageBox(QMessageBox::Information, tr("Connect device"), tr("This is the first time you have connected this device. Strawberry will now scan the device to find music files - this may take some time."), QMessageBox::Cancel));
QPushButton *pushbutton = dialog->addButton(tr("Connect device"), QMessageBox::AcceptRole);
dialog->exec();
if (dialog->clickedButton() != pushbutton) return QVariant();
@@ -357,7 +358,7 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
const_cast<DeviceManager*>(this)->Connect(info);
}
if (!info->device_) return QVariant();
return QVariant::fromValue<std::shared_ptr<MusicStorage>>(info->device_);
return QVariant::fromValue<SharedPtr<MusicStorage>>(info->device_);
case Role_MountPath: {
if (!info->device_) return QVariant();
@@ -551,9 +552,9 @@ void DeviceManager::PhysicalDeviceChanged(const QString &id) {
}
std::shared_ptr<ConnectedDevice> DeviceManager::Connect(const QModelIndex &idx) {
SharedPtr<ConnectedDevice> DeviceManager::Connect(const QModelIndex &idx) {
std::shared_ptr<ConnectedDevice> ret;
SharedPtr<ConnectedDevice> ret;
DeviceInfo *info = IndexToItem(idx);
if (!info) return ret;
@@ -562,9 +563,9 @@ std::shared_ptr<ConnectedDevice> DeviceManager::Connect(const QModelIndex &idx)
}
std::shared_ptr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *info) {
SharedPtr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *info) {
std::shared_ptr<ConnectedDevice> ret;
SharedPtr<ConnectedDevice> ret;
if (!info) return ret;
if (info->device_) { // Already connected
@@ -661,10 +662,10 @@ std::shared_ptr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *info) {
emit dataChanged(idx, idx);
QObject::connect(info->device_.get(), &ConnectedDevice::TaskStarted, this, &DeviceManager::DeviceTaskStarted);
QObject::connect(info->device_.get(), &ConnectedDevice::SongCountUpdated, this, &DeviceManager::DeviceSongCountUpdated);
QObject::connect(info->device_.get(), &ConnectedDevice::DeviceConnectFinished, this, &DeviceManager::DeviceConnectFinished);
QObject::connect(info->device_.get(), &ConnectedDevice::DeviceCloseFinished, this, &DeviceManager::DeviceCloseFinished);
QObject::connect(&*info->device_, &ConnectedDevice::TaskStarted, this, &DeviceManager::DeviceTaskStarted);
QObject::connect(&*info->device_, &ConnectedDevice::SongCountUpdated, this, &DeviceManager::DeviceSongCountUpdated);
QObject::connect(&*info->device_, &ConnectedDevice::DeviceConnectFinished, this, &DeviceManager::DeviceConnectFinished);
QObject::connect(&*info->device_, &ConnectedDevice::DeviceCloseFinished, this, &DeviceManager::DeviceCloseFinished);
ret->ConnectAsync();
return ret;
@@ -717,18 +718,18 @@ DeviceInfo *DeviceManager::GetDevice(const QModelIndex &idx) const {
}
std::shared_ptr<ConnectedDevice> DeviceManager::GetConnectedDevice(const QModelIndex &idx) const {
SharedPtr<ConnectedDevice> DeviceManager::GetConnectedDevice(const QModelIndex &idx) const {
std::shared_ptr<ConnectedDevice> ret;
SharedPtr<ConnectedDevice> ret;
DeviceInfo *info = IndexToItem(idx);
if (!info) return ret;
return info->device_;
}
std::shared_ptr<ConnectedDevice> DeviceManager::GetConnectedDevice(DeviceInfo *info) const {
SharedPtr<ConnectedDevice> DeviceManager::GetConnectedDevice(DeviceInfo *info) const {
std::shared_ptr<ConnectedDevice> ret;
SharedPtr<ConnectedDevice> ret;
if (!info) return ret;
return info->device_;
@@ -829,7 +830,7 @@ void DeviceManager::DeviceTaskStarted(const int id) {
for (int i = 0; i < devices_.count(); ++i) {
DeviceInfo *info = devices_[i];
if (info->device_.get() == device) {
if (&*info->device_ == device) {
QModelIndex index = ItemToIndex(info);
if (!index.isValid()) continue;
active_tasks_[id] = index;

View File

@@ -24,8 +24,6 @@
#include "config.h"
#include <memory>
#include <QObject>
#include <QMetaObject>
#include <QThreadPool>
@@ -39,6 +37,8 @@
#include <QUrl>
#include <QIcon>
#include "core/scoped_ptr.h"
#include "core/shared_ptr.h"
#include "core/song.h"
#include "core/musicstorage.h"
#include "core/simpletreemodel.h"
@@ -95,8 +95,8 @@ class DeviceManager : public SimpleTreeModel<DeviceInfo> {
int GetDatabaseId(const QModelIndex &idx) const;
DeviceLister *GetLister(const QModelIndex &idx) const;
DeviceInfo *GetDevice(const QModelIndex &idx) const;
std::shared_ptr<ConnectedDevice> GetConnectedDevice(const QModelIndex &idx) const;
std::shared_ptr<ConnectedDevice> GetConnectedDevice(DeviceInfo *info) const;
SharedPtr<ConnectedDevice> GetConnectedDevice(const QModelIndex &idx) const;
SharedPtr<ConnectedDevice> GetConnectedDevice(DeviceInfo *info) const;
DeviceInfo *FindDeviceById(const QString &id) const;
DeviceInfo *FindDeviceByUrl(const QList<QUrl> &url) const;
@@ -104,8 +104,8 @@ class DeviceManager : public SimpleTreeModel<DeviceInfo> {
DeviceInfo *FindEquivalentDevice(DeviceInfo *info) const;
// Actions on devices
std::shared_ptr<ConnectedDevice> Connect(DeviceInfo *info);
std::shared_ptr<ConnectedDevice> Connect(const QModelIndex &idx);
SharedPtr<ConnectedDevice> Connect(DeviceInfo *info);
SharedPtr<ConnectedDevice> Connect(const QModelIndex &idx);
void Disconnect(DeviceInfo *info, const QModelIndex &idx);
void Forget(const QModelIndex &idx);
void UnmountAsync(const QModelIndex &idx);
@@ -153,7 +153,7 @@ class DeviceManager : public SimpleTreeModel<DeviceInfo> {
private:
Application *app_;
DeviceDatabaseBackend *backend_;
ScopedPtr<DeviceDatabaseBackend> backend_;
DeviceStateFilterModel *connected_devices_model_;

View File

@@ -22,7 +22,6 @@
#include "config.h"
#include <functional>
#include <memory>
#include <QtGlobal>
#include <QWidget>
@@ -46,6 +45,7 @@
#include <QStackedWidget>
#include <QTableWidget>
#include "core/shared_ptr.h"
#include "core/iconloader.h"
#include "core/musicstorage.h"
#include "widgets/freespacebar.h"
@@ -75,12 +75,12 @@ DeviceProperties::DeviceProperties(QWidget *parent)
DeviceProperties::~DeviceProperties() { delete ui_; }
void DeviceProperties::SetDeviceManager(DeviceManager *manager) {
void DeviceProperties::SetDeviceManager(SharedPtr<DeviceManager> manager) {
manager_ = manager;
QObject::connect(manager_, &DeviceManager::dataChanged, this, &DeviceProperties::ModelChanged);
QObject::connect(manager_, &DeviceManager::rowsInserted, this, &DeviceProperties::ModelChanged);
QObject::connect(manager_, &DeviceManager::rowsRemoved, this, &DeviceProperties::ModelChanged);
QObject::connect(&*manager_, &DeviceManager::dataChanged, this, &DeviceProperties::ModelChanged);
QObject::connect(&*manager_, &DeviceManager::rowsInserted, this, &DeviceProperties::ModelChanged);
QObject::connect(&*manager_, &DeviceManager::rowsRemoved, this, &DeviceProperties::ModelChanged);
}
@@ -204,7 +204,7 @@ void DeviceProperties::UpdateHardwareInfo() {
void DeviceProperties::UpdateFormats() {
DeviceLister *lister = manager_->GetLister(index_);
std::shared_ptr<ConnectedDevice> device = manager_->GetConnectedDevice(index_);
SharedPtr<ConnectedDevice> device = manager_->GetConnectedDevice(index_);
// Transcode mode
MusicStorage::TranscodeMode mode = static_cast<MusicStorage::TranscodeMode>(index_.data(DeviceManager::Role_TranscodeMode).toInt());

View File

@@ -24,6 +24,8 @@
#include "config.h"
#include <memory>
#include <QObject>
#include <QDialog>
#include <QFuture>
@@ -31,6 +33,7 @@
#include <QList>
#include <QString>
#include "core/shared_ptr.h"
#include "core/song.h"
class QWidget;
@@ -45,7 +48,7 @@ class DeviceProperties : public QDialog {
explicit DeviceProperties(QWidget *parent = nullptr);
~DeviceProperties() override;
void SetDeviceManager(DeviceManager *manager);
void SetDeviceManager(SharedPtr<DeviceManager> manager);
void ShowDevice(const QModelIndex &idx);
public slots:
@@ -64,7 +67,7 @@ class DeviceProperties : public QDialog {
private:
Ui_DeviceProperties *ui_;
DeviceManager *manager_;
SharedPtr<DeviceManager> manager_;
QPersistentModelIndex index_;
bool updating_formats_;

View File

@@ -48,6 +48,7 @@
#include <QMessageBox>
#include <QtEvents>
#include "core/scoped_ptr.h"
#include "core/iconloader.h"
#include "core/application.h"
#include "core/deletefiles.h"
@@ -66,6 +67,8 @@
#include "deviceproperties.h"
#include "deviceview.h"
using std::make_unique;
const int DeviceItemDelegate::kIconPadding = 6;
DeviceItemDelegate::DeviceItemDelegate(QObject *parent) : CollectionItemDelegate(parent) {}
@@ -203,11 +206,11 @@ void DeviceView::SetApplication(Application *app) {
Q_ASSERT(app_ == nullptr);
app_ = app;
QObject::connect(app_->device_manager(), &DeviceManager::DeviceConnected, this, &DeviceView::DeviceConnected);
QObject::connect(app_->device_manager(), &DeviceManager::DeviceDisconnected, this, &DeviceView::DeviceDisconnected);
QObject::connect(&*app_->device_manager(), &DeviceManager::DeviceConnected, this, &DeviceView::DeviceConnected);
QObject::connect(&*app_->device_manager(), &DeviceManager::DeviceDisconnected, this, &DeviceView::DeviceDisconnected);
sort_model_ = new QSortFilterProxyModel(this);
sort_model_->setSourceModel(app_->device_manager());
sort_model_->setSourceModel(&*app_->device_manager());
sort_model_->setDynamicSortFilter(true);
sort_model_->setSortCaseSensitivity(Qt::CaseInsensitive);
sort_model_->sort(0);
@@ -220,7 +223,7 @@ void DeviceView::SetApplication(Application *app) {
properties_dialog_->SetDeviceManager(app_->device_manager());
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_->collection_model()->directory_model());
}
@@ -266,7 +269,7 @@ void DeviceView::contextMenuEvent(QContextMenuEvent *e) {
bool is_filesystem_device = false;
if (parent_device_index.isValid()) {
std::shared_ptr<ConnectedDevice> device = app_->device_manager()->GetConnectedDevice(parent_device_index);
SharedPtr<ConnectedDevice> device = app_->device_manager()->GetConnectedDevice(parent_device_index);
if (device && !device->LocalPath().isEmpty()) is_filesystem_device = true;
}
@@ -312,7 +315,7 @@ void DeviceView::DeviceConnected(const QModelIndex &idx) {
if (!idx.isValid()) return;
std::shared_ptr<ConnectedDevice> device = app_->device_manager()->GetConnectedDevice(idx);
SharedPtr<ConnectedDevice> device = app_->device_manager()->GetConnectedDevice(idx);
if (!device) return;
QModelIndex sort_idx = sort_model_->mapFromSource(idx);
@@ -339,7 +342,7 @@ void DeviceView::Forget() {
QModelIndex device_idx = MapToDevice(menu_index_);
QString unique_id = app_->device_manager()->data(device_idx, DeviceManager::Role_UniqueId).toString();
if (app_->device_manager()->GetLister(device_idx) && app_->device_manager()->GetLister(device_idx)->AskForScan(unique_id)) {
std::unique_ptr<QMessageBox> dialog(new QMessageBox(
ScopedPtr<QMessageBox> dialog(new QMessageBox(
QMessageBox::Question, tr("Forget device"),
tr("Forgetting a device will remove it from this list and Strawberry will have to rescan all the songs again next time you connect it."),
QMessageBox::Cancel, this));
@@ -427,7 +430,7 @@ void DeviceView::Delete() {
return;
}
std::shared_ptr<MusicStorage> storage = device_index.data(MusicStorage::Role_Storage).value<std::shared_ptr<MusicStorage>>();
SharedPtr<MusicStorage> storage = device_index.data(MusicStorage::Role_Storage).value<SharedPtr<MusicStorage>>();
DeleteFiles *delete_files = new DeleteFiles(app_->task_manager(), storage, false);
QObject::connect(delete_files, &DeleteFiles::Finished, this, &DeviceView::DeleteFinished);

View File

@@ -24,14 +24,13 @@
#include "config.h"
#include <memory>
#include <QObject>
#include <QStyleOption>
#include <QStyleOptionViewItem>
#include <QAbstractItemModel>
#include <QString>
#include "core/scoped_ptr.h"
#include "core/song.h"
#include "collection/collectionitemdelegate.h"
#include "widgets/autoexpandingtreeview.h"
@@ -107,8 +106,8 @@ class DeviceView : public AutoExpandingTreeView {
MergedProxyModel *merged_model_;
QSortFilterProxyModel *sort_model_;
std::unique_ptr<DeviceProperties> properties_dialog_;
std::unique_ptr<OrganizeDialog> organize_dialog_;
ScopedPtr<DeviceProperties> properties_dialog_;
ScopedPtr<OrganizeDialog> organize_dialog_;
QMenu *device_menu_;
QAction *eject_action_;

View File

@@ -26,6 +26,7 @@
#include <QUrl>
#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/application.h"
#include "core/song.h"
@@ -38,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)
FilesystemDevice::FilesystemDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, const int database_id, const bool first_time, QObject *parent)
: FilesystemMusicStorage(Song::Source::Device, url.toLocalFile()),
ConnectedDevice(url, lister, unique_id, manager, app, database_id, first_time, parent),
watcher_(new CollectionWatcher(Song::Source::Device)),
@@ -52,17 +53,17 @@ FilesystemDevice::FilesystemDevice(const QUrl &url, DeviceLister *lister, const
watcher_->set_backend(backend_);
watcher_->set_task_manager(app_->task_manager());
QObject::connect(backend_, &CollectionBackend::DirectoryDiscovered, watcher_, &CollectionWatcher::AddDirectory);
QObject::connect(backend_, &CollectionBackend::DirectoryDeleted, watcher_, &CollectionWatcher::RemoveDirectory);
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(&*backend_, &CollectionBackend::DirectoryDiscovered, watcher_, &CollectionWatcher::AddDirectory);
QObject::connect(&*backend_, &CollectionBackend::DirectoryDeleted, watcher_, &CollectionWatcher::RemoveDirectory);
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::ScanStarted, this, &FilesystemDevice::TaskStarted);
}
@@ -92,12 +93,12 @@ void FilesystemDevice::Close() {
Q_ASSERT(QThread::currentThread() == thread());
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, &FilesystemDevice::ExitFinished);
QObject::connect(&*backend_, &CollectionBackend::ExitFinished, this, &FilesystemDevice::ExitFinished);
QObject::connect(watcher_, &CollectionWatcher::ExitFinished, this, &FilesystemDevice::ExitFinished);
backend_->ExitAsync();
watcher_->ExitAsync();

View File

@@ -30,6 +30,7 @@
#include <QStringList>
#include <QUrl>
#include "core/shared_ptr.h"
#include "core/filesystemmusicstorage.h"
#include "connecteddevice.h"
@@ -43,7 +44,7 @@ class FilesystemDevice : public ConnectedDevice, public virtual FilesystemMusicS
Q_OBJECT
public:
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);
Q_INVOKABLE FilesystemDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<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; }

View File

@@ -40,6 +40,7 @@
#include <QStandardPaths>
#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/application.h"
#include "collection/collectionbackend.h"
#include "collection/collectionmodel.h"
@@ -50,7 +51,9 @@
class DeviceLister;
class DeviceManager;
GPodDevice::GPodDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, const int database_id, const bool first_time, QObject *parent)
using std::make_shared;
GPodDevice::GPodDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, const int database_id, const bool first_time, QObject *parent)
: ConnectedDevice(url, lister, unique_id, manager, app, database_id, first_time, parent),
loader_(nullptr),
loader_thread_(nullptr),
@@ -197,7 +200,7 @@ bool GPodDevice::CopyToStorage(const CopyJob &job) {
QString temp_path = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
#endif
if (!QDir(temp_path).exists()) QDir().mkpath(temp_path);
std::shared_ptr<QTemporaryFile> cover_file = std::make_shared<QTemporaryFile>(temp_path + "/track-albumcover-XXXXXX.jpg");
SharedPtr<QTemporaryFile> cover_file = make_shared<QTemporaryFile>(temp_path + "/track-albumcover-XXXXXX.jpg");
cover_file->setAutoRemove(true);
if (cover_file->open()) {
cover_file->close();

View File

@@ -24,8 +24,6 @@
#include "config.h"
#include <memory>
#include <gpod/itdb.h>
#include <QObject>
@@ -37,6 +35,7 @@
#include <QUrl>
#include <QTemporaryFile>
#include "core/shared_ptr.h"
#include "core/song.h"
#include "core/musicstorage.h"
#include "connecteddevice.h"
@@ -51,7 +50,7 @@ class GPodDevice : public ConnectedDevice, public virtual MusicStorage {
Q_OBJECT
public:
Q_INVOKABLE GPodDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr);
Q_INVOKABLE GPodDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr);
~GPodDevice() override;
bool Init() override;
@@ -98,7 +97,7 @@ class GPodDevice : public ConnectedDevice, public virtual MusicStorage {
QMutex db_busy_;
SongList songs_to_add_;
SongList songs_to_remove_;
QList<std::shared_ptr<QTemporaryFile>> cover_files_;
QList<SharedPtr<QTemporaryFile>> cover_files_;
};
#endif // GPODDEVICE_H

View File

@@ -30,12 +30,13 @@
#include <QString>
#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/song.h"
#include "core/taskmanager.h"
#include "collection/collectionbackend.h"
#include "gpodloader.h"
GPodLoader::GPodLoader(const QString &mount_point, TaskManager *task_manager, CollectionBackend *backend, std::shared_ptr<ConnectedDevice> device, QObject *parent)
GPodLoader::GPodLoader(const QString &mount_point, SharedPtr<TaskManager> task_manager, SharedPtr<CollectionBackend> backend, SharedPtr<ConnectedDevice> device, QObject *parent)
: QObject(parent),
device_(device),
mount_point_(mount_point),

View File

@@ -24,12 +24,12 @@
#include "config.h"
#include <memory>
#include <gpod/itdb.h>
#include <QObject>
#include <QString>
#include "core/shared_ptr.h"
#include "core/song.h"
class QThread;
@@ -41,7 +41,7 @@ class GPodLoader : public QObject {
Q_OBJECT
public:
explicit GPodLoader(const QString &mount_point, TaskManager *task_manager, CollectionBackend *backend, std::shared_ptr<ConnectedDevice> device, QObject *parent = nullptr);
explicit GPodLoader(const QString &mount_point, SharedPtr<TaskManager> task_manager, SharedPtr<CollectionBackend> backend, SharedPtr<ConnectedDevice> device, QObject *parent = nullptr);
~GPodLoader() override;
void set_music_path_prefix(const QString &prefix) { path_prefix_ = prefix; }
@@ -61,14 +61,14 @@ class GPodLoader : public QObject {
Itdb_iTunesDB *TryLoad();
private:
std::shared_ptr<ConnectedDevice> device_;
SharedPtr<ConnectedDevice> device_;
QThread *original_thread_;
QString mount_point_;
QString path_prefix_;
Song::FileType type_;
TaskManager *task_manager_;
CollectionBackend *backend_;
SharedPtr<TaskManager> task_manager_;
SharedPtr<CollectionBackend> backend_;
bool abort_;
};

View File

@@ -35,7 +35,9 @@
#include "core/song.h"
class MtpConnection : public QObject, public std::enable_shared_from_this<MtpConnection> {
using std::enable_shared_from_this;
class MtpConnection : public QObject, public enable_shared_from_this<MtpConnection> {
Q_OBJECT
public:

View File

@@ -34,6 +34,7 @@
#include <QUrl>
#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/application.h"
#include "core/musicstorage.h"
#include "collection/collectionmodel.h"
@@ -48,7 +49,7 @@ class DeviceManager;
bool MtpDevice::sInitializedLibMTP = false;
MtpDevice::MtpDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, const int database_id, const bool first_time, QObject *parent)
MtpDevice::MtpDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, const int database_id, const bool first_time, QObject *parent)
: ConnectedDevice(url, lister, unique_id, manager, app, database_id, first_time, parent),
loader_(nullptr),
loader_thread_(nullptr),

View File

@@ -24,8 +24,6 @@
#include "config.h"
#include <memory>
#include <QObject>
#include <QMutex>
#include <QList>
@@ -33,6 +31,8 @@
#include <QStringList>
#include <QUrl>
#include "core/scoped_ptr.h"
#include "core/shared_ptr.h"
#include "core/song.h"
#include "connecteddevice.h"
@@ -48,7 +48,7 @@ class MtpDevice : public ConnectedDevice {
Q_OBJECT
public:
Q_INVOKABLE MtpDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, DeviceManager *manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr);
Q_INVOKABLE MtpDevice(const QUrl &url, DeviceLister *lister, const QString &unique_id, SharedPtr<DeviceManager> manager, Application *app, const int database_id, const bool first_time, QObject *parent = nullptr);
~MtpDevice() override;
static QStringList url_schemes() { return QStringList() << "mtp"; }
@@ -90,8 +90,7 @@ class MtpDevice : public ConnectedDevice {
SongList songs_to_add_;
SongList songs_to_remove_;
std::unique_ptr<MtpConnection> connection_;
ScopedPtr<MtpConnection> connection_;
};
#endif // MTPDEVICE_H

View File

@@ -23,17 +23,21 @@
#include <libmtp.h>
#include <QObject>
#include <QUrl>
#include <memory>
#include <QObject>
#include <QUrl>
#include "core/shared_ptr.h"
#include "core/taskmanager.h"
#include "core/song.h"
#include "collection/collectionbackend.h"
#include "mtpconnection.h"
#include "mtploader.h"
MtpLoader::MtpLoader(const QUrl &url, TaskManager *task_manager, CollectionBackend *backend, QObject *parent)
using std::make_unique;
MtpLoader::MtpLoader(const QUrl &url, SharedPtr<TaskManager> task_manager, SharedPtr<CollectionBackend> backend, QObject *parent)
: QObject(parent),
url_(url),
task_manager_(task_manager),
@@ -62,7 +66,7 @@ void MtpLoader::LoadDatabase() {
bool MtpLoader::TryLoad() {
connection_ = std::make_unique<MtpConnection>(url_);
connection_ = make_unique<MtpConnection>(url_);
if (!connection_ || !connection_->is_valid()) {
emit Error(tr("Error connecting MTP device %1").arg(url_.toString()));

View File

@@ -24,12 +24,13 @@
#include "config.h"
#include <memory>
#include <QObject>
#include <QString>
#include <QUrl>
#include "core/scoped_ptr.h"
#include "core/shared_ptr.h"
class QThread;
class TaskManager;
class CollectionBackend;
@@ -39,7 +40,7 @@ class MtpLoader : public QObject {
Q_OBJECT
public:
explicit MtpLoader(const QUrl &url, TaskManager *task_manager, CollectionBackend *backend, QObject *parent = nullptr);
explicit MtpLoader(const QUrl &url, SharedPtr<TaskManager> task_manager, SharedPtr<CollectionBackend> backend, QObject *parent = nullptr);
~MtpLoader() override;
bool Init();
@@ -58,9 +59,9 @@ class MtpLoader : public QObject {
private:
QUrl url_;
TaskManager *task_manager_;
CollectionBackend *backend_;
std::unique_ptr<MtpConnection> connection_;
SharedPtr<TaskManager> task_manager_;
SharedPtr<CollectionBackend> backend_;
ScopedPtr<MtpConnection> connection_;
QThread *original_thread_;
bool abort_;

View File

@@ -42,6 +42,8 @@
#include <QJsonArray>
#include "core/logging.h"
#include "core/scoped_ptr.h"
#include "core/shared_ptr.h"
#include "utilities/diskutils.h"
#include "udisks2lister.h"
@@ -52,6 +54,9 @@
#include "udisks2filesystem.h"
#include "udisks2job.h"
using std::make_unique;
using std::make_shared;
Udisks2Lister::Udisks2Lister(QObject *parent) : DeviceLister(parent) {}
Udisks2Lister::~Udisks2Lister() = default;
@@ -180,7 +185,7 @@ void Udisks2Lister::UpdateDeviceFreeSpace(const QString &id) {
bool Udisks2Lister::Init() {
udisks2_interface_ = std::make_unique<OrgFreedesktopDBusObjectManagerInterface>(udisks2_service_, "/org/freedesktop/UDisks2", QDBusConnection::systemBus());
udisks2_interface_ = make_unique<OrgFreedesktopDBusObjectManagerInterface>(udisks2_service_, "/org/freedesktop/UDisks2", QDBusConnection::systemBus());
QDBusPendingReply<ManagedObjectList> reply = udisks2_interface_->GetManagedObjects();
reply.waitForFinished();
@@ -206,8 +211,8 @@ bool Udisks2Lister::Init() {
emit DeviceAdded(id);
}
QObject::connect(udisks2_interface_.get(), &OrgFreedesktopDBusObjectManagerInterface::InterfacesAdded, this, &Udisks2Lister::DBusInterfaceAdded);
QObject::connect(udisks2_interface_.get(), &OrgFreedesktopDBusObjectManagerInterface::InterfacesRemoved, this, &Udisks2Lister::DBusInterfaceRemoved);
QObject::connect(&*udisks2_interface_, &OrgFreedesktopDBusObjectManagerInterface::InterfacesAdded, this, &Udisks2Lister::DBusInterfaceAdded);
QObject::connect(&*udisks2_interface_, &OrgFreedesktopDBusObjectManagerInterface::InterfacesRemoved, this, &Udisks2Lister::DBusInterfaceRemoved);
return true;
@@ -219,7 +224,7 @@ void Udisks2Lister::DBusInterfaceAdded(const QDBusObjectPath &path, const Interf
if (interface.key() != "org.freedesktop.UDisks2.Job") continue;
std::shared_ptr<OrgFreedesktopUDisks2JobInterface> job = std::make_shared<OrgFreedesktopUDisks2JobInterface>(udisks2_service_, path.path(), QDBusConnection::systemBus());
SharedPtr<OrgFreedesktopUDisks2JobInterface> job = make_shared<OrgFreedesktopUDisks2JobInterface>(udisks2_service_, path.path(), QDBusConnection::systemBus());
if (!job->isValid()) continue;
@@ -247,7 +252,7 @@ void Udisks2Lister::DBusInterfaceAdded(const QDBusObjectPath &path, const Interf
mounting_jobs_[path].dbus_interface = job;
mounting_jobs_[path].is_mount = is_mount_job;
mounting_jobs_[path].mounted_partitions = mounted_partitions;
QObject::connect(job.get(), &OrgFreedesktopUDisks2JobInterface::Completed, this, &Udisks2Lister::JobCompleted);
QObject::connect(&*job, &OrgFreedesktopUDisks2JobInterface::Completed, this, &Udisks2Lister::JobCompleted);
}
}
}

View File

@@ -24,8 +24,6 @@
#include "config.h"
#include <memory>
#include <QtGlobal>
#include <QObject>
#include <QMutex>
@@ -40,6 +38,9 @@
#include <QJsonArray>
#include <QJsonObject>
#include "core/scoped_ptr.h"
#include "core/shared_ptr.h"
#include "dbus/metatypes.h"
#include "devicelister.h"
@@ -85,7 +86,7 @@ class Udisks2Lister : public DeviceLister {
Udisks2Job();
bool is_mount;
QList<QDBusObjectPath> mounted_partitions;
std::shared_ptr<OrgFreedesktopUDisks2JobInterface> dbus_interface;
SharedPtr<OrgFreedesktopUDisks2JobInterface> dbus_interface;
};
QMutex jobs_lock_;
@@ -122,7 +123,7 @@ class Udisks2Lister : public DeviceLister {
QMap<QString, PartitionData> device_data_;
private:
std::unique_ptr<OrgFreedesktopDBusObjectManagerInterface> udisks2_interface_;
ScopedPtr<OrgFreedesktopDBusObjectManagerInterface> udisks2_interface_;
static constexpr char udisks2_service_[] = "org.freedesktop.UDisks2";
};