From 3564b083e8f01ca4ffc9e5d8d4c9ca1a750960bb Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Sat, 13 Feb 2021 17:13:11 +0100 Subject: [PATCH] Attempt to fix threading mess in ImageProvider --- src/ippdiscovery.cpp | 34 ++++++++-------------------------- src/ippdiscovery.h | 1 - src/ippprinter.h | 2 +- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/ippdiscovery.cpp b/src/ippdiscovery.cpp index 7e0ba02..c51c51c 100644 --- a/src/ippdiscovery.cpp +++ b/src/ippdiscovery.cpp @@ -1,4 +1,5 @@ #include "ippdiscovery.h" +#include "ippprinter.h" #include #define A 1 @@ -264,26 +265,6 @@ void IppDiscovery::readPendingDatagrams() } -void IppDiscovery::ignoreKnownSslErrors(QNetworkReply *reply, const QList &errors) -{ - QList IgnoredSslErrors = {QSslError::NoError, - QSslError::SelfSignedCertificate, - QSslError::HostNameMismatch, - QSslError::UnableToGetLocalIssuerCertificate, - QSslError::UnableToVerifyFirstCertificate - }; - - qDebug() << errors; - for (QList::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) { //TODO: consider caching images (doesn't appear to be needed currently) Q_UNUSED(size); @@ -292,7 +273,7 @@ QImage IppDiscovery::requestImage(const QString &id, QSize *size, const QSize &r QImage img; - QNetworkAccessManager* nam = new QNetworkAccessManager(this); + QNetworkAccessManager* nam = new QNetworkAccessManager(); QUrl url(id); qDebug() << url.host() << _AAs; // TODO IPv6 @@ -304,13 +285,14 @@ QImage IppDiscovery::requestImage(const QString &id, QSize *size, const QSize &r QNetworkRequest request(url); request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION); + connect(nam, &QNetworkAccessManager::sslErrors, + &IppPrinter::ignoreKnownSslErrors); + QNetworkReply* reply = nam->get(request); - QEventLoop el; - connect(reply, SIGNAL(finished()),&el,SLOT(quit())); - connect(nam, SIGNAL(sslErrors(QNetworkReply*,QList)), - this, SLOT(ignoreKnownSslErrors(QNetworkReply*, const QList&))); - el.exec(); + QEventLoop loop; + connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); if (reply->error() == QNetworkReply::NoError) { diff --git a/src/ippdiscovery.h b/src/ippdiscovery.h index 470a2fd..f7df8cd 100644 --- a/src/ippdiscovery.h +++ b/src/ippdiscovery.h @@ -26,7 +26,6 @@ signals: public slots: void readPendingDatagrams(); void update(); - void ignoreKnownSslErrors(QNetworkReply *reply, const QList &errors); protected: private: diff --git a/src/ippprinter.h b/src/ippprinter.h index 5c07344..4e02a69 100644 --- a/src/ippprinter.h +++ b/src/ippprinter.h @@ -64,7 +64,7 @@ public slots: void getJobsRequestFinished(QNetworkReply* reply); void cancelJobFinished(QNetworkReply* reply); - void ignoreKnownSslErrors(QNetworkReply *reply, const QList &errors); + static void ignoreKnownSslErrors(QNetworkReply *reply, const QList &errors); void convertDone(QNetworkRequest request, QTemporaryFile* data); void convertFailed(QString message);