src/platform/qt/ConfigController.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef QGBA_CONFIG_CONTROLLER
7#define QGBA_CONFIG_CONTROLLER
8
9#include <QMap>
10#include <QObject>
11#include <QSettings>
12#include <QVariant>
13
14#include <functional>
15
16extern "C" {
17#include "gba/supervisor/config.h"
18#include "util/configuration.h"
19}
20
21class QAction;
22class QMenu;
23
24struct GBAArguments;
25struct GBACartridgeOverride;
26
27namespace QGBA {
28
29class ConfigOption : public QObject {
30Q_OBJECT
31
32public:
33 ConfigOption(QObject* parent = nullptr);
34
35 void connect(std::function<void(const QVariant&)>, QObject* parent = nullptr);
36
37 QAction* addValue(const QString& text, const QVariant& value, QMenu* parent = nullptr);
38 QAction* addValue(const QString& text, const char* value, QMenu* parent = nullptr);
39 QAction* addBoolean(const QString& text, QMenu* parent = nullptr);
40
41public slots:
42 void setValue(bool value);
43 void setValue(int value);
44 void setValue(unsigned value);
45 void setValue(const char* value);
46 void setValue(const QVariant& value);
47
48signals:
49 void valueChanged(const QVariant& value);
50
51private:
52 QMap<QObject*, std::function<void(const QVariant&)>> m_slots;
53 QList<QPair<QAction*, QVariant>> m_actions;
54};
55
56class ConfigController : public QObject {
57Q_OBJECT
58
59public:
60 constexpr static const char* const PORT = "qt";
61 static const int MRU_LIST_SIZE = 10;
62
63 ConfigController(QObject* parent = nullptr);
64 ~ConfigController();
65
66 const GBAOptions* options() const { return &m_opts; }
67 bool parseArguments(GBAArguments* args, int argc, char* argv[]);
68
69 ConfigOption* addOption(const char* key);
70 void updateOption(const char* key);
71
72 QString getOption(const char* key) const;
73
74 QVariant getQtOption(const QString& key, const QString& group = QString()) const;
75
76 QList<QString> getMRU() const;
77 void setMRU(const QList<QString>& mru);
78
79 Configuration* overrides() { return GBAConfigGetOverrides(&m_config); }
80 void saveOverride(const GBACartridgeOverride&);
81
82 Configuration* input() { return GBAConfigGetInput(&m_config); }
83
84public slots:
85 void setOption(const char* key, bool value);
86 void setOption(const char* key, int value);
87 void setOption(const char* key, unsigned value);
88 void setOption(const char* key, const char* value);
89 void setOption(const char* key, const QVariant& value);
90 void setQtOption(const QString& key, const QVariant& value, const QString& group = QString());
91
92 void makePortable();
93 void write();
94
95private:
96 Configuration* defaults() { return &m_config.defaultsTable; }
97
98 GBAConfig m_config;
99 GBAOptions m_opts;
100
101 QMap<QString, ConfigOption*> m_optionSet;
102 QSettings* m_settings;
103};
104
105}
106
107#endif