From 4943cbea505aacdd33bf93c3365588ba73785d4d Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 13 Oct 2016 09:07:15 +0900 Subject: BaseJob: Use saved parameters instead of overriding apiPath(), query() and data() in each job class --- jobs/mediathumbnailjob.cpp | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) (limited to 'jobs/mediathumbnailjob.cpp') diff --git a/jobs/mediathumbnailjob.cpp b/jobs/mediathumbnailjob.cpp index 975a533d..dee06372 100644 --- a/jobs/mediathumbnailjob.cpp +++ b/jobs/mediathumbnailjob.cpp @@ -25,21 +25,21 @@ using namespace QMatrixClient; class MediaThumbnailJob::Private { public: - QUrl url; QPixmap thumbnail; - QSize requestedSize; - ThumbnailType thumbnailType; }; MediaThumbnailJob::MediaThumbnailJob(ConnectionData* data, QUrl url, QSize requestedSize, ThumbnailType thumbnailType) - : BaseJob(data, JobHttpType::GetJob, "MediaThumbnailJob") + : BaseJob(data, JobHttpType::GetJob, "MediaThumbnailJob", + QString("/_matrix/media/v1/thumbnail/%1%2").arg(url.host(), url.path()), + Query( + { { "width", QString::number(requestedSize.width()) } + , { "height", QString::number(requestedSize.height()) } + , { "method", + thumbnailType == ThumbnailType::Scale ? "scale" : "crop" } + })) , d(new Private) -{ - d->url = url; - d->requestedSize = requestedSize; - d->thumbnailType = thumbnailType; -} +{ } MediaThumbnailJob::~MediaThumbnailJob() { @@ -51,23 +51,6 @@ QPixmap MediaThumbnailJob::thumbnail() return d->thumbnail; } -QString MediaThumbnailJob::apiPath() const -{ - return QString("/_matrix/media/v1/thumbnail/%1%2").arg(d->url.host()).arg(d->url.path()); -} - -QUrlQuery MediaThumbnailJob::query() const -{ - QUrlQuery query; - query.addQueryItem("width", QString::number(d->requestedSize.width())); - query.addQueryItem("height", QString::number(d->requestedSize.height())); - if( d->thumbnailType == ThumbnailType::Scale ) - query.addQueryItem("method", "scale"); - else - query.addQueryItem("method", "crop"); - return query; -} - BaseJob::Status MediaThumbnailJob::parseReply(QByteArray data) { if( !d->thumbnail.loadFromData(data) ) -- cgit v1.2.3