Remove NewClosure
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QtConcurrent>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QIODevice>
|
||||
#include <QDataStream>
|
||||
#include <QBuffer>
|
||||
@@ -59,7 +60,6 @@
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/closure.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/mimedata.h"
|
||||
#include "core/tagreaderclient.h"
|
||||
@@ -406,7 +406,12 @@ void Playlist::SongSaveComplete(TagReaderReply *reply, const QPersistentModelInd
|
||||
PlaylistItemPtr item = item_at(idx.row());
|
||||
if (item) {
|
||||
QFuture<void> future = item->BackgroundReload();
|
||||
NewClosure(future, this, SLOT(ItemReloadComplete(QPersistentModelIndex)), idx);
|
||||
QFutureWatcher<void> *watcher = new QFutureWatcher<void>();
|
||||
watcher->setFuture(future);
|
||||
QObject::connect(watcher, &QFutureWatcher<void>::finished, this, [this, watcher, idx]() {
|
||||
ItemReloadComplete(idx);
|
||||
watcher->deleteLater();
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1407,20 +1412,24 @@ void Playlist::Restore() {
|
||||
|
||||
cancel_restore_ = false;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QFuture<QList<PlaylistItemPtr>> future = QtConcurrent::run(&PlaylistBackend::GetPlaylistItems, backend_, id_);
|
||||
QFuture<PlaylistItemList> future = QtConcurrent::run(&PlaylistBackend::GetPlaylistItems, backend_, id_);
|
||||
#else
|
||||
QFuture<QList<PlaylistItemPtr>> future = QtConcurrent::run(backend_, &PlaylistBackend::GetPlaylistItems, id_);
|
||||
QFuture<PlaylistItemList> future = QtConcurrent::run(backend_, &PlaylistBackend::GetPlaylistItems, id_);
|
||||
#endif
|
||||
NewClosure(future, this, SLOT(ItemsLoaded(QFuture<PlaylistItemList>)), future);
|
||||
QFutureWatcher<PlaylistItemList> *watcher = new QFutureWatcher<PlaylistItemList>();
|
||||
watcher->setFuture(future);
|
||||
QObject::connect(watcher, &QFutureWatcher<PlaylistItemList>::finished, this, &Playlist::ItemsLoaded);
|
||||
|
||||
}
|
||||
|
||||
void Playlist::ItemsLoaded(QFuture<PlaylistItemList> future) {
|
||||
void Playlist::ItemsLoaded() {
|
||||
|
||||
QFutureWatcher<PlaylistItemList> *watcher = static_cast<QFutureWatcher<PlaylistItemList>*>(sender());
|
||||
PlaylistItemList items = watcher->result();
|
||||
watcher->deleteLater();
|
||||
|
||||
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()) {
|
||||
|
||||
@@ -377,7 +377,7 @@ class Playlist : public QAbstractListModel {
|
||||
void QueueLayoutChanged();
|
||||
void SongSaveComplete(TagReaderReply *reply, const QPersistentModelIndex &idx);
|
||||
void ItemReloadComplete(const QPersistentModelIndex &idx);
|
||||
void ItemsLoaded(QFuture<PlaylistItemList> future);
|
||||
void ItemsLoaded();
|
||||
void SongInsertVetoListenerDestroyed();
|
||||
|
||||
private:
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <QThread>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QAbstractItemView>
|
||||
#include <QCompleter>
|
||||
@@ -62,7 +63,6 @@
|
||||
#include <QtEvents>
|
||||
#include <QLinearGradient>
|
||||
|
||||
#include "core/closure.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/player.h"
|
||||
@@ -405,7 +405,9 @@ static TagCompletionModel *InitCompletionModel(CollectionBackend *backend, Playl
|
||||
TagCompleter::TagCompleter(CollectionBackend *backend, Playlist::Column column, QLineEdit *editor) : QCompleter(editor), editor_(editor) {
|
||||
|
||||
QFuture<TagCompletionModel*> future = QtConcurrent::run(&InitCompletionModel, backend, column);
|
||||
NewClosure(future, this, SLOT(ModelReady(QFuture<TagCompletionModel*>)), future);
|
||||
QFutureWatcher<TagCompletionModel*> *watcher = new QFutureWatcher<TagCompletionModel*>();
|
||||
watcher->setFuture(future);
|
||||
QObject::connect(watcher, &QFutureWatcher<TagCompletionModel*>::finished, this, &TagCompleter::ModelReady);
|
||||
|
||||
}
|
||||
|
||||
@@ -413,9 +415,11 @@ TagCompleter::~TagCompleter() {
|
||||
delete model();
|
||||
}
|
||||
|
||||
void TagCompleter::ModelReady(QFuture<TagCompletionModel*> future) {
|
||||
void TagCompleter::ModelReady() {
|
||||
|
||||
TagCompletionModel *model = future.result();
|
||||
QFutureWatcher<TagCompletionModel*> *watcher = static_cast<QFutureWatcher<TagCompletionModel*>*>(sender());
|
||||
TagCompletionModel *model = watcher->result();
|
||||
watcher->deleteLater();
|
||||
setModel(model);
|
||||
setCaseSensitivity(Qt::CaseInsensitive);
|
||||
editor_->setCompleter(this);
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QTreeView>
|
||||
#include <QFuture>
|
||||
#include <QCompleter>
|
||||
#include <QLocale>
|
||||
#include <QVariant>
|
||||
@@ -151,7 +150,7 @@ class TagCompleter : public QCompleter {
|
||||
~TagCompleter() override;
|
||||
|
||||
private slots:
|
||||
void ModelReady(QFuture<TagCompletionModel*> future);
|
||||
void ModelReady();
|
||||
|
||||
private:
|
||||
QLineEdit *editor_;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <QDialog>
|
||||
#include <QtConcurrent>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
@@ -45,7 +46,6 @@
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/closure.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/player.h"
|
||||
#include "core/utilities.h"
|
||||
@@ -220,18 +220,23 @@ void PlaylistManager::Save(const int id, const QString &filename, const Playlist
|
||||
else {
|
||||
// Playlist is not in the playlist manager: probably save action was triggered from the left side bar and the playlist isn't loaded.
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QFuture<QList<Song>> future = QtConcurrent::run(&PlaylistBackend::GetPlaylistSongs, playlist_backend_, id);
|
||||
QFuture<SongList> future = QtConcurrent::run(&PlaylistBackend::GetPlaylistSongs, playlist_backend_, id);
|
||||
#else
|
||||
QFuture<QList<Song>> future = QtConcurrent::run(playlist_backend_, &PlaylistBackend::GetPlaylistSongs, id);
|
||||
QFuture<SongList> future = QtConcurrent::run(playlist_backend_, &PlaylistBackend::GetPlaylistSongs, id);
|
||||
#endif
|
||||
NewClosure(future, this, SLOT(ItemsLoadedForSavePlaylist(QFuture<SongList>, QString, Playlist::Path)), future, filename, path_type);
|
||||
QFutureWatcher<SongList> *watcher = new QFutureWatcher<SongList>();
|
||||
watcher->setFuture(future);
|
||||
QObject::connect(watcher, &QFutureWatcher<SongList>::finished, this, [this, watcher, filename, path_type]() {
|
||||
ItemsLoadedForSavePlaylist(watcher->result(), filename, path_type);
|
||||
watcher->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PlaylistManager::ItemsLoadedForSavePlaylist(QFuture<SongList> future, const QString &filename, const Playlist::Path path_type) {
|
||||
void PlaylistManager::ItemsLoadedForSavePlaylist(const SongList &songs, const QString &filename, const Playlist::Path path_type) {
|
||||
|
||||
parser_->Save(future.result(), filename, path_type);
|
||||
parser_->Save(songs, filename, path_type);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ class PlaylistManager : public PlaylistManagerInterface {
|
||||
void OneOfPlaylistsChanged();
|
||||
void UpdateSummaryText();
|
||||
void SongsDiscovered(const SongList& songs);
|
||||
void ItemsLoadedForSavePlaylist(QFuture<SongList> future, const QString& filename, const Playlist::Path path_type);
|
||||
void ItemsLoadedForSavePlaylist(const SongList &songs, const QString& filename, const Playlist::Path path_type);
|
||||
void PlaylistLoaded();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user