diff options
Diffstat (limited to 'src/config.hpp')
-rw-r--r-- | src/config.hpp | 103 |
1 files changed, 36 insertions, 67 deletions
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 <QtWidgets> -#include <fud_status.hpp> #include <fud_result.hpp> +#include <fud_status.hpp> #include <map> #include <optional> #include <qkeysequence.h> #include <qlist.h> #include <set> #include <string> +#include <filesystem> 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<GetsuyomiConfig, fud::FudStatus>; +using GetConfigResult = fud::Result<GetsuyomiConfig, fud::FudStatus>; +using ShortcutList = QList<QKeySequence>; +using ShortcutSet = std::set<QKeySequence>; +using ShortcutMap = std::map<ActionType, ShortcutSet>; +using ShortcutRevMap = std::map<QKeySequence, ActionType>; + +std::optional<std::string> 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<QKeySequence>; -using ShortcutSet = std::set<QKeySequence>; -using ShortcutMap = std::map<ActionType, ShortcutSet>; -using ShortcutRevMap = std::map<QKeySequence, ActionType>; - 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<QKeySequence, ShortcutDisplay*> 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 |