Remove most usages of QFutureWatcher

This commit is contained in:
John Maguire 2015-11-27 14:22:59 +00:00
parent 2d61fe6c87
commit f300946c81
29 changed files with 184 additions and 271 deletions

View File

@ -200,6 +200,15 @@ _detail::ClosureBase* NewClosure(QFuture<T> future, QObject* receiver,
return NewClosure(watcher, SIGNAL(finished()), receiver, slot, args...); return NewClosure(watcher, SIGNAL(finished()), receiver, slot, args...);
} }
template <typename T, typename F, typename... Args>
_detail::ClosureBase* NewClosure(QFuture<T> future, const F& callback,
const Args&... args) {
QFutureWatcher<T>* watcher = new QFutureWatcher<T>;
watcher->setFuture(future);
QObject::connect(watcher, SIGNAL(finished()), watcher, SLOT(deleteLater()));
return NewClosure(watcher, SIGNAL(finished()), callback, args...);
}
void DoAfter(QObject* receiver, const char* slot, int msec); void DoAfter(QObject* receiver, const char* slot, int msec);
void DoAfter(std::function<void()> callback, std::chrono::milliseconds msec); void DoAfter(std::function<void()> callback, std::chrono::milliseconds msec);
void DoInAMinuteOrSo(QObject* receiver, const char* slot); void DoInAMinuteOrSo(QObject* receiver, const char* slot);

View File

@ -29,7 +29,6 @@
#ifndef CORE_SONG_H_ #ifndef CORE_SONG_H_
#define CORE_SONG_H_ #define CORE_SONG_H_
#include <QFuture>
#include <QImage> #include <QImage>
#include <QMetaType> #include <QMetaType>
#include <QSharedDataPointer> #include <QSharedDataPointer>

View File

@ -20,7 +20,6 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <QFutureWatcher>
#include <QScrollBar> #include <QScrollBar>
#include <QtConcurrentRun> #include <QtConcurrentRun>
@ -86,9 +85,8 @@ void DeviceProperties::ShowDevice(int row) {
<< "phone-palm-pre"; << "phone-palm-pre";
for (const QString& icon_name : icon_names) { for (const QString& icon_name : icon_names) {
QListWidgetItem* item = new QListWidgetItem(IconLoader::Load(icon_name, QListWidgetItem* item = new QListWidgetItem(
IconLoader::Base), IconLoader::Load(icon_name, IconLoader::Base), QString(), ui_->icon);
QString(), ui_->icon);
item->setData(Qt::UserRole, icon_name); item->setData(Qt::UserRole, icon_name);
} }
@ -226,10 +224,8 @@ void DeviceProperties::UpdateFormats() {
QFuture<bool> future = QtConcurrent::run(std::bind( QFuture<bool> future = QtConcurrent::run(std::bind(
&ConnectedDevice::GetSupportedFiletypes, device, &supported_formats_)); &ConnectedDevice::GetSupportedFiletypes, device, &supported_formats_));
QFutureWatcher<bool>* watcher = new QFutureWatcher<bool>(this); NewClosure(future, this, SLOT(UpdateFormatsFinished(QFuture<bool>)),
watcher->setFuture(future); future);
connect(watcher, SIGNAL(finished()), SLOT(UpdateFormatsFinished()));
ui_->formats_stack->setCurrentWidget(ui_->formats_page_loading); ui_->formats_stack->setCurrentWidget(ui_->formats_page_loading);
updating_formats_ = true; updating_formats_ = true;
@ -265,12 +261,10 @@ void DeviceProperties::accept() {
void DeviceProperties::OpenDevice() { manager_->Connect(index_.row()); } void DeviceProperties::OpenDevice() { manager_->Connect(index_.row()); }
void DeviceProperties::UpdateFormatsFinished() { void DeviceProperties::UpdateFormatsFinished(QFuture<bool> future) {
QFutureWatcher<bool>* watcher = static_cast<QFutureWatcher<bool>*>(sender());
watcher->deleteLater();
updating_formats_ = false; updating_formats_ = false;
if (!watcher->future().result()) { if (!future.result()) {
supported_formats_.clear(); supported_formats_.clear();
} }

View File

@ -19,6 +19,7 @@
#define DEVICEPROPERTIES_H #define DEVICEPROPERTIES_H
#include <QDialog> #include <QDialog>
#include <QFuture>
#include <QPersistentModelIndex> #include <QPersistentModelIndex>
#include "core/song.h" #include "core/song.h"
@ -47,7 +48,7 @@ class DeviceProperties : public QDialog {
private slots: private slots:
void ModelChanged(); void ModelChanged();
void OpenDevice(); void OpenDevice();
void UpdateFormatsFinished(); void UpdateFormatsFinished(QFuture<bool> future);
private: private:
Ui_DeviceProperties* ui_; Ui_DeviceProperties* ui_;

View File

@ -18,6 +18,7 @@
#ifndef SEARCHPROVIDER_H #ifndef SEARCHPROVIDER_H
#define SEARCHPROVIDER_H #define SEARCHPROVIDER_H
#include <QFuture>
#include <QIcon> #include <QIcon>
#include <QMetaType> #include <QMetaType>
#include <QObject> #include <QObject>

View File

@ -24,7 +24,6 @@
#include <algorithm> #include <algorithm>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFutureWatcher>
#include <QMenu> #include <QMenu>
#include <QMultiHash> #include <QMultiHash>
#include <QNetworkReply> #include <QNetworkReply>
@ -75,8 +74,8 @@ IcecastService::IcecastService(Application* app, InternetModel* parent)
IcecastService::~IcecastService() {} IcecastService::~IcecastService() {}
QStandardItem* IcecastService::CreateRootItem() { QStandardItem* IcecastService::CreateRootItem() {
root_ = new QStandardItem(IconLoader::Load("icon_radio", root_ = new QStandardItem(IconLoader::Load("icon_radio", IconLoader::Lastfm),
IconLoader::Lastfm), kServiceName); kServiceName);
root_->setData(true, InternetModel::Role_CanLazyLoad); root_->setData(true, InternetModel::Role_CanLazyLoad);
return root_; return root_;
} }
@ -128,13 +127,9 @@ void IcecastService::DownloadDirectoryFinished(QNetworkReply* reply,
QFuture<IcecastBackend::StationList> future = QFuture<IcecastBackend::StationList> future =
QtConcurrent::run(this, &IcecastService::ParseDirectory, reply); QtConcurrent::run(this, &IcecastService::ParseDirectory, reply);
QFutureWatcher<void>* watcher = new QFutureWatcher<void>(this); NewClosure(future, this, SLOT(ParseDirectoryFinished(
watcher->setFuture(future); QFuture<IcecastBackend::StationList>, int)),
NewClosure( future, task_id);
watcher, SIGNAL(finished()), this,
SLOT(ParseDirectoryFinished(QFuture<IcecastBackend::StationList>, int)),
future, task_id);
connect(watcher, SIGNAL(finished()), watcher, SLOT(deleteLater()));
} }
namespace { namespace {

View File

@ -24,7 +24,6 @@
#include "jamendoservice.h" #include "jamendoservice.h"
#include <QDesktopServices> #include <QDesktopServices>
#include <QFutureWatcher>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QNetworkReply> #include <QNetworkReply>
@ -146,9 +145,8 @@ JamendoService::JamendoService(Application* app, InternetModel* parent)
JamendoService::~JamendoService() {} JamendoService::~JamendoService() {}
QStandardItem* JamendoService::CreateRootItem() { QStandardItem* JamendoService::CreateRootItem() {
QStandardItem* item = QStandardItem* item = new QStandardItem(
new QStandardItem(IconLoader::Load("jamendo", IconLoader::Provider), IconLoader::Load("jamendo", IconLoader::Provider), kServiceName);
kServiceName);
item->setData(true, InternetModel::Role_CanLazyLoad); item->setData(true, InternetModel::Role_CanLazyLoad);
return item; return item;
} }
@ -205,8 +203,7 @@ void JamendoService::DownloadDirectory() {
void JamendoService::DownloadDirectoryProgress(qint64 received, qint64 total) { void JamendoService::DownloadDirectoryProgress(qint64 received, qint64 total) {
float progress = static_cast<float>(received) / total; float progress = static_cast<float>(received) / total;
app_->task_manager()->SetTaskProgress(load_database_task_id_, app_->task_manager()->SetTaskProgress(load_database_task_id_,
static_cast<int>(progress * 100), static_cast<int>(progress * 100), 100);
100);
} }
void JamendoService::DownloadDirectoryFinished() { void JamendoService::DownloadDirectoryFinished() {
@ -230,9 +227,7 @@ void JamendoService::DownloadDirectoryFinished() {
QFuture<void> future = QFuture<void> future =
QtConcurrent::run(this, &JamendoService::ParseDirectory, gzip); QtConcurrent::run(this, &JamendoService::ParseDirectory, gzip);
QFutureWatcher<void>* watcher = new QFutureWatcher<void>(); NewClosure(future, this, SLOT(ParseDirectoryFinished()));
watcher->setFuture(future);
connect(watcher, SIGNAL(finished()), SLOT(ParseDirectoryFinished()));
} }
void JamendoService::ParseDirectory(QIODevice* device) const { void JamendoService::ParseDirectory(QIODevice* device) const {
@ -408,9 +403,6 @@ Song JamendoService::ReadTrack(const QString& artist, const QString& album,
} }
void JamendoService::ParseDirectoryFinished() { void JamendoService::ParseDirectoryFinished() {
QFutureWatcher<void>* watcher = static_cast<QFutureWatcher<void>*>(sender());
delete watcher;
// show smart playlists // show smart playlists
library_model_->set_show_smart_playlists(true); library_model_->set_show_smart_playlists(true);
library_model_->Reset(); library_model_->Reset();
@ -424,14 +416,12 @@ void JamendoService::EnsureMenuCreated() {
context_menu_ = new QMenu; context_menu_ = new QMenu;
context_menu_->addActions(GetPlaylistActions()); context_menu_->addActions(GetPlaylistActions());
album_info_ = context_menu_->addAction(IconLoader::Load("view-media-lyrics", album_info_ = context_menu_->addAction(
IconLoader::Base), IconLoader::Load("view-media-lyrics", IconLoader::Base),
tr("Album info on jamendo.com..."), tr("Album info on jamendo.com..."), this, SLOT(AlbumInfo()));
this, SLOT(AlbumInfo())); download_album_ = context_menu_->addAction(
download_album_ = context_menu_->addAction(IconLoader::Load("download", IconLoader::Load("download", IconLoader::Base),
IconLoader::Base), tr("Download this album..."), this, SLOT(DownloadAlbum()));
tr("Download this album..."), this,
SLOT(DownloadAlbum()));
context_menu_->addSeparator(); context_menu_->addSeparator();
context_menu_->addAction(IconLoader::Load("download", IconLoader::Base), context_menu_->addAction(IconLoader::Load("download", IconLoader::Base),
tr("Open %1 in browser").arg("jamendo.com"), this, tr("Open %1 in browser").arg("jamendo.com"), this,

View File

@ -20,7 +20,6 @@
#include <functional> #include <functional>
#include <QFuture> #include <QFuture>
#include <QFutureWatcher>
#include <QIODevice> #include <QIODevice>
#include <QMetaEnum> #include <QMetaEnum>
#include <QNetworkCacheMetaData> #include <QNetworkCacheMetaData>
@ -63,8 +62,6 @@ const char* LibraryModel::kSmartPlaylistsSettingsGroup =
const int LibraryModel::kSmartPlaylistsVersion = 4; const int LibraryModel::kSmartPlaylistsVersion = 4;
const int LibraryModel::kPrettyCoverSize = 32; const int LibraryModel::kPrettyCoverSize = 32;
const qint64 LibraryModel::kIconCacheSize = 100000000; //~100MB const qint64 LibraryModel::kIconCacheSize = 100000000; //~100MB
typedef QFuture<LibraryModel::QueryResult> RootQueryFuture;
typedef QFutureWatcher<LibraryModel::QueryResult> RootQueryWatcher;
static bool IsArtistGroupBy(const LibraryModel::GroupBy by) { static bool IsArtistGroupBy(const LibraryModel::GroupBy by) {
return by == LibraryModel::GroupBy_Artist || return by == LibraryModel::GroupBy_Artist ||
@ -228,7 +225,8 @@ void LibraryModel::SongsDiscovered(const SongList& songs) {
key = PrettyYearAlbum(qMax(0, song.year()), song.album()); key = PrettyYearAlbum(qMax(0, song.year()), song.album());
break; break;
case GroupBy_OriginalYearAlbum: case GroupBy_OriginalYearAlbum:
key = PrettyYearAlbum(qMax(0, song.effective_originalyear()), song.album()); key = PrettyYearAlbum(qMax(0, song.effective_originalyear()),
song.album());
break; break;
case GroupBy_FileType: case GroupBy_FileType:
key = song.filetype(); key = song.filetype();
@ -732,18 +730,16 @@ void LibraryModel::LazyPopulate(LibraryItem* parent, bool signal) {
} }
void LibraryModel::ResetAsync() { void LibraryModel::ResetAsync() {
RootQueryFuture future = QFuture<LibraryModel::QueryResult> future =
QtConcurrent::run(this, &LibraryModel::RunQuery, root_); QtConcurrent::run(this, &LibraryModel::RunQuery, root_);
RootQueryWatcher* watcher = new RootQueryWatcher(this); NewClosure(future, this,
watcher->setFuture(future); SLOT(ResetAsyncQueryFinished(QFuture<LibraryModel::QueryResult>)),
future);
connect(watcher, SIGNAL(finished()), SLOT(ResetAsyncQueryFinished()));
} }
void LibraryModel::ResetAsyncQueryFinished() { void LibraryModel::ResetAsyncQueryFinished(
RootQueryWatcher* watcher = static_cast<RootQueryWatcher*>(sender()); QFuture<LibraryModel::QueryResult> future) {
const struct QueryResult result = watcher->result(); const struct QueryResult result = future.result();
watcher->deleteLater();
BeginReset(); BeginReset();
root_->lazy_loaded = true; root_->lazy_loaded = true;
@ -960,9 +956,10 @@ LibraryItem* LibraryModel::ItemFromQuery(GroupBy type, bool signal,
item->metadata.set_album(row.value(2).toString()); item->metadata.set_album(row.value(2).toString());
item->metadata.set_grouping(row.value(3).toString()); item->metadata.set_grouping(row.value(3).toString());
effective_originalyear = qMax(0, item->metadata.effective_originalyear()); effective_originalyear = qMax(0, item->metadata.effective_originalyear());
item->key = PrettyYearAlbum(effective_originalyear, item->metadata.album()); item->key =
item->sort_text = SortTextForNumber(effective_originalyear) + item->metadata.grouping() PrettyYearAlbum(effective_originalyear, item->metadata.album());
+ item->metadata.album(); item->sort_text = SortTextForNumber(effective_originalyear) +
item->metadata.grouping() + item->metadata.album();
break; break;
case GroupBy_Year: case GroupBy_Year:
@ -1050,7 +1047,8 @@ LibraryItem* LibraryModel::ItemFromSong(GroupBy type, bool signal,
item->metadata.set_originalyear(originalyear); item->metadata.set_originalyear(originalyear);
item->metadata.set_album(s.album()); item->metadata.set_album(s.album());
item->key = PrettyYearAlbum(effective_originalyear, s.album()); item->key = PrettyYearAlbum(effective_originalyear, s.album());
item->sort_text = SortTextForNumber(effective_originalyear) + s.grouping() + s.album(); item->sort_text =
SortTextForNumber(effective_originalyear) + s.grouping() + s.album();
break; break;
case GroupBy_Year: case GroupBy_Year:

View File

@ -195,7 +195,7 @@ signals:
void TotalSongCountUpdatedSlot(int count); void TotalSongCountUpdatedSlot(int count);
// Called after ResetAsync // Called after ResetAsync
void ResetAsyncQueryFinished(); void ResetAsyncQueryFinished(QFuture<LibraryModel::QueryResult> future);
void AlbumArtLoaded(quint64 id, const QImage& image); void AlbumArtLoaded(quint64 id, const QImage& image);

View File

@ -182,20 +182,14 @@ void MoodbarItemDelegate::StartLoadingColors(const QUrl& url,
Data* data) { Data* data) {
data->state_ = Data::State_LoadingColors; data->state_ = Data::State_LoadingColors;
QFutureWatcher<ColorVector>* watcher = new QFutureWatcher<ColorVector>();
NewClosure(watcher, SIGNAL(finished()), this,
SLOT(ColorsLoaded(QUrl, QFutureWatcher<ColorVector>*)), url,
watcher);
QFuture<ColorVector> future = QtConcurrent::run( QFuture<ColorVector> future = QtConcurrent::run(
MoodbarRenderer::Colors, bytes, style_, qApp->palette()); MoodbarRenderer::Colors, bytes, style_, qApp->palette());
watcher->setFuture(future); NewClosure(future, this, SLOT(ColorsLoaded(QUrl, QFuture<ColorVector>)), url,
future);
} }
void MoodbarItemDelegate::ColorsLoaded(const QUrl& url, void MoodbarItemDelegate::ColorsLoaded(const QUrl& url,
QFutureWatcher<ColorVector>* watcher) { QFuture<ColorVector> future) {
watcher->deleteLater();
Data* data = data_[url]; Data* data = data_[url];
if (!data) { if (!data) {
return; return;
@ -205,7 +199,7 @@ void MoodbarItemDelegate::ColorsLoaded(const QUrl& url,
return; return;
} }
data->colors_ = watcher->result(); data->colors_ = future.result();
// Load the image next. // Load the image next.
StartLoadingImage(url, data); StartLoadingImage(url, data);
@ -214,19 +208,13 @@ void MoodbarItemDelegate::ColorsLoaded(const QUrl& url,
void MoodbarItemDelegate::StartLoadingImage(const QUrl& url, Data* data) { void MoodbarItemDelegate::StartLoadingImage(const QUrl& url, Data* data) {
data->state_ = Data::State_LoadingImage; data->state_ = Data::State_LoadingImage;
QFutureWatcher<QImage>* watcher = new QFutureWatcher<QImage>();
NewClosure(watcher, SIGNAL(finished()), this,
SLOT(ImageLoaded(QUrl, QFutureWatcher<QImage>*)), url, watcher);
QFuture<QImage> future = QtConcurrent::run( QFuture<QImage> future = QtConcurrent::run(
MoodbarRenderer::RenderToImage, data->colors_, data->desired_size_); MoodbarRenderer::RenderToImage, data->colors_, data->desired_size_);
watcher->setFuture(future); NewClosure(future, this, SLOT(ImageLoaded(QUrl, QFuture<QImage>)), url,
future);
} }
void MoodbarItemDelegate::ImageLoaded(const QUrl& url, void MoodbarItemDelegate::ImageLoaded(const QUrl& url, QFuture<QImage> future) {
QFutureWatcher<QImage>* watcher) {
watcher->deleteLater();
Data* data = data_[url]; Data* data = data_[url];
if (!data) { if (!data) {
return; return;
@ -236,7 +224,7 @@ void MoodbarItemDelegate::ImageLoaded(const QUrl& url,
return; return;
} }
QImage image(watcher->result()); QImage image(future.result());
// If the desired size changed then don't even bother converting the image // If the desired size changed then don't even bother converting the image
// to a pixmap, just reload it at the new size. // to a pixmap, just reload it at the new size.

View File

@ -21,8 +21,8 @@
#include "moodbarrenderer.h" #include "moodbarrenderer.h"
#include <QCache> #include <QCache>
#include <QFuture>
#include <QItemDelegate> #include <QItemDelegate>
#include <QFutureWatcher>
#include <QUrl> #include <QUrl>
class Application; class Application;
@ -45,8 +45,8 @@ class MoodbarItemDelegate : public QItemDelegate {
void ReloadSettings(); void ReloadSettings();
void DataLoaded(const QUrl& url, MoodbarPipeline* pipeline); void DataLoaded(const QUrl& url, MoodbarPipeline* pipeline);
void ColorsLoaded(const QUrl& url, QFutureWatcher<ColorVector>* watcher); void ColorsLoaded(const QUrl& url, QFuture<ColorVector> future);
void ImageLoaded(const QUrl& url, QFutureWatcher<QImage>* watcher); void ImageLoaded(const QUrl& url, QFuture<QImage> future);
private: private:
struct Data { struct Data {

View File

@ -1457,10 +1457,6 @@ void Playlist::Save() const {
dynamic_playlist_); dynamic_playlist_);
} }
namespace {
typedef QFutureWatcher<QList<PlaylistItemPtr>> PlaylistItemFutureWatcher;
}
void Playlist::Restore() { void Playlist::Restore() {
if (!backend_) return; if (!backend_) return;
@ -1470,17 +1466,12 @@ void Playlist::Restore() {
QFuture<QList<PlaylistItemPtr>> future = QFuture<QList<PlaylistItemPtr>> future =
QtConcurrent::run(backend_, &PlaylistBackend::GetPlaylistItems, id_); QtConcurrent::run(backend_, &PlaylistBackend::GetPlaylistItems, id_);
PlaylistItemFutureWatcher* watcher = new PlaylistItemFutureWatcher(this); NewClosure(future, this, SLOT(ItemsLoaded(QFuture<PlaylistItemList>)),
watcher->setFuture(future); future);
connect(watcher, SIGNAL(finished()), SLOT(ItemsLoaded()));
} }
void Playlist::ItemsLoaded() { void Playlist::ItemsLoaded(QFuture<PlaylistItemList> future) {
PlaylistItemFutureWatcher* watcher = PlaylistItemList items = future.result();
static_cast<PlaylistItemFutureWatcher*>(sender());
watcher->deleteLater();
PlaylistItemList items = watcher->future().result();
// backend returns empty elements for library items which it couldn't // backend returns empty elements for library items which it couldn't
// match (because they got deleted); we don't need those // match (because they got deleted); we don't need those

View File

@ -394,7 +394,7 @@ signals:
void SongSaveComplete(TagReaderReply* reply, void SongSaveComplete(TagReaderReply* reply,
const QPersistentModelIndex& index); const QPersistentModelIndex& index);
void ItemReloadComplete(const QPersistentModelIndex& index); void ItemReloadComplete(const QPersistentModelIndex& index);
void ItemsLoaded(); void ItemsLoaded(QFuture<PlaylistItemList> future);
void SongInsertVetoListenerDestroyed(); void SongInsertVetoListenerDestroyed();
private: private:

View File

@ -20,7 +20,6 @@
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
#include <QFuture> #include <QFuture>
#include <QFutureWatcher>
#include <QHeaderView> #include <QHeaderView>
#include <QHelpEvent> #include <QHelpEvent>
#include <QLinearGradient> #include <QLinearGradient>
@ -400,19 +399,12 @@ TagCompleter::TagCompleter(LibraryBackend* backend, Playlist::Column column,
: QCompleter(editor), editor_(editor) { : QCompleter(editor), editor_(editor) {
QFuture<TagCompletionModel*> future = QFuture<TagCompletionModel*> future =
QtConcurrent::run(&InitCompletionModel, backend, column); QtConcurrent::run(&InitCompletionModel, backend, column);
QFutureWatcher<TagCompletionModel*>* watcher = NewClosure(future, this, SLOT(ModelReady(QFuture<TagCompletionModel*>)),
new QFutureWatcher<TagCompletionModel*>(this); future);
watcher->setFuture(future);
connect(watcher, SIGNAL(finished()), SLOT(ModelReady()));
} }
void TagCompleter::ModelReady() { void TagCompleter::ModelReady(QFuture<TagCompletionModel*> future) {
QFutureWatcher<TagCompletionModel*>* watcher = TagCompletionModel* model = future.result();
dynamic_cast<QFutureWatcher<TagCompletionModel*>*>(sender());
if (!watcher) return;
TagCompletionModel* model = watcher->result();
setModel(model); setModel(model);
setCaseSensitivity(Qt::CaseInsensitive); setCaseSensitivity(Qt::CaseInsensitive);
editor_->setCompleter(this); editor_->setCompleter(this);
@ -421,7 +413,6 @@ void TagCompleter::ModelReady() {
QWidget* TagCompletionItemDelegate::createEditor(QWidget* parent, QWidget* TagCompletionItemDelegate::createEditor(QWidget* parent,
const QStyleOptionViewItem&, const QStyleOptionViewItem&,
const QModelIndex&) const { const QModelIndex&) const {
QLineEdit* editor = new QLineEdit(parent); QLineEdit* editor = new QLineEdit(parent);
new TagCompleter(backend_, column_, editor); new TagCompleter(backend_, column_, editor);

View File

@ -159,7 +159,7 @@ class TagCompleter : public QCompleter {
QLineEdit* editor); QLineEdit* editor);
private slots: private slots:
void ModelReady(); void ModelReady(QFuture<TagCompletionModel*> future);
private: private:
QLineEdit* editor_; QLineEdit* editor_;
@ -169,7 +169,7 @@ class TagCompletionItemDelegate : public PlaylistDelegateBase {
public: public:
TagCompletionItemDelegate(QObject* parent, LibraryBackend* backend, TagCompletionItemDelegate(QObject* parent, LibraryBackend* backend,
Playlist::Column column) Playlist::Column column)
: PlaylistDelegateBase(parent), backend_(backend), column_(column) {}; : PlaylistDelegateBase(parent), backend_(backend), column_(column){};
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
const QModelIndex& index) const; const QModelIndex& index) const;

View File

@ -20,6 +20,7 @@
#include <memory> #include <memory>
#include <QFuture>
#include <QMap> #include <QMap>
#include <QMetaType> #include <QMetaType>
#include <QStandardItem> #include <QStandardItem>
@ -97,7 +98,10 @@ class PlaylistItem : public std::enable_shared_from_this<PlaylistItem> {
protected: protected:
bool should_skip_; bool should_skip_;
enum DatabaseColumn { Column_LibraryId, Column_InternetService, }; enum DatabaseColumn {
Column_LibraryId,
Column_InternetService,
};
virtual QVariant DatabaseValue(DatabaseColumn) const { virtual QVariant DatabaseValue(DatabaseColumn) const {
return QVariant(QVariant::String); return QVariant(QVariant::String);

View File

@ -33,7 +33,6 @@
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QFuture> #include <QFuture>
#include <QFutureWatcher>
#include <QMessageBox> #include <QMessageBox>
#include <QtConcurrentRun> #include <QtConcurrentRun>
#include <QtDebug> #include <QtDebug>
@ -185,21 +184,16 @@ void PlaylistManager::Save(int id, const QString& filename,
// from the left side bar and the playlist isn't loaded. // from the left side bar and the playlist isn't loaded.
QFuture<QList<Song>> future = QtConcurrent::run( QFuture<QList<Song>> future = QtConcurrent::run(
playlist_backend_, &PlaylistBackend::GetPlaylistSongs, id); playlist_backend_, &PlaylistBackend::GetPlaylistSongs, id);
QFutureWatcher<SongList>* watcher = new QFutureWatcher<SongList>(this); NewClosure(future, this, SLOT(ItemsLoadedForSavePlaylist(
watcher->setFuture(future); QFuture<SongList>, QString, Playlist::Path)),
future, filename, path_type);
NewClosure(watcher, SIGNAL(finished()), this,
SLOT(ItemsLoadedForSavePlaylist(QFutureWatcher<SongList>*,
QString, Playlist::Path)),
watcher, filename);
} }
} }
void PlaylistManager::ItemsLoadedForSavePlaylist( void PlaylistManager::ItemsLoadedForSavePlaylist(QFuture<SongList> future,
QFutureWatcher<SongList>* watcher, const QString& filename, const QString& filename,
Playlist::Path path_type) { Playlist::Path path_type) {
SongList song_list = watcher->future().result(); parser_->Save(future.result(), filename, path_type);
parser_->Save(song_list, filename, path_type);
} }
void PlaylistManager::SaveWithUI(int id, const QString& suggested_filename) { void PlaylistManager::SaveWithUI(int id, const QString& suggested_filename) {
@ -471,7 +465,7 @@ void PlaylistManager::InsertUrls(int id, const QList<QUrl>& urls, int pos,
} }
void PlaylistManager::InsertSongs(int id, const SongList& songs, int pos, void PlaylistManager::InsertSongs(int id, const SongList& songs, int pos,
bool play_now, bool enqueue) { bool play_now, bool enqueue) {
Q_ASSERT(playlists_.contains(id)); Q_ASSERT(playlists_.contains(id));
playlists_[id].p->InsertSongs(songs, pos, play_now, enqueue); playlists_[id].p->InsertSongs(songs, pos, play_now, enqueue);

View File

@ -221,7 +221,7 @@ class PlaylistManager : public PlaylistManagerInterface {
void InsertUrls(int id, const QList<QUrl>& urls, int pos = -1, void InsertUrls(int id, const QList<QUrl>& urls, int pos = -1,
bool play_now = false, bool enqueue = false); bool play_now = false, bool enqueue = false);
void InsertSongs(int id, const SongList& songs, int pos = -1, void InsertSongs(int id, const SongList& songs, int pos = -1,
bool play_now = false, bool enqueue = false); bool play_now = false, bool enqueue = false);
// Removes items with given indices from the playlist. This operation is not // Removes items with given indices from the playlist. This operation is not
// undoable. // undoable.
void RemoveItemsWithoutUndo(int id, const QList<int>& indices); void RemoveItemsWithoutUndo(int id, const QList<int>& indices);
@ -234,7 +234,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(QFutureWatcher<SongList>* watcher, void ItemsLoadedForSavePlaylist(QFuture<SongList> future,
const QString& filename, const QString& filename,
Playlist::Path path_type); Playlist::Path path_type);

View File

@ -15,18 +15,16 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>. along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "generator.h" #include "smartplaylists/generatorinserter.h"
#include "generatorinserter.h"
#include "core/taskmanager.h"
#include "playlist/playlist.h"
#include <QFutureWatcher>
#include <QtConcurrentRun> #include <QtConcurrentRun>
namespace smart_playlists { #include "core/closure.h"
#include "core/taskmanager.h"
#include "playlist/playlist.h"
#include "smartplaylists/generator.h"
typedef QFuture<PlaylistItemList> Future; namespace smart_playlists {
typedef QFutureWatcher<PlaylistItemList> FutureWatcher;
GeneratorInserter::GeneratorInserter(TaskManager* task_manager, GeneratorInserter::GeneratorInserter(TaskManager* task_manager,
LibraryBackend* library, QObject* parent) LibraryBackend* library, QObject* parent)
@ -57,18 +55,13 @@ void GeneratorInserter::Load(Playlist* destination, int row, bool play_now,
connect(generator.get(), SIGNAL(Error(QString)), SIGNAL(Error(QString))); connect(generator.get(), SIGNAL(Error(QString)), SIGNAL(Error(QString)));
Future future = QtConcurrent::run(Generate, generator, dynamic_count); QFuture<PlaylistItemList> future =
FutureWatcher* watcher = new FutureWatcher(this); QtConcurrent::run(Generate, generator, dynamic_count);
watcher->setFuture(future); NewClosure(future, this, SLOT(Finished(QFuture<PlaylistItemList>)), future);
connect(watcher, SIGNAL(finished()), SLOT(Finished()));
} }
void GeneratorInserter::Finished() { void GeneratorInserter::Finished(QFuture<PlaylistItemList> future) {
FutureWatcher* watcher = static_cast<FutureWatcher*>(sender()); PlaylistItemList items = future.result();
watcher->deleteLater();
PlaylistItemList items = watcher->result();
if (items.isEmpty()) { if (items.isEmpty()) {
if (is_dynamic_) { if (is_dynamic_) {

View File

@ -20,8 +20,11 @@
#include "generator_fwd.h" #include "generator_fwd.h"
#include <QFuture>
#include <QObject> #include <QObject>
#include "playlist/playlist.h"
class LibraryBackend; class LibraryBackend;
class Playlist; class Playlist;
class TaskManager; class TaskManager;
@ -45,7 +48,7 @@ signals:
void PlayRequested(const QModelIndex& index); void PlayRequested(const QModelIndex& index);
private slots: private slots:
void Finished(); void Finished(QFuture<PlaylistItemList> future);
private: private:
TaskManager* task_manager_; TaskManager* task_manager_;

View File

@ -20,7 +20,6 @@
#include <memory> #include <memory>
#include <QFutureWatcher>
#include <QtConcurrentRun> #include <QtConcurrentRun>
#include "querygenerator.h" #include "querygenerator.h"
@ -28,9 +27,6 @@
namespace smart_playlists { namespace smart_playlists {
typedef QFuture<PlaylistItemList> Future;
typedef QFutureWatcher<PlaylistItemList> FutureWatcher;
SearchPreview::SearchPreview(QWidget* parent) SearchPreview::SearchPreview(QWidget* parent)
: QWidget(parent), ui_(new Ui_SmartPlaylistSearchPreview), model_(nullptr) { : QWidget(parent), ui_(new Ui_SmartPlaylistSearchPreview), model_(nullptr) {
ui_->setupUi(this); ui_->setupUi(this);
@ -95,17 +91,12 @@ void SearchPreview::RunSearch(const Search& search) {
ui_->busy_container->show(); ui_->busy_container->show();
ui_->count_label->hide(); ui_->count_label->hide();
Future future = QtConcurrent::run(DoRunSearch, generator_); QFuture<PlaylistItemList> future = QtConcurrent::run(DoRunSearch, generator_);
NewClosure(future, this, SLOT(SearchFinished(QFuture<PlaylistItemList>)),
FutureWatcher* watcher = new FutureWatcher(this); future);
watcher->setFuture(future);
connect(watcher, SIGNAL(finished()), SLOT(SearchFinished()));
} }
void SearchPreview::SearchFinished() { void SearchPreview::SearchFinished(QFuture<PlaylistItemList> future) {
FutureWatcher* watcher = static_cast<FutureWatcher*>(sender());
watcher->deleteLater();
last_search_ = last_search_ =
std::dynamic_pointer_cast<QueryGenerator>(generator_)->search(); std::dynamic_pointer_cast<QueryGenerator>(generator_)->search();
generator_.reset(); generator_.reset();
@ -118,7 +109,7 @@ void SearchPreview::SearchFinished() {
return; return;
} }
PlaylistItemList all_items = watcher->result(); PlaylistItemList all_items = future.result();
PlaylistItemList displayed_items = all_items.mid(0, Generator::kDefaultLimit); PlaylistItemList displayed_items = all_items.mid(0, Generator::kDefaultLimit);
model_->Clear(); model_->Clear();

View File

@ -21,6 +21,7 @@
#include "search.h" #include "search.h"
#include "smartplaylists/generator_fwd.h" #include "smartplaylists/generator_fwd.h"
#include <QFuture>
#include <QWidget> #include <QWidget>
class Application; class Application;
@ -49,7 +50,7 @@ class SearchPreview : public QWidget {
void RunSearch(const Search& search); void RunSearch(const Search& search);
private slots: private slots:
void SearchFinished(); void SearchFinished(QFuture<PlaylistItemList> future);
private: private:
Ui_SmartPlaylistSearchPreview* ui_; Ui_SmartPlaylistSearchPreview* ui_;

View File

@ -15,25 +15,24 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>. along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "config.h" #include "songinfo/songinfoview.h"
#include "songinfoprovider.h"
#include "songinfoview.h"
#include "taglyricsinfoprovider.h"
#include "ultimatelyricsprovider.h"
#include "ultimatelyricsreader.h"
#ifdef HAVE_LIBLASTFM
#include "lastfmtrackinfoprovider.h"
#endif
#include <QFuture> #include <QFuture>
#include <QFutureWatcher>
#include <QSettings> #include <QSettings>
#include <QtConcurrentRun> #include <QtConcurrentRun>
const char* SongInfoView::kSettingsGroup = "SongInfo"; #include "config.h"
#include "core/closure.h"
#include "songinfo/songinfoprovider.h"
#include "songinfo/taglyricsinfoprovider.h"
#include "songinfo/ultimatelyricsprovider.h"
#include "songinfo/ultimatelyricsreader.h"
typedef QList<SongInfoProvider*> ProviderList; #ifdef HAVE_LIBLASTFM
#include "songinfo/lastfmtrackinfoprovider.h"
#endif
const char* SongInfoView::kSettingsGroup = "SongInfo";
SongInfoView::SongInfoView(QWidget* parent) SongInfoView::SongInfoView(QWidget* parent)
: SongInfoBase(parent), ultimate_reader_(new UltimateLyricsReader(this)) { : SongInfoBase(parent), ultimate_reader_(new UltimateLyricsReader(this)) {
@ -41,10 +40,8 @@ SongInfoView::SongInfoView(QWidget* parent)
QFuture<ProviderList> future = QFuture<ProviderList> future =
QtConcurrent::run(ultimate_reader_.get(), &UltimateLyricsReader::Parse, QtConcurrent::run(ultimate_reader_.get(), &UltimateLyricsReader::Parse,
QString(":lyrics/ultimate_providers.xml")); QString(":lyrics/ultimate_providers.xml"));
QFutureWatcher<ProviderList>* watcher = NewClosure(future, this, SLOT(UltimateLyricsParsed(QFuture<ProviderList>)),
new QFutureWatcher<ProviderList>(this); future);
watcher->setFuture(future);
connect(watcher, SIGNAL(finished()), SLOT(UltimateLyricsParsed()));
#ifdef HAVE_LIBLASTFM #ifdef HAVE_LIBLASTFM
fetcher_->AddProvider(new LastfmTrackInfoProvider); fetcher_->AddProvider(new LastfmTrackInfoProvider);
@ -54,15 +51,11 @@ SongInfoView::SongInfoView(QWidget* parent)
SongInfoView::~SongInfoView() {} SongInfoView::~SongInfoView() {}
void SongInfoView::UltimateLyricsParsed() { void SongInfoView::UltimateLyricsParsed(QFuture<ProviderList> future) {
QFutureWatcher<ProviderList>* watcher = for (SongInfoProvider* provider : future.result()) {
static_cast<QFutureWatcher<ProviderList>*>(sender());
for (SongInfoProvider* provider : watcher->result()) {
fetcher_->AddProvider(provider); fetcher_->AddProvider(provider);
} }
watcher->deleteLater();
ultimate_reader_.reset(); ultimate_reader_.reset();
ReloadSettings(); ReloadSettings();

View File

@ -49,8 +49,9 @@ class SongInfoView : public SongInfoBase {
private: private:
SongInfoProvider* ProviderByName(const QString& name) const; SongInfoProvider* ProviderByName(const QString& name) const;
typedef QList<SongInfoProvider*> ProviderList;
private slots: private slots:
void UltimateLyricsParsed(); void UltimateLyricsParsed(QFuture<ProviderList> future);
private: private:
std::unique_ptr<UltimateLyricsReader> ultimate_reader_; std::unique_ptr<UltimateLyricsReader> ultimate_reader_;

View File

@ -15,26 +15,14 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>. along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "albumcovermanager.h" #include "ui/edittagdialog.h"
#include "edittagdialog.h"
#include "trackselectiondialog.h"
#include "ui_edittagdialog.h" #include "ui_edittagdialog.h"
#include "core/application.h"
#include "core/logging.h" #include <limits>
#include "core/tagreaderclient.h"
#include "core/utilities.h"
#include "covers/albumcoverloader.h"
#include "covers/coverproviders.h"
#include "library/library.h"
#include "library/librarybackend.h"
#include "playlist/playlistdelegates.h"
#include "ui/albumcoverchoicecontroller.h"
#include "ui/coverfromurldialog.h"
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
#include <QFuture> #include <QFuture>
#include <QFutureWatcher>
#include <QLabel> #include <QLabel>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
@ -43,7 +31,19 @@
#include <QtConcurrentRun> #include <QtConcurrentRun>
#include <QtDebug> #include <QtDebug>
#include <limits> #include "core/application.h"
#include "core/logging.h"
#include "core/tagreaderclient.h"
#include "core/utilities.h"
#include "covers/albumcoverloader.h"
#include "covers/coverproviders.h"
#include "library/librarybackend.h"
#include "library/library.h"
#include "playlist/playlistdelegates.h"
#include "ui/albumcoverchoicecontroller.h"
#include "ui/albumcovermanager.h"
#include "ui/coverfromurldialog.h"
#include "ui/trackselectiondialog.h"
const char* EditTagDialog::kHintText = const char* EditTagDialog::kHintText =
QT_TR_NOOP("(different across multiple songs)"); QT_TR_NOOP("(different across multiple songs)");
@ -158,12 +158,10 @@ EditTagDialog::EditTagDialog(Application* app, QWidget* parent)
ui_->art->setAcceptDrops(true); ui_->art->setAcceptDrops(true);
// Add the next/previous buttons // Add the next/previous buttons
previous_button_ = previous_button_ = new QPushButton(
new QPushButton(IconLoader::Load("go-previous", IconLoader::Base), IconLoader::Load("go-previous", IconLoader::Base), tr("Previous"), this);
tr("Previous"), this); next_button_ = new QPushButton(IconLoader::Load("go-next", IconLoader::Base),
next_button_ = tr("Next"), this);
new QPushButton(IconLoader::Load("go-next", IconLoader::Base),
tr("Next"), this);
ui_->button_box->addButton(previous_button_, QDialogButtonBox::ResetRole); ui_->button_box->addButton(previous_button_, QDialogButtonBox::ResetRole);
ui_->button_box->addButton(next_button_, QDialogButtonBox::ResetRole); ui_->button_box->addButton(next_button_, QDialogButtonBox::ResetRole);
@ -251,20 +249,15 @@ void EditTagDialog::SetSongs(const SongList& s, const PlaylistItemList& items) {
// Reload tags in the background // Reload tags in the background
QFuture<QList<Data>> future = QFuture<QList<Data>> future =
QtConcurrent::run(this, &EditTagDialog::LoadData, s); QtConcurrent::run(this, &EditTagDialog::LoadData, s);
QFutureWatcher<QList<Data>>* watcher = new QFutureWatcher<QList<Data>>(this); NewClosure(future, this,
watcher->setFuture(future); SLOT(SetSongsFinished(QFuture<QList<EditTagDialog::Data>>)),
connect(watcher, SIGNAL(finished()), SLOT(SetSongsFinished())); future);
} }
void EditTagDialog::SetSongsFinished() { void EditTagDialog::SetSongsFinished(QFuture<QList<Data>> future) {
QFutureWatcher<QList<Data>>* watcher =
dynamic_cast<QFutureWatcher<QList<Data>>*>(sender());
if (!watcher) return;
watcher->deleteLater();
if (!SetLoading(QString())) return; if (!SetLoading(QString())) return;
data_ = watcher->result(); 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);
@ -708,16 +701,10 @@ void EditTagDialog::accept() {
// Save tags in the background // Save tags in the background
QFuture<void> future = QFuture<void> future =
QtConcurrent::run(this, &EditTagDialog::SaveData, data_); QtConcurrent::run(this, &EditTagDialog::SaveData, data_);
QFutureWatcher<void>* watcher = new QFutureWatcher<void>(this); NewClosure(future, this, SLOT(AcceptFinished()));
watcher->setFuture(future);
connect(watcher, SIGNAL(finished()), SLOT(AcceptFinished()));
} }
void EditTagDialog::AcceptFinished() { void EditTagDialog::AcceptFinished() {
QFutureWatcher<void>* watcher = dynamic_cast<QFutureWatcher<void>*>(sender());
if (!watcher) return;
watcher->deleteLater();
if (!SetLoading(QString())) return; if (!SetLoading(QString())) return;
QDialog::accept(); QDialog::accept();

View File

@ -64,8 +64,26 @@ signals:
void showEvent(QShowEvent*); void showEvent(QShowEvent*);
void hideEvent(QHideEvent*); void hideEvent(QHideEvent*);
private:
struct Data {
Data(const Song& song = Song()) : original_(song), current_(song) {}
static QVariant value(const Song& song, const QString& id);
QVariant original_value(const QString& id) const {
return value(original_, id);
}
QVariant current_value(const QString& id) const {
return value(current_, id);
}
void set_value(const QString& id, const QVariant& value);
Song original_;
Song current_;
};
private slots: private slots:
void SetSongsFinished(); void SetSongsFinished(QFuture<QList<EditTagDialog::Data>> future);
void AcceptFinished(); void AcceptFinished();
void SelectionChanged(); void SelectionChanged();
@ -90,23 +108,6 @@ signals:
void NextSong(); void NextSong();
private: private:
struct Data {
Data(const Song& song = Song()) : original_(song), current_(song) {}
static QVariant value(const Song& song, const QString& id);
QVariant original_value(const QString& id) const {
return value(original_, id);
}
QVariant current_value(const QString& id) const {
return value(current_, id);
}
void set_value(const QString& id, const QVariant& value);
Song original_;
Song current_;
};
struct FieldData { struct FieldData {
FieldData(QLabel* label = nullptr, QWidget* editor = nullptr, FieldData(QLabel* label = nullptr, QWidget* editor = nullptr,
const QString& id = QString()) const QString& id = QString())

View File

@ -22,7 +22,6 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QFutureWatcher>
#include <QHash> #include <QHash>
#include <QMenu> #include <QMenu>
#include <QPushButton> #include <QPushButton>
@ -53,7 +52,8 @@ OrganiseDialog::OrganiseDialog(TaskManager* task_manager, QWidget* parent)
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()), connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
SLOT(Reset())); SLOT(Reset()));
ui_->aftercopying->setItemIcon(1, IconLoader::Load("edit-delete", IconLoader::Base)); ui_->aftercopying->setItemIcon(
1, IconLoader::Load("edit-delete", IconLoader::Base));
// Valid tags // Valid tags
QMap<QString, QString> tags; QMap<QString, QString> tags;
@ -155,12 +155,7 @@ bool OrganiseDialog::SetUrls(const QList<QUrl>& urls) {
bool OrganiseDialog::SetFilenames(const QStringList& filenames) { bool OrganiseDialog::SetFilenames(const QStringList& filenames) {
songs_future_ = songs_future_ =
QtConcurrent::run(this, &OrganiseDialog::LoadSongsBlocking, filenames); QtConcurrent::run(this, &OrganiseDialog::LoadSongsBlocking, filenames);
QFutureWatcher<SongList>* watcher = new QFutureWatcher<SongList>(this); NewClosure(songs_future_, [=]() { SetSongs(songs_future_.result()); });
watcher->setFuture(songs_future_);
NewClosure(watcher, SIGNAL(finished()), [=]() {
SetSongs(songs_future_.result());
watcher->deleteLater();
});
SetLoadingSongs(true); SetLoadingSongs(true);
return true; return true;

View File

@ -21,6 +21,7 @@
#include <memory> #include <memory>
#include <QDialog> #include <QDialog>
#include <QFuture>
#include <QMap> #include <QMap>
#include <QUrl> #include <QUrl>
@ -60,7 +61,7 @@ class OrganiseDialog : public QDialog {
void SetCopy(bool copy); void SetCopy(bool copy);
signals: signals:
void FileCopied(int); void FileCopied(int);
public slots: public slots:

View File

@ -15,13 +15,10 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>. along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "iconloader.h" #include "ui/trackselectiondialog.h"
#include "trackselectiondialog.h"
#include "ui_trackselectiondialog.h" #include "ui_trackselectiondialog.h"
#include "core/tagreaderclient.h"
#include <QFileInfo> #include <QFileInfo>
#include <QFutureWatcher>
#include <QPushButton> #include <QPushButton>
#include <QShortcut> #include <QShortcut>
#include <QTreeWidget> #include <QTreeWidget>
@ -29,6 +26,9 @@
#include <QtConcurrentRun> #include <QtConcurrentRun>
#include <QtDebug> #include <QtDebug>
#include "core/tagreaderclient.h"
#include "ui/iconloader.h"
TrackSelectionDialog::TrackSelectionDialog(QWidget* parent) TrackSelectionDialog::TrackSelectionDialog(QWidget* parent)
: QDialog(parent), ui_(new Ui_TrackSelectionDialog), save_on_close_(false) { : QDialog(parent), ui_(new Ui_TrackSelectionDialog), save_on_close_(false) {
// Setup dialog window // Setup dialog window
@ -43,10 +43,9 @@ TrackSelectionDialog::TrackSelectionDialog(QWidget* parent)
SetLoading(QString()); SetLoading(QString());
// Add the next/previous buttons // Add the next/previous buttons
previous_button_ = previous_button_ = new QPushButton(
new QPushButton(IconLoader::Load("go-previous", IconLoader::Base), IconLoader::Load("go-previous", IconLoader::Base), tr("Previous"), this);
tr("Previous"), this); next_button_ = new QPushButton(IconLoader::Load("go-next", IconLoader::Base),
next_button_ = new QPushButton(IconLoader::Load("go-next", IconLoader::Base),
tr("Next"), this); tr("Next"), this);
ui_->button_box->addButton(previous_button_, QDialogButtonBox::ResetRole); ui_->button_box->addButton(previous_button_, QDialogButtonBox::ResetRole);
ui_->button_box->addButton(next_button_, QDialogButtonBox::ResetRole); ui_->button_box->addButton(next_button_, QDialogButtonBox::ResetRole);
@ -258,10 +257,7 @@ void TrackSelectionDialog::accept() {
// Save tags in the background // Save tags in the background
QFuture<void> future = QFuture<void> future =
QtConcurrent::run(&TrackSelectionDialog::SaveData, data_); QtConcurrent::run(&TrackSelectionDialog::SaveData, data_);
QFutureWatcher<void>* watcher = new QFutureWatcher<void>(this); NewClosure(future, this, SLOT(AcceptFinished()));
watcher->setFuture(future);
connect(watcher, SIGNAL(finished()), SLOT(AcceptFinished()));
return; return;
} }
@ -278,10 +274,6 @@ void TrackSelectionDialog::accept() {
} }
void TrackSelectionDialog::AcceptFinished() { void TrackSelectionDialog::AcceptFinished() {
QFutureWatcher<void>* watcher = dynamic_cast<QFutureWatcher<void>*>(sender());
if (!watcher) return;
watcher->deleteLater();
SetLoading(QString()); SetLoading(QString());
QDialog::accept(); QDialog::accept();
} }