Attempt to fix threading mess in ImageProvider

This commit is contained in:
Anton Thomasson 2021-02-13 17:13:11 +01:00
parent 588e3b00c5
commit 3564b083e8
3 changed files with 9 additions and 28 deletions

View file

@ -1,4 +1,5 @@
#include "ippdiscovery.h" #include "ippdiscovery.h"
#include "ippprinter.h"
#include <seaprint_version.h> #include <seaprint_version.h>
#define A 1 #define A 1
@ -264,26 +265,6 @@ void IppDiscovery::readPendingDatagrams()
} }
void IppDiscovery::ignoreKnownSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
{
QList<QSslError> IgnoredSslErrors = {QSslError::NoError,
QSslError::SelfSignedCertificate,
QSslError::HostNameMismatch,
QSslError::UnableToGetLocalIssuerCertificate,
QSslError::UnableToVerifyFirstCertificate
};
qDebug() << errors;
for (QList<QSslError>::const_iterator it = errors.constBegin(); it != errors.constEnd(); it++) {
if(!IgnoredSslErrors.contains(it->error())) {
qDebug() << "Bad error: " << int(it->error()) << it->error();
return;
}
}
// For whatever reason, it doesn't work to pass IgnoredSslErrors here
reply->ignoreSslErrors(errors);
}
QImage IppDiscovery::requestImage(const QString &id, QSize *size, const QSize &requestedSize) QImage IppDiscovery::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{ //TODO: consider caching images (doesn't appear to be needed currently) { //TODO: consider caching images (doesn't appear to be needed currently)
Q_UNUSED(size); Q_UNUSED(size);
@ -292,7 +273,7 @@ QImage IppDiscovery::requestImage(const QString &id, QSize *size, const QSize &r
QImage img; QImage img;
QNetworkAccessManager* nam = new QNetworkAccessManager(this); QNetworkAccessManager* nam = new QNetworkAccessManager();
QUrl url(id); QUrl url(id);
qDebug() << url.host() << _AAs; qDebug() << url.host() << _AAs;
// TODO IPv6 // TODO IPv6
@ -304,13 +285,14 @@ QImage IppDiscovery::requestImage(const QString &id, QSize *size, const QSize &r
QNetworkRequest request(url); QNetworkRequest request(url);
request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION); request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION);
connect(nam, &QNetworkAccessManager::sslErrors,
&IppPrinter::ignoreKnownSslErrors);
QNetworkReply* reply = nam->get(request); QNetworkReply* reply = nam->get(request);
QEventLoop el; QEventLoop loop;
connect(reply, SIGNAL(finished()),&el,SLOT(quit())); connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
connect(nam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), loop.exec();
this, SLOT(ignoreKnownSslErrors(QNetworkReply*, const QList<QSslError>&)));
el.exec();
if (reply->error() == QNetworkReply::NoError) if (reply->error() == QNetworkReply::NoError)
{ {

View file

@ -26,7 +26,6 @@ signals:
public slots: public slots:
void readPendingDatagrams(); void readPendingDatagrams();
void update(); void update();
void ignoreKnownSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
protected: protected:
private: private:

View file

@ -64,7 +64,7 @@ public slots:
void getJobsRequestFinished(QNetworkReply* reply); void getJobsRequestFinished(QNetworkReply* reply);
void cancelJobFinished(QNetworkReply* reply); void cancelJobFinished(QNetworkReply* reply);
void ignoreKnownSslErrors(QNetworkReply *reply, const QList<QSslError> &errors); static void ignoreKnownSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
void convertDone(QNetworkRequest request, QTemporaryFile* data); void convertDone(QNetworkRequest request, QTemporaryFile* data);
void convertFailed(QString message); void convertFailed(QString message);