aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-09-13 21:10:36 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-09-15 18:48:15 +0900
commitcb3848c1e7fe09c2e778d38139c399b9f0484ce5 (patch)
tree2112a43641cd0622884e79f626a1c8a056885286
parent5ad32f13b8a7a8552e2b6c56571bd8177b3fabb2 (diff)
downloadlibquotient-cb3848c1e7fe09c2e778d38139c399b9f0484ce5.tar.gz
libquotient-cb3848c1e7fe09c2e778d38139c399b9f0484ce5.zip
MediaThumbnailJob: get rid of useless pimpl; add scaledThumbnail()
Also use scaledThumbnail() in User::requestAvatar()
-rw-r--r--jobs/mediathumbnailjob.cpp17
-rw-r--r--jobs/mediathumbnailjob.h5
-rw-r--r--user.cpp5
3 files changed, 9 insertions, 18 deletions
diff --git a/jobs/mediathumbnailjob.cpp b/jobs/mediathumbnailjob.cpp
index 9bb731b9..9579f6b2 100644
--- a/jobs/mediathumbnailjob.cpp
+++ b/jobs/mediathumbnailjob.cpp
@@ -23,12 +23,6 @@
using namespace QMatrixClient;
-class MediaThumbnailJob::Private
-{
- public:
- QPixmap thumbnail;
-};
-
MediaThumbnailJob::MediaThumbnailJob(const ConnectionData* data, QUrl url, QSize requestedSize,
ThumbnailType thumbnailType)
: BaseJob(data, HttpVerb::Get, "MediaThumbnailJob",
@@ -39,22 +33,21 @@ MediaThumbnailJob::MediaThumbnailJob(const ConnectionData* data, QUrl url, QSize
, { "method",
thumbnailType == ThumbnailType::Scale ? "scale" : "crop" }
}))
- , d(new Private)
{ }
-MediaThumbnailJob::~MediaThumbnailJob()
+QPixmap MediaThumbnailJob::thumbnail()
{
- delete d;
+ return pixmap;
}
-QPixmap MediaThumbnailJob::thumbnail()
+QPixmap MediaThumbnailJob::scaledThumbnail(QSize toSize)
{
- return d->thumbnail;
+ return pixmap.scaled(toSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
BaseJob::Status MediaThumbnailJob::parseReply(QByteArray data)
{
- if( !d->thumbnail.loadFromData(data) )
+ if( !pixmap.loadFromData(data) )
{
qCDebug(JOBS) << "MediaThumbnailJob: could not read image data";
}
diff --git a/jobs/mediathumbnailjob.h b/jobs/mediathumbnailjob.h
index 307d0a99..186da829 100644
--- a/jobs/mediathumbnailjob.h
+++ b/jobs/mediathumbnailjob.h
@@ -31,15 +31,14 @@ namespace QMatrixClient
public:
MediaThumbnailJob(const ConnectionData* data, QUrl url, QSize requestedSize,
ThumbnailType thumbnailType=ThumbnailType::Scale);
- virtual ~MediaThumbnailJob();
QPixmap thumbnail();
+ QPixmap scaledThumbnail(QSize toSize);
protected:
Status parseReply(QByteArray data) override;
private:
- class Private;
- Private* d;
+ QPixmap pixmap;
};
}
diff --git a/user.cpp b/user.cpp
index 8d37eef6..f9f48539 100644
--- a/user.cpp
+++ b/user.cpp
@@ -170,12 +170,11 @@ void User::requestAvatar()
void User::Private::requestAvatar()
{
- MediaThumbnailJob* job = connection->getThumbnail(avatarUrl, requestedSize);
+ auto* job = connection->callApi<MediaThumbnailJob>(avatarUrl, requestedSize);
connect( job, &MediaThumbnailJob::success, [=]() {
avatarOngoingRequest = false;
avatarValid = true;
- avatar = job->thumbnail().scaled(requestedSize,
- Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ avatar = job->scaledThumbnail(requestedSize);
scaledAvatars.clear();
emit q->avatarChanged(q);
});