aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2024-05-01 11:17:07 +0300
committeraqua <aqua@iserlohn-fortress.net>2024-05-01 11:17:07 +0300
commit7feefe9d5c922481081d31b12e02f42d9e028ef9 (patch)
tree6aee14710adeef4bcc0a86dd800df927f86342fd
parentAdded libConfiguration unit test (diff)
downloadsmolbote-master.tar.xz
Drop python-kcofiglib build time dependencyHEADmaster
-rw-r--r--Kconfig226
-rw-r--r--lib/configuration/CMakeLists.txt14
-rw-r--r--lib/configuration/configuration.h18
-rwxr-xr-xlib/configuration/gen-default-cfg.py43
-rw-r--r--lib/configuration/init_global.cpp.in25
-rw-r--r--lib/configuration/qt_specialization.cpp16
-rw-r--r--lib/configuration/qt_specialization.h8
-rw-r--r--linux/config.yaml63
-rw-r--r--linux/makepkg/PKGBUILD7
-rwxr-xr-xscripts/gen-default-cfg.py51
-rw-r--r--src/CMakeLists.txt12
-rw-r--r--src/applicationmenu.cpp12
-rw-r--r--src/bookmarks/bookmarkstoolbar.cpp6
-rw-r--r--src/browser.cpp26
-rw-r--r--src/main.cpp5
-rw-r--r--src/mainwindow/addressbar.cpp4
-rw-r--r--src/mainwindow/mainwindow.cpp8
-rw-r--r--src/mainwindow/menubar.cpp24
-rw-r--r--src/mainwindow/widgets/navigationbar.cpp14
-rw-r--r--src/settings.h.in32
20 files changed, 219 insertions, 395 deletions
diff --git a/Kconfig b/Kconfig
deleted file mode 100644
index 37d3d9c..0000000
--- a/Kconfig
+++ /dev/null
@@ -1,226 +0,0 @@
-menu "Application"
- config POI_NAME
- string "Application name"
- default "smolbote"
- config POI_ICON
- string "Path to icon"
- default ":/icons/poi.svg"
- config POI_CFG_PATH
- string "Configuration location"
- default "~/.config/smolbote/smolbote.cfg"
-endmenu
-
-menu "Keyboard shortcuts"
- comment "Main Window shortcuts"
- config shortcuts.session.save
- string "Save Session shortcut"
- default "Ctrl+S,S"
- config shortcuts.session.open
- string "Load Session shortcut"
- default "Ctrl+S,O"
- config shortcuts.window.newgroup
- string "New Group shortcut"
- default "Ctrl+G"
- config shortcuts.window.newwindow
- string "New Window shortcut"
- default "Ctrl+N"
- config shortcuts.window.about
- string "Show About Dialog"
- default "F1"
- config shortcuts.window.quit
- string "Quit shortcut"
- default "Ctrl+Q"
- config shortcuts.window.search
- string "Show or hide search box"
- default "F3"
- config shortcuts.window.downloads.show
- string "Show downloads dialog in this window"
- default "Ctrl+D"
-
- comment "Navigation Bar shortcuts"
- config navigationbar.show
- string "Toggle navigation bar"
- default "Ctrl+Shift+N"
- config shortcuts.navigation.back
- string "Go back in history"
- default "Ctrl+Left"
- config shortcuts.navigation.backmenu
- string "Show Back history menu"
- default "Ctrl+Down"
- config shortcuts.navigation.forward
- string "Go forward in history"
- default "Ctrl+Right"
- config shortcuts.navigation.forwardmenu
- string "Show Forward history menu"
- default "Ctrl+Up"
- config shortcuts.navigation.refresh
- string "Refresh the page"
- default "F5"
- config shortcuts.navigation.reload
- string "Reload the page"
- default "Ctrl+F5"
- config shortcuts.navigation.home
- string "Load homepage"
- default "Ctrl+Home"
-
- comment "Address Bar shortcuts"
- config shortcuts.address.focus
- string "Focus the Address Bar"
- default "F4"
- config shortcuts.address.menu
- string "Show Address Bar menu"
- default "F2"
-
- comment "Subwindow shortcuts"
- config shortcuts.subwindow.close
- string "Close Subwindow shortcut"
- default "Ctrl+Shift+W"
- config shortcuts.subwindow.fullscreen
- string "Make current subwindow fullscreen"
- default "F11"
- config shortcuts.subwindow.newtab
- string "Create new tab"
- default "Ctrl+T"
- config shortcuts.subwindow.closetab
- string "Close current tab"
- default "Ctrl+W"
- config shortcuts.subwindow.restoretab
- string "Restore last closed tab"
- default "Ctrl+Shift+T"
- config shortcuts.subwindow.tableft
- string "Switch to the tab on the left"
- default "Ctrl+O"
- config shortcuts.subwindow.movetableft
- string "Move tab to the left"
- default "Ctrl+Shift+O"
- config shortcuts.subwindow.tabright
- string "Switch to the tab on the right"
- default "Ctrl+P"
- config shortcuts.subwindow.movetabright
- string "Move tab to the right"
- default "Ctrl+Shift+P"
-
-endmenu
-
-menu "Main Window"
- config mainwindow.title
- string "Main window title"
- default "smolbote"
- config mainwindow.width
- int "Main window width"
- default 1280
- config mainwindow.height
- int "Main window height"
- default 720
-endmenu
-
-menu "Bookmarks"
- config bookmarks.path
- string "Bookmarks location"
- default "~/.config/smolbote/bookmarks.xbel"
- config shortcuts.window.bookmarks.show
- string "Show bookmarks dialog in this window"
- default "Ctrl+B"
- config bookmarks.toolbar.show
- string "Toggle bookmarks toolbar visibility"
- default "Ctrl+Shift+B"
- config bookmarks.toolbar.movable
- bool "Default bookmarks toolbar movable"
- default n
- config bookmarks.toolbar.visible
- bool "Default bookmarks toolbar visibility"
- default n
-endmenu
-
-menu "Profile Settings"
- config profile.path
- string "Profile load location"
- default "~/.config/smolbote/profiles.d"
- config profile.default
- string "Default profile"
- default ""
- config profile.search
- string "Search engine"
- default "https://duckduckgo.com/?q=%1&ia=web"
- config profile.homepage
- string "Homepage"
- default "about:blank"
- config profile.newtab
- string "New tab page"
- default "about:blank"
-endmenu
-
-config USEPLUGINS
- bool "Enable plugins"
- default y
-
-menu "Plugin Settings"
- depends on USEPLUGINS
- config PLUGINS_PATH
- string "Plugin load location"
- default "~/.config/smolbote/plugins.d"
- choice PLUGINS_SIGNATURE_CHECK
- bool "Plugin Signature enforcement"
- default PLUGINS_SIGNATURE_CHECKED
- config PLUGINS_SIGNATURE_IGNORED
- bool "Don't check plugin signatures"
- config PLUGINS_SIGNATURE_CHECKED
- bool "Don't load plugins with invalid signatures"
- config PLUGINS_SIGNATURE_ENFORCED
- bool "Only load plugins with valid signatures"
- endchoice
- config PLUGINS_SIGNATURE_HASH
- string "Hashing algorithm used by the signature"
- default "SHA256"
-endmenu
-
-comment "Default paths"
-config filter.path
- string "Host filter path"
- default "~/.config/smolbote/hosts.d"
-config downloads.path
- string "Downloads location"
- default "~/Downloads"
-config session.path
- string "Session location"
- default "~/.config/smolbote/session.d"
-
-config USEPLASMA
- bool "Enable KDE Frameworks integration"
- default n
-
-menu "KDE Integration"
- depends on USEPLASMA
-
- config PLASMA_BLUR
- bool "Enable translucent background and blur behind window"
- default n
-
- config WALLET_FOLDER
- string "KDE Wallet folder name"
- default "smolbote"
-endmenu
-
-config USEBREAKPAD
- bool "Enable Breakpad integration"
- default n
-
-menu "Breakpad Integration"
- depends on USEBREAKPAD
-
- config PATH_CRASHDUMP
- string "Crash dump location"
- default "~/.config/smolbote/crash.d"
-
- config PATH_CRASHHANDLER
- string "Crash handler location"
- default "poi-crash"
-endmenu
-
-menu "Workarounds"
- config QTBUG_65223
- bool "Manually emit loadFinished"
- default y
- help
- See QTBUG-65223: loadStarted is emitted twice when loading link with anchor
-endmenu
diff --git a/lib/configuration/CMakeLists.txt b/lib/configuration/CMakeLists.txt
index 7952eba..2e77782 100644
--- a/lib/configuration/CMakeLists.txt
+++ b/lib/configuration/CMakeLists.txt
@@ -1,8 +1,20 @@
+# generate init_global.cpp
+add_custom_command(
+ OUTPUT init_global.cpp
+ COMMAND ${CMAKE_CURRENT_LIST_DIR}/gen-default-cfg.py
+ --config ${PROJECT_SOURCE_DIR}/linux/config.yaml
+ --template ${CMAKE_CURRENT_LIST_DIR}/init_global.cpp.in
+ --output init_global.cpp
+ DEPENDS
+ ${CMAKE_CURRENT_LIST_DIR}/gen-default-cfg.py
+ ${PROJECT_SOURCE_DIR}/linux/config.yaml
+)
add_library(configuration STATIC
configuration.cpp configuration.h
+ init_global.cpp
qt_specialization.cpp qt_specialization.h
)
-target_link_libraries(configuration PUBLIC Qt6::Gui)
+target_link_libraries(configuration PUBLIC Qt6::Gui spdlog::spdlog)
target_include_directories(configuration PUBLIC ${CMAKE_CURRENT_LIST_DIR})
add_executable(test_configuration test/configuration.cpp)
diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h
index 30f258c..f2de92f 100644
--- a/lib/configuration/configuration.h
+++ b/lib/configuration/configuration.h
@@ -12,6 +12,8 @@
#include <initializer_list>
#include <memory>
#include <optional>
+#include <source_location>
+#include <spdlog/spdlog.h>
#include <string>
#include <type_traits>
#include <unordered_map>
@@ -44,10 +46,10 @@ public:
void read(std::basic_istream<char> &input);
template <typename T>
- [[nodiscard]] std::optional<T> value(const char *path) const
+ [[nodiscard]] std::optional<T> value(const char *path, const std::source_location location = std::source_location::current()) const
{
if(use_global) {
- return instance()->value<T>(path);
+ return instance()->value<T>(path, location);
}
if(count(path) == 0) {
@@ -58,13 +60,14 @@ public:
}
template <concept_value_t T>
- [[nodiscard]] std::optional<T> value(const char *p_path) const
+ [[nodiscard]] std::optional<T> value(const char *p_path, const std::source_location location = std::source_location::current()) const
{
if(use_global) {
- return instance()->value<T>(p_path);
+ return instance()->value<T>(p_path, location);
}
if(this->count(p_path) == 0) {
+ spdlog::warn("requested non-existent configuration value {} at {}:{}", p_path, location.file_name(), location.line());
return std::nullopt;
}
@@ -79,11 +82,11 @@ public:
}
} else if(std::holds_alternative<bool>(value)) {
- if constexpr(std::is_constructible<T, bool>::value) {
+ if constexpr(std::is_constructible_v<T, bool> || std::is_same_v<T, bool>) {
return std::get<bool>(value);
} else if constexpr(std::is_arithmetic_v<T>) {
return static_cast<T>(std::get<bool>(value));
- } else if constexpr(std::is_constructible<T, const char *>::value) {
+ } else if constexpr(std::is_constructible_v<T, const char *>) {
return std::get<bool>(value) ? T{ "true" } : T{ "false" };
}
@@ -115,11 +118,12 @@ public:
}
template <typename T>
- T &shortcut(T & /* unused */, const char * /* unused */) const
+ T &shortcut(T & /* unused */, const char * /* unused */, const std::source_location location = std::source_location::current()) const
{
return T{};
}
+ static std::string init_global(const std::string &p_path);
static void move_global(std::unique_ptr<Configuration> && conf);
protected:
diff --git a/lib/configuration/gen-default-cfg.py b/lib/configuration/gen-default-cfg.py
new file mode 100755
index 0000000..5d9f8da
--- /dev/null
+++ b/lib/configuration/gen-default-cfg.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+import sys
+import argparse
+import yaml
+
+def v_to_str(value):
+ if type(value) is str:
+ return f"std::string(\"{value}\")"
+ if type(value) is int:
+ return value
+ if type(value) is bool:
+ return "true" if True else "false"
+
+def kv_pairs_to_str(section, pairs):
+ pairs_str = "\n".join([f" {{ \"{section}/{key}\", {v_to_str(pairs[key])} }}," for key in pairs])
+ return pairs_str
+
+def writeConfigInitList(config, file):
+ for node in config:
+ for section, pairs in node.items():
+ print(kv_pairs_to_str(section, pairs), file=file)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--config", type=argparse.FileType('r'), required=True, help="configuration yaml")
+ parser.add_argument("--template", type=argparse.FileType('r'), required=True, help="settings.h.in")
+ parser.add_argument("--output", type=argparse.FileType('w'), default=sys.stdout, help="Output location")
+ args = parser.parse_args()
+
+ config = yaml.safe_load(args.config)
+ print("config: ", config)
+
+ print("/* Autogenerated file", file=args.output)
+ print(" * config: {}".format(args.config), file=args.output)
+ print(" */", file=args.output)
+
+ for line in args.template:
+ if "@__DEFAULT_CFG__" in line:
+ writeConfigInitList(config, args.output)
+ else:
+ print(line, end='', file=args.output)
diff --git a/lib/configuration/init_global.cpp.in b/lib/configuration/init_global.cpp.in
new file mode 100644
index 0000000..9179130
--- /dev/null
+++ b/lib/configuration/init_global.cpp.in
@@ -0,0 +1,25 @@
+/*
+ * This is a generated file.
+ *
+ * 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/cgit/smolbote.git
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "configuration.h"
+
+std::string Configuration::init_global(const std::string &p_path)
+{
+ auto value_map = std::make_unique<Configuration, std::initializer_list<std::pair<std::string, conf_value_t>>>({
+ /* @__DEFAULT_CFG__ */
+ });
+
+ // load the actual configuration file
+ const auto cfgpath = p_path.empty() ? value_map->value<std::string>("poi/config").value() : p_path;
+ value_map->read_file(cfgpath);
+
+ move_global(std::move(value_map));
+ return cfgpath;
+}
diff --git a/lib/configuration/qt_specialization.cpp b/lib/configuration/qt_specialization.cpp
index a97ed2b..cd7a99a 100644
--- a/lib/configuration/qt_specialization.cpp
+++ b/lib/configuration/qt_specialization.cpp
@@ -1,23 +1,23 @@
#include "configuration.h"
template <>
-[[nodiscard]] std::optional<QString> Configuration::value(const char *path) const
+[[nodiscard]] std::optional<QString> Configuration::value(const char *path, std::source_location location) const
{
- const auto result = value<std::string>(path);
+ const auto result = value<std::string>(path, location);
return result ? std::make_optional(QString::fromStdString(result.value())) : std::nullopt;
}
template <>
-[[nodiscard]] std::optional<QStringList> Configuration::value(const char *path) const
+[[nodiscard]] std::optional<QStringList> Configuration::value(const char *path, std::source_location location) const
{
- const auto result = value<std::string>(path);
+ const auto result = value<std::string>(path, location);
return result ? std::make_optional(QString::fromStdString(result.value()).split(';')) : std::nullopt;
}
template <>
-QAction &Configuration::shortcut(QAction &action, const char *name) const
+QAction &Configuration::shortcut(QAction &action, const char *name, const std::source_location location) const
{
- if(const auto result = value<QString>(name)) {
+ if(const auto result = value<QString>(name, location)) {
const QString old_tooltip = action.toolTip();
const auto &result_value = result.value();
@@ -28,9 +28,9 @@ QAction &Configuration::shortcut(QAction &action, const char *name) const
}
template <>
-QKeySequence &Configuration::shortcut(QKeySequence &sequence, const char *name) const
+QKeySequence &Configuration::shortcut(QKeySequence &sequence, const char *name, const std::source_location location) const
{
- if(const auto result = value<QString>(name)) {
+ if(const auto result = value<QString>(name, location)) {
const auto &result_value = result.value();
sequence = QKeySequence::fromString(result_value);
diff --git a/lib/configuration/qt_specialization.h b/lib/configuration/qt_specialization.h
index af8466e..26f9593 100644
--- a/lib/configuration/qt_specialization.h
+++ b/lib/configuration/qt_specialization.h
@@ -5,11 +5,11 @@
#include <QStringList>
template <>
-[[nodiscard]] std::optional<QString> Configuration::value(const char *path) const;
+[[nodiscard]] std::optional<QString> Configuration::value(const char *path, std::source_location location) const;
template <>
-[[nodiscard]] std::optional<QStringList> Configuration::value(const char *path) const;
+[[nodiscard]] std::optional<QStringList> Configuration::value(const char *path, std::source_location location) const;
template <>
-QAction &Configuration::shortcut(QAction &, const char *) const;
+QAction &Configuration::shortcut(QAction &, const char *, const std::source_location) const;
template <>
-QKeySequence &Configuration::shortcut(QKeySequence &, const char *) const;
+QKeySequence &Configuration::shortcut(QKeySequence &, const char *, const std::source_location) const;
diff --git a/linux/config.yaml b/linux/config.yaml
new file mode 100644
index 0000000..38e6e6e
--- /dev/null
+++ b/linux/config.yaml
@@ -0,0 +1,63 @@
+---
+- poi:
+ name: smolbote
+ icon: :/icons/poi.svg
+ config: ~/.config/smolbote/smolbote.cfg
+
+- shortcuts:
+ session.save: Ctrl+S,S
+ session.open: Ctrl+S,O
+
+ window.newgroup: Ctrl+G
+ window.newwindow: Ctrl+N
+ window.about: F1
+ window.quit: Ctrl+Q
+ window.search: F3
+ window.bookmarks.show: Ctrl+B
+ window.downloads.show: Ctrl+D
+
+ navigationbar.show: Ctrl+Shift+N
+ navigation.back: Ctrl+Left
+ navigation.backmenu: Ctrl+Down
+ navigation.forward: Ctrl+Right
+ navigation.forwardmenu: Ctrl+Up
+ navigation.refresh: F5
+ navigation.reload: Ctrl+F5
+ navigation.home: Ctrl+Home
+
+ address.focus: F4
+ address.menu: F2
+
+ subwindow.close: Ctrl+Shift+W
+ subwindow.fullscreen: F11
+ subwindow.newtab: Ctrl+T
+ subwindow.closetab: Ctrl+W
+ subwindow.restoretab: Ctrl+Shift+T
+ subwindow.tableft: Ctrl+O
+ subwindow.movetableft: Ctrl+Shift+O
+ subwindow.tabright: Ctrl+P
+ subwindow.movetabright: Ctrl+Shift+P
+
+- mainwindow:
+ title: smolbote
+ width: 1280
+ height: 720
+
+- bookmarks:
+ path: ~/.config/smolbote/bookmarks.xbel
+ toolbar.show: Ctrl+Shift+B
+ toolbar.movable: false
+ toolbar.visible: true
+
+- downloads:
+ path: ~/Downloads
+
+- profile:
+ path: ~/.config/smolbote/profiles.d
+ default: default
+ search: https://duckduckgo.com/?q=%1&ia=web
+ homepage: about:blank
+ newtab: about:blank
+
+- session:
+ path: ~/.config/smolbote/session.d
diff --git a/linux/makepkg/PKGBUILD b/linux/makepkg/PKGBUILD
index 749da87..efdea15 100644
--- a/linux/makepkg/PKGBUILD
+++ b/linux/makepkg/PKGBUILD
@@ -16,7 +16,7 @@ arch=('x86_64' 'aarch64')
license=('GPL3')
depends=('qt6-svg' 'qt6-webengine' 'spdlog' 'fmt')
-makedepends=('git' 'cmake' 'python-kconfiglib' 'openssl' 'qt6-tools' 'scdoc')
+makedepends=('git' 'cmake' 'openssl' 'qt6-tools' 'scdoc')
optdepends=('firejail: launch a sandboxed instance')
# use git+file:///path/to/your/repo to build from a local repo
@@ -29,12 +29,11 @@ b2sums=('SKIP'
validpgpkeys=(BB1C090188E3E32B375C13FD095DE26BC16D2E98) # Aqua-sama <aqua@iserlohn-fortress.net>
prepare() {
+ msg2 "Populate third_party packages..."
mkdir "$srcdir/smolbote/third_party"
ln -s "$srcdir/SingleApplication-3.4.1" "$srcdir/smolbote/third_party/SingleApplication"
- cd $srcdir/smolbote
- KCONFIG_CONFIG=linux/.config alldefconfig
-
+ msg2 "Configure..."
cmake -S $srcdir/smolbote -B $srcdir/build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
diff --git a/scripts/gen-default-cfg.py b/scripts/gen-default-cfg.py
deleted file mode 100755
index dc88ceb..0000000
--- a/scripts/gen-default-cfg.py
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/env python3
-
-import sys
-import argparse
-import kconfiglib
-
-def node_to_str(node):
- if(node.item.type == kconfiglib.STRING):
- return "std::string(\"" + node.item.str_value + "\")"
- elif(node.item.type == kconfiglib.INT):
- return "int(" + node.item.str_value + ")"
- elif(node.item.type == kconfiglib.BOOL):
- tri_val_str = ("false", "unknown", "true")[node.item.tri_value]
- return "bool(" + tri_val_str + ")"
-
- return None
-
-def writeItem(node, file):
- while node:
- if isinstance(node.item, kconfiglib.Symbol):
- name = node.item.name.lower().replace('_', '.')
- print("\t{ \"" + name + "\", " + node_to_str(node) + " },", file=file)
-
- if node.list:
- writeItem(node.list, file)
-
- node = node.next
-
-
-if __name__ == "__main__":
- parser = argparse.ArgumentParser()
- parser.add_argument("--kconfig", nargs="?", default="Kconfig", help="Top-level Kconfig")
- parser.add_argument("--dotconfig", nargs="?", help=".config")
- parser.add_argument("--input", type=argparse.FileType('r'), help="settings.h.in")
- parser.add_argument("--output", type=argparse.FileType('w'), default=sys.stdout, help="Output location")
- args = parser.parse_args()
-
- kconf = kconfiglib.Kconfig(args.kconfig)
- if args.dotconfig is not None:
- kconf.load_config(args.dotconfig)
-
- print("/* Autogenerated file", file=args.output)
- print(" * kconfig: {}".format(args.kconfig), file=args.output)
- print(" * dotconfig: {}".format(args.dotconfig), file=args.output)
- print(" */", file=args.output)
-
- for line in args.input:
- if "@__DEFAULT_CFG__" in line:
- writeItem(kconf.top_node.list, file=args.output)
- else:
- print(line, end='', file=args.output)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9afb862..f80dbc7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,14 +1,3 @@
-# settings.h
-add_custom_command(
- OUTPUT settings.h
- COMMAND ${PROJECT_SOURCE_DIR}/scripts/gen-default-cfg.py
- --kconfig ${PROJECT_SOURCE_DIR}/Kconfig
- --dotconfig ${PROJECT_SOURCE_DIR}/linux/.config
- --input ${CMAKE_CURRENT_LIST_DIR}/settings.h.in
- --output settings.h
- DEPENDS ${PROJECT_SOURCE_DIR}/linux/.config
-)
-
# version.h
configure_file(version.h.in version.h)
@@ -70,7 +59,6 @@ add_executable(poi
# resources
${PROJECT_SOURCE_DIR}/data/resources.qrc
)
-target_sources(poi PRIVATE settings.h)
target_include_directories(poi PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_BINARY_DIR})
target_enable_warnings(poi)
target_link_libraries(poi
diff --git a/src/applicationmenu.cpp b/src/applicationmenu.cpp
index dc888e7..aff5576 100644
--- a/src/applicationmenu.cpp
+++ b/src/applicationmenu.cpp
@@ -22,31 +22,31 @@ ApplicationMenu::ApplicationMenu(Browser *app, QWidget *parent)
setTitle(qApp->applicationName());
Configuration conf;
- const auto sessionPath = conf.value<QString>("session.path").value();
+ const auto sessionPath = conf.value<QString>("session/path").value();
auto *actionSaveSession = addAction(tr("Save Session"), this, [sessionPath]() {
auto *sessionDialog = new SaveSessionDialog(nullptr);
if(sessionDialog->exec() == QDialog::Accepted) {
sessionDialog->save(sessionPath);
}
});
- conf.shortcut<QAction>(*actionSaveSession, "shortcuts.session.save");
+ conf.shortcut<QAction>(*actionSaveSession, "shortcuts/session.save");
auto *actionOpenSession = addAction(tr("Open Session"), this, []() {
auto *sessionDialog = new SessionDialog(nullptr);
sessionDialog->exec();
});
- conf.shortcut<QAction>(*actionOpenSession, "shortcuts.session.open");
+ conf.shortcut<QAction>(*actionOpenSession, "shortcuts/session.open");
bottom_pluginSeparator = addSeparator();
auto *actionAbout = addAction(tr("About"), app, &Browser::about);
- conf.shortcut<QAction>(*actionAbout, "shortcuts.window.about");
+ conf.shortcut<QAction>(*actionAbout, "shortcuts/window.about");
auto *action_aboutPlugins = addAction(tr("About Plugins"), app, &Browser::aboutPlugins);
- conf.shortcut(*action_aboutPlugins, "app.shortcuts.about.plugins");
+ conf.shortcut(*action_aboutPlugins, "shortcuts/about.plugins");
auto *actionQuit = addAction(tr("Quit"), app, &Browser::quit);
- conf.shortcut<QAction>(*actionQuit, "shortcuts.window.quit");
+ conf.shortcut<QAction>(*actionQuit, "shortcuts/window.quit");
}
void ApplicationMenu::addPlugin(QPluginLoader *plugin)
diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp
index 52dcae2..3174874 100644
--- a/src/bookmarks/bookmarkstoolbar.cpp
+++ b/src/bookmarks/bookmarkstoolbar.cpp
@@ -18,10 +18,10 @@ BookmarksToolbar::BookmarksToolbar(const BookmarkModel *model, MainWindow *paren
m_window = parent;
Configuration conf;
- setObjectName("bookmarks.toolbar");
+ setObjectName("bookmarks/toolbar");
setWindowTitle(tr("Bookmarks Toolbar"));
- setMovable(conf.value<bool>("bookmarks.toolbar.movable").value());
- setVisible(conf.value<bool>("bookmarks.toolbar.visible").value());
+ setMovable(conf.value<bool>("bookmarks/toolbar.movable").value());
+ setVisible(conf.value<bool>("bookmarks/toolbar.visible").value());
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
const auto *root = model->root();
diff --git a/src/browser.cpp b/src/browser.cpp
index a2ae8c9..74da540 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -40,11 +40,11 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
{
Configuration conf;
- setApplicationName(conf.value<QString>("poi.name").value());
- setWindowIcon(QIcon(conf.value<QString>("poi.icon").value()));
+ setApplicationName(conf.value<QString>("poi/name").value());
+ setWindowIcon(QIcon(conf.value<QString>("poi/icon").value()));
setApplicationVersion(QVersionNumber::fromString(QLatin1String(poi_Version)).toString());
- if(const auto _translation = conf.value<QString>("browser.translation")) {
+ if(const auto _translation = conf.value<QString>("browser/translation")) {
auto *translator = new QTranslator(this);
if(translator->load(_translation.value()))
installTranslator(translator);
@@ -52,7 +52,7 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
delete translator;
}
- if(const auto _locale = conf.value<QString>("browser.locale")) {
+ if(const auto _locale = conf.value<QString>("browser/locale")) {
auto *locale = new QTranslator(this);
if(locale->load("qt_" + _locale.value(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
installTranslator(locale);
@@ -60,11 +60,11 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
delete locale;
}
- if(auto iconTheme = conf.value<QString>("browser.iconTheme")) {
+ if(auto iconTheme = conf.value<QString>("browser/iconTheme")) {
QIcon::setThemeName(iconTheme.value());
}
- if(auto stylesheet = conf.value<QString>("browser.stylesheet")) {
+ if(auto stylesheet = conf.value<QString>("browser/stylesheet")) {
QFile f(stylesheet.value());
if(f.open(QIODevice::ReadOnly)) {
setStyleSheet(f.readAll());
@@ -74,11 +74,11 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
// load profiles
{
- const auto profiles = Util::files(conf.value<QString>("profile.path").value(), { "*.profile" });
- const auto search = conf.value<QString>("profile.search").value();
- const auto homepage = QUrl::fromUserInput(conf.value<QString>("profile.homepage").value());
- const auto newtab = QUrl::fromUserInput(conf.value<QString>("profile.newtab").value());
- const auto default_id = conf.value<QString>("profile.default").value();
+ const auto profiles = Util::files(conf.value<QString>("profile/path").value(), { "*.profile" });
+ const auto search = conf.value<QString>("profile/search").value();
+ const auto homepage = QUrl::fromUserInput(conf.value<QString>("profile/homepage").value());
+ const auto newtab = QUrl::fromUserInput(conf.value<QString>("profile/newtab").value());
+ const auto default_id = conf.value<QString>("profile/default").value();
m_profileManager = std::make_unique<WebProfileManager<false>>(profiles, default_id, search, homepage, newtab);
m_profileManager->make_global();
@@ -92,13 +92,13 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary)
}
// downloads
- m_downloads = std::make_unique<DownloadsWidget>(conf.value<QString>("downloads.path").value());
+ m_downloads = std::make_unique<DownloadsWidget>(conf.value<QString>("downloads/path").value());
m_profileManager->walk([this](const QString &, WebProfile *profile, QSettings *) {
connect(profile, &QWebEngineProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
});
// bookmarks
- m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(conf.value<std::string>("bookmarks.path").value()));
+ m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(conf.value<std::string>("bookmarks/path").value()));
connect(m_bookmarks.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) {
m_windows.last()->createTab(url);
});
diff --git a/src/main.cpp b/src/main.cpp
index 42acf5c..8cd1d34 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -10,7 +10,6 @@
#include "configuration.h"
#include "session/sessiondialog.h"
#include "session_json.hpp"
-#include "settings.h"
#include <QCommandLineParser>
#include <QFile>
#include <QPluginLoader>
@@ -72,14 +71,14 @@ int main(int argc, char **argv)
// set this, otherwise the webview becomes black when using a stylesheet
QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
- init_conf(parser.value(cmd_config).toStdString());
+ spdlog::info("Loaded configuration: {}", Configuration::init_global(parser.value(cmd_config).toStdString()));
Browser app(argc, argv);
parser.process(app);
const auto profile = []() {
Configuration conf;
- return conf.value<QString>("profile.default").value();
+ return conf.value<QString>("profile/default").value();
}();
QStringList urls = parser.positionalArguments();
diff --git a/src/mainwindow/addressbar.cpp b/src/mainwindow/addressbar.cpp
index d37a6a7..ed1cb3e 100644
--- a/src/mainwindow/addressbar.cpp
+++ b/src/mainwindow/addressbar.cpp
@@ -19,9 +19,9 @@ AddressBar::AddressBar(QWidget *parent)
ui->setupUi(this);
Configuration conf;
- ui->urlBar->menuAction->setShortcut(QKeySequence(conf.value<QString>("shortcuts.address.menu").value()));
+ ui->urlBar->menuAction->setShortcut(QKeySequence(conf.value<QString>("shortcuts/address.menu").value()));
- auto *focusShortcut = new QShortcut(QKeySequence(conf.value<QString>("shortcuts.address.focus").value()), parent);
+ auto *focusShortcut = new QShortcut(QKeySequence(conf.value<QString>("shortcuts/address.focus").value()), parent);
connect(focusShortcut, &QShortcut::activated, ui->urlBar, [this]() {
ui->urlBar->setFocus();
ui->urlBar->selectAll();
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 64c149c..bd5d0c2 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -30,16 +30,16 @@ MainWindow::MainWindow(const Session::MainWindow &mainwindow_data, QMenu *appMen
Configuration config;
// create UI
- defaultWindowTitle = config.value<QString>("mainwindow.title").value();
+ defaultWindowTitle = config.value<QString>("mainwindow/title").value();
setWindowTitle(defaultWindowTitle);
- resize(config.value<int>("mainwindow.width").value(), config.value<int>("mainwindow.height").value());
- if(config.value<bool>("mainwindow.maximized").value_or(false)) {
+ resize(config.value<int>("mainwindow/width").value(), config.value<int>("mainwindow/height").value());
+ if(config.value<bool>("mainwindow/maximized").value_or(false)) {
setWindowState(Qt::WindowMaximized);
}
show();
navigationToolBar = new NavigationBar(this);
- navigationToolBar->setMovable(config.value<bool>("navigation.movable").value_or(false));
+ navigationToolBar->setMovable(config.value<bool>("navigation/movable").value_or(false));
addToolBar(Qt::TopToolBarArea, navigationToolBar);
navigationToolBar->connectWebView(nullptr);
diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp
index e557d50..e479e8d 100644
--- a/src/mainwindow/menubar.cpp
+++ b/src/mainwindow/menubar.cpp
@@ -79,30 +79,30 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent)
auto *actionBookmarks = window->addAction(tr("Bookmarks"), browser, [browser, parent]() {
browser->showWidget(browser->bookmarks(), parent);
});
- conf.shortcut<QAction>(*actionBookmarks, "shortcuts.window.bookmarks.show");
+ conf.shortcut<QAction>(*actionBookmarks, "shortcuts/window.bookmarks.show");
auto *actionDownloads = window->addAction(tr("Downloads"), browser, [browser, parent]() {
browser->showWidget(browser->downloads(), parent);
});
- conf.shortcut<QAction>(*actionDownloads, "shortcuts.window.downloads.show");
+ conf.shortcut<QAction>(*actionDownloads, "shortcuts/window.downloads.show");
window->addSeparator();
auto *actionNewWindow = window->addAction(tr("New Window"), browser, [browser]() {
const Session::MainWindow window_data;
browser->open({ window_data }, false);
});
- conf.shortcut<QAction>(*actionNewWindow, "shortcuts.window.newwindow");
+ conf.shortcut<QAction>(*actionNewWindow, "shortcuts/window.newwindow");
auto *actionNewSubwindow = window->addAction(tr("New Subwindow"), parent, [parent]() {
const Session::SubWindow session;
parent->createSubWindow(session);
});
- conf.shortcut<QAction>(*actionNewSubwindow, "shortcuts.window.newgroup");
+ conf.shortcut<QAction>(*actionNewSubwindow, "shortcuts/window.newgroup");
auto *actionCloseSubwindow = window->addAction(tr("Close Subwindow"), parent, [parent]() {
parent->currentSubWindow()->close();
});
- conf.shortcut<QAction>(*actionCloseSubwindow, "shortcuts.subwindow.close");
+ conf.shortcut<QAction>(*actionCloseSubwindow, "shortcuts/subwindow.close");
window->addSeparator()->setText(tr("Toolbars"));
@@ -140,7 +140,7 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent)
_subwindow->setCurrentTab(index);
});
});
- conf.shortcut<QAction>(*actionNewTab, "shortcuts.subwindow.newtab");
+ conf.shortcut<QAction>(*actionNewTab, "shortcuts/subwindow.newtab");
subwindow->addSeparator();
@@ -150,7 +150,7 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent)
_subwindow->setCurrentTab(index);
});
});
- conf.shortcut<QAction>(*actionRestoreTab, "shortcuts.subwindow.restoretab");
+ conf.shortcut<QAction>(*actionRestoreTab, "shortcuts/subwindow.restoretab");
auto *restoreTabsMenu = subwindow->addMenu(tr("Restore previous tab"));
connect(restoreTabsMenu, &QMenu::aboutToShow, parent, [parent, restoreTabsMenu]() {
@@ -200,28 +200,28 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent)
_subwindow->setCurrentTab(qMax(0, currentIdx - 1));
});
});
- conf.shortcut<QAction>(*leftTab, "shortcuts.subwindow.tableft");
+ conf.shortcut<QAction>(*leftTab, "shortcuts/subwindow.tableft");
auto *moveTabLeft = subwindow->addAction(tr("Move tab left"), parent, [parent]() {
run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) {
_subwindow->moveTab(currentIdx, currentIdx - 1);
});
});
- conf.shortcut<QAction>(*moveTabLeft, "shortcuts.subwindow.movetableft");
+ conf.shortcut<QAction>(*moveTabLeft, "shortcuts/subwindow.movetableft");
auto *rightTab = subwindow->addAction(tr("Switch to tab on the right"), parent, [parent]() {
run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) {
_subwindow->setCurrentTab(qMin(currentIdx + 1, _subwindow->tabCount() - 1));
});
});
- conf.shortcut<QAction>(*rightTab, "shortcuts.subwindow.tabright");
+ conf.shortcut<QAction>(*rightTab, "shortcuts/subwindow.tabright");
auto *moveTabRight = subwindow->addAction(tr("Move tab right"), parent, [parent]() {
run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) {
_subwindow->moveTab(currentIdx, currentIdx + 1);
});
});
- conf.shortcut<QAction>(*moveTabRight, "shortcuts.subwindow.movetabright");
+ conf.shortcut<QAction>(*moveTabRight, "shortcuts/subwindow.movetabright");
subwindow->addSeparator();
@@ -230,7 +230,7 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent)
_subwindow->closeTab(currentIdx);
});
});
- conf.shortcut<QAction>(*closeTab, "shortcuts.subwindow.closetab");
+ conf.shortcut<QAction>(*closeTab, "shortcuts/subwindow.closetab");
subwindow->addAction(tr("Close tabs to the left"), parent, [parent]() {
run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) {
diff --git a/src/mainwindow/widgets/navigationbar.cpp b/src/mainwindow/widgets/navigationbar.cpp
index 799ebec..6da6f6c 100644
--- a/src/mainwindow/widgets/navigationbar.cpp
+++ b/src/mainwindow/widgets/navigationbar.cpp
@@ -29,7 +29,7 @@ NavigationBar::NavigationBar(QWidget *parent)
// Back button
backAction = addAction(Util::icon(QStyle::SP_ArrowBack), tr("Back"));
- config.shortcut<QAction>(*backAction, "shortcuts.navigation.back");
+ config.shortcut<QAction>(*backAction, "shortcuts/navigation.back");
connect(backAction, &QAction::triggered, this, [this]() {
m_view->history()->back();
});
@@ -47,7 +47,7 @@ NavigationBar::NavigationBar(QWidget *parent)
});
backAction->setMenu(backMenu);
- auto *backMenuShortcut = new QShortcut(QKeySequence(config.value<QString>("shortcuts.navigation.backmenu").value()), this);
+ auto *backMenuShortcut = new QShortcut(QKeySequence(config.value<QString>("shortcuts/navigation.backmenu").value()), this);
connect(backMenuShortcut, &QShortcut::activated, backMenu, [this, backMenu]() {
if(backAction->isEnabled()) {
auto *widget = this->widgetForAction(backAction);
@@ -57,7 +57,7 @@ NavigationBar::NavigationBar(QWidget *parent)
// Forward button
forwardAction = addAction(Util::icon(QStyle::SP_ArrowForward), tr("Forward"));
- config.shortcut<QAction>(*forwardAction, "shortcuts.navigation.forward");
+ config.shortcut<QAction>(*forwardAction, "shortcuts/navigation.forward");
connect(forwardAction, &QAction::triggered, this, [this]() {
m_view->history()->forward();
});
@@ -75,7 +75,7 @@ NavigationBar::NavigationBar(QWidget *parent)
});
forwardAction->setMenu(forwardMenu);
- auto *forwardMenuShortcut = new QShortcut(QKeySequence(config.value<QString>("shortcuts.navigation.forwardmenu").value()), this);
+ auto *forwardMenuShortcut = new QShortcut(QKeySequence(config.value<QString>("shortcuts/navigation.forwardmenu").value()), this);
connect(forwardMenuShortcut, &QShortcut::activated, forwardMenu, [this, forwardMenu]() {
if(forwardAction->isEnabled()) {
auto *widget = this->widgetForAction(forwardAction);
@@ -85,7 +85,7 @@ NavigationBar::NavigationBar(QWidget *parent)
// Stop/Refresh button
stopReloadAction = addAction(Util::icon(QStyle::SP_BrowserReload), tr("Refresh"));
- config.shortcut<QAction>(*stopReloadAction, "shortcuts.navigation.refresh");
+ config.shortcut<QAction>(*stopReloadAction, "shortcuts/navigation.refresh");
connect(stopReloadAction, &QAction::triggered, this, [this]() {
if(m_view->isLoaded())
m_view->reload();
@@ -93,14 +93,14 @@ NavigationBar::NavigationBar(QWidget *parent)
m_view->stop();
});
- auto *reloadShortcut = new QShortcut(QKeySequence(config.value<QString>("shortcuts.navigation.reload").value()), this);
+ auto *reloadShortcut = new QShortcut(QKeySequence(config.value<QString>("shortcuts/navigation.reload").value()), this);
connect(reloadShortcut, &QShortcut::activated, this, [this]() {
m_view->triggerPageAction(QWebEnginePage::ReloadAndBypassCache);
});
// Home button
homeAction = addAction(Util::icon(QStyle::SP_DirHomeIcon), tr("Home"));
- config.shortcut<QAction>(*homeAction, "shortcuts.navigation.home");
+ config.shortcut<QAction>(*homeAction, "shortcuts/navigation.home");
connect(homeAction, &QAction::triggered, this, [this]() {
m_view->load(m_view->profile()->homepage());
});
diff --git a/src/settings.h.in b/src/settings.h.in
deleted file mode 100644
index 88fbcf5..0000000
--- a/src/settings.h.in
+++ /dev/null
@@ -1,32 +0,0 @@
-#pragma once
-
-#include <QStandardPaths>
-#include <configuration.h>
-#include <fstream>
-
-inline const std::string init_conf(const std::string &path)
-{
- auto value_map = std::make_unique<Configuration, std::initializer_list<std::pair<std::string, conf_value_t>>>({
- @__DEFAULT_CFG__
- });
-
- const std::string cfgpath = [&]() {
- if(path.empty())
- return value_map->value<std::string>("poi.cfg.path").value();
-
- auto p = path;
- if(p.front() == '~')
- p.replace(0, 1, QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString());
- return p;
- }();
-
- std::fstream fs;
- fs.open(cfgpath, std::fstream::in);
- if(fs.is_open()) {
- value_map->read(fs);
- fs.close();
- }
-
- Configuration::move_global(std::move(value_map));
- return cfgpath;
-}