diff --git a/src/devices/afcdevice.cpp b/src/devices/afcdevice.cpp index 997e930bb..24dc73329 100644 --- a/src/devices/afcdevice.cpp +++ b/src/devices/afcdevice.cpp @@ -43,7 +43,8 @@ void AfcDevice::Init() { InitBackendDirectory(local_path_, first_time_, false); model_->Init(); - transfer_ = new AfcTransfer(url_.host(), local_path_, manager_->task_manager()); + transfer_ = new AfcTransfer(url_.host(), local_path_, manager_->task_manager(), + shared_from_this()); transfer_->moveToThread(loader_thread_); connect(transfer_, SIGNAL(TaskStarted(int)), SIGNAL(TaskStarted(int))); @@ -62,7 +63,8 @@ void AfcDevice::CopyFinished(bool success) { } // Now load the songs from the local database - loader_ = new GPodLoader(local_path_, manager_->task_manager(), backend_); + loader_ = new GPodLoader(local_path_, manager_->task_manager(), backend_, + shared_from_this()); loader_->set_music_path_prefix("afc://" + url_.host()); loader_->set_song_type(Song::Type_Stream); loader_->moveToThread(loader_thread_); @@ -139,7 +141,7 @@ void AfcDevice::FinaliseDatabase() { // Copy the files back to the iPod // No need to start another thread since we're already in the organiser thread - AfcTransfer transfer(url_.host(), local_path_, NULL); + AfcTransfer transfer(url_.host(), local_path_, NULL, shared_from_this()); itdb_start_sync(db_); bool success = transfer.CopyToDevice(); diff --git a/src/devices/afctransfer.cpp b/src/devices/afctransfer.cpp index c86c007c7..104e0d9da 100644 --- a/src/devices/afctransfer.cpp +++ b/src/devices/afctransfer.cpp @@ -25,8 +25,9 @@ #include AfcTransfer::AfcTransfer(const QString& uuid, const QString& local_destination, - TaskManager* task_manager, QObject* parent) - : QObject(parent), + TaskManager* task_manager, boost::shared_ptr device) + : QObject(NULL), + device_(device), task_manager_(task_manager), uuid_(uuid), local_destination_(local_destination) @@ -38,6 +39,9 @@ AfcTransfer::AfcTransfer(const QString& uuid, const QString& local_destination, important_directories_ << "/iTunes_Control/iTunes"; } +AfcTransfer::~AfcTransfer() { +} + void AfcTransfer::CopyFromDevice() { int task_id = 0; if (task_manager_) { diff --git a/src/devices/afctransfer.h b/src/devices/afctransfer.h index 5d96930b6..f6671ee46 100644 --- a/src/devices/afctransfer.h +++ b/src/devices/afctransfer.h @@ -20,6 +20,9 @@ #include #include +#include + +class ConnectedDevice; class iMobileDeviceConnection; class TaskManager; @@ -30,7 +33,8 @@ class AfcTransfer : public QObject { public: AfcTransfer(const QString& uuid, const QString& local_destination, - TaskManager* task_manager, QObject* parent = 0); + TaskManager* task_manager, boost::shared_ptr device); + ~AfcTransfer(); bool CopyToDevice(); @@ -50,6 +54,7 @@ private: static bool Copy(QIODevice* source, QIODevice* destination); private: + boost::shared_ptr device_; QThread* original_thread_; TaskManager* task_manager_; diff --git a/src/devices/connecteddevice.h b/src/devices/connecteddevice.h index ff1f1b98e..84b9f3f4a 100644 --- a/src/devices/connecteddevice.h +++ b/src/devices/connecteddevice.h @@ -23,13 +23,16 @@ #include #include +#include + class Database; class DeviceLister; class DeviceManager; class LibraryBackend; class LibraryModel; -class ConnectedDevice : public QObject, public virtual MusicStorage { +class ConnectedDevice : public QObject, public virtual MusicStorage, + public boost::enable_shared_from_this { Q_OBJECT public: diff --git a/src/devices/gpoddevice.cpp b/src/devices/gpoddevice.cpp index e935cc570..f81c9e394 100644 --- a/src/devices/gpoddevice.cpp +++ b/src/devices/gpoddevice.cpp @@ -40,7 +40,8 @@ void GPodDevice::Init() { InitBackendDirectory(url_.path(), first_time_); model_->Init(); - loader_ = new GPodLoader(url_.path(), manager_->task_manager(), backend_); + loader_ = new GPodLoader(url_.path(), manager_->task_manager(), backend_, + shared_from_this()); loader_->moveToThread(loader_thread_); connect(loader_, SIGNAL(Error(QString)), SIGNAL(Error(QString))); diff --git a/src/devices/gpodloader.cpp b/src/devices/gpodloader.cpp index 1938fd1c4..fee8f3a32 100644 --- a/src/devices/gpodloader.cpp +++ b/src/devices/gpodloader.cpp @@ -14,6 +14,7 @@ along with Clementine. If not, see . */ +#include "connecteddevice.h" #include "gpodloader.h" #include "core/song.h" #include "core/taskmanager.h" @@ -24,8 +25,9 @@ #include GPodLoader::GPodLoader(const QString& mount_point, TaskManager* task_manager, - LibraryBackend* backend, QObject *parent) - : QObject(parent), + LibraryBackend* backend, boost::shared_ptr device) + : QObject(NULL), + device_(device), mount_point_(mount_point), type_(Song::Type_Unknown), task_manager_(task_manager), @@ -34,6 +36,9 @@ GPodLoader::GPodLoader(const QString& mount_point, TaskManager* task_manager, original_thread_ = thread(); } +GPodLoader::~GPodLoader() { +} + void GPodLoader::LoadDatabase() { int task_id = task_manager_->StartTask(tr("Loading iPod database")); emit TaskStarted(task_id); diff --git a/src/devices/gpodloader.h b/src/devices/gpodloader.h index 078d9ac4a..d456b259b 100644 --- a/src/devices/gpodloader.h +++ b/src/devices/gpodloader.h @@ -24,6 +24,7 @@ #include "core/song.h" +class ConnectedDevice; class LibraryBackend; class TaskManager; @@ -32,7 +33,8 @@ class GPodLoader : public QObject { public: GPodLoader(const QString& mount_point, TaskManager* task_manager, - LibraryBackend* backend, QObject* parent = 0); + LibraryBackend* backend, boost::shared_ptr device); + ~GPodLoader(); void set_music_path_prefix(const QString& prefix) { path_prefix_ = prefix; } void set_song_type(Song::FileType type) { type_ = type; } @@ -46,6 +48,7 @@ signals: void LoadFinished(Itdb_iTunesDB* db); private: + boost::shared_ptr device_; QThread* original_thread_; QString mount_point_;