From 33494dcddcb64f9fccae215f1100cfa885c72039 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 26 Nov 2015 18:51:32 +0000 Subject: [PATCH] Remove BoundFutureWatcher --- src/core/boundfuturewatcher.h | 40 ----------------------------- src/engines/gstengine.cpp | 34 ++++++++---------------- src/engines/gstengine.h | 9 ++----- src/globalsearch/searchprovider.cpp | 25 +++++++----------- src/globalsearch/searchprovider.h | 6 ++--- 5 files changed, 25 insertions(+), 89 deletions(-) delete mode 100644 src/core/boundfuturewatcher.h diff --git a/src/core/boundfuturewatcher.h b/src/core/boundfuturewatcher.h deleted file mode 100644 index b4c42ed7a..000000000 --- a/src/core/boundfuturewatcher.h +++ /dev/null @@ -1,40 +0,0 @@ -/* This file is part of Clementine. - Copyright 2010, 2014, John Maguire - Copyright 2014, Krzysztof Sobiecki - - Clementine is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Clementine is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Clementine. If not, see . -*/ - -#ifndef CORE_BOUNDFUTUREWATCHER_H_ -#define CORE_BOUNDFUTUREWATCHER_H_ - -#include - -#include - -template -class BoundFutureWatcher : public QFutureWatcher, boost::noncopyable { - public: - explicit BoundFutureWatcher(const D& data, QObject* parent = nullptr) - : QFutureWatcher(parent), data_(data) {} - - ~BoundFutureWatcher() {} - - const D& data() const { return data_; } - - private: - D data_; -}; - -#endif // CORE_BOUNDFUTUREWATCHER_H_ diff --git a/src/engines/gstengine.cpp b/src/engines/gstengine.cpp index 6d6dc0bf7..7013836c6 100644 --- a/src/engines/gstengine.cpp +++ b/src/engines/gstengine.cpp @@ -43,6 +43,7 @@ #include "config.h" #include "devicefinder.h" #include "gstenginepipeline.h" +#include "core/closure.h" #include "core/logging.h" #include "core/taskmanager.h" #include "core/timeconstants.h" @@ -454,10 +455,8 @@ bool GstEngine::Play(quint64 offset_nanosec) { QFuture future = current_pipeline_->SetState(GST_STATE_PLAYING); - PlayFutureWatcher* watcher = new PlayFutureWatcher( - PlayFutureWatcherArg(offset_nanosec, current_pipeline_->id()), this); - watcher->setFuture(future); - connect(watcher, SIGNAL(finished()), SLOT(PlayDone())); + NewClosure(future, this, SLOT(PlayDone()), offset_nanosec, + current_pipeline_->id()); if (is_fading_out_to_pause_) { current_pipeline_->SetState(GST_STATE_PAUSED); @@ -466,14 +465,11 @@ bool GstEngine::Play(quint64 offset_nanosec) { return true; } -void GstEngine::PlayDone() { - PlayFutureWatcher* watcher = static_cast(sender()); - watcher->deleteLater(); +void GstEngine::PlayDone(QFuture future, + const quint64 offset_nanosec, const int pipeline_id) { + GstStateChangeReturn ret = future.result(); - GstStateChangeReturn ret = watcher->result(); - quint64 offset_nanosec = watcher->data().first; - - if (!current_pipeline_ || watcher->data().second != current_pipeline_->id()) { + if (!current_pipeline_ || pipeline_id != current_pipeline_->id()) { return; } @@ -852,21 +848,13 @@ int GstEngine::AddBackgroundStream(shared_ptr pipeline) { background_streams_[stream_id] = pipeline; QFuture future = pipeline->SetState(GST_STATE_PLAYING); - BoundFutureWatcher* watcher = - new BoundFutureWatcher(stream_id, this); - watcher->setFuture(future); - connect(watcher, SIGNAL(finished()), SLOT(BackgroundStreamPlayDone())); - + NewClosure(future, this, SLOT(BackgroundStreamPlayDone()), stream_id); return stream_id; } -void GstEngine::BackgroundStreamPlayDone() { - BoundFutureWatcher* watcher = - static_cast*>(sender()); - watcher->deleteLater(); - - const int stream_id = watcher->data(); - GstStateChangeReturn ret = watcher->result(); +void GstEngine::BackgroundStreamPlayDone(QFuture future, + int stream_id) { + GstStateChangeReturn ret = future.result(); if (ret == GST_STATE_CHANGE_FAILURE) { qLog(Warning) << "Could not set thread to PLAYING."; diff --git a/src/engines/gstengine.h b/src/engines/gstengine.h index f242a366d..57ab8dfce 100644 --- a/src/engines/gstengine.h +++ b/src/engines/gstengine.h @@ -35,7 +35,6 @@ #include "bufferconsumer.h" #include "enginebase.h" -#include "core/boundfuturewatcher.h" #include "core/timeconstants.h" class QTimer; @@ -139,18 +138,14 @@ class GstEngine : public Engine::Base, public BufferConsumer { void FadeoutPauseFinished(); void SeekNow(); void BackgroundStreamFinished(); - void BackgroundStreamPlayDone(); - void PlayDone(); + void BackgroundStreamPlayDone(QFuture, int); + void PlayDone(QFuture future, const quint64, const int); void BufferingStarted(); void BufferingProgress(int percent); void BufferingFinished(); private: - typedef QPair PlayFutureWatcherArg; - typedef BoundFutureWatcher - PlayFutureWatcher; - struct PluginDetails { QString name; QString description; diff --git a/src/globalsearch/searchprovider.cpp b/src/globalsearch/searchprovider.cpp index 80206df78..6a95f861e 100644 --- a/src/globalsearch/searchprovider.cpp +++ b/src/globalsearch/searchprovider.cpp @@ -16,14 +16,15 @@ */ #include "searchprovider.h" -#include "core/boundfuturewatcher.h" -#include "internet/core/internetsongmimedata.h" -#include "playlist/songmimedata.h" #include #include #include +#include "core/closure.h" +#include "internet/core/internetsongmimedata.h" +#include "playlist/songmimedata.h" + const int SearchProvider::kArtHeight = 32; SearchProvider::SearchProvider(Application* app, QObject* parent) @@ -80,22 +81,14 @@ BlockingSearchProvider::BlockingSearchProvider(Application* app, void BlockingSearchProvider::SearchAsync(int id, const QString& query) { QFuture future = QtConcurrent::run(this, &BlockingSearchProvider::Search, id, query); - - BoundFutureWatcher* watcher = - new BoundFutureWatcher(id); - watcher->setFuture(future); - connect(watcher, SIGNAL(finished()), SLOT(BlockingSearchFinished())); + NewClosure(future, this, + SLOT(BlockingSearchFinished(QFuture, int)), id); } -void BlockingSearchProvider::BlockingSearchFinished() { - BoundFutureWatcher* watcher = - static_cast*>(sender()); - - const int id = watcher->data(); - emit ResultsAvailable(id, watcher->result()); +void BlockingSearchProvider::BlockingSearchFinished(QFuture future, + const int id) { + emit ResultsAvailable(id, future.result()); emit SearchFinished(id); - - watcher->deleteLater(); } QImage SearchProvider::ScaleAndPad(const QImage& image) { diff --git a/src/globalsearch/searchprovider.h b/src/globalsearch/searchprovider.h index eff5d808e..d750eba47 100644 --- a/src/globalsearch/searchprovider.h +++ b/src/globalsearch/searchprovider.h @@ -143,8 +143,8 @@ class SearchProvider : public QObject { // be reimplemented virtual bool IsLoggedIn() { return true; } virtual void ShowConfig() {} // Remember to set the CanShowConfig hint - // Returns the Internet service in charge of this provider, or nullptr if there - // is none + // Returns the Internet service in charge of this provider, or nullptr if + // there is none. virtual InternetService* internet_service() { return nullptr; } static QImage ScaleAndPad(const QImage& image); @@ -208,7 +208,7 @@ class BlockingSearchProvider : public SearchProvider { virtual ResultList Search(int id, const QString& query) = 0; private slots: - void BlockingSearchFinished(); + void BlockingSearchFinished(QFuture future, const int id); }; Q_DECLARE_METATYPE(SearchProvider*)