aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp27
-rw-r--r--jobs/basejob.h10
-rw-r--r--jobs/mediathumbnailjob.cpp11
-rw-r--r--jobs/mediathumbnailjob.h6
4 files changed, 28 insertions, 26 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 2f5c381a..405cb9e0 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -52,6 +52,7 @@ class BaseJob::Private
{ }
void sendRequest();
+ const JobTimeoutConfig& getCurrentTimeoutConfig() const;
const ConnectionData* connection = nullptr;
@@ -68,8 +69,10 @@ class BaseJob::Private
QTimer timer;
QTimer retryTimer;
- size_t maxRetries = 3;
- size_t retriesTaken = 0;
+ QVector<JobTimeoutConfig> errorStrategy =
+ { { 90, 5 }, { 90, 10 }, { 120, 30 } };
+ int maxRetries = errorStrategy.size();
+ int retriesTaken = 0;
LoggingCategory logCat = JOBS;
};
@@ -187,7 +190,6 @@ void BaseJob::sendRequest()
if (!d->requestQuery.isEmpty())
qCDebug(d->logCat) << " query:" << d->requestQuery.toString();
d->sendRequest();
- connect( d->reply.data(), &QNetworkReply::sslErrors, this, &BaseJob::sslErrors );
connect( d->reply.data(), &QNetworkReply::finished, this, &BaseJob::gotReply );
if (d->reply->isRunning())
{
@@ -296,16 +298,19 @@ void BaseJob::finishJob()
deleteLater();
}
+const JobTimeoutConfig& BaseJob::Private::getCurrentTimeoutConfig() const
+{
+ return errorStrategy[std::min(retriesTaken, errorStrategy.size() - 1)];
+}
+
BaseJob::duration_t BaseJob::getCurrentTimeout() const
{
- static const std::array<int, 4> timeouts = { 90, 90, 120, 120 };
- return timeouts[std::min(d->retriesTaken, timeouts.size() - 1)] * 1000;
+ return d->getCurrentTimeoutConfig().jobTimeout * 1000;
}
BaseJob::duration_t BaseJob::getNextRetryInterval() const
{
- static const std::array<int, 3> intervals = { 5, 10, 30 };
- return intervals[std::min(d->retriesTaken, intervals.size() - 1)] * 1000;
+ return d->getCurrentTimeoutConfig().nextRetryInterval * 1000;
}
BaseJob::duration_t BaseJob::millisToRetry() const
@@ -364,14 +369,6 @@ void BaseJob::timeout()
finishJob();
}
-void BaseJob::sslErrors(const QList<QSslError>& errors)
-{
- foreach (const QSslError &error, errors) {
- qCWarning(d->logCat) << "SSL ERROR" << error.errorString();
- }
- d->reply->ignoreSslErrors(); // TODO: insecure! should prompt user first
-}
-
void BaseJob::setLoggingCategory(LoggingCategory lcf)
{
d->logCat = lcf;
diff --git a/jobs/basejob.h b/jobs/basejob.h
index 66812774..e3a379fa 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -36,6 +36,12 @@ namespace QMatrixClient
enum class HttpVerb { Get, Put, Post, Delete };
+ struct JobTimeoutConfig
+ {
+ int jobTimeout;
+ int nextRetryInterval;
+ };
+
class BaseJob: public QObject
{
Q_OBJECT
@@ -162,7 +168,7 @@ namespace QMatrixClient
* @param nextAttempt the 1-based number of attempt (will always be more than 1)
* @param inMilliseconds the interval after which the next attempt will be taken
*/
- void retryScheduled(size_t nextAttempt, int inMilliseconds);
+ void retryScheduled(int nextAttempt, int inMilliseconds);
/**
* Emitted when the job is finished, in any case. It is used to notify
@@ -179,7 +185,6 @@ namespace QMatrixClient
* to avoid dangling pointers in your list.
*
* @param job the job that emitted this signal
- * @internal
*
* @see success, failure
*/
@@ -262,7 +267,6 @@ namespace QMatrixClient
virtual ~BaseJob();
protected slots:
void timeout();
- void sslErrors(const QList<QSslError>& errors);
private slots:
void sendRequest();
diff --git a/jobs/mediathumbnailjob.cpp b/jobs/mediathumbnailjob.cpp
index 5945493a..c0d67a63 100644
--- a/jobs/mediathumbnailjob.cpp
+++ b/jobs/mediathumbnailjob.cpp
@@ -36,19 +36,20 @@ MediaThumbnailJob::MediaThumbnailJob(QUrl url, QSize requestedSize,
}))
{ }
-QPixmap MediaThumbnailJob::thumbnail() const
+QImage MediaThumbnailJob::thumbnail() const
{
- return pixmap;
+ return _thumbnail;
}
-QPixmap MediaThumbnailJob::scaledThumbnail(QSize toSize) const
+QImage MediaThumbnailJob::scaledThumbnail(QSize toSize) const
{
- return pixmap.scaled(toSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ return _thumbnail.scaled(toSize,
+ Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
BaseJob::Status MediaThumbnailJob::parseReply(QByteArray data)
{
- if( !pixmap.loadFromData(data) )
+ if( !_thumbnail.loadFromData(data) )
{
qCDebug(JOBS) << "MediaThumbnailJob: could not read image data";
}
diff --git a/jobs/mediathumbnailjob.h b/jobs/mediathumbnailjob.h
index 292e7f14..f8f36fe9 100644
--- a/jobs/mediathumbnailjob.h
+++ b/jobs/mediathumbnailjob.h
@@ -32,13 +32,13 @@ namespace QMatrixClient
MediaThumbnailJob(QUrl url, QSize requestedSize,
ThumbnailType thumbnailType = ThumbnailType::Scale);
- QPixmap thumbnail() const;
- QPixmap scaledThumbnail(QSize toSize) const;
+ QImage thumbnail() const;
+ QImage scaledThumbnail(QSize toSize) const;
protected:
Status parseReply(QByteArray data) override;
private:
- QPixmap pixmap;
+ QImage _thumbnail;
};
} // namespace QMatrixClient