Pass shared_ptrs to music storage things to the organiser thread so they won't get deleted if the device is disconnected
This commit is contained in:
parent
43a27979dc
commit
5e00eb11de
@ -24,7 +24,8 @@
|
|||||||
|
|
||||||
const int DeleteFiles::kBatchSize = 50;
|
const int DeleteFiles::kBatchSize = 50;
|
||||||
|
|
||||||
DeleteFiles::DeleteFiles(TaskManager* task_manager, MusicStorage* storage)
|
DeleteFiles::DeleteFiles(TaskManager* task_manager,
|
||||||
|
boost::shared_ptr<MusicStorage> storage)
|
||||||
: thread_(NULL),
|
: thread_(NULL),
|
||||||
task_manager_(task_manager),
|
task_manager_(task_manager),
|
||||||
storage_(storage),
|
storage_(storage),
|
||||||
@ -35,6 +36,9 @@ DeleteFiles::DeleteFiles(TaskManager* task_manager, MusicStorage* storage)
|
|||||||
original_thread_ = thread();
|
original_thread_ = thread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteFiles::~DeleteFiles() {
|
||||||
|
}
|
||||||
|
|
||||||
void DeleteFiles::Start(const SongList& songs) {
|
void DeleteFiles::Start(const SongList& songs) {
|
||||||
if (thread_)
|
if (thread_)
|
||||||
return;
|
return;
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
|
||||||
class MusicStorage;
|
class MusicStorage;
|
||||||
@ -28,7 +30,8 @@ class DeleteFiles : public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DeleteFiles(TaskManager* task_manager, MusicStorage* storage);
|
DeleteFiles(TaskManager* task_manager, boost::shared_ptr<MusicStorage> storage);
|
||||||
|
~DeleteFiles();
|
||||||
|
|
||||||
static const int kBatchSize;
|
static const int kBatchSize;
|
||||||
|
|
||||||
@ -42,7 +45,7 @@ private:
|
|||||||
QThread* thread_;
|
QThread* thread_;
|
||||||
QThread* original_thread_;
|
QThread* original_thread_;
|
||||||
TaskManager* task_manager_;
|
TaskManager* task_manager_;
|
||||||
MusicStorage* storage_;
|
boost::shared_ptr<MusicStorage> storage_;
|
||||||
|
|
||||||
SongList songs_;
|
SongList songs_;
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
class MusicStorage {
|
class MusicStorage {
|
||||||
public:
|
public:
|
||||||
MusicStorage();
|
MusicStorage();
|
||||||
@ -48,5 +50,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(MusicStorage*);
|
Q_DECLARE_METATYPE(MusicStorage*);
|
||||||
|
Q_DECLARE_METATYPE(boost::shared_ptr<MusicStorage>);
|
||||||
|
|
||||||
#endif // MUSICSTORAGE_H
|
#endif // MUSICSTORAGE_H
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
|
|
||||||
const int Organise::kBatchSize = 10;
|
const int Organise::kBatchSize = 10;
|
||||||
|
|
||||||
Organise::Organise(TaskManager* task_manager, MusicStorage* destination,
|
Organise::Organise(TaskManager* task_manager,
|
||||||
|
boost::shared_ptr<MusicStorage> destination,
|
||||||
const OrganiseFormat &format, bool copy, bool overwrite,
|
const OrganiseFormat &format, bool copy, bool overwrite,
|
||||||
const QStringList& files, bool eject_after)
|
const QStringList& files, bool eject_after)
|
||||||
: thread_(NULL),
|
: thread_(NULL),
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include "organiseformat.h"
|
#include "organiseformat.h"
|
||||||
|
|
||||||
class MusicStorage;
|
class MusicStorage;
|
||||||
@ -28,7 +30,8 @@ class Organise : public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Organise(TaskManager* task_manager, MusicStorage* destination,
|
Organise(TaskManager* task_manager,
|
||||||
|
boost::shared_ptr<MusicStorage> destination,
|
||||||
const OrganiseFormat& format, bool copy, bool overwrite,
|
const OrganiseFormat& format, bool copy, bool overwrite,
|
||||||
const QStringList& files, bool eject_after);
|
const QStringList& files, bool eject_after);
|
||||||
|
|
||||||
@ -43,7 +46,7 @@ private:
|
|||||||
QThread* thread_;
|
QThread* thread_;
|
||||||
QThread* original_thread_;
|
QThread* original_thread_;
|
||||||
TaskManager* task_manager_;
|
TaskManager* task_manager_;
|
||||||
MusicStorage* destination_;
|
boost::shared_ptr<MusicStorage> destination_;
|
||||||
|
|
||||||
const OrganiseFormat format_;
|
const OrganiseFormat format_;
|
||||||
const bool copy_;
|
const bool copy_;
|
||||||
|
@ -251,7 +251,7 @@ QVariant DeviceManager::data(const QModelIndex& index, int role) const {
|
|||||||
const_cast<DeviceManager*>(this)->Connect(index.row());
|
const_cast<DeviceManager*>(this)->Connect(index.row());
|
||||||
if (!info.device_)
|
if (!info.device_)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
return QVariant::fromValue<MusicStorage*>(info.device_.get());
|
return QVariant::fromValue<boost::shared_ptr<MusicStorage> >(info.device_);
|
||||||
|
|
||||||
case Role_MountPath:
|
case Role_MountPath:
|
||||||
if (!info.device_)
|
if (!info.device_)
|
||||||
|
@ -345,7 +345,8 @@ void DeviceView::Delete() {
|
|||||||
QMessageBox::Yes, QMessageBox::Cancel) != QMessageBox::Yes)
|
QMessageBox::Yes, QMessageBox::Cancel) != QMessageBox::Yes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MusicStorage* storage = device_index.data(MusicStorage::Role_Storage).value<MusicStorage*>();
|
boost::shared_ptr<MusicStorage> storage =
|
||||||
|
device_index.data(MusicStorage::Role_Storage).value<boost::shared_ptr<MusicStorage> >();
|
||||||
|
|
||||||
DeleteFiles* delete_files = new DeleteFiles(manager_->task_manager(), storage);
|
DeleteFiles* delete_files = new DeleteFiles(manager_->task_manager(), storage);
|
||||||
delete_files->Start(GetSelectedSongs());
|
delete_files->Start(GetSelectedSongs());
|
||||||
|
@ -31,14 +31,13 @@ LibraryDirectoryModel::LibraryDirectoryModel(LibraryBackend* backend, QObject* p
|
|||||||
}
|
}
|
||||||
|
|
||||||
LibraryDirectoryModel::~LibraryDirectoryModel() {
|
LibraryDirectoryModel::~LibraryDirectoryModel() {
|
||||||
qDeleteAll(storage_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryDirectoryModel::DirectoryDiscovered(const Directory &dir) {
|
void LibraryDirectoryModel::DirectoryDiscovered(const Directory &dir) {
|
||||||
QStandardItem* item = new QStandardItem(dir.path);
|
QStandardItem* item = new QStandardItem(dir.path);
|
||||||
item->setData(dir.id, kIdRole);
|
item->setData(dir.id, kIdRole);
|
||||||
item->setIcon(dir_icon_);
|
item->setIcon(dir_icon_);
|
||||||
storage_ << new FilesystemMusicStorage(dir.path);
|
storage_ << boost::shared_ptr<MusicStorage>(new FilesystemMusicStorage(dir.path));
|
||||||
appendRow(item);
|
appendRow(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ void LibraryDirectoryModel::DirectoryDeleted(const Directory &dir) {
|
|||||||
for (int i=0 ; i<rowCount() ; ++i) {
|
for (int i=0 ; i<rowCount() ; ++i) {
|
||||||
if (item(i, 0)->data(kIdRole).toInt() == dir.id) {
|
if (item(i, 0)->data(kIdRole).toInt() == dir.id) {
|
||||||
removeRow(i);
|
removeRow(i);
|
||||||
delete storage_.takeAt(i);
|
storage_.removeAt(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,10 @@
|
|||||||
#ifndef LIBRARYDIRECTORYMODEL_H
|
#ifndef LIBRARYDIRECTORYMODEL_H
|
||||||
#define LIBRARYDIRECTORYMODEL_H
|
#define LIBRARYDIRECTORYMODEL_H
|
||||||
|
|
||||||
#include <QStandardItemModel>
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
|
|
||||||
@ -48,7 +50,7 @@ class LibraryDirectoryModel : public QStandardItemModel {
|
|||||||
|
|
||||||
QIcon dir_icon_;
|
QIcon dir_icon_;
|
||||||
LibraryBackend* backend_;
|
LibraryBackend* backend_;
|
||||||
QList<MusicStorage*> storage_;
|
QList<boost::shared_ptr<MusicStorage> > storage_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIBRARYDIRECTORYMODEL_H
|
#endif // LIBRARYDIRECTORYMODEL_H
|
||||||
|
@ -300,8 +300,10 @@ void LibraryView::Delete() {
|
|||||||
// We can cheat and always take the storage of the first directory, since
|
// We can cheat and always take the storage of the first directory, since
|
||||||
// they'll all be FilesystemMusicStorage in a library and deleting doesn't
|
// they'll all be FilesystemMusicStorage in a library and deleting doesn't
|
||||||
// check the actual directory.
|
// check the actual directory.
|
||||||
MusicStorage* storage = library_->directory_model()->index(0, 0).data(
|
boost::shared_ptr<MusicStorage> storage =
|
||||||
MusicStorage::Role_Storage).value<MusicStorage*>();
|
library_->directory_model()->index(0, 0).data(MusicStorage::Role_Storage)
|
||||||
|
.value<boost::shared_ptr<MusicStorage> >();
|
||||||
|
|
||||||
DeleteFiles* delete_files = new DeleteFiles(task_manager_, storage);
|
DeleteFiles* delete_files = new DeleteFiles(task_manager_, storage);
|
||||||
delete_files->Start(songs);
|
delete_files->Start(songs);
|
||||||
}
|
}
|
||||||
|
@ -177,11 +177,12 @@ void OrganiseDialog::InsertTag(const QString &tag) {
|
|||||||
void OrganiseDialog::UpdatePreviews() {
|
void OrganiseDialog::UpdatePreviews() {
|
||||||
const QModelIndex destination = ui_->destination->model()->index(
|
const QModelIndex destination = ui_->destination->model()->index(
|
||||||
ui_->destination->currentIndex(), 0);
|
ui_->destination->currentIndex(), 0);
|
||||||
MusicStorage* storage = NULL;
|
boost::shared_ptr<MusicStorage> storage;
|
||||||
bool has_local_destination = false;
|
bool has_local_destination = false;
|
||||||
|
|
||||||
if (destination.isValid()) {
|
if (destination.isValid()) {
|
||||||
storage = destination.data(MusicStorage::Role_Storage).value<MusicStorage*>();
|
storage = destination.data(MusicStorage::Role_Storage)
|
||||||
|
.value<boost::shared_ptr<MusicStorage> >();
|
||||||
if (storage) {
|
if (storage) {
|
||||||
has_local_destination = !storage->LocalPath().isEmpty();
|
has_local_destination = !storage->LocalPath().isEmpty();
|
||||||
}
|
}
|
||||||
@ -274,8 +275,9 @@ void OrganiseDialog::accept() {
|
|||||||
|
|
||||||
const QModelIndex destination = ui_->destination->model()->index(
|
const QModelIndex destination = ui_->destination->model()->index(
|
||||||
ui_->destination->currentIndex(), 0);
|
ui_->destination->currentIndex(), 0);
|
||||||
MusicStorage* storage =
|
boost::shared_ptr<MusicStorage> storage =
|
||||||
destination.data(MusicStorage::Role_Storage).value<MusicStorage*>();
|
destination.data(MusicStorage::Role_Storage)
|
||||||
|
.value<boost::shared_ptr<MusicStorage> >();
|
||||||
|
|
||||||
// It deletes itself when it's finished.
|
// It deletes itself when it's finished.
|
||||||
const bool copy = ui_->aftercopying->currentIndex() == 0;
|
const bool copy = ui_->aftercopying->currentIndex() == 0;
|
||||||
|
@ -63,7 +63,6 @@ FileView::FileView(QWidget* parent)
|
|||||||
|
|
||||||
FileView::~FileView() {
|
FileView::~FileView() {
|
||||||
delete ui_;
|
delete ui_;
|
||||||
delete storage_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileView::SetPath(const QString& path) {
|
void FileView::SetPath(const QString& path) {
|
||||||
|
@ -22,7 +22,10 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
class FilesystemMusicStorage;
|
class FilesystemMusicStorage;
|
||||||
|
class MusicStorage;
|
||||||
class TaskManager;
|
class TaskManager;
|
||||||
class Ui_FileView;
|
class Ui_FileView;
|
||||||
|
|
||||||
@ -89,7 +92,7 @@ class FileView : public QWidget {
|
|||||||
QUndoStack* undo_stack_;
|
QUndoStack* undo_stack_;
|
||||||
|
|
||||||
TaskManager* task_manager_;
|
TaskManager* task_manager_;
|
||||||
FilesystemMusicStorage* storage_;
|
boost::shared_ptr<MusicStorage> storage_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FILEVIEW_H
|
#endif // FILEVIEW_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user