From 47e0ff88edd4660513f1d4f3d731008461532a13 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Wed, 2 Oct 2024 15:07:24 -0500 Subject: Get and save user keybinds. --- src/config.hpp | 103 ++++++++++++++++++++------------------------------------- 1 file changed, 36 insertions(+), 67 deletions(-) (limited to 'src/config.hpp') diff --git a/src/config.hpp b/src/config.hpp index 5937a9b..bc5698e 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -1,18 +1,26 @@ #ifndef GETSUYOMI_CONFIG_HPP #define GETSUYOMI_CONFIG_HPP -#include -#include #include +#include #include #include #include #include #include #include +#include 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, @@ -30,6 +38,27 @@ enum class ActionType 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) { @@ -64,11 +93,6 @@ constexpr const char* actionTypeToString(ActionType action) } } -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); @@ -95,11 +119,15 @@ class Shortcuts { 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{}; @@ -112,6 +140,7 @@ struct GetsuyomiConfig { std::string dataHome{}; std::string configHome{}; std::string stateHome{}; + std::filesystem::path configFilename{}; ShortcutList openFileShortcuts{}; ShortcutList openDirectoryShortcuts{}; @@ -129,66 +158,6 @@ struct GetsuyomiConfig { 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 -- cgit v1.2.3