summaryrefslogtreecommitdiff
path: root/src/config.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-30 00:36:19 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-30 00:36:19 -0500
commit6f2b61b676a16482fdac70a58a8e875c4d68e713 (patch)
treee2f8b2376847b5b13b278572c0fae8a6bc4d0e82 /src/config.hpp
parentdacd752bbf46f2afb08b4b8d730ba3619528dda4 (diff)
Add configuration handling.
Diffstat (limited to 'src/config.hpp')
-rw-r--r--src/config.hpp144
1 files changed, 143 insertions, 1 deletions
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 <QtWidgets>
+#include <fud_status.hpp>
+#include <map>
+#include <optional>
+#include <qkeysequence.h>
+#include <qlist.h>
+#include <set>
#include <string>
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<QKeySequence>;
+using ShortcutSet = std::set<QKeySequence>;
+using ShortcutMap = std::map<ActionType, ShortcutSet>;
+using ShortcutRevMap = std::map<QKeySequence, ActionType>;
+
+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<ActionType> actions() const;
+
+ std::optional<ActionType> action(QKeySequence keySequence) const;
+
+ std::optional<ShortcutList> 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