diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 12 | ||||
-rw-r--r-- | src/applicationmenu.cpp | 12 | ||||
-rw-r--r-- | src/bookmarks/bookmarkstoolbar.cpp | 6 | ||||
-rw-r--r-- | src/browser.cpp | 26 | ||||
-rw-r--r-- | src/main.cpp | 5 | ||||
-rw-r--r-- | src/mainwindow/addressbar.cpp | 4 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 8 | ||||
-rw-r--r-- | src/mainwindow/menubar.cpp | 24 | ||||
-rw-r--r-- | src/mainwindow/widgets/navigationbar.cpp | 14 | ||||
-rw-r--r-- | src/settings.h.in | 32 |
10 files changed, 49 insertions, 94 deletions
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; -} |