only show "ignore ssl errors"-option when necessary (i.e. there was an error or the user did specify this before)

This commit is contained in:
Hauke Schade 2014-11-16 17:13:42 +01:00
parent 664ee6cabd
commit 9366775b9f
4 changed files with 23 additions and 6 deletions

View file

@ -19,14 +19,17 @@
* http://www.gnu.org/licenses/.
*/
#include "mynetworkmanager.hh"
#include <QtNetwork/QNetworkDiskCache>
#include <QtNetwork/QSslConfiguration>
#include <QtCore/QDebug>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QStandardPaths>
#include <QtCore/QStandardPaths>
#else
#include <QDesktopServices>
#include <QtCore/QDesktopServices>
#endif
#include <QDebug>
#include "mynetworkmanager.hh"
#include "settings.hh"
QScopedPointer<MyNetworkManager> MyNetworkManager::m_instance(0);
@ -36,6 +39,7 @@ MyNetworkManager *MyNetworkManager::instance() {
m_instance.reset(new MyNetworkManager);
m_instance->_numRequests = 0;
m_instance->_gotSSLError = false;
return m_instance.data();
}
@ -86,6 +90,12 @@ void MyNetworkManager::onError() {
}
void MyNetworkManager::onSslErrors(QNetworkReply *reply, const QList<QSslError> &errors) {
bool alreadyGotSSLError = this->gotSSLError();
this->_gotSSLError = true;
if (alreadyGotSSLError != this->_gotSSLError) {
emit this->gotSSLErrorChanged();
}
if (Settings::instance()->ignoreSSLErrors()) {
qDebug("onSslErrors");
reply->ignoreSslErrors(errors);

View file

@ -43,6 +43,7 @@ class MyNetworkManager : public QObject, public QDeclarativeNetworkAccessManager
Q_OBJECT
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
Q_PROPERTY(bool gotSSLError READ gotSSLError NOTIFY gotSSLErrorChanged)
public: // QDeclarativeNetworkAccessManagerFactory
QNetworkAccessManager *create(QObject *parent);
@ -52,8 +53,13 @@ public: // QDeclarativeNetworkAccessManagerFactory
return this->_numRequests > 0;
}
bool gotSSLError() const {
return this->_gotSSLError;
}
signals:
void loadingChanged();
void gotSSLErrorChanged();
private slots:
void onSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
@ -64,6 +70,7 @@ private slots:
private:
static QScopedPointer<MyNetworkManager> m_instance;
int _numRequests;
bool _gotSSLError;
QMutex _mutex;
void incNumRequests() {

View file

@ -91,7 +91,7 @@ Page {
}
TextSwitch {
text: qsTr('Ignore SSL Errors')
visible: server.text.substring(0, 5) === "https"
visible: server.text.substring(0, 5) === "https" && (settings.ignoreSSLErrors || network.gotSSLError)
checked: settings.ignoreSSLErrors
onCheckedChanged: settings.ignoreSSLErrors = checked
enabled: !network.loading

View file

@ -112,7 +112,7 @@ Dialog {
TextSwitch {
id: ignoreSSLErrors
text: qsTr('Ignore SSL Errors')
visible: server.text.substring(0, 5) === "https"
visible: server.text.substring(0, 5) === "https" && (settings.ignoreSSLErrors || network.gotSSLError)
checked: false
}
Row {