From 6f2b61b676a16482fdac70a58a8e875c4d68e713 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Mon, 30 Sep 2024 00:36:19 -0500 Subject: Add configuration handling. --- src/config.hpp | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 1 deletion(-) (limited to 'src/config.hpp') diff --git a/src/config.hpp b/src/config.hpp index cb6a74a..81da2dc 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -1,18 +1,160 @@ #ifndef GETSUYOMI_CONFIG_HPP #define GETSUYOMI_CONFIG_HPP +#include +#include +#include +#include +#include +#include +#include #include namespace getsuyomi { +enum class ActionType +{ + OpenFile, + OpenDirectory, + Quit, + Configure, + // Help, + // About + // GotoFirst, + Next, + Back, + // GotoLast, + SinglePage, + DualPage, + MangaPage +}; + +constexpr const char* actionTypeToString(ActionType action) +{ + switch (action) { + case ActionType::OpenFile: + return "OpenFile"; + case ActionType::OpenDirectory: + return "OpenDirectory"; + case ActionType::Quit: + return "Quit"; + case ActionType::Configure: + return "Configure"; + // case ActionType::Help: + return "Help"; + // case ActionType::About: + // return "About"; + // case ActionType::GotoFirst: + // return "GotoFirst"; + case ActionType::Next: + return "Next"; + case ActionType::Back: + return "Back"; + // case ActionType::GotoLast: + // return "GotoLast"; + case ActionType::SinglePage: + return "SinglePage"; + case ActionType::DualPage: + return "DualPage"; + case ActionType::MangaPage: + return "MangaPage"; + default: + return "Unknown"; + } +} + +using ShortcutList = QList; +using ShortcutSet = std::set; +using ShortcutMap = std::map; +using ShortcutRevMap = std::map; + +ShortcutSet shortcutSetFromList(const ShortcutList& shortcutList); + +class Shortcuts { + public: + Shortcuts(ShortcutMap&& shortcutMap); + + [[nodiscard]] bool contains(QKeySequence keySequence) const; + [[nodiscard]] bool contains(ActionType action) const; + + std::vector actions() const; + + std::optional action(QKeySequence keySequence) const; + + std::optional shortcuts(ActionType action) const; + + fud::FudStatus bind(ActionType action, QKeySequence keySequence); + fud::FudStatus remove(QKeySequence keySequence); + fud::FudStatus clear(ActionType action); + + [[nodiscard]] bool valid() const; + + const ShortcutMap& shortcutMap() const; + + private: + bool m_valid{false}; + + ShortcutMap m_actionToShortcuts; + ShortcutSet m_shortcuts; + ShortcutRevMap m_shortcutToAction; +}; + struct GetsuyomiConfig { std::string home{}; std::string dataHome{}; std::string configHome{}; std::string stateHome{}; + + ShortcutList openFileShortcuts{}; + ShortcutList openDirectoryShortcuts{}; + ShortcutList quitShortcuts{}; + + ShortcutList settingsShortcuts{}; + + ShortcutList nextShortcuts{}; + ShortcutList backShortcuts{}; + + ShortcutMap shortcuts() const; }; -} // namespace getsuyomi +class ShortcutCollector : public QWidget { + public: + ShortcutCollector(QWidget* parent, ActionType action, Shortcuts& shortcuts); + ~ShortcutCollector() = default; + ShortcutCollector(const ShortcutCollector&) = delete; + ShortcutCollector(ShortcutCollector&&) = delete; + ShortcutCollector& operator=(const ShortcutCollector&) = delete; + ShortcutCollector& operator=(ShortcutCollector&&) = delete; + private slots: + void removeShortcut(int row, int); + + private: + ActionType m_action; + Shortcuts& m_shortcuts; + QKeySequenceEdit* m_shortcutEditor{nullptr}; + QGridLayout* m_layout{nullptr}; + ShortcutList m_actionList{}; + QTableWidget* m_shortcutTable{nullptr}; +}; + +class Settings : public QDialog { + public: + Settings(QWidget* parent, Shortcuts&& shortcuts); + Settings(const Settings&) = delete; + Settings(Settings&& rhs) = delete; + ~Settings() = default; + Settings& operator=(const Settings&) = delete; + Settings& operator=(Settings&& rhs) = delete; + + [[nodiscard]] bool valid() const; + + const Shortcuts& shortcuts() const; + + private: + Shortcuts m_shortcuts; +}; + +} // namespace getsuyomi #endif -- cgit v1.2.3