Port a few more things to closures.
This commit is contained in:
parent
20196edcac
commit
d6b2fc79f5
@ -15,19 +15,21 @@
|
||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "albumcoverfetcher.h"
|
||||
#include "albumcoverfetchersearch.h"
|
||||
#include "coverprovider.h"
|
||||
#include "coverproviders.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/network.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QMutexLocker>
|
||||
#include <QNetworkReply>
|
||||
#include <QTimer>
|
||||
#include <QtDebug>
|
||||
|
||||
#include <cmath>
|
||||
#include "albumcoverfetcher.h"
|
||||
#include "coverprovider.h"
|
||||
#include "coverproviders.h"
|
||||
#include "core/closure.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/network.h"
|
||||
|
||||
const int AlbumCoverFetcherSearch::kSearchTimeoutMs = 10000;
|
||||
const int AlbumCoverFetcherSearch::kImageLoadTimeoutMs = 2500;
|
||||
@ -148,7 +150,8 @@ void AlbumCoverFetcherSearch::FetchMoreImages() {
|
||||
|
||||
RedirectFollower* image_reply = new RedirectFollower(
|
||||
network_->get(QNetworkRequest(result.image_url)));
|
||||
connect(image_reply, SIGNAL(finished()), SLOT(ProviderCoverFetchFinished()));
|
||||
NewClosure(image_reply, SIGNAL(finished()), this,
|
||||
SLOT(ProviderCoverFetchFinished(RedirectFollower*)), image_reply);
|
||||
pending_image_loads_[image_reply] = result.provider;
|
||||
image_load_timeout_->AddReply(image_reply);
|
||||
|
||||
@ -161,8 +164,7 @@ void AlbumCoverFetcherSearch::FetchMoreImages() {
|
||||
}
|
||||
}
|
||||
|
||||
void AlbumCoverFetcherSearch::ProviderCoverFetchFinished() {
|
||||
RedirectFollower* reply = qobject_cast<RedirectFollower*>(sender());
|
||||
void AlbumCoverFetcherSearch::ProviderCoverFetchFinished(RedirectFollower* reply) {
|
||||
reply->deleteLater();
|
||||
const QString provider = pending_image_loads_.take(reply);
|
||||
|
||||
|
@ -57,7 +57,7 @@ signals:
|
||||
|
||||
private slots:
|
||||
void ProviderSearchFinished(int id, const QList<CoverSearchResult>& results);
|
||||
void ProviderCoverFetchFinished();
|
||||
void ProviderCoverFetchFinished(RedirectFollower* reply);
|
||||
void TerminateSearch();
|
||||
|
||||
private:
|
||||
|
@ -16,12 +16,6 @@
|
||||
*/
|
||||
|
||||
#include "albumcoverloader.h"
|
||||
#include "config.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/network.h"
|
||||
#include "core/tagreaderclient.h"
|
||||
#include "core/utilities.h"
|
||||
#include "internet/internetmodel.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QDir>
|
||||
@ -29,6 +23,14 @@
|
||||
#include <QUrl>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "config.h"
|
||||
#include "core/closure.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/network.h"
|
||||
#include "core/tagreaderclient.h"
|
||||
#include "core/utilities.h"
|
||||
#include "internet/internetmodel.h"
|
||||
|
||||
#ifdef HAVE_SPOTIFY
|
||||
# include "internet/spotifyservice.h"
|
||||
#endif
|
||||
@ -165,6 +167,8 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(
|
||||
QUrl url(filename);
|
||||
QNetworkReply* reply = network_->get(QNetworkRequest(url));
|
||||
connect(reply, SIGNAL(finished()), SLOT(RemoteFetchFinished()));
|
||||
NewClosure(reply, SIGNAL(finished()), this,
|
||||
SLOT(RemoteFetchFinished(QNetworkReply*)), reply);
|
||||
|
||||
remote_tasks_.insert(reply, task);
|
||||
return TryLoadResult(true, false, QImage());
|
||||
@ -209,10 +213,7 @@ void AlbumCoverLoader::SpotifyImageLoaded(const QString& id, const QImage& image
|
||||
emit ImageLoaded(task.id, scaled, image);
|
||||
}
|
||||
|
||||
void AlbumCoverLoader::RemoteFetchFinished() {
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
if (!reply)
|
||||
return;
|
||||
void AlbumCoverLoader::RemoteFetchFinished(QNetworkReply* reply) {
|
||||
reply->deleteLater();
|
||||
|
||||
Task task = remote_tasks_.take(reply);
|
||||
@ -226,7 +227,8 @@ void AlbumCoverLoader::RemoteFetchFinished() {
|
||||
QNetworkRequest request = reply->request();
|
||||
request.setUrl(redirect.toUrl());
|
||||
QNetworkReply* redirected_reply = network_->get(request);
|
||||
connect(redirected_reply, SIGNAL(finished()), SLOT(RemoteFetchFinished()));
|
||||
NewClosure(redirected_reply, SIGNAL(finished()), this,
|
||||
SLOT(RemoteFetchFinished(QNetworkReply*)), redirected_reply);
|
||||
|
||||
remote_tasks_.insert(redirected_reply, task);
|
||||
return;
|
||||
|
@ -61,7 +61,7 @@ class AlbumCoverLoader : public QObject {
|
||||
|
||||
protected slots:
|
||||
void ProcessTasks();
|
||||
void RemoteFetchFinished();
|
||||
void RemoteFetchFinished(QNetworkReply* reply);
|
||||
void SpotifyImageLoaded(const QString& url, const QImage& image);
|
||||
|
||||
protected:
|
||||
|
@ -1,10 +1,12 @@
|
||||
#include "kittenloader.h"
|
||||
#include "core/network.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include "core/closure.h"
|
||||
#include "core/network.h"
|
||||
|
||||
const char* KittenLoader::kFlickrKittenUrl =
|
||||
"http://api.flickr.com/services/rest/"
|
||||
"?method=flickr.photos.search"
|
||||
@ -49,11 +51,11 @@ void KittenLoader::FetchMoreKittens() {
|
||||
QNetworkRequest req = QNetworkRequest(QUrl(kFlickrKittenUrl));
|
||||
QNetworkReply* reply = network_->get(req);
|
||||
connect(reply, SIGNAL(finished()), SLOT(KittensRetrieved()));
|
||||
NewClosure(reply, SIGNAL(finished()), this,
|
||||
SLOT(KittensRetrieved(QNetworkReply*)), reply);
|
||||
}
|
||||
|
||||
void KittenLoader::KittensRetrieved() {
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
Q_ASSERT(reply);
|
||||
void KittenLoader::KittensRetrieved(QNetworkReply* reply) {
|
||||
reply->deleteLater();
|
||||
|
||||
QXmlStreamReader reader(reply);
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <QQueue>
|
||||
#include <QUrl>
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class KittenLoader : public AlbumCoverLoader {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -14,7 +16,7 @@ class KittenLoader : public AlbumCoverLoader {
|
||||
virtual quint64 LoadKitten(const AlbumCoverLoaderOptions& options);
|
||||
|
||||
private slots:
|
||||
void KittensRetrieved();
|
||||
void KittensRetrieved(QNetworkReply* reply);
|
||||
void FetchMoreKittens();
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user