diff --git a/src/collection/collectionmodel.cpp b/src/collection/collectionmodel.cpp index 97ba98e0a..4dd928e63 100644 --- a/src/collection/collectionmodel.cpp +++ b/src/collection/collectionmodel.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,7 @@ #include #include "core/application.h" +#include "core/closure.h" #include "core/database.h" #include "core/iconloader.h" #include "core/logging.h" @@ -857,15 +859,18 @@ void CollectionModel::LazyPopulate(CollectionItem *parent, const bool signal) { } void CollectionModel::ResetAsync() { - (void)QtConcurrent::run([=]() { ResetAsyncQueryFinished(RunQuery(root_)); }); + QFuture future = QtConcurrent::run(this, &CollectionModel::RunQuery, root_); + NewClosure(future, this, SLOT(ResetAsyncQueryFinished(QFuture)), future); } -void CollectionModel::ResetAsyncQueryFinished(QueryResult result) { +void CollectionModel::ResetAsyncQueryFinished(QFuture future) { if (QThread::currentThread() != thread() && QThread::currentThread() != backend_->thread()) { backend_->Close(); } + const struct QueryResult result = future.result(); + BeginReset(); root_->lazy_loaded = true; diff --git a/src/collection/collectionmodel.h b/src/collection/collectionmodel.h index 23835927f..949820b2e 100644 --- a/src/collection/collectionmodel.h +++ b/src/collection/collectionmodel.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -212,7 +213,7 @@ class CollectionModel : public SimpleTreeModel { void ClearDiskCache(); // Called after ResetAsync - void ResetAsyncQueryFinished(QueryResult result); + void ResetAsyncQueryFinished(QFuture future); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result); diff --git a/src/dialogs/edittagdialog.cpp b/src/dialogs/edittagdialog.cpp index f10545ba7..f8d33243f 100644 --- a/src/dialogs/edittagdialog.cpp +++ b/src/dialogs/edittagdialog.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -285,15 +286,16 @@ void EditTagDialog::SetSongs(const SongList &s, const PlaylistItemList &items) { ui_->song_list->clear(); // Reload tags in the background - (void)QtConcurrent::run([=]{ SetSongsFinished(LoadData(s)); }); + QFuture> future = QtConcurrent::run(this, &EditTagDialog::LoadData, s); + NewClosure(future, this, SLOT(SetSongsFinished(QFuture>)), future); } -void EditTagDialog::SetSongsFinished(QList _data) { +void EditTagDialog::SetSongsFinished(QFuture> future) { if (!SetLoading(QString())) return; - data_ = _data; + data_ = future.result(); if (data_.count() == 0) { // If there were no valid songs, disable everything ui_->song_list->setEnabled(false); diff --git a/src/dialogs/edittagdialog.h b/src/dialogs/edittagdialog.h index 71731c270..1f926f651 100644 --- a/src/dialogs/edittagdialog.h +++ b/src/dialogs/edittagdialog.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -99,7 +100,7 @@ class EditTagDialog : public QDialog { }; private slots: - void SetSongsFinished(QList _data); + void SetSongsFinished(QFuture> future); void AcceptFinished(); void SelectionChanged(); diff --git a/src/organise/organisedialog.cpp b/src/organise/organisedialog.cpp index 869b4fb9b..be7528850 100644 --- a/src/organise/organisedialog.cpp +++ b/src/organise/organisedialog.cpp @@ -344,9 +344,10 @@ bool OrganiseDialog::SetUrls(const QList &urls) { bool OrganiseDialog::SetFilenames(const QStringList &filenames) { - SetLoadingSongs(true); - songs_future_ = QtConcurrent::run([=]{ SetSongs(LoadSongsBlocking(filenames)); }); + songs_future_ = QtConcurrent::run(this, &OrganiseDialog::LoadSongsBlocking, filenames); + NewClosure(songs_future_, [=]() { SetSongs(songs_future_.result()); }); + SetLoadingSongs(true); return true; } diff --git a/src/organise/organisedialog.h b/src/organise/organisedialog.h index 93c044752..b74b38853 100644 --- a/src/organise/organisedialog.h +++ b/src/organise/organisedialog.h @@ -117,7 +117,7 @@ class OrganiseDialog : public QDialog { OrganiseFormat format_; - QFuture songs_future_; + QFuture songs_future_; SongList songs_; Organise::NewSongInfoList new_songs_info_; quint64 total_size_; diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index 298117afa..fd9c968c1 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -1314,15 +1314,17 @@ void Playlist::Restore() { collection_items_by_id_.clear(); cancel_restore_ = false; - - (void)QtConcurrent::run([=]() { ItemsLoaded(backend_->GetPlaylistItems(id_)); }); + QFuture> future = QtConcurrent::run(backend_, &PlaylistBackend::GetPlaylistItems, id_); + NewClosure(future, this, SLOT(ItemsLoaded(QFuture)), future); } -void Playlist::ItemsLoaded(PlaylistItemList items) { +void Playlist::ItemsLoaded(QFuture future) { if (cancel_restore_) return; + PlaylistItemList items = future.result(); + // Backend returns empty elements for collection items which it couldn't match (because they got deleted); we don't need those QMutableListIterator it(items); while (it.hasNext()) { @@ -1351,7 +1353,7 @@ void Playlist::ItemsLoaded(PlaylistItemList items) { // Should we gray out deleted songs asynchronously on startup? if (greyout) { - (void)QtConcurrent::run([=]() { InvalidateDeletedSongs(); }); + QtConcurrent::run(this, &Playlist::InvalidateDeletedSongs); } emit PlaylistLoaded(); diff --git a/src/playlist/playlist.h b/src/playlist/playlist.h index ff5297a7f..c5ef6d186 100644 --- a/src/playlist/playlist.h +++ b/src/playlist/playlist.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -348,7 +349,7 @@ class Playlist : public QAbstractListModel { void QueueLayoutChanged(); void SongSaveComplete(TagReaderReply *reply, const QPersistentModelIndex &index); void ItemReloadComplete(const QPersistentModelIndex &index); - void ItemsLoaded(PlaylistItemList items); + void ItemsLoaded(QFuture future); void SongInsertVetoListenerDestroyed(); void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result); diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index 4b0d4a8dc..d9162a0a5 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -42,6 +42,7 @@ #include #include "core/application.h" +#include "core/closure.h" #include "core/logging.h" #include "core/player.h" #include "core/utilities.h" @@ -210,11 +211,18 @@ void PlaylistManager::Save(int id, const QString &filename, Playlist::Path path_ } else { // Playlist is not in the playlist manager: probably save action was triggered from the left side bar and the playlist isn't loaded. - (void)QtConcurrent::run([=]() { parser_->Save(playlist_backend_->GetPlaylistSongs(id), filename, path_type); }); + QFuture> future = QtConcurrent::run(playlist_backend_, &PlaylistBackend::GetPlaylistSongs, id); + NewClosure(future, this, SLOT(ItemsLoadedForSavePlaylist(QFuture, QString, Playlist::Path)), future, filename, path_type); } } +void PlaylistManager::ItemsLoadedForSavePlaylist(QFuture future, const QString &filename, Playlist::Path path_type) { + + parser_->Save(future.result(), filename, path_type); + +} + void PlaylistManager::SaveWithUI(int id, const QString &playlist_name) { QSettings settings; diff --git a/src/playlist/playlistmanager.h b/src/playlist/playlistmanager.h index 6836ddab0..d4cc39a83 100644 --- a/src/playlist/playlistmanager.h +++ b/src/playlist/playlistmanager.h @@ -215,6 +215,7 @@ class PlaylistManager : public PlaylistManagerInterface { void OneOfPlaylistsChanged(); void UpdateSummaryText(); void SongsDiscovered(const SongList& songs); + void ItemsLoadedForSavePlaylist(QFuture future, const QString& filename, Playlist::Path path_type); void PlaylistLoaded(); private: diff --git a/src/playlist/songloaderinserter.cpp b/src/playlist/songloaderinserter.cpp index 7483e9eb3..67f46460d 100644 --- a/src/playlist/songloaderinserter.cpp +++ b/src/playlist/songloaderinserter.cpp @@ -83,7 +83,7 @@ void SongLoaderInserter::Load(Playlist *destination, int row, bool play_now, boo deleteLater(); } else { - (void)QtConcurrent::run([=]{ AsyncLoad(); }); + QtConcurrent::run(this, &SongLoaderInserter::AsyncLoad); } }