Remove BoundFutureWatcher
This commit is contained in:
parent
689858026e
commit
33494dcddc
|
@ -1,40 +0,0 @@
|
|||
/* This file is part of Clementine.
|
||||
Copyright 2010, 2014, John Maguire <john.maguire@gmail.com>
|
||||
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CORE_BOUNDFUTUREWATCHER_H_
|
||||
#define CORE_BOUNDFUTUREWATCHER_H_
|
||||
|
||||
#include <QFutureWatcher>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
template <typename T, typename D>
|
||||
class BoundFutureWatcher : public QFutureWatcher<T>, boost::noncopyable {
|
||||
public:
|
||||
explicit BoundFutureWatcher(const D& data, QObject* parent = nullptr)
|
||||
: QFutureWatcher<T>(parent), data_(data) {}
|
||||
|
||||
~BoundFutureWatcher() {}
|
||||
|
||||
const D& data() const { return data_; }
|
||||
|
||||
private:
|
||||
D data_;
|
||||
};
|
||||
|
||||
#endif // CORE_BOUNDFUTUREWATCHER_H_
|
|
@ -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<GstStateChangeReturn> 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<PlayFutureWatcher*>(sender());
|
||||
watcher->deleteLater();
|
||||
void GstEngine::PlayDone(QFuture<GstStateChangeReturn> 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<GstEnginePipeline> pipeline) {
|
|||
background_streams_[stream_id] = pipeline;
|
||||
|
||||
QFuture<GstStateChangeReturn> future = pipeline->SetState(GST_STATE_PLAYING);
|
||||
BoundFutureWatcher<GstStateChangeReturn, int>* watcher =
|
||||
new BoundFutureWatcher<GstStateChangeReturn, int>(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<GstStateChangeReturn, int>* watcher =
|
||||
static_cast<BoundFutureWatcher<GstStateChangeReturn, int>*>(sender());
|
||||
watcher->deleteLater();
|
||||
|
||||
const int stream_id = watcher->data();
|
||||
GstStateChangeReturn ret = watcher->result();
|
||||
void GstEngine::BackgroundStreamPlayDone(QFuture<GstStateChangeReturn> future,
|
||||
int stream_id) {
|
||||
GstStateChangeReturn ret = future.result();
|
||||
|
||||
if (ret == GST_STATE_CHANGE_FAILURE) {
|
||||
qLog(Warning) << "Could not set thread to PLAYING.";
|
||||
|
|
|
@ -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<GstStateChangeReturn>, int);
|
||||
void PlayDone(QFuture<GstStateChangeReturn> future, const quint64, const int);
|
||||
|
||||
void BufferingStarted();
|
||||
void BufferingProgress(int percent);
|
||||
void BufferingFinished();
|
||||
|
||||
private:
|
||||
typedef QPair<quint64, int> PlayFutureWatcherArg;
|
||||
typedef BoundFutureWatcher<GstStateChangeReturn, PlayFutureWatcherArg>
|
||||
PlayFutureWatcher;
|
||||
|
||||
struct PluginDetails {
|
||||
QString name;
|
||||
QString description;
|
||||
|
|
|
@ -16,14 +16,15 @@
|
|||
*/
|
||||
|
||||
#include "searchprovider.h"
|
||||
#include "core/boundfuturewatcher.h"
|
||||
#include "internet/core/internetsongmimedata.h"
|
||||
#include "playlist/songmimedata.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QUrl>
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
#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<ResultList> future =
|
||||
QtConcurrent::run(this, &BlockingSearchProvider::Search, id, query);
|
||||
|
||||
BoundFutureWatcher<ResultList, int>* watcher =
|
||||
new BoundFutureWatcher<ResultList, int>(id);
|
||||
watcher->setFuture(future);
|
||||
connect(watcher, SIGNAL(finished()), SLOT(BlockingSearchFinished()));
|
||||
NewClosure(future, this,
|
||||
SLOT(BlockingSearchFinished(QFuture<ResultList>, int)), id);
|
||||
}
|
||||
|
||||
void BlockingSearchProvider::BlockingSearchFinished() {
|
||||
BoundFutureWatcher<ResultList, int>* watcher =
|
||||
static_cast<BoundFutureWatcher<ResultList, int>*>(sender());
|
||||
|
||||
const int id = watcher->data();
|
||||
emit ResultsAvailable(id, watcher->result());
|
||||
void BlockingSearchProvider::BlockingSearchFinished(QFuture<ResultList> future,
|
||||
const int id) {
|
||||
emit ResultsAvailable(id, future.result());
|
||||
emit SearchFinished(id);
|
||||
|
||||
watcher->deleteLater();
|
||||
}
|
||||
|
||||
QImage SearchProvider::ScaleAndPad(const QImage& image) {
|
||||
|
|
|
@ -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<ResultList> future, const int id);
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(SearchProvider*)
|
||||
|
|
Loading…
Reference in New Issue