diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-10-01 06:14:36 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-10-01 06:14:36 -0500 |
commit | 99c6c809b961f2eb3c8538bfa50de7f2f98587ea (patch) | |
tree | 29f27cc33d08b5fc158a3ddbb885114ce4e00493 /src/main_window.cpp | |
parent | a6b4485ac5ea0673e0ce35dab14e2df26c27823e (diff) |
Get configurations to apply when accepting.
Diffstat (limited to 'src/main_window.cpp')
-rw-r--r-- | src/main_window.cpp | 93 |
1 files changed, 58 insertions, 35 deletions
diff --git a/src/main_window.cpp b/src/main_window.cpp index dea951c..82e6ef2 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -50,6 +50,26 @@ FudStatus createXdgDirectory(const std::string& directoryName) return FudStatus::Success; } +void setUserConfig(GetsuyomiConfig& config, const ShortcutMap& shortcutMap) +{ + auto binder = [&](ShortcutList& shortcuts, ActionType action) { + shortcuts = shortcutListFromSet(shortcutMap.at(action)); + }; + + binder(config.openFileShortcuts, ActionType::OpenFile); + binder(config.openDirectoryShortcuts, ActionType::OpenDirectory); + binder(config.quitShortcuts, ActionType::Quit); + + binder(config.settingsShortcuts, ActionType::Configure); + + binder(config.nextShortcuts, ActionType::Next); + binder(config.backShortcuts, ActionType::Back); + + binder(config.singlePageShortcuts, ActionType::SinglePage); + binder(config.dualPageShortcuts, ActionType::DualPage); + binder(config.mangaPageShortcuts, ActionType::MangaPage); +} + GetConfigResult getUserConfig() { auto configResult = getEnvironment(); @@ -74,22 +94,7 @@ GetConfigResult getUserConfig() auto configFileName = std::filesystem::path(config.configHome).append("config.lua"); auto shortcutMap = Shortcuts::fromUserConfig(configFileName); - auto binder = [&](ShortcutList& shortcuts, ActionType action) { - shortcuts = shortcutListFromSet(shortcutMap.at(action)); - }; - - binder(config.openFileShortcuts, ActionType::OpenFile); - binder(config.openDirectoryShortcuts, ActionType::OpenDirectory); - binder(config.quitShortcuts, ActionType::Quit); - - binder(config.settingsShortcuts, ActionType::Configure); - - binder(config.nextShortcuts, ActionType::Next); - binder(config.backShortcuts, ActionType::Back); - - binder(config.singlePageShortcuts, ActionType::SinglePage); - binder(config.dualPageShortcuts, ActionType::DualPage); - binder(config.mangaPageShortcuts, ActionType::MangaPage); + setUserConfig(config, shortcutMap); return GetConfigResult::okay(config); } @@ -130,48 +135,30 @@ FudStatus GetsuyomiApp::setup() void GetsuyomiApp::createActions() { m_openFile = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen), tr("&Open File"), this); - m_openFile->setShortcuts(m_config.openFileShortcuts); - m_openFile->setStatusTip(tr("Open a file")); connect(m_openFile, &QAction::triggered, this, &GetsuyomiApp::openFile); m_openDirectory = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::FolderOpen), tr("Open &Directory"), this); - m_openDirectory->setShortcuts(m_config.openDirectoryShortcuts); - m_openDirectory->setStatusTip(tr("Open a directory")); connect(m_openDirectory, &QAction::triggered, this, &GetsuyomiApp::openDirectory); m_quitAction = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::ApplicationExit), tr("&Quit"), this); - m_quitAction->setShortcuts(m_config.quitShortcuts); - m_quitAction->setStatusTip(tr("Quit")); connect(m_quitAction, &QAction::triggered, this, &GetsuyomiApp::quit); m_settingsAction = new QAction(QIcon("resources/gear.svg"), tr("&Settings"), this); - m_settingsAction->setShortcuts(m_config.settingsShortcuts); - m_settingsAction->setStatusTip(tr("Configure getsuyomi")); connect(m_settingsAction, &QAction::triggered, this, &GetsuyomiApp::configure); m_nextAction = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::GoNext), tr("Next"), this); - m_nextAction->setShortcuts(m_config.nextShortcuts); - m_nextAction->setStatusTip(tr("Next")); connect(m_nextAction, &QAction::triggered, this, &GetsuyomiApp::next); m_backAction = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::GoPrevious), tr("Back"), this); - m_backAction->setShortcuts(m_config.backShortcuts); - m_backAction->setStatusTip(tr("Back")); connect(m_backAction, &QAction::triggered, this, &GetsuyomiApp::back); m_setSinglePageLayout = new QAction(QIcon("../resources/pageSingle.png"), tr("Single Page Layout"), this); - m_setSinglePageLayout->setShortcuts(m_config.singlePageShortcuts); - m_setSinglePageLayout->setStatusTip(tr("Set Single Page Layout")); connect(m_setSinglePageLayout, &QAction::triggered, this, &GetsuyomiApp::setSinglePageLayout); m_setDualPageLayout = new QAction(QIcon("../resources/pageDual.png"), tr("Dual Page Layout"), this); - m_setDualPageLayout->setShortcuts(m_config.dualPageShortcuts); - m_setDualPageLayout->setStatusTip(tr("Set Dual Page Layout")); connect(m_setDualPageLayout, &QAction::triggered, this, &GetsuyomiApp::setDualPageLayout); m_setMangaLayout = new QAction(QIcon("../resources/pageManga.png"), tr("Manga Page Layout"), this); - m_setMangaLayout->setShortcuts(m_config.mangaPageShortcuts); - m_setMangaLayout->setStatusTip(tr("Set Manga Page Layout")); connect(m_setMangaLayout, &QAction::triggered, this, &GetsuyomiApp::setMangaLayout); m_setPageLayoutGroup = new QActionGroup(this); @@ -179,6 +166,38 @@ void GetsuyomiApp::createActions() m_setPageLayoutGroup->addAction(m_setDualPageLayout); m_setPageLayoutGroup->addAction(m_setMangaLayout); m_setPageLayoutGroup->setExclusionPolicy(QActionGroup::ExclusionPolicy::Exclusive); + + bindShortcuts(); +} + +void GetsuyomiApp::bindShortcuts() +{ + m_openFile->setShortcuts(m_config.openFileShortcuts); + m_openFile->setStatusTip(tr("Open a file")); + + m_openDirectory->setShortcuts(m_config.openDirectoryShortcuts); + m_openDirectory->setStatusTip(tr("Open a directory")); + + m_quitAction->setShortcuts(m_config.quitShortcuts); + m_quitAction->setStatusTip(tr("Quit")); + + m_settingsAction->setShortcuts(m_config.settingsShortcuts); + m_settingsAction->setStatusTip(tr("Configure getsuyomi")); + + m_nextAction->setShortcuts(m_config.nextShortcuts); + m_nextAction->setStatusTip(tr("Next")); + + m_backAction->setShortcuts(m_config.backShortcuts); + m_backAction->setStatusTip(tr("Back")); + + m_setSinglePageLayout->setShortcuts(m_config.singlePageShortcuts); + m_setSinglePageLayout->setStatusTip(tr("Set Single Page Layout")); + + m_setDualPageLayout->setShortcuts(m_config.dualPageShortcuts); + m_setDualPageLayout->setStatusTip(tr("Set Dual Page Layout")); + + m_setMangaLayout->setShortcuts(m_config.mangaPageShortcuts); + m_setMangaLayout->setStatusTip(tr("Set Manga Page Layout")); } void GetsuyomiApp::createMenus() @@ -282,7 +301,11 @@ void GetsuyomiApp::configure() qCritical("Invalid settings"); return; } - settings.exec(); + if (settings.exec()) { + const auto& shortcuts = settings.shortcuts(); + setUserConfig(m_config, shortcuts.shortcutMap()); + bindShortcuts(); + } } void GetsuyomiApp::next() |