aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt12
-rw-r--r--lib/navigation/CMakeLists.txt7
-rw-r--r--src/addressbar/completer.cpp74
-rw-r--r--src/addressbar/completer.h33
-rw-r--r--src/addressbar/urllineedit.cpp (renamed from lib/navigation/urllineedit.cpp)75
-rw-r--r--src/addressbar/urllineedit.h (renamed from lib/navigation/urllineedit.h)15
-rw-r--r--src/mainwindow/mainwindow.cpp6
-rw-r--r--src/webengine/webpage.cpp9
-rw-r--r--src/webengine/webpage.h3
-rw-r--r--src/webengine/webview.cpp8
-rw-r--r--src/webengine/webview.h1
11 files changed, 158 insertions, 85 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0147a9f..0d1491f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,7 +46,6 @@ endif (UseLibCpp)
add_subdirectory(lib/settings)
add_subdirectory(lib/bookmarks)
add_subdirectory(lib/downloads)
-add_subdirectory(lib/navigation)
add_subdirectory(plugins/ProfileEditor)
@@ -81,6 +80,12 @@ set(SourceCode
src/mainwindow/widgets/searchform.h
src/mainwindow/widgets/searchform.ui
+ # address bar
+ src/addressbar/completer.cpp
+ src/addressbar/completer.h
+ src/addressbar/urllineedit.cpp
+ src/addressbar/urllineedit.h
+
# todo: move all to src/mainwindow
"src/widgets/mainwindowmenubar.cpp"
"src/widgets/mainwindowmenubar.h"
@@ -109,8 +114,7 @@ set(SourceCode
"src/forms/cookiesform.ui"
# plugin interfaces
- plugins/interfaces.h
- )
+ plugins/interfaces.h)
add_executable(poi ${SourceCode})
@@ -120,6 +124,6 @@ target_include_directories(poi
target_link_libraries(poi Qt5::Core Qt5::Widgets Qt5::Concurrent Qt5::WebEngineWidgets)
target_link_libraries(poi configuration)
-target_link_libraries(poi bookmarks downloads navigation)
+target_link_libraries(poi bookmarks downloads)
install(TARGETS poi RUNTIME DESTINATION bin CONFIGURATIONS Release)
diff --git a/lib/navigation/CMakeLists.txt b/lib/navigation/CMakeLists.txt
deleted file mode 100644
index 4f0208b..0000000
--- a/lib/navigation/CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-cmake_minimum_required(VERSION 3.1.0)
-
-add_library(navigation
- urllineedit.cpp
- urllineedit.h)
-
-target_link_libraries(navigation Qt5::Widgets Qt5::WebEngineWidgets)
diff --git a/src/addressbar/completer.cpp b/src/addressbar/completer.cpp
new file mode 100644
index 0000000..4c95bce
--- /dev/null
+++ b/src/addressbar/completer.cpp
@@ -0,0 +1,74 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "completer.h"
+#include <QKeyEvent>
+
+Completer::Completer(QWidget *parent)
+ : QListView(parent)
+{
+ setWindowFlags(Qt::ToolTip);
+}
+
+bool Completer::updateItems(const QModelIndexList &list)
+{
+ if(list.isEmpty())
+ return false;
+
+ // list is not empty
+ QStringList l;
+ for(const QModelIndex &idx : list) {
+ l.append(idx.data(Qt::EditRole).toString());
+ }
+
+ auto *model = new QStringListModel(l, this);
+ setModel(model);
+
+ delete completionModel;
+ completionModel = model;
+
+ return true;
+}
+
+bool Completer::keyPressed(QKeyEvent *event)
+{
+ if(isHidden())
+ return false;
+
+ Q_CHECK_PTR(completionModel);
+
+ int count = completionModel->rowCount();
+ const QModelIndex currentIndex = this->currentIndex();
+
+ switch(event->key()) {
+ case Qt::Key_Down:
+ if(currentIndex.row() + 1 >= count) {
+ setCurrentIndex(completionModel->index(0, 0));
+ } else {
+ setCurrentIndex(completionModel->index(currentIndex.row() + 1, 0));
+ }
+ break;
+
+ case Qt::Key_Up:
+ if(currentIndex.row() == 0) {
+ setCurrentIndex(completionModel->index(count - 1, 0));
+ } else {
+ setCurrentIndex(completionModel->index(currentIndex.row() - 1, 0));
+ }
+ break;
+
+ case Qt::Key_Escape:
+ hide();
+ break;
+
+ default:
+ break;
+ }
+
+ return true;
+}
diff --git a/src/addressbar/completer.h b/src/addressbar/completer.h
new file mode 100644
index 0000000..adf5d8e
--- /dev/null
+++ b/src/addressbar/completer.h
@@ -0,0 +1,33 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_COMPLETER_H
+#define SMOLBOTE_COMPLETER_H
+
+#include <QListView>
+#include <QStringListModel>
+
+class Completer : public QListView
+{
+
+ Q_OBJECT
+
+public:
+ explicit Completer(QWidget *parent = nullptr);
+
+ bool updateItems(const QModelIndexList &list);
+
+ bool keyPressed(QKeyEvent *event);
+
+private:
+ QStringListModel *completionModel;
+
+};
+
+
+#endif //SMOLBOTE_COMPLETER_H
diff --git a/lib/navigation/urllineedit.cpp b/src/addressbar/urllineedit.cpp
index fdbfc63..d34fdcb 100644
--- a/lib/navigation/urllineedit.cpp
+++ b/src/addressbar/urllineedit.cpp
@@ -7,25 +7,16 @@
*/
#include "urllineedit.h"
-#include <QMenu>
-#include <QStyle>
+#include <QLabel>
#include <QTimer>
#include <QWidgetAction>
-// ssl menu
-#include <QLabel>
-
-// completer
-#include <QListView>
-#include <QStringListModel>
-
UrlLineEdit::UrlLineEdit(QWidget *parent)
: QLineEdit(parent)
- , m_listView(new QListView(this))
+ , m_listView(new Completer(this))
{
setPlaceholderText(tr("Enter address"));
- m_listView->setWindowFlags(Qt::ToolTip);
m_listView->setVisible(false);
connect(this, &UrlLineEdit::textEdited, this, &UrlLineEdit::updateCompleter);
@@ -69,18 +60,24 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
});
}
-QAction *UrlLineEdit::pageAction()
-{
- Q_CHECK_PTR(m_pageAction);
- return m_pageAction;
-}
-
void UrlLineEdit::setCompleterModel(QAbstractItemModel *model)
{
Q_CHECK_PTR(model);
m_bookmarksModel = model;
}
+void UrlLineEdit::connectWebView(WebView *view)
+{
+ Q_CHECK_PTR(view);
+
+ disconnect(urlChangedConnection);
+
+ setUrl(view->url());
+ m_pageAction->setMenu(view->pageMenu());
+
+ urlChangedConnection = connect(view, &WebView::urlChanged, this, &UrlLineEdit::setUrl);
+}
+
void UrlLineEdit::setUrl(const QUrl &url)
{
QString urlText = url.toString();
@@ -108,20 +105,12 @@ void UrlLineEdit::updateCompleter(const QString &text)
}
const QModelIndexList res = m_bookmarksModel->match(QModelIndex(), Qt::EditRole, text, 7);
- if(res.isEmpty()) {
+
+ if(!m_listView->updateItems(res)) {
m_listView->hide();
return;
}
- QStringList l;
- for(const QModelIndex &idx : res) {
- l.append(idx.data(Qt::EditRole).toString());
- }
-
- auto *m = new QStringListModel(l, this);
-
- m_listView->setModel(m);
-
// positioning
m_listView->setFixedWidth(width());
m_listView->move(mapToGlobal(QPoint(0, height())));
@@ -140,41 +129,25 @@ void UrlLineEdit::focusInEvent(QFocusEvent *event)
//QTimer::singleShot(0, this, SLOT(selectAll()));
}
+void UrlLineEdit::focusOutEvent(QFocusEvent *event)
+{
+ setUrl(QUrl::fromUserInput(text()));
+ QLineEdit::focusOutEvent(event);
+}
+
void UrlLineEdit::keyPressEvent(QKeyEvent *event)
{
- if(!m_listView->isHidden()) {
+ if(m_listView->keyPressed(event)) {
int key = event->key();
- int count = m_listView->model()->rowCount();
QModelIndex currentIndex = m_listView->currentIndex();
- switch(key) {
- case Qt::Key_Down:
- if(currentIndex.row() + 1 >= count) {
- m_listView->setCurrentIndex(m_listView->model()->index(0, 0));
- } else {
- m_listView->setCurrentIndex(m_listView->model()->index(currentIndex.row() + 1, 0));
- }
- break;
- case Qt::Key_Up:
- if(currentIndex.row() == 0) {
- m_listView->setCurrentIndex(m_listView->model()->index(count - 1, 0));
- } else {
- m_listView->setCurrentIndex(m_listView->model()->index(currentIndex.row() - 1, 0));
- }
- break;
+ if(key == Qt::Key::Key_Enter || key == Qt::Key_Return) {
- case Qt::Key_Enter:
- case Qt::Key_Return:
if(currentIndex.isValid()) {
setText(currentIndex.data().toString());
}
m_listView->hide();
return;
- case Qt::Key_Escape:
- m_listView->hide();
- break;
- default:
- break;
}
}
QLineEdit::keyPressEvent(event);
diff --git a/lib/navigation/urllineedit.h b/src/addressbar/urllineedit.h
index 2d2a267..4e62128 100644
--- a/lib/navigation/urllineedit.h
+++ b/src/addressbar/urllineedit.h
@@ -12,19 +12,18 @@
#include <QAction>
#include <QLineEdit>
#include <QTextLayout>
+#include <src/webengine/webview.h>
+#include "completer.h"
class QAbstractItemModel;
class QMenu;
class QLabel;
-class QListView;
class UrlLineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit UrlLineEdit(QWidget *parent = nullptr);
- QAction *pageAction();
-
void setCompleterModel(QAbstractItemModel *model);
signals:
@@ -32,14 +31,16 @@ signals:
void searchTermEntered(const QString &term);
public slots:
+ void connectWebView(WebView *view);
void setUrl(const QUrl &url);
void showSslError(const QString &message);
void updateCompleter(const QString &text);
protected:
- void focusInEvent(QFocusEvent *event);
- void keyPressEvent(QKeyEvent *event);
+ void focusInEvent(QFocusEvent *event) override;
+ void focusOutEvent(QFocusEvent *event) override;
+ void keyPressEvent(QKeyEvent *event) override;
private:
void setTextFormat(const QTextLayout::FormatRange &format);
@@ -56,7 +57,9 @@ private:
// completer
QAbstractItemModel *m_bookmarksModel = nullptr;
- QListView *m_listView;
+ Completer *m_listView;
+
+ QMetaObject::Connection urlChangedConnection;
};
#endif // URLLINEEDIT_H
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index a45c89e..d5efe5c 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -15,7 +15,7 @@
#include <QMessageBox>
#include <bookmarks/bookmarkswidget.h>
#include <downloads/downloadswidget.h>
-#include <navigation/urllineedit.h>
+#include <src/addressbar/urllineedit.h>
#include <settings/settingsdialog.h>
MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent)
@@ -270,9 +270,7 @@ void MainWindow::handleTabChanged(WebView *view)
// connect signals
m_navigationBar->connectWebView(view);
- connect(view, &WebView::urlChanged, m_addressBar, &UrlLineEdit::setUrl);
- m_addressBar->setUrl(view->url());
- m_addressBar->pageAction()->setMenu(view->pageMenu());
+ m_addressBar->connectWebView(view);
connect(view, &WebView::titleChanged, this, &MainWindow::handleTitleUpdated);
diff --git a/src/webengine/webpage.cpp b/src/webengine/webpage.cpp
index b2f8c43..7a2a5e7 100644
--- a/src/webengine/webpage.cpp
+++ b/src/webengine/webpage.cpp
@@ -8,6 +8,7 @@
#include "webpage.h"
+#include <QMessageBox>
#include <QWebEngineFullScreenRequest>
WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
@@ -25,6 +26,10 @@ WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
bool WebPage::certificateError(const QWebEngineCertificateError &certificateError)
{
- emit certificateErrorMessage(certificateError.errorDescription());
- return certificateError.isOverridable();
+ auto resp = QMessageBox::warning(nullptr,
+ tr("SSL error"),
+ tr("An SSL error has occurred:<br>%1").arg(certificateError.errorDescription()),
+ QMessageBox::Ignore, QMessageBox::Abort);
+
+ return resp == QMessageBox::Ignore;
}
diff --git a/src/webengine/webpage.h b/src/webengine/webpage.h
index 0c7c3b9..674f278 100644
--- a/src/webengine/webpage.h
+++ b/src/webengine/webpage.h
@@ -17,9 +17,6 @@ class WebPage : public QWebEnginePage
public:
explicit WebPage(QWebEngineProfile *profile, QObject *parent = nullptr);
-signals:
- void certificateErrorMessage(const QString &message);
-
protected:
bool certificateError(const QWebEngineCertificateError &certificateError);
};
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index fa03dd4..263fb67 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -30,7 +30,7 @@
#include <QStatusBar>
// ssl errors
-#include "lib/navigation/urllineedit.h"
+#include "src/addressbar/urllineedit.h"
WebView::WebView(MainWindow *parentMainWindow, QWidget *parent)
: QWebEngineView(parent)
@@ -144,7 +144,6 @@ void WebView::setPage(WebPage *page)
// make sure the page gets cleaned up if we replace it by taking ownership
page->setParent(this);
connect(page, &WebPage::linkHovered, this, &WebView::handleLinkHovered);
- connect(page, &WebPage::certificateErrorMessage, this, &WebView::handleCertificateError);
QWebEngineView::setPage(page);
}
@@ -192,8 +191,3 @@ 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 5242d0d..957d181 100644
--- a/src/webengine/webview.h
+++ b/src/webengine/webview.h
@@ -35,7 +35,6 @@ protected:
private slots:
void handleLinkHovered(const QString &url);
- void handleCertificateError(const QString &message);
private:
MainWindow *m_parent = nullptr;