diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index a7576befd..3867d2f25 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -666,7 +666,7 @@ bool Playlist::dropMimeData(const QMimeData* data, Qt::DropAction action, int ro } void Playlist::InsertUrls(const QList &urls, int pos, bool play_now, bool enqueue) { - SongLoaderInserter* inserter = new SongLoaderInserter(task_manager_, library_, this); + SongLoaderInserter* inserter = new SongLoaderInserter(task_manager_, library_); connect(inserter, SIGNAL(Error(QString)), SIGNAL(LoadTracksError(QString))); inserter->Load(this, pos, play_now, enqueue, urls); diff --git a/src/playlist/songloaderinserter.cpp b/src/playlist/songloaderinserter.cpp index 6bdb86556..a52cc4c3b 100644 --- a/src/playlist/songloaderinserter.cpp +++ b/src/playlist/songloaderinserter.cpp @@ -21,9 +21,8 @@ #include "core/taskmanager.h" SongLoaderInserter::SongLoaderInserter( - TaskManager* task_manager, LibraryBackendInterface* library, QObject *parent) - : QObject(parent), - task_manager_(task_manager), + TaskManager* task_manager, LibraryBackendInterface* library) + : task_manager_(task_manager), destination_(NULL), row_(-1), play_now_(true), @@ -44,6 +43,8 @@ void SongLoaderInserter::Load(Playlist *destination, row_ = row; play_now_ = play_now; + connect(destination, SIGNAL(destroyed()), SLOT(DestinationDestroyed())); + foreach (const QUrl& url, urls) { SongLoader* loader = new SongLoader(library_, this); SongLoader::Result ret = loader->Load(url); @@ -70,6 +71,10 @@ void SongLoaderInserter::Load(Playlist *destination, } } +void SongLoaderInserter::DestinationDestroyed() { + destination_ = NULL; +} + void SongLoaderInserter::PendingLoadFinished(bool success) { SongLoader* loader = qobject_cast(sender()); if (!loader || !pending_.contains(loader)) @@ -91,7 +96,9 @@ void SongLoaderInserter::PendingLoadFinished(bool success) { } void SongLoaderInserter::Finished() { - destination_->InsertSongsOrLibraryItems(songs_, row_, play_now_, enqueue_); + if (destination_) { + destination_->InsertSongsOrLibraryItems(songs_, row_, play_now_, enqueue_); + } deleteLater(); } diff --git a/src/playlist/songloaderinserter.h b/src/playlist/songloaderinserter.h index 2e550caab..bc89973c6 100644 --- a/src/playlist/songloaderinserter.h +++ b/src/playlist/songloaderinserter.h @@ -34,7 +34,7 @@ class QModelIndex; class SongLoaderInserter : public QObject { Q_OBJECT public: - SongLoaderInserter(TaskManager* task_manager, LibraryBackendInterface* library, QObject* parent = 0); + SongLoaderInserter(TaskManager* task_manager, LibraryBackendInterface* library); ~SongLoaderInserter(); void Load(Playlist* destination, int row, bool play_now, bool enqueue, @@ -45,6 +45,7 @@ signals: private slots: void PendingLoadFinished(bool success); + void DestinationDestroyed(); private: void Finished(); diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index cff2aec2a..030d50a47 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -53,7 +53,6 @@ #include "playlist/playlistview.h" #include "playlist/queue.h" #include "playlist/queuemanager.h" -#include "playlist/songloaderinserter.h" #include "playlist/songplaylistitem.h" #include "playlistparsers/playlistparser.h" #include "radio/magnatuneservice.h"