aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp24
-rw-r--r--jobs/basejob.h8
-rw-r--r--jobs/mediathumbnailjob.cpp17
-rw-r--r--jobs/mediathumbnailjob.h5
-rw-r--r--jobs/passwordlogin.cpp2
5 files changed, 27 insertions, 29 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 26ceb268..3057ed75 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -24,6 +24,7 @@
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtCore/QTimer>
+#include <QtCore/QStringBuilder>
#include <array>
@@ -76,7 +77,7 @@ class BaseJob::Private
inline QDebug operator<<(QDebug dbg, const BaseJob* j)
{
- return dbg << "Job" << j->objectName();
+ return dbg << j->objectName();
}
BaseJob::BaseJob(const ConnectionData* connection, HttpVerb verb,
@@ -89,7 +90,6 @@ BaseJob::BaseJob(const ConnectionData* connection, HttpVerb verb,
connect (&d->timer, &QTimer::timeout, this, &BaseJob::timeout);
d->retryTimer.setSingleShot(true);
connect (&d->retryTimer, &QTimer::timeout, this, &BaseJob::start);
- qCDebug(d->logCat) << this << "created";
}
BaseJob::~BaseJob()
@@ -159,6 +159,8 @@ void BaseJob::start()
{
emit aboutToStart();
d->retryTimer.stop(); // In case we were counting down at the moment
+ qCDebug(d->logCat) << this << "sending request to"
+ << d->apiEndpoint % '?' % d->requestQuery.toString();
d->sendRequest();
connect( d->reply.data(), &QNetworkReply::sslErrors, this, &BaseJob::sslErrors );
connect( d->reply.data(), &QNetworkReply::finished, this, &BaseJob::gotReply );
@@ -219,16 +221,17 @@ BaseJob::Status BaseJob::parseJson(const QJsonDocument&)
void BaseJob::stop()
{
d->timer.stop();
- if (!d->reply)
+ if (d->reply)
{
- qCWarning(d->logCat) << this << "stopped with empty network reply";
- }
- else if (d->reply->isRunning())
- {
- qCWarning(d->logCat) << this << "stopped without ready network reply";
d->reply->disconnect(this); // Ignore whatever comes from the reply
- d->reply->abort();
+ if (d->reply->isRunning())
+ {
+ qCWarning(d->logCat) << this << "stopped without ready network reply";
+ d->reply->abort();
+ }
}
+ else
+ qCWarning(d->logCat) << this << "stopped with empty network reply";
}
void BaseJob::finishJob()
@@ -320,6 +323,9 @@ void BaseJob::setStatus(int code, QString message)
void BaseJob::abandon()
{
+ this->disconnect();
+ if (d->reply)
+ d->reply->disconnect(this);
deleteLater();
}
diff --git a/jobs/basejob.h b/jobs/basejob.h
index 0ec40a7a..b8cc9511 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -63,7 +63,7 @@ namespace QMatrixClient
public:
using QUrlQuery::QUrlQuery;
Query() = default;
- explicit Query(const std::initializer_list< QPair<QString, QString> >& l)
+ Query(const std::initializer_list< QPair<QString, QString> >& l)
{
setQueryItems(l);
}
@@ -77,12 +77,12 @@ namespace QMatrixClient
class Data : public QJsonObject
{
public:
+ using QJsonObject::QJsonObject;
Data() = default;
- Data(const QJsonObject& o) : QJsonObject(o) { }
- Data(QJsonObject&& o) : QJsonObject(std::move(o)) { }
+ explicit Data(const QJsonObject& o) : QJsonObject(o) { }
#if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0))
// This method exists in QJsonObject of newer Qt versions
- explicit Data(const std::initializer_list< QPair<QString, QString> >& l)
+ Data(const std::initializer_list< QPair<QString, QJsonValue> >& l)
{
for (auto i: l)
insert(i.first, i.second);
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/jobs/passwordlogin.cpp b/jobs/passwordlogin.cpp
index 081e19bc..09108215 100644
--- a/jobs/passwordlogin.cpp
+++ b/jobs/passwordlogin.cpp
@@ -33,7 +33,7 @@ PasswordLogin::PasswordLogin(const ConnectionData* connection, QString user, QSt
, "_matrix/client/r0/login"
, Query()
, Data(
- { { "type", "m.login.password" }
+ { { "type", QStringLiteral("m.login.password") }
, { "user", user }
, { "password", password }
})