summaryrefslogtreecommitdiff
path: root/src/main_window.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-30 08:37:38 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-30 08:37:38 -0500
commita6b4485ac5ea0673e0ce35dab14e2df26c27823e (patch)
treed46f099858ae81622be1e7a6f7b5bd47d4c1cf27 /src/main_window.cpp
parent6f2b61b676a16482fdac70a58a8e875c4d68e713 (diff)
More setup to configurable controls.
Diffstat (limited to 'src/main_window.cpp')
-rw-r--r--src/main_window.cpp74
1 files changed, 27 insertions, 47 deletions
diff --git a/src/main_window.cpp b/src/main_window.cpp
index 007705f..dea951c 100644
--- a/src/main_window.cpp
+++ b/src/main_window.cpp
@@ -5,12 +5,12 @@
#include <QString>
#include <cerrno>
+#include <fcntl.h>
#include <filesystem>
#include <fud_result.hpp>
#include <fud_status.hpp>
#include <string>
#include <sys/stat.h>
-#include <fcntl.h>
#include <vector>
namespace getsuyomi {
@@ -29,15 +29,14 @@ FudStatus createXdgDirectory(const std::string& directoryName)
{
constexpr mode_t xdgMode = 0700;
auto dirStatus = mkdir(directoryName.c_str(), xdgMode);
- if (dirStatus == 0)
- {
+ if (dirStatus == 0) {
return FudStatus::Success;
}
if (errno != EEXIST) {
return FudStatus::Failure;
}
- struct stat statBuffer{};
+ struct stat statBuffer {};
dirStatus = stat(directoryName.c_str(), &statBuffer);
if (dirStatus != 0) {
@@ -72,36 +71,25 @@ GetConfigResult getUserConfig()
return GetConfigResult::error(dirStatus);
}
- LuaContext luaContext{};
- if (!luaContext.valid()) {
- return GetConfigResult::error(FudStatus::Failure);
- }
-
auto configFileName = std::filesystem::path(config.configHome).append("config.lua");
- qDebug("configFileName is %s", configFileName.c_str());
+ auto shortcutMap = Shortcuts::fromUserConfig(configFileName);
- constexpr mode_t configFileMode = 0600;
- auto fdResult = open(configFileName.c_str(), O_CREAT, configFileMode);
- if (fdResult == -1) {
- if (errno != EEXIST) {
- return GetConfigResult::error(FudStatus::Failure);
- }
- }
- close(fdResult);
+ auto binder = [&](ShortcutList& shortcuts, ActionType action) {
+ shortcuts = shortcutListFromSet(shortcutMap.at(action));
+ };
- auto luaStatus = luaContext.loadFile(configFileName.c_str());
- if (luaStatus != FudStatus::Success)
- {
- qCritical("Failed to load file in lua %s", fud::FudStatusToString(luaStatus));
- return GetConfigResult::error(luaStatus);
- }
+ binder(config.openFileShortcuts, ActionType::OpenFile);
+ binder(config.openDirectoryShortcuts, ActionType::OpenDirectory);
+ binder(config.quitShortcuts, ActionType::Quit);
- auto result = luaContext.getGlobalString(actionTypeToString(ActionType::OpenFile));
- if (result.isError())
- {
- qCritical("Failed to get variable from lua %s", fud::FudStatusToString(result.getError()));
- return GetConfigResult::error(result.getError());
- }
+ 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);
return GetConfigResult::okay(config);
}
@@ -142,55 +130,47 @@ FudStatus GetsuyomiApp::setup()
void GetsuyomiApp::createActions()
{
m_openFile = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::DocumentOpen), tr("&Open File"), this);
- m_openFile->setShortcuts(QKeySequence::Open);
+ 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->setShortcut(Qt::CTRL | Qt::ALT | Qt::Key_O);
+ 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(QKeySequence::Quit);
+ 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->setShortcut(Qt::CTRL | Qt::Key_P);
+ m_settingsAction->setShortcuts(m_config.settingsShortcuts);
m_settingsAction->setStatusTip(tr("Configure getsuyomi"));
connect(m_settingsAction, &QAction::triggered, this, &GetsuyomiApp::configure);
- auto nextShortcuts = QList<QKeySequence>{};
- nextShortcuts.append(QKeySequence{Qt::Key_L});
- nextShortcuts.append(QKeySequence{Qt::Key_Right});
- nextShortcuts.append(QKeySequence{Qt::Key_Down});
m_nextAction = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::GoNext), tr("Next"), this);
- m_nextAction->setShortcuts(nextShortcuts);
+ m_nextAction->setShortcuts(m_config.nextShortcuts);
m_nextAction->setStatusTip(tr("Next"));
connect(m_nextAction, &QAction::triggered, this, &GetsuyomiApp::next);
- auto backShortcuts = QList<QKeySequence>{};
- backShortcuts.append(QKeySequence{Qt::Key_H});
- backShortcuts.append(QKeySequence{Qt::Key_Left});
- backShortcuts.append(QKeySequence{Qt::Key_Up});
m_backAction = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::GoPrevious), tr("Back"), this);
- m_backAction->setShortcuts(backShortcuts);
+ 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->setShortcut(QKeySequence{Qt::Key_S});
+ 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->setShortcut(QKeySequence{Qt::Key_D});
+ 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->setShortcut(QKeySequence{Qt::Key_M});
+ m_setMangaLayout->setShortcuts(m_config.mangaPageShortcuts);
m_setMangaLayout->setStatusTip(tr("Set Manga Page Layout"));
connect(m_setMangaLayout, &QAction::triggered, this, &GetsuyomiApp::setMangaLayout);