Use lambdas for QtConcurrent::run instead of NewClosure
This commit is contained in:
parent
425dac478e
commit
af67de8aa6
|
@ -27,10 +27,9 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QtGlobal>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QtConcurrent>
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QFuture>
|
||||
#include <QDataStream>
|
||||
#include <QMimeData>
|
||||
#include <QIODevice>
|
||||
|
@ -52,7 +51,6 @@
|
|||
#include <QtDebug>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/closure.h"
|
||||
#include "core/database.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/logging.h"
|
||||
|
@ -859,18 +857,15 @@ void CollectionModel::LazyPopulate(CollectionItem *parent, const bool signal) {
|
|||
}
|
||||
|
||||
void CollectionModel::ResetAsync() {
|
||||
QFuture<CollectionModel::QueryResult> future = QtConcurrent::run(this, &CollectionModel::RunQuery, root_);
|
||||
NewClosure(future, this, SLOT(ResetAsyncQueryFinished(QFuture<CollectionModel::QueryResult>)), future);
|
||||
(void)QtConcurrent::run([=]() { ResetAsyncQueryFinished(RunQuery(root_)); });
|
||||
}
|
||||
|
||||
void CollectionModel::ResetAsyncQueryFinished(QFuture<CollectionModel::QueryResult> future) {
|
||||
void CollectionModel::ResetAsyncQueryFinished(QueryResult result) {
|
||||
|
||||
if (QThread::currentThread() != thread() && QThread::currentThread() != backend_->thread()) {
|
||||
backend_->Close();
|
||||
}
|
||||
|
||||
const struct QueryResult result = future.result();
|
||||
|
||||
BeginReset();
|
||||
root_->lazy_loaded = true;
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QFuture>
|
||||
#include <QDataStream>
|
||||
#include <QMetaType>
|
||||
#include <QPair>
|
||||
|
@ -213,7 +212,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
|
|||
void ClearDiskCache();
|
||||
|
||||
// Called after ResetAsync
|
||||
void ResetAsyncQueryFinished(QFuture<CollectionModel::QueryResult> future);
|
||||
void ResetAsyncQueryFinished(QueryResult result);
|
||||
|
||||
void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
#include <limits>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QFuture>
|
||||
#include <QtConcurrent>
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
|
@ -286,16 +285,15 @@ void EditTagDialog::SetSongs(const SongList &s, const PlaylistItemList &items) {
|
|||
ui_->song_list->clear();
|
||||
|
||||
// Reload tags in the background
|
||||
QFuture<QList<Data>> future = QtConcurrent::run(this, &EditTagDialog::LoadData, s);
|
||||
NewClosure(future, this, SLOT(SetSongsFinished(QFuture<QList<EditTagDialog::Data>>)), future);
|
||||
(void)QtConcurrent::run([=]{ SetSongsFinished(LoadData(s)); });
|
||||
|
||||
}
|
||||
|
||||
void EditTagDialog::SetSongsFinished(QFuture<QList<Data>> future) {
|
||||
void EditTagDialog::SetSongsFinished(QList<Data> _data) {
|
||||
|
||||
if (!SetLoading(QString())) return;
|
||||
|
||||
data_ = future.result();
|
||||
data_ = _data;
|
||||
if (data_.count() == 0) {
|
||||
// If there were no valid songs, disable everything
|
||||
ui_->song_list->setEnabled(false);
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <QObject>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QDialog>
|
||||
#include <QFuture>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
@ -100,7 +99,7 @@ class EditTagDialog : public QDialog {
|
|||
};
|
||||
|
||||
private slots:
|
||||
void SetSongsFinished(QFuture<QList<EditTagDialog::Data>> future);
|
||||
void SetSongsFinished(QList<Data> _data);
|
||||
void AcceptFinished();
|
||||
|
||||
void SelectionChanged();
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <QObject>
|
||||
#include <QCoreApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QtConcurrent>
|
||||
#include <QFuture>
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
|
@ -40,7 +40,7 @@
|
|||
#include "gststartup.h"
|
||||
|
||||
GstStartup::GstStartup(QObject *parent) : QObject(parent) {
|
||||
initialising_ = QtConcurrent::run(this, &GstStartup::InitialiseGStreamer);
|
||||
initialising_ = QtConcurrent::run([=]{ InitialiseGStreamer(); });
|
||||
}
|
||||
|
||||
GstStartup::~GstStartup() {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QtConcurrent>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QDialog>
|
||||
#include <QScreen>
|
||||
|
@ -344,10 +344,9 @@ bool OrganiseDialog::SetUrls(const QList<QUrl> &urls) {
|
|||
|
||||
bool OrganiseDialog::SetFilenames(const QStringList &filenames) {
|
||||
|
||||
songs_future_ = QtConcurrent::run(this, &OrganiseDialog::LoadSongsBlocking, filenames);
|
||||
NewClosure(songs_future_, [=]() { SetSongs(songs_future_.result()); });
|
||||
|
||||
SetLoadingSongs(true);
|
||||
songs_future_ = QtConcurrent::run([=]{ SetSongs(LoadSongsBlocking(filenames)); });
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ class OrganiseDialog : public QDialog {
|
|||
|
||||
OrganiseFormat format_;
|
||||
|
||||
QFuture<SongList> songs_future_;
|
||||
QFuture<void> songs_future_;
|
||||
SongList songs_;
|
||||
Organise::NewSongInfoList new_songs_info_;
|
||||
quint64 total_size_;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QCoreApplication>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QtConcurrent>
|
||||
#include <QFuture>
|
||||
#include <QIODevice>
|
||||
#include <QDataStream>
|
||||
|
@ -1314,17 +1314,15 @@ void Playlist::Restore() {
|
|||
collection_items_by_id_.clear();
|
||||
|
||||
cancel_restore_ = false;
|
||||
QFuture<QList<PlaylistItemPtr>> future = QtConcurrent::run(backend_, &PlaylistBackend::GetPlaylistItems, id_);
|
||||
NewClosure(future, this, SLOT(ItemsLoaded(QFuture<PlaylistItemList>)), future);
|
||||
|
||||
(void)QtConcurrent::run([=]() { ItemsLoaded(backend_->GetPlaylistItems(id_)); });
|
||||
|
||||
}
|
||||
|
||||
void Playlist::ItemsLoaded(QFuture<PlaylistItemList> future) {
|
||||
void Playlist::ItemsLoaded(PlaylistItemList items) {
|
||||
|
||||
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<PlaylistItemPtr> it(items);
|
||||
while (it.hasNext()) {
|
||||
|
@ -1353,7 +1351,7 @@ void Playlist::ItemsLoaded(QFuture<PlaylistItemList> future) {
|
|||
|
||||
// Should we gray out deleted songs asynchronously on startup?
|
||||
if (greyout) {
|
||||
QtConcurrent::run(this, &Playlist::InvalidateDeletedSongs);
|
||||
(void)QtConcurrent::run([=]() { InvalidateDeletedSongs(); });
|
||||
}
|
||||
|
||||
emit PlaylistLoaded();
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <QAbstractItemModel>
|
||||
#include <QAbstractListModel>
|
||||
#include <QPersistentModelIndex>
|
||||
#include <QFuture>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QMultiMap>
|
||||
|
@ -349,7 +348,7 @@ class Playlist : public QAbstractListModel {
|
|||
void QueueLayoutChanged();
|
||||
void SongSaveComplete(TagReaderReply *reply, const QPersistentModelIndex &index);
|
||||
void ItemReloadComplete(const QPersistentModelIndex &index);
|
||||
void ItemsLoaded(QFuture<PlaylistItemList> future);
|
||||
void ItemsLoaded(PlaylistItemList items);
|
||||
void SongInsertVetoListenerDestroyed();
|
||||
void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QDialog>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QtConcurrent>
|
||||
#include <QFuture>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
|
@ -42,7 +42,6 @@
|
|||
#include <QtDebug>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/closure.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/player.h"
|
||||
#include "core/utilities.h"
|
||||
|
@ -211,18 +210,11 @@ 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.
|
||||
QFuture<QList<Song>> future = QtConcurrent::run(playlist_backend_, &PlaylistBackend::GetPlaylistSongs, id);
|
||||
NewClosure(future, this, SLOT(ItemsLoadedForSavePlaylist(QFuture<SongList>, QString, Playlist::Path)), future, filename, path_type);
|
||||
(void)QtConcurrent::run([=]() { parser_->Save(playlist_backend_->GetPlaylistSongs(id), filename, path_type); });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PlaylistManager::ItemsLoadedForSavePlaylist(QFuture<SongList> 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;
|
||||
|
|
|
@ -215,7 +215,6 @@ class PlaylistManager : public PlaylistManagerInterface {
|
|||
void OneOfPlaylistsChanged();
|
||||
void UpdateSummaryText();
|
||||
void SongsDiscovered(const SongList& songs);
|
||||
void ItemsLoadedForSavePlaylist(QFuture<SongList> future, const QString& filename, Playlist::Path path_type);
|
||||
void PlaylistLoaded();
|
||||
|
||||
private:
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <QtConcurrentRun>
|
||||
#include <QtConcurrent>
|
||||
#include <QtAlgorithms>
|
||||
#include <QList>
|
||||
#include <QUrl>
|
||||
|
@ -83,7 +83,7 @@ void SongLoaderInserter::Load(Playlist *destination, int row, bool play_now, boo
|
|||
deleteLater();
|
||||
}
|
||||
else {
|
||||
QtConcurrent::run(this, &SongLoaderInserter::AsyncLoad);
|
||||
(void)QtConcurrent::run([=]{ AsyncLoad(); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue