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 "config.h"
|
||||||
#include "devicefinder.h"
|
#include "devicefinder.h"
|
||||||
#include "gstenginepipeline.h"
|
#include "gstenginepipeline.h"
|
||||||
|
#include "core/closure.h"
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/taskmanager.h"
|
#include "core/taskmanager.h"
|
||||||
#include "core/timeconstants.h"
|
#include "core/timeconstants.h"
|
||||||
|
@ -454,10 +455,8 @@ bool GstEngine::Play(quint64 offset_nanosec) {
|
||||||
|
|
||||||
QFuture<GstStateChangeReturn> future =
|
QFuture<GstStateChangeReturn> future =
|
||||||
current_pipeline_->SetState(GST_STATE_PLAYING);
|
current_pipeline_->SetState(GST_STATE_PLAYING);
|
||||||
PlayFutureWatcher* watcher = new PlayFutureWatcher(
|
NewClosure(future, this, SLOT(PlayDone()), offset_nanosec,
|
||||||
PlayFutureWatcherArg(offset_nanosec, current_pipeline_->id()), this);
|
current_pipeline_->id());
|
||||||
watcher->setFuture(future);
|
|
||||||
connect(watcher, SIGNAL(finished()), SLOT(PlayDone()));
|
|
||||||
|
|
||||||
if (is_fading_out_to_pause_) {
|
if (is_fading_out_to_pause_) {
|
||||||
current_pipeline_->SetState(GST_STATE_PAUSED);
|
current_pipeline_->SetState(GST_STATE_PAUSED);
|
||||||
|
@ -466,14 +465,11 @@ bool GstEngine::Play(quint64 offset_nanosec) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GstEngine::PlayDone() {
|
void GstEngine::PlayDone(QFuture<GstStateChangeReturn> future,
|
||||||
PlayFutureWatcher* watcher = static_cast<PlayFutureWatcher*>(sender());
|
const quint64 offset_nanosec, const int pipeline_id) {
|
||||||
watcher->deleteLater();
|
GstStateChangeReturn ret = future.result();
|
||||||
|
|
||||||
GstStateChangeReturn ret = watcher->result();
|
if (!current_pipeline_ || pipeline_id != current_pipeline_->id()) {
|
||||||
quint64 offset_nanosec = watcher->data().first;
|
|
||||||
|
|
||||||
if (!current_pipeline_ || watcher->data().second != current_pipeline_->id()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -852,21 +848,13 @@ int GstEngine::AddBackgroundStream(shared_ptr<GstEnginePipeline> pipeline) {
|
||||||
background_streams_[stream_id] = pipeline;
|
background_streams_[stream_id] = pipeline;
|
||||||
|
|
||||||
QFuture<GstStateChangeReturn> future = pipeline->SetState(GST_STATE_PLAYING);
|
QFuture<GstStateChangeReturn> future = pipeline->SetState(GST_STATE_PLAYING);
|
||||||
BoundFutureWatcher<GstStateChangeReturn, int>* watcher =
|
NewClosure(future, this, SLOT(BackgroundStreamPlayDone()), stream_id);
|
||||||
new BoundFutureWatcher<GstStateChangeReturn, int>(stream_id, this);
|
|
||||||
watcher->setFuture(future);
|
|
||||||
connect(watcher, SIGNAL(finished()), SLOT(BackgroundStreamPlayDone()));
|
|
||||||
|
|
||||||
return stream_id;
|
return stream_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GstEngine::BackgroundStreamPlayDone() {
|
void GstEngine::BackgroundStreamPlayDone(QFuture<GstStateChangeReturn> future,
|
||||||
BoundFutureWatcher<GstStateChangeReturn, int>* watcher =
|
int stream_id) {
|
||||||
static_cast<BoundFutureWatcher<GstStateChangeReturn, int>*>(sender());
|
GstStateChangeReturn ret = future.result();
|
||||||
watcher->deleteLater();
|
|
||||||
|
|
||||||
const int stream_id = watcher->data();
|
|
||||||
GstStateChangeReturn ret = watcher->result();
|
|
||||||
|
|
||||||
if (ret == GST_STATE_CHANGE_FAILURE) {
|
if (ret == GST_STATE_CHANGE_FAILURE) {
|
||||||
qLog(Warning) << "Could not set thread to PLAYING.";
|
qLog(Warning) << "Could not set thread to PLAYING.";
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
|
|
||||||
#include "bufferconsumer.h"
|
#include "bufferconsumer.h"
|
||||||
#include "enginebase.h"
|
#include "enginebase.h"
|
||||||
#include "core/boundfuturewatcher.h"
|
|
||||||
#include "core/timeconstants.h"
|
#include "core/timeconstants.h"
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
@ -139,18 +138,14 @@ class GstEngine : public Engine::Base, public BufferConsumer {
|
||||||
void FadeoutPauseFinished();
|
void FadeoutPauseFinished();
|
||||||
void SeekNow();
|
void SeekNow();
|
||||||
void BackgroundStreamFinished();
|
void BackgroundStreamFinished();
|
||||||
void BackgroundStreamPlayDone();
|
void BackgroundStreamPlayDone(QFuture<GstStateChangeReturn>, int);
|
||||||
void PlayDone();
|
void PlayDone(QFuture<GstStateChangeReturn> future, const quint64, const int);
|
||||||
|
|
||||||
void BufferingStarted();
|
void BufferingStarted();
|
||||||
void BufferingProgress(int percent);
|
void BufferingProgress(int percent);
|
||||||
void BufferingFinished();
|
void BufferingFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef QPair<quint64, int> PlayFutureWatcherArg;
|
|
||||||
typedef BoundFutureWatcher<GstStateChangeReturn, PlayFutureWatcherArg>
|
|
||||||
PlayFutureWatcher;
|
|
||||||
|
|
||||||
struct PluginDetails {
|
struct PluginDetails {
|
||||||
QString name;
|
QString name;
|
||||||
QString description;
|
QString description;
|
||||||
|
|
|
@ -16,14 +16,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "searchprovider.h"
|
#include "searchprovider.h"
|
||||||
#include "core/boundfuturewatcher.h"
|
|
||||||
#include "internet/core/internetsongmimedata.h"
|
|
||||||
#include "playlist/songmimedata.h"
|
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
|
|
||||||
|
#include "core/closure.h"
|
||||||
|
#include "internet/core/internetsongmimedata.h"
|
||||||
|
#include "playlist/songmimedata.h"
|
||||||
|
|
||||||
const int SearchProvider::kArtHeight = 32;
|
const int SearchProvider::kArtHeight = 32;
|
||||||
|
|
||||||
SearchProvider::SearchProvider(Application* app, QObject* parent)
|
SearchProvider::SearchProvider(Application* app, QObject* parent)
|
||||||
|
@ -80,22 +81,14 @@ BlockingSearchProvider::BlockingSearchProvider(Application* app,
|
||||||
void BlockingSearchProvider::SearchAsync(int id, const QString& query) {
|
void BlockingSearchProvider::SearchAsync(int id, const QString& query) {
|
||||||
QFuture<ResultList> future =
|
QFuture<ResultList> future =
|
||||||
QtConcurrent::run(this, &BlockingSearchProvider::Search, id, query);
|
QtConcurrent::run(this, &BlockingSearchProvider::Search, id, query);
|
||||||
|
NewClosure(future, this,
|
||||||
BoundFutureWatcher<ResultList, int>* watcher =
|
SLOT(BlockingSearchFinished(QFuture<ResultList>, int)), id);
|
||||||
new BoundFutureWatcher<ResultList, int>(id);
|
|
||||||
watcher->setFuture(future);
|
|
||||||
connect(watcher, SIGNAL(finished()), SLOT(BlockingSearchFinished()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockingSearchProvider::BlockingSearchFinished() {
|
void BlockingSearchProvider::BlockingSearchFinished(QFuture<ResultList> future,
|
||||||
BoundFutureWatcher<ResultList, int>* watcher =
|
const int id) {
|
||||||
static_cast<BoundFutureWatcher<ResultList, int>*>(sender());
|
emit ResultsAvailable(id, future.result());
|
||||||
|
|
||||||
const int id = watcher->data();
|
|
||||||
emit ResultsAvailable(id, watcher->result());
|
|
||||||
emit SearchFinished(id);
|
emit SearchFinished(id);
|
||||||
|
|
||||||
watcher->deleteLater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage SearchProvider::ScaleAndPad(const QImage& image) {
|
QImage SearchProvider::ScaleAndPad(const QImage& image) {
|
||||||
|
|
|
@ -143,8 +143,8 @@ class SearchProvider : public QObject {
|
||||||
// be reimplemented
|
// be reimplemented
|
||||||
virtual bool IsLoggedIn() { return true; }
|
virtual bool IsLoggedIn() { return true; }
|
||||||
virtual void ShowConfig() {} // Remember to set the CanShowConfig hint
|
virtual void ShowConfig() {} // Remember to set the CanShowConfig hint
|
||||||
// Returns the Internet service in charge of this provider, or nullptr if there
|
// Returns the Internet service in charge of this provider, or nullptr if
|
||||||
// is none
|
// there is none.
|
||||||
virtual InternetService* internet_service() { return nullptr; }
|
virtual InternetService* internet_service() { return nullptr; }
|
||||||
|
|
||||||
static QImage ScaleAndPad(const QImage& image);
|
static QImage ScaleAndPad(const QImage& image);
|
||||||
|
@ -208,7 +208,7 @@ class BlockingSearchProvider : public SearchProvider {
|
||||||
virtual ResultList Search(int id, const QString& query) = 0;
|
virtual ResultList Search(int id, const QString& query) = 0;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void BlockingSearchFinished();
|
void BlockingSearchFinished(QFuture<ResultList> future, const int id);
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(SearchProvider*)
|
Q_DECLARE_METATYPE(SearchProvider*)
|
||||||
|
|
Loading…
Reference in New Issue