diff options
-rw-r--r-- | BUGS.md | 7 | ||||
-rw-r--r-- | smolbote.qbs | 1 | ||||
-rw-r--r-- | src/mainwindow.cpp | 12 | ||||
-rw-r--r-- | src/mainwindow.h | 4 | ||||
-rw-r--r-- | src/webengine/webview.cpp | 40 | ||||
-rw-r--r-- | src/webengine/webview.h | 8 | ||||
-rw-r--r-- | src/widgets/mainwindowtabbar.cpp | 6 | ||||
-rw-r--r-- | src/widgets/mainwindowtabbar.h | 2 | ||||
l--------- | test/bookmarks.xbel | 1 | ||||
-rw-r--r-- | test/config/config.qrc | 5 | ||||
-rw-r--r-- | test/config/main.cpp | 28 | ||||
-rw-r--r-- | test/config/poi.cfg | 1 | ||||
-rw-r--r-- | test/filter.json | 15 | ||||
l--------- | test/poi.conf | 1 | ||||
-rw-r--r-- | test/test.qbs | 38 |
15 files changed, 63 insertions, 106 deletions
@@ -8,11 +8,14 @@ How to reproduce: enter an address into the address bar, load the page, crash on ### User config doesn't generate on first run if .config/smolbote doesn't exist -### Opening links in new tab doesn't work - ### Close tab shortcut doesn't work +### Search terms in address bar +QUrl always seems to return true when checking if valid url + ## To do list ### Search function +### Instance check on startup + diff --git a/smolbote.qbs b/smolbote.qbs index c3af913..05a42b0 100644 --- a/smolbote.qbs +++ b/smolbote.qbs @@ -22,7 +22,6 @@ Project { "src/lib/navigation/navigation.qbs", "lib/settings/settings.qbs", "lib/adblock/adblock.qbs", - "test/test.qbs", ] Probes.PkgConfigProbe { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0e2abd7..3546f83 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -169,15 +169,18 @@ void MainWindow::newTab(const QUrl &url) m_tabBarAdded = true; ui->mainToolBar->addWidget(tabBar); } - tabBar->addTab(createWebView(url, m_profile.get())); + tabBar->addTab(createWebView(url, m_profile.get(), this)); } -void MainWindow::newWindow(const QUrl &url) +MainWindow *MainWindow::newWindow(const QUrl &url) { Browser *instance = static_cast<Browser*>(qApp->instance()); MainWindow *window = instance->createWindow(); window->setProfile(m_profile); - window->newTab(url); + if(!url.isEmpty()) { + window->newTab(url); + } + return window; } void MainWindow::focusAddress() @@ -282,8 +285,7 @@ void MainWindow::handleTabChanged(WebView *view) m_addressBar->setUrl(view->url()); m_addressBar->pageAction()->setMenu(view->pageMenu()); - connect(view, SIGNAL(titleChanged(QString)), this, SLOT(handleTitleUpdated(QString))); - connect(view, SIGNAL(linkHovered(QString)), ui->statusBar, SLOT(showMessage(QString))); + connect(view, &WebView::titleChanged, this, &MainWindow::handleTitleUpdated); m_progressBar->connectWebView(view); diff --git a/src/mainwindow.h b/src/mainwindow.h index 3d6e417..31a3d2f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -34,6 +34,8 @@ class MainWindow : public QMainWindow { Q_OBJECT + friend class WebView; + public: MainWindow(std::shared_ptr<Configuration> config, QWidget *parent = nullptr); ~MainWindow() override; @@ -45,7 +47,7 @@ public slots: void showSettingsDialog(); void newTab(const QUrl &url = QUrl("")); - void newWindow(const QUrl &url = QUrl("")); + MainWindow *newWindow(const QUrl &url = QUrl("")); void setProfile(std::shared_ptr<WebEngineProfile> profile); WebEngineProfile *profile(); diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp index 5463610..ff2780c 100644 --- a/src/webengine/webview.cpp +++ b/src/webengine/webview.cpp @@ -28,9 +28,15 @@ #include <QPrinterInfo> #include <QPrintDialog> -WebView::WebView(QWidget *parent) : +#include "mainwindow.h" +#include <QStatusBar> + +WebView::WebView(MainWindow *parentMainWindow, QWidget *parent) : QWebEngineView(parent) { + Q_CHECK_PTR(parentMainWindow); + m_parent = parentMainWindow; + m_pageMenu = new QMenu(); m_pageMenu->setMinimumWidth(240); @@ -125,7 +131,37 @@ void WebView::setPage(QWebEnginePage *page) QWebEngineView::setPage(page); } +WebView *WebView::createWindow(QWebEnginePage::WebWindowType type) +{ + WebView *view = new WebView(m_parent); + switch (type) { + case QWebEnginePage::WebBrowserWindow: + // a complete web browser window + m_parent->newWindow()->tabBar->addTab(view); + break; + + case QWebEnginePage::WebBrowserTab: + // a web browser tab + m_parent->tabBar->setCurrentIndex(m_parent->tabBar->addTab(view)); + break; + + case QWebEnginePage::WebDialog: + // a window without decorations + m_parent->newWindow()->tabBar->addTab(view); + break; + + case QWebEnginePage::WebBrowserBackgroundTab: + // a web browser tab, but don't swap to it + m_parent->tabBar->addTab(view); + break; + } + + return view; +} + void WebView::handleLinkHovered(const QString &url) { - emit linkHovered(url); + if(isVisible()) { + m_parent->statusBar()->showMessage(url); + } } diff --git a/src/webengine/webview.h b/src/webengine/webview.h index 10654fa..d30a1fd 100644 --- a/src/webengine/webview.h +++ b/src/webengine/webview.h @@ -12,11 +12,12 @@ #include <QWebEngineView> #include <QMenu> +class MainWindow; class WebView : public QWebEngineView { Q_OBJECT public: - explicit WebView(QWidget *parent = nullptr); + explicit WebView(MainWindow *parentMainWindow, QWidget *parent = nullptr); ~WebView(); QMenu *pageMenu(); @@ -24,13 +25,16 @@ public: void setPage(QWebEnginePage *page); signals: - void linkHovered(const QString &url); void newBookmark(const QString &title, const QUrl &url); +protected: + WebView *createWindow(QWebEnginePage::WebWindowType type); + private slots: void handleLinkHovered(const QString &url); private: + MainWindow *m_parent = nullptr; QMenu *m_pageMenu = nullptr; }; diff --git a/src/widgets/mainwindowtabbar.cpp b/src/widgets/mainwindowtabbar.cpp index e7209c4..9991043 100644 --- a/src/widgets/mainwindowtabbar.cpp +++ b/src/widgets/mainwindowtabbar.cpp @@ -112,7 +112,7 @@ QSize MainWindowTabBar::tabSizeHint(int index) const void MainWindowTabBar::handleCurrentChanged(int index) { if(index < 0) { - addTab(createWebView(m_parent->profile()->homepage(), m_parent->profile())); + addTab(createWebView(m_parent->profile()->homepage(), m_parent->profile(), m_parent)); return; } @@ -141,9 +141,9 @@ void MainWindowTabBar::updateVectorArrangement(int from, int to) m_views.move(from, to); } -WebView *createWebView(const QUrl &url, WebEngineProfile *profile) +WebView *createWebView(const QUrl &url, WebEngineProfile *profile, MainWindow *parent) { - WebView *view = new WebView(nullptr); + WebView *view = new WebView(parent); QWebEnginePage *page = new QWebEnginePage(profile); view->setPage(page); page->load(url); diff --git a/src/widgets/mainwindowtabbar.h b/src/widgets/mainwindowtabbar.h index c8ccfb4..67f51e0 100644 --- a/src/widgets/mainwindowtabbar.h +++ b/src/widgets/mainwindowtabbar.h @@ -50,6 +50,6 @@ private: MainWindow *m_parent; }; -WebView *createWebView(const QUrl &url, WebEngineProfile *profile); +WebView *createWebView(const QUrl &url, WebEngineProfile *profile, MainWindow *parent); #endif // WEBVIEWTABBAR_H diff --git a/test/bookmarks.xbel b/test/bookmarks.xbel deleted file mode 120000 index 8644c64..0000000 --- a/test/bookmarks.xbel +++ /dev/null @@ -1 +0,0 @@ -../data/bookmarks.xbel
\ No newline at end of file diff --git a/test/config/config.qrc b/test/config/config.qrc deleted file mode 100644 index ab60a1b..0000000 --- a/test/config/config.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>poi.cfg</file> - </qresource> -</RCC> diff --git a/test/config/main.cpp b/test/config/main.cpp deleted file mode 100644 index 7be84d0..0000000 --- a/test/config/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include <iostream> -#include "settings/configuration.h" - -#include <QFile> - -int main(int argc, char** argv) -{ - Configuration *settings = new Configuration(); - - // Use QFile so we can easily access qrc: - QFile defaultCfg(":/poi.cfg"); - defaultCfg.open(QIODevice::ReadOnly); - - std::cout << "UserCfg: " << (settings->readUserConfiguration("file.cfg") ? "true" : "false") << std::endl; - std::cout << "DefaultCfg: " << (settings->readDefaultConfiguration(defaultCfg.readAll().toStdString()) ? "true" : "false") << std::endl; - - std::cout << "test = " << settings->value<std::string>("test").value_or("unknown") << std::endl; - - return 0; -} diff --git a/test/config/poi.cfg b/test/config/poi.cfg deleted file mode 100644 index 5fd6f29..0000000 --- a/test/config/poi.cfg +++ /dev/null @@ -1 +0,0 @@ -test = "value"; diff --git a/test/filter.json b/test/filter.json deleted file mode 100644 index d52efe7..0000000 --- a/test/filter.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "Poi Test Filter List", - "url": "https://neueland.iserlohn-fortress.net/filter.json", - "rules": { - "": { - "google-analytics.com": true, - "js-agent.newrelic.com": true, - "js": true - }, - "duckduckgo.com": { - "css": false, - "js": false - } - } -} diff --git a/test/poi.conf b/test/poi.conf deleted file mode 120000 index a713f73..0000000 --- a/test/poi.conf +++ /dev/null @@ -1 +0,0 @@ -../data/poi.toml
\ No newline at end of file diff --git a/test/test.qbs b/test/test.qbs deleted file mode 100644 index 3088a90..0000000 --- a/test/test.qbs +++ /dev/null @@ -1,38 +0,0 @@ -import qbs -import qbs.Probes - -Project { - name: "Tests" - - Probes.PkgConfigProbe { - id: libconfig - name: "libconfig++" - } - - // References aren't needed because test.qbs is the last reference in smolbote.qbs -// references: [ -// "../lib/settings/settings.qbs" -// ] - - CppApplication { - name: "configtest" - - cpp.includePaths: ['../lib'] - cpp.cxxLanguageVersion: "c++17" - cpp.cxxFlags: libconfig.cflags - cpp.linkerFlags: libconfig.libs - - Depends { - name: "Qt" - versionAtLeast: "5.9.0" - submodules: ["core"] - } - Depends { name: "settings" } - - files: [ - "config/config.qrc", - "config/main.cpp", - ] - - } -} |