aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Configuration.hpp23
-rw-r--r--src/LuaRuntime.cpp6
-rw-r--r--src/WindowActionRouter.cpp16
-rw-r--r--src/widgets/BrowserWindow.cpp2
-rw-r--r--src/widgets/WebViewStack.cpp6
5 files changed, 30 insertions, 23 deletions
diff --git a/src/Configuration.hpp b/src/Configuration.hpp
index 06335dc..a1eca51 100644
--- a/src/Configuration.hpp
+++ b/src/Configuration.hpp
@@ -1,14 +1,33 @@
#pragma once
#include <QtCore>
+#include <unordered_map>
class Configuration : public QObject {
Q_OBJECT
+private:
+ std::unordered_map<QString, QVariant> config_map{
+ {"new_view_url", "https://duckduckgo.com"},
+ {"close_window_when_no_views", true},
+ };
+
public:
using QObject::QObject;
- QString new_view_url = "https://duckduckgo.com";
+ void set_config(const QString &name, const QVariant &value) {
+ qDebug() << "config update" << name << value;
+ config_map[name] = value;
+ emit config_updated(name, value);
+ }
+
+ QVariant get_config(const QString &name) const { return config_map.at(name); }
+
+ QString new_view_url() const { return get_config("new_view_url").toString(); }
+ bool close_window_when_no_views() const {
+ return get_config("close_window_when_no_views").toBool();
+ }
- bool close_window_when_no_views = true;
+signals:
+ void config_updated(const QString &name, const QVariant &value);
};
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp
index 5646d2b..127e014 100644
--- a/src/LuaRuntime.cpp
+++ b/src/LuaRuntime.cpp
@@ -156,12 +156,12 @@ QVariant LuaRuntime::get_lua_value(int idx, QVariant default_value) {
if (lua_isstring(state, idx))
return lua_tostring(state, idx);
- if (lua_isnumber(state, idx))
- return lua_tonumber(state, idx);
-
if (lua_isboolean(state, idx))
return lua_toboolean(state, idx);
+ if (lua_isnumber(state, idx))
+ return lua_tonumber(state, idx);
+
return lua_tostring(state, idx);
}
diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp
index 4bac3ad..bba15d1 100644
--- a/src/WindowActionRouter.cpp
+++ b/src/WindowActionRouter.cpp
@@ -10,11 +10,7 @@
#include "widgets/WebViewStack.hpp"
QVariant WindowActionRouter::fetch_config_value(const QString &key) {
- if (key == "new_view_url")
- return configuration->new_view_url;
- if (key == "close_window_when_no_views")
- return configuration->close_window_when_no_views;
- return "";
+ return configuration->get_config(key);
}
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
@@ -24,15 +20,7 @@ void WindowActionRouter::initialize(Configuration *config) {
connect(&runtime, &LuaRuntime::keymap_added, this, &WindowActionRouter::add_keymap);
- connect(&runtime, &LuaRuntime::config_updated, this,
- [this](const QString &key, const QVariant &value) {
- qDebug() << key << value;
- if (key == "new_view_url") {
- configuration->new_view_url = value.toString();
- } else if (key == "close_window_when_no_views") {
- configuration->close_window_when_no_views = value.toBool();
- }
- });
+ connect(&runtime, &LuaRuntime::config_updated, configuration, &Configuration::set_config);
connect(&runtime, &LuaRuntime::history_back_requested, this,
[this](WebViewId webview_id, qsizetype history_index) {
diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp
index 2c4c5b4..dbefdd6 100644
--- a/src/widgets/BrowserWindow.cpp
+++ b/src/widgets/BrowserWindow.cpp
@@ -27,7 +27,7 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringLi
// Open webviews for given urls
if (urls.isEmpty()) {
- webview_stack->open_url(configuration.new_view_url);
+ webview_stack->open_url(configuration.new_view_url());
} else {
for (const auto &url : urls) {
webview_stack->open_url(url, OpenType::OpenUrlInView);
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp
index f15ab64..bdec508 100644
--- a/src/widgets/WebViewStack.cpp
+++ b/src/widgets/WebViewStack.cpp
@@ -126,10 +126,10 @@ void WebViewStack::close(WebViewId webview_id) {
webview->deleteLater();
if (webview_list.isEmpty()) {
- if (configuration->close_window_when_no_views) {
+ if (configuration->close_window_when_no_views()) {
emit close_window_requested();
} else {
- create_new_webview(configuration->new_view_url, true);
+ create_new_webview(configuration->new_view_url(), true);
}
}
}
@@ -204,7 +204,7 @@ QUrl WebViewStack::current_url() {
auto *webview = current_webview();
if (webview == nullptr) {
qDebug() << "No current webview";
- return QUrl{configuration->new_view_url};
+ return QUrl{configuration->new_view_url()};
}
return webview->url();