Partial revert commit af67de8

This commit is contained in:
Jonas Kvinge
2020-07-19 19:07:12 +02:00
parent e043a03eb6
commit ff73dd2183
11 changed files with 39 additions and 17 deletions

View File

@@ -30,6 +30,7 @@
#include <QtConcurrent> #include <QtConcurrent>
#include <QThread> #include <QThread>
#include <QMutex> #include <QMutex>
#include <QFuture>
#include <QDataStream> #include <QDataStream>
#include <QMimeData> #include <QMimeData>
#include <QIODevice> #include <QIODevice>
@@ -51,6 +52,7 @@
#include <QtDebug> #include <QtDebug>
#include "core/application.h" #include "core/application.h"
#include "core/closure.h"
#include "core/database.h" #include "core/database.h"
#include "core/iconloader.h" #include "core/iconloader.h"
#include "core/logging.h" #include "core/logging.h"
@@ -857,15 +859,18 @@ void CollectionModel::LazyPopulate(CollectionItem *parent, const bool signal) {
} }
void CollectionModel::ResetAsync() { void CollectionModel::ResetAsync() {
(void)QtConcurrent::run([=]() { ResetAsyncQueryFinished(RunQuery(root_)); }); QFuture<CollectionModel::QueryResult> future = QtConcurrent::run(this, &CollectionModel::RunQuery, root_);
NewClosure(future, this, SLOT(ResetAsyncQueryFinished(QFuture<CollectionModel::QueryResult>)), future);
} }
void CollectionModel::ResetAsyncQueryFinished(QueryResult result) { void CollectionModel::ResetAsyncQueryFinished(QFuture<CollectionModel::QueryResult> future) {
if (QThread::currentThread() != thread() && QThread::currentThread() != backend_->thread()) { if (QThread::currentThread() != thread() && QThread::currentThread() != backend_->thread()) {
backend_->Close(); backend_->Close();
} }
const struct QueryResult result = future.result();
BeginReset(); BeginReset();
root_->lazy_loaded = true; root_->lazy_loaded = true;

View File

@@ -27,6 +27,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <QObject> #include <QObject>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QFuture>
#include <QDataStream> #include <QDataStream>
#include <QMetaType> #include <QMetaType>
#include <QPair> #include <QPair>
@@ -212,7 +213,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
void ClearDiskCache(); void ClearDiskCache();
// Called after ResetAsync // Called after ResetAsync
void ResetAsyncQueryFinished(QueryResult result); void ResetAsyncQueryFinished(QFuture<CollectionModel::QueryResult> future);
void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result); void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);

View File

@@ -26,6 +26,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <QtConcurrent> #include <QtConcurrent>
#include <QFuture>
#include <QObject> #include <QObject>
#include <QWidget> #include <QWidget>
#include <QDialog> #include <QDialog>
@@ -285,15 +286,16 @@ void EditTagDialog::SetSongs(const SongList &s, const PlaylistItemList &items) {
ui_->song_list->clear(); ui_->song_list->clear();
// Reload tags in the background // Reload tags in the background
(void)QtConcurrent::run([=]{ SetSongsFinished(LoadData(s)); }); QFuture<QList<Data>> future = QtConcurrent::run(this, &EditTagDialog::LoadData, s);
NewClosure(future, this, SLOT(SetSongsFinished(QFuture<QList<EditTagDialog::Data>>)), future);
} }
void EditTagDialog::SetSongsFinished(QList<Data> _data) { void EditTagDialog::SetSongsFinished(QFuture<QList<Data>> future) {
if (!SetLoading(QString())) return; if (!SetLoading(QString())) return;
data_ = _data; data_ = future.result();
if (data_.count() == 0) { if (data_.count() == 0) {
// If there were no valid songs, disable everything // If there were no valid songs, disable everything
ui_->song_list->setEnabled(false); ui_->song_list->setEnabled(false);

View File

@@ -27,6 +27,7 @@
#include <QObject> #include <QObject>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QDialog> #include <QDialog>
#include <QFuture>
#include <QList> #include <QList>
#include <QVariant> #include <QVariant>
#include <QString> #include <QString>
@@ -99,7 +100,7 @@ class EditTagDialog : public QDialog {
}; };
private slots: private slots:
void SetSongsFinished(QList<Data> _data); void SetSongsFinished(QFuture<QList<EditTagDialog::Data>> future);
void AcceptFinished(); void AcceptFinished();
void SelectionChanged(); void SelectionChanged();

View File

@@ -344,9 +344,10 @@ bool OrganiseDialog::SetUrls(const QList<QUrl> &urls) {
bool OrganiseDialog::SetFilenames(const QStringList &filenames) { bool OrganiseDialog::SetFilenames(const QStringList &filenames) {
SetLoadingSongs(true); songs_future_ = QtConcurrent::run(this, &OrganiseDialog::LoadSongsBlocking, filenames);
songs_future_ = QtConcurrent::run([=]{ SetSongs(LoadSongsBlocking(filenames)); }); NewClosure(songs_future_, [=]() { SetSongs(songs_future_.result()); });
SetLoadingSongs(true);
return true; return true;
} }

View File

@@ -117,7 +117,7 @@ class OrganiseDialog : public QDialog {
OrganiseFormat format_; OrganiseFormat format_;
QFuture<void> songs_future_; QFuture<SongList> songs_future_;
SongList songs_; SongList songs_;
Organise::NewSongInfoList new_songs_info_; Organise::NewSongInfoList new_songs_info_;
quint64 total_size_; quint64 total_size_;

View File

@@ -1314,15 +1314,17 @@ void Playlist::Restore() {
collection_items_by_id_.clear(); collection_items_by_id_.clear();
cancel_restore_ = false; cancel_restore_ = false;
QFuture<QList<PlaylistItemPtr>> future = QtConcurrent::run(backend_, &PlaylistBackend::GetPlaylistItems, id_);
(void)QtConcurrent::run([=]() { ItemsLoaded(backend_->GetPlaylistItems(id_)); }); NewClosure(future, this, SLOT(ItemsLoaded(QFuture<PlaylistItemList>)), future);
} }
void Playlist::ItemsLoaded(PlaylistItemList items) { void Playlist::ItemsLoaded(QFuture<PlaylistItemList> future) {
if (cancel_restore_) return; 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 // 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); QMutableListIterator<PlaylistItemPtr> it(items);
while (it.hasNext()) { while (it.hasNext()) {
@@ -1351,7 +1353,7 @@ void Playlist::ItemsLoaded(PlaylistItemList items) {
// Should we gray out deleted songs asynchronously on startup? // Should we gray out deleted songs asynchronously on startup?
if (greyout) { if (greyout) {
(void)QtConcurrent::run([=]() { InvalidateDeletedSongs(); }); QtConcurrent::run(this, &Playlist::InvalidateDeletedSongs);
} }
emit PlaylistLoaded(); emit PlaylistLoaded();

View File

@@ -29,6 +29,7 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QPersistentModelIndex> #include <QPersistentModelIndex>
#include <QFuture>
#include <QList> #include <QList>
#include <QMap> #include <QMap>
#include <QMultiMap> #include <QMultiMap>
@@ -348,7 +349,7 @@ class Playlist : public QAbstractListModel {
void QueueLayoutChanged(); void QueueLayoutChanged();
void SongSaveComplete(TagReaderReply *reply, const QPersistentModelIndex &index); void SongSaveComplete(TagReaderReply *reply, const QPersistentModelIndex &index);
void ItemReloadComplete(const QPersistentModelIndex &index); void ItemReloadComplete(const QPersistentModelIndex &index);
void ItemsLoaded(PlaylistItemList items); void ItemsLoaded(QFuture<PlaylistItemList> future);
void SongInsertVetoListenerDestroyed(); void SongInsertVetoListenerDestroyed();
void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result); void AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result);

View File

@@ -42,6 +42,7 @@
#include <QtDebug> #include <QtDebug>
#include "core/application.h" #include "core/application.h"
#include "core/closure.h"
#include "core/logging.h" #include "core/logging.h"
#include "core/player.h" #include "core/player.h"
#include "core/utilities.h" #include "core/utilities.h"
@@ -210,11 +211,18 @@ void PlaylistManager::Save(int id, const QString &filename, Playlist::Path path_
} }
else { else {
// Playlist is not in the playlist manager: probably save action was triggered from the left side bar and the playlist isn't loaded. // 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<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 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) { void PlaylistManager::SaveWithUI(int id, const QString &playlist_name) {
QSettings settings; QSettings settings;

View File

@@ -215,6 +215,7 @@ class PlaylistManager : public PlaylistManagerInterface {
void OneOfPlaylistsChanged(); void OneOfPlaylistsChanged();
void UpdateSummaryText(); void UpdateSummaryText();
void SongsDiscovered(const SongList& songs); void SongsDiscovered(const SongList& songs);
void ItemsLoadedForSavePlaylist(QFuture<SongList> future, const QString& filename, Playlist::Path path_type);
void PlaylistLoaded(); void PlaylistLoaded();
private: private:

View File

@@ -83,7 +83,7 @@ void SongLoaderInserter::Load(Playlist *destination, int row, bool play_now, boo
deleteLater(); deleteLater();
} }
else { else {
(void)QtConcurrent::run([=]{ AsyncLoad(); }); QtConcurrent::run(this, &SongLoaderInserter::AsyncLoad);
} }
} }