aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-12-20 14:57:07 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-12-20 14:57:07 +0100
commitf66090da906348aea769173c2d2333015a898c84 (patch)
tree9a22d7ea632f4b16b604aed4565dbeb28bc4727e /src
parentCan now open links in new tab (diff)
downloadsmolbote-f66090da906348aea769173c2d2333015a898c84.tar.xz
Added SSL cert warnings
Diffstat (limited to 'src')
-rw-r--r--src/lib/navigation/urllineedit.cpp24
-rw-r--r--src/lib/navigation/urllineedit.h6
-rw-r--r--src/webengine/webpage.cpp12
-rw-r--r--src/webengine/webpage.h19
-rw-r--r--src/webengine/webview.cpp16
-rw-r--r--src/webengine/webview.h4
-rw-r--r--src/widgets/mainwindowtabbar.cpp4
7 files changed, 77 insertions, 8 deletions
diff --git a/src/lib/navigation/urllineedit.cpp b/src/lib/navigation/urllineedit.cpp
index cf33939..5d20cef 100644
--- a/src/lib/navigation/urllineedit.cpp
+++ b/src/lib/navigation/urllineedit.cpp
@@ -15,14 +15,28 @@
#include <QWidgetAction>
+// ssl menu
+#include <QLabel>
+
UrlLineEdit::UrlLineEdit(QWidget *parent) :
QLineEdit(parent)
{
setPlaceholderText(tr("Enter address"));
- // test action
- m_sslAction = addAction(style()->standardIcon(QStyle::SP_ComputerIcon), QLineEdit::LeadingPosition);
+ // ssl menu
+ m_sslMenu = new QMenu(this);
+ m_sslLabel = new QLabel(m_sslMenu);
+ QWidgetAction *sslErrorAction = new QWidgetAction(m_sslMenu);
+ sslErrorAction->setDefaultWidget(m_sslLabel);
+ m_sslMenu->addAction(sslErrorAction);
+
+ m_sslAction = addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition);
m_sslAction->setToolTip(tr("TODO: Display SSL Status popup here"));
+ m_sslAction->setMenu(m_sslMenu);
+
+ connect(m_sslAction, &QAction::triggered, this, [this]() {
+ m_sslMenu->exec(this->mapToGlobal(QPoint(0, height())));
+ });
QAction *completerAction = addAction(style()->standardIcon(QStyle::SP_TitleBarMinButton), QLineEdit::TrailingPosition);
@@ -105,6 +119,12 @@ void UrlLineEdit::setUrl(const QUrl &url)
setText(urlText);
}
+void UrlLineEdit::showSslError(const QString &message)
+{
+ m_sslLabel->setText(message);
+ m_sslAction->trigger();
+}
+
void UrlLineEdit::focusInEvent(QFocusEvent *event)
{
clearTextFormat();
diff --git a/src/lib/navigation/urllineedit.h b/src/lib/navigation/urllineedit.h
index 19be2d2..cef0830 100644
--- a/src/lib/navigation/urllineedit.h
+++ b/src/lib/navigation/urllineedit.h
@@ -15,6 +15,7 @@
#include <QAction>
class QMenu;
+class QLabel;
class UrlLineEdit : public QLineEdit
{
Q_OBJECT
@@ -30,6 +31,7 @@ signals:
public slots:
void setUrl(const QUrl &url);
+ void showSslError(const QString &message);
protected:
void focusInEvent(QFocusEvent *event);
@@ -48,6 +50,10 @@ private:
QAction *m_sslAction = nullptr;
QAction *m_pageAction = nullptr;
+ // ssl menu
+ QMenu *m_sslMenu;
+ QLabel *m_sslLabel;
+
QMenu *m_menu;
QListWidget *listWidget;
};
diff --git a/src/webengine/webpage.cpp b/src/webengine/webpage.cpp
new file mode 100644
index 0000000..79ba809
--- /dev/null
+++ b/src/webengine/webpage.cpp
@@ -0,0 +1,12 @@
+#include "webpage.h"
+
+WebPage::WebPage(QWebEngineProfile *profile, QObject *parent) :
+ QWebEnginePage(profile, parent)
+{
+}
+
+bool WebPage::certificateError(const QWebEngineCertificateError &certificateError)
+{
+ emit certificateErrorMessage(certificateError.errorDescription());
+ return certificateError.isOverridable();
+}
diff --git a/src/webengine/webpage.h b/src/webengine/webpage.h
new file mode 100644
index 0000000..6ae0802
--- /dev/null
+++ b/src/webengine/webpage.h
@@ -0,0 +1,19 @@
+#ifndef WEBPAGE_H
+#define WEBPAGE_H
+
+#include <QWebEnginePage>
+
+class WebPage : public QWebEnginePage
+{
+ Q_OBJECT
+public:
+ explicit WebPage(QWebEngineProfile *profile, QObject *parent = nullptr);
+
+signals:
+ void certificateErrorMessage(const QString &message);
+
+protected:
+ bool certificateError(const QWebEngineCertificateError &certificateError);
+};
+
+#endif // WEBPAGE_H
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index ff2780c..4f7b386 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -31,6 +31,9 @@
#include "mainwindow.h"
#include <QStatusBar>
+// ssl errors
+#include "lib/navigation/urllineedit.h"
+
WebView::WebView(MainWindow *parentMainWindow, QWidget *parent) :
QWebEngineView(parent)
{
@@ -124,10 +127,12 @@ QMenu *WebView::pageMenu()
return m_pageMenu;
}
-void WebView::setPage(QWebEnginePage *page)
+void WebView::setPage(WebPage *page)
{
- disconnect(this->page(), SIGNAL(linkHovered(QString)), this, SLOT(handleLinkHovered(QString)));
- connect(page, SIGNAL(linkHovered(QString)), this, SLOT(handleLinkHovered(QString)));
+ Q_CHECK_PTR(page);
+ //this->page()->deleteLater();
+ connect(page, &WebPage::linkHovered, this, &WebView::handleLinkHovered);
+ connect(page, &WebPage::certificateErrorMessage, this, &WebView::handleCertificateError);
QWebEngineView::setPage(page);
}
@@ -165,3 +170,8 @@ void WebView::handleLinkHovered(const QString &url)
m_parent->statusBar()->showMessage(url);
}
}
+
+void WebView::handleCertificateError(const QString &message)
+{
+ m_parent->m_addressBar->showSslError(message);
+}
diff --git a/src/webengine/webview.h b/src/webengine/webview.h
index d30a1fd..ed191e5 100644
--- a/src/webengine/webview.h
+++ b/src/webengine/webview.h
@@ -11,6 +11,7 @@
#include <QWebEngineView>
#include <QMenu>
+#include "webengine/webpage.h"
class MainWindow;
class WebView : public QWebEngineView
@@ -22,7 +23,7 @@ public:
QMenu *pageMenu();
- void setPage(QWebEnginePage *page);
+ void setPage(WebPage *page);
signals:
void newBookmark(const QString &title, const QUrl &url);
@@ -32,6 +33,7 @@ protected:
private slots:
void handleLinkHovered(const QString &url);
+ void handleCertificateError(const QString &message);
private:
MainWindow *m_parent = nullptr;
diff --git a/src/widgets/mainwindowtabbar.cpp b/src/widgets/mainwindowtabbar.cpp
index 9991043..7256f09 100644
--- a/src/widgets/mainwindowtabbar.cpp
+++ b/src/widgets/mainwindowtabbar.cpp
@@ -77,7 +77,7 @@ void MainWindowTabBar::setProfile(WebEngineProfile *profile)
Q_CHECK_PTR(profile);
for(auto view : qAsConst(m_views)) {
- QWebEnginePage *page = new QWebEnginePage(profile);
+ WebPage *page = new WebPage(profile);
page->load(view->url());
view->setPage(page);
}
@@ -144,7 +144,7 @@ void MainWindowTabBar::updateVectorArrangement(int from, int to)
WebView *createWebView(const QUrl &url, WebEngineProfile *profile, MainWindow *parent)
{
WebView *view = new WebView(parent);
- QWebEnginePage *page = new QWebEnginePage(profile);
+ WebPage *page = new WebPage(profile);
view->setPage(page);
page->load(url);