Add icon for when printer passes SSL validation

This commit is contained in:
Anton Thomasson 2021-06-26 13:27:32 +02:00
parent ab81e701fa
commit b5ea29b372
4 changed files with 44 additions and 13 deletions

View file

@ -265,11 +265,22 @@ Page {
+ (Utils.existsAndNotEmpty("printer-location", printer) ? " • "+printer.attrs["printer-location"].value : "")
}
Label {
id: uri_label
color: canPrint || selectedFile == "" ? Theme.highlightColor : Theme.secondaryColor
font.pixelSize: Theme.fontSizeTiny
text: printer.url
Row {
Icon {
visible: printer.isIpps && !printer.tainted
color: canPrint || selectedFile == "" ? Theme.highlightColor : Theme.secondaryColor
height: Theme.fontSizeTiny
width: Theme.fontSizeTiny
anchors.verticalCenter: parent.verticalCenter
source: "image://theme/icon-m-browser-permissions"
}
Label {
id: uri_label
color: canPrint || selectedFile == "" ? Theme.highlightColor : Theme.secondaryColor
font.pixelSize: Theme.fontSizeTiny
text: printer.url
}
}
Row {

View file

@ -430,7 +430,7 @@ 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::onSslErrors);
connect(nam, &QNetworkAccessManager::sslErrors, &IppPrinter::ignoreSslErrors);
QNetworkReply* reply = nam->get(request);

View file

@ -13,16 +13,16 @@ IppPrinter::IppPrinter()
_job_cancel_nam = new QNetworkAccessManager(this);
connect(_nam, &QNetworkAccessManager::finished, this, &IppPrinter::getPrinterAttributesFinished);
connect(_nam, &QNetworkAccessManager::sslErrors, &IppPrinter::onSslErrors);
connect(_nam, &QNetworkAccessManager::sslErrors, this, &IppPrinter::onSslErrors);
connect(_print_nam, &QNetworkAccessManager::finished, this, &IppPrinter::printRequestFinished);
connect(_print_nam, &QNetworkAccessManager::sslErrors, &IppPrinter::onSslErrors);
connect(_print_nam, &QNetworkAccessManager::sslErrors, this, &IppPrinter::onSslErrors);
connect(_jobs_nam, &QNetworkAccessManager::finished,this, &IppPrinter::getJobsRequestFinished);
connect(_jobs_nam, &QNetworkAccessManager::sslErrors, &IppPrinter::onSslErrors);
connect(_jobs_nam, &QNetworkAccessManager::sslErrors, this, &IppPrinter::onSslErrors);
connect(_job_cancel_nam, &QNetworkAccessManager::finished,this, &IppPrinter::cancelJobFinished);
connect(_job_cancel_nam, &QNetworkAccessManager::sslErrors, &IppPrinter::onSslErrors);
connect(_job_cancel_nam, &QNetworkAccessManager::sslErrors, this, &IppPrinter::onSslErrors);
QObject::connect(this, &IppPrinter::urlChanged, this, &IppPrinter::onUrlChanged);
qRegisterMetaType<QTemporaryFile*>("QTemporaryFile*");
@ -41,6 +41,7 @@ IppPrinter::IppPrinter()
connect(_worker, &ConvertWorker::failed, this, &IppPrinter::convertFailed);
_workerThread.start();
_tainted = false;
}
IppPrinter::~IppPrinter() {
@ -262,8 +263,14 @@ void IppPrinter::cancelJobFinished(QNetworkReply *reply)
getJobs();
}
void IppPrinter::onSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
{
_tainted = true;
emit taintedChanged();
return ignoreSslErrors(reply, errors);
}
void IppPrinter::ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
{
bool ignore = Settings::instance()->ignoreSslErrors();
qDebug() << reply->request().url() << "SSL handshake failed" << errors << ignore;
@ -563,7 +570,6 @@ void IppPrinter::print(QJsonObject attrs, QString filename)
bool IppPrinter::getJobs() {
qDebug() << "getting jobs";
QJsonObject o = opAttrs();
o.insert("requested-attributes", QJsonObject {{"tag", IppMsg::Keyword}, {"value", "all"}});
@ -597,6 +603,11 @@ bool IppPrinter::cancelJob(qint32 jobId) {
return true;
}
bool IppPrinter::isIpps()
{
return _url.scheme() == "ipps";
}
QUrl IppPrinter::httpUrl() {
qDebug() << _url;
QUrl url = _url;

View file

@ -18,6 +18,9 @@ class IppPrinter : public QObject
Q_PROPERTY(QString busyMessage MEMBER _busyMessage NOTIFY busyMessageChanged)
Q_PROPERTY(QString progress MEMBER _progress NOTIFY progressChanged)
Q_PROPERTY(bool tainted MEMBER _tainted NOTIFY taintedChanged)
Q_PROPERTY(bool isIpps READ isIpps() NOTIFY urlChanged)
public:
IppPrinter();
~IppPrinter();
@ -31,6 +34,8 @@ public:
Q_INVOKABLE bool getJobs();
Q_INVOKABLE bool cancelJob(qint32 jobId);
bool isIpps();
signals:
void urlChanged();
void attrsChanged();
@ -61,6 +66,7 @@ signals:
void additionalDocumentFormatsChanged();
void busyMessageChanged();
void progressChanged();
void taintedChanged();
public slots:
void print(QJsonObject attrs, QString file);
@ -73,7 +79,8 @@ public slots:
void getJobsRequestFinished(QNetworkReply* reply);
void cancelJobFinished(QNetworkReply* reply);
static void onSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
void onSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
static void ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
void convertDone(QNetworkRequest request, QTemporaryFile* data);
void convertFailed(QString message);
@ -108,6 +115,8 @@ private:
QThread _workerThread;
ConvertWorker* _worker;
bool _tainted;
};
#endif // IPPPRINTER_H