aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-07-25 16:24:20 +0530
committerAkshay Nair <phenax5@gmail.com>2025-07-25 16:24:20 +0530
commit7e3b6182c4581fcb39ab1d0ef2eb07fe9fa1d8b6 (patch)
tree13808a26ad4e1f948d7fe0c042a2bdedb2658ee4 /src/widgets
parent43f3261635e1667367cfd31a2f746832e94c3957 (diff)
downloadnull-browser-7e3b6182c4581fcb39ab1d0ef2eb07fe9fa1d8b6.tar.gz
null-browser-7e3b6182c4581fcb39ab1d0ef2eb07fe9fa1d8b6.zip
Remove window mediator class
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/BrowserApp.cpp18
-rw-r--r--src/widgets/BrowserApp.hpp3
-rw-r--r--src/widgets/BrowserWindow.cpp28
-rw-r--r--src/widgets/BrowserWindow.hpp24
4 files changed, 58 insertions, 15 deletions
diff --git a/src/widgets/BrowserApp.cpp b/src/widgets/BrowserApp.cpp
index 54fd44a..9326d45 100644
--- a/src/widgets/BrowserApp.cpp
+++ b/src/widgets/BrowserApp.cpp
@@ -35,19 +35,23 @@ BrowserApp::BrowserApp(Configuration &configuration) : configuration(configurati
// Initializes profile
for (auto *profile : profiles) {
- profile->setDownloadPath(configuration.downloads_dir());
- profile->setHttpUserAgent(configuration.user_agent());
- profile->setNotificationPresenter([](std::unique_ptr<QWebEngineNotification> notification) {
- auto *event = new NotificationReceivedEvent(std::move(notification));
- WindowActionRouter::instance().dispatch_event(event);
- });
- profile->setPersistentPermissionsPolicy(configuration.permission_persistance_policy());
+ setup_profile(profile);
}
connect(&window_action_router, &WindowActionRouter::new_window_requested, this,
[this](const QUrl &url) { create_window({url.toString()}); });
};
+void BrowserApp::setup_profile(QWebEngineProfile *profile) {
+ profile->setDownloadPath(configuration.downloads_dir());
+ profile->setHttpUserAgent(configuration.user_agent());
+ profile->setNotificationPresenter([](std::unique_ptr<QWebEngineNotification> notification) {
+ auto *event = new NotificationReceivedEvent(std::move(notification));
+ WindowActionRouter::instance().dispatch_event(event);
+ });
+ profile->setPersistentPermissionsPolicy(configuration.permission_persistance_policy());
+}
+
BrowserWindow *BrowserApp::create_window(const QStringList &urls) {
auto *window = new BrowserWindow((const Configuration &)configuration, &default_profile, urls);
window->setWindowTitle("null-browser");
diff --git a/src/widgets/BrowserApp.hpp b/src/widgets/BrowserApp.hpp
index c659763..dcfe6f4 100644
--- a/src/widgets/BrowserApp.hpp
+++ b/src/widgets/BrowserApp.hpp
@@ -3,6 +3,7 @@
#include "Configuration.hpp"
#include "widgets/BrowserWindow.hpp"
#include <qlist.h>
+#include <qwebengineprofile.h>
class BrowserApp : public QObject {
Q_OBJECT
@@ -19,4 +20,6 @@ private:
Configuration &configuration;
QWebEngineProfile default_profile{"default"};
QList<QWebEngineProfile *> profiles{&default_profile};
+
+ void setup_profile(QWebEngineProfile *profile);
};
diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp
index 8e1555f..c565cb9 100644
--- a/src/widgets/BrowserWindow.cpp
+++ b/src/widgets/BrowserWindow.cpp
@@ -6,7 +6,6 @@
#include <QtCore>
#include "Configuration.hpp"
-#include "WindowMediator.hpp"
#include "keymap/KeymapEvaluator.hpp"
#include "widgets/BrowserWindow.hpp"
#include "widgets/WebViewStack.hpp"
@@ -23,7 +22,7 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, QWebEngineProfi
centralWidget()->setLayout(layout);
// Stack of web views
- auto *webview_stack = new WebViewStack(&configuration, profile);
+ webview_stack = new WebViewStack(&configuration, profile, this);
layout->addWidget(webview_stack);
// Open webviews for given urls
@@ -40,16 +39,19 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, QWebEngineProfi
keymap.define_mode("n", {.passthrough = false});
keymap.define_mode("i", {.passthrough = true});
- win_mediator = new WindowMediator(webview_stack);
-
// Update window title when webview changes
connect(webview_stack, &WebViewStack::current_webview_title_changed, this, [this](int index) {
- auto webviews = win_mediator->get_webview_list();
+ auto webviews = webview_stack->get_webview_list();
if (index >= 0 && index < webviews.count()) {
const auto &webview = webviews.at(index);
setWindowTitle(webview.title);
}
});
+
+ connect(webview_stack, &WebViewStack::new_window_requested, this,
+ &BrowserWindow::new_window_requested);
+ connect(webview_stack, &WebViewStack::close_window_requested, this,
+ &BrowserWindow::close_window_requested);
}
bool BrowserWindow::on_window_key_event(QKeyEvent *event) {
@@ -58,3 +60,19 @@ bool BrowserWindow::on_window_key_event(QKeyEvent *event) {
return should_skip;
}
+
+void BrowserWindow::update_user_agent(const QString &user_agent) {
+ auto *profile = webview_stack->get_profile();
+ profile->setHttpUserAgent(user_agent);
+}
+
+void BrowserWindow::update_downloads_dir(const QString &downloads_dir) {
+ auto *profile = webview_stack->get_profile();
+ profile->setDownloadPath(downloads_dir);
+}
+
+void BrowserWindow::update_permissions_persistance(const QString &persistance) {
+ auto *profile = webview_stack->get_profile();
+ auto persistance_policy = Configuration::to_permission_persistance_policy(persistance);
+ profile->setPersistentPermissionsPolicy(persistance_policy);
+}
diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp
index ee59e5a..6c49006 100644
--- a/src/widgets/BrowserWindow.hpp
+++ b/src/widgets/BrowserWindow.hpp
@@ -3,8 +3,8 @@
#include <QMainWindow>
#include "Configuration.hpp"
-#include "WindowMediator.hpp"
#include "utils.hpp"
+#include "widgets/WebViewStack.hpp"
using WindowId = qsizetype;
@@ -15,20 +15,38 @@ public:
BrowserWindow(const Configuration &configuration,
QWebEngineProfile *profile = new QWebEngineProfile, const QStringList &urls = {});
- DEFINE_GETTER(mediator, win_mediator)
DEFINE_GETTER(get_id, win_id)
DEFINE_SETTER(set_id, win_id)
+ DELEGATE(webview_stack, has_webview, has_webview)
+ DELEGATE(webview_stack, current_webview_id, current_webview_id)
+ DELEGATE(webview_stack, get_webview_list, get_webview_list)
+ DELEGATE(webview_stack, set_search_text, set_search_text)
+ DELEGATE(webview_stack, open_devtools, open_devtools)
+ DELEGATE(webview_stack, open_url, open_url)
+ DELEGATE(webview_stack, webview_history_back, history_back)
+ DELEGATE(webview_stack, webview_history_forward, history_forward)
+ DELEGATE(webview_stack, close, close_webview)
+ DELEGATE(webview_stack, focus_webview, select_webview)
+ DELEGATE(webview_stack, scroll, scroll)
+ DELEGATE(webview_stack, scroll_to_top, scroll_to_top)
+ DELEGATE(webview_stack, scroll_to_bottom, scroll_to_bottom)
bool on_window_key_event(QKeyEvent *event);
void closeEvent(QCloseEvent * /*event*/) override { emit closed(); };
+ void update_user_agent(const QString &user_agent);
+ void update_downloads_dir(const QString &downloads_dir);
+ void update_permissions_persistance(const QString &persistance);
+
signals:
void closed();
+ void new_window_requested(const QUrl &url);
+ void close_window_requested();
private:
- WindowMediator *win_mediator;
const Configuration &configuration;
+ WebViewStack *webview_stack;
WindowId win_id = -1;
};