From 00e214b683da61b753f141ed87a0cbefdf0ba19d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 14 Nov 2018 15:09:37 +0100 Subject: Handle unsupported protocols --- src/slxbrowser.cpp | 21 +++++++++++++++++---- src/slxbrowser.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/slxbrowser.cpp b/src/slxbrowser.cpp index a8fc1d8..02a3d50 100644 --- a/src/slxbrowser.cpp +++ b/src/slxbrowser.cpp @@ -7,9 +7,10 @@ #include SLXbrowser::SLXbrowser(QString url, bool fullscreen, bool ignoreSslErrors, int reloadIntervalSeconds) - : QMainWindow(NULL), + : QMainWindow(nullptr), _url(url), _ignoreSslErrors(ignoreSslErrors), + _unsupportedUri(false), _reloadIntervalMs(reloadIntervalSeconds * 1000) { if (fullscreen) { @@ -68,7 +69,7 @@ void SLXbrowser::loadStarted() void SLXbrowser::loadFinished(bool ok) { _progress->hide(); - if (!_browser->wasAbortedDownload() && !ok) { + if (!_browser->wasAbortedDownload() && !_unsupportedUri && !ok) { _browser->page()->mainFrame()->setHtml("

Page Load Error

");
 		QWebElement el = _browser->page()->mainFrame()->documentElement().findFirst("#content");
 		QString str;
@@ -90,8 +91,15 @@ void SLXbrowser::loadFinished(bool ok)
 		_normalError.clear();
 		_reset.start(30000);
 	} else if (_reloadIntervalMs > 0) {
-		_reset.start(_reloadIntervalMs);
+        _reset.start(_reloadIntervalMs);
 	}
+    if (_unsupportedUri && !ok) {
+        QMessageBox::warning(this->parentWidget(), QString::fromUtf8("Denied"),
+                QString::fromUtf8("This URL type is not supported.\n\n"
+                        "Diese Art Link wird nicht unterstützt.\n\n"
+                        "(z.B. Mail)"));
+    }
+    _unsupportedUri = false;
 }
 
 void SLXbrowser::loadProgress(int progress)
@@ -110,7 +118,12 @@ void SLXbrowser::sslErrors(QNetworkReply* reply, const QList& errors)
 
 void SLXbrowser::requestFinished(QNetworkReply *reply)
 {
-	if (reply->error() != QNetworkReply::NoError) {
+    if (reply->error() == QNetworkReply::NoError) {
+        _unsupportedUri = false;
+    } else if (reply->error() == QNetworkReply::ProtocolUnknownError) {
+        _unsupportedUri = true;
+    } else {
+        qDebug() << reply->error();
 		_normalError = reply->errorString();
 	}
 }
diff --git a/src/slxbrowser.h b/src/slxbrowser.h
index acbb7d8..c036821 100644
--- a/src/slxbrowser.h
+++ b/src/slxbrowser.h
@@ -29,6 +29,7 @@ private slots:
 private:
 	QString _url;
 	bool _ignoreSslErrors;
+    bool _unsupportedUri;
 	WebView *_browser;
 	QProgressBar *_progress;
 	QTimer _reset;
-- 
cgit v1.2.3-55-g7522