#ifndef GETSUYOMI_CONFIG_HPP #define GETSUYOMI_CONFIG_HPP #include #include #include #include #include #include #include #include class QKeySequence; namespace getsuyomi { constexpr const char* AppVendor = "libfud"; constexpr const char* AppName = "getsuyomi"; constexpr const char* AppVersionString = "1.0.0"; constexpr const char* HOME{"HOME"}; enum class ActionType { OpenFile, OpenDirectory, Quit, Configure, // Help, // About // GotoFirst, Next, Back, // GotoLast, SinglePage, DualPage, MangaPage }; struct GetsuyomiConfig; using GetEnvResult = fud::Result; using GetConfigResult = fud::Result; using ShortcutList = QList; using ShortcutSet = std::set; using ShortcutMap = std::map; using ShortcutRevMap = std::map; std::optional getEnvVar(const char* envVar); void getEnvVar(const std::string& homeVar, const std::string& envVar, std::string& envValue, const char* backup); GetEnvResult getEnvironment(); fud::FudStatus createXdgDirectory(const std::string& directoryName); void setUserConfig(GetsuyomiConfig& config, const ShortcutMap& shortcutMap); GetConfigResult getUserConfig(); 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"; } } ShortcutSet shortcutSetFromList(const ShortcutList& shortcutList); ShortcutList shortcutListFromSet(const ShortcutSet& shortcutSet); 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); fud::FudStatus save(const std::filesystem::path& configFileName) const; private: Shortcuts() = default; static Shortcuts fromLuaConfig(const std::filesystem::path& configFileName); // fud::FudStatus saveAsLuaConfig(const std::f 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{}; std::filesystem::path configFilename{}; ShortcutList openFileShortcuts{}; ShortcutList openDirectoryShortcuts{}; ShortcutList quitShortcuts{}; ShortcutList settingsShortcuts{}; ShortcutList nextShortcuts{}; ShortcutList backShortcuts{}; ShortcutList singlePageShortcuts{}; ShortcutList dualPageShortcuts{}; ShortcutList mangaPageShortcuts{}; ShortcutMap shortcuts() const; }; } // namespace getsuyomi #endif