#ifndef GETSUYOMI_CONFIG_HPP #define GETSUYOMI_CONFIG_HPP #include #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); ShortcutList shortcutListFromSet(const ShortcutSet& 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; static ShortcutMap fromUserConfig(const std::filesystem::path& configFileName); private: Shortcuts() = default; static Shortcuts fromLuaConfig(const std::filesystem::path& configFileName); 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{}; ShortcutList singlePageShortcuts{}; ShortcutList dualPageShortcuts{}; ShortcutList mangaPageShortcuts{}; ShortcutMap shortcuts() const; }; class ShortcutDisplay : public QWidget { Q_OBJECT public: ShortcutDisplay(QWidget* parent, QKeySequence shortcut); signals: void removeClicked(QKeySequence shortcut); private: QKeySequence m_binding; private slots: void removeOnClicked(); }; constexpr auto foo = sizeof(QKeySequence); class ShortcutCollector : public QWidget { Q_OBJECT 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: void createBinding(QKeySequence binding); private slots: void checkBinding(); void addBinding(); void removeBinding(QKeySequence shortcut); private: ActionType m_action; Shortcuts& m_shortcuts; std::map m_bindings; QKeySequenceEdit* m_shortcutEditor{nullptr}; QPushButton* m_acceptButton{nullptr}; QVBoxLayout* m_layout{nullptr}; }; class Settings : public QDialog { Q_OBJECT 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