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 "core/config.h"
18#include "util/configuration.h"
19#include "platform/commandline.h"
20}
21
22class QAction;
23class QMenu;
24
25struct mArguments;
26struct GBACartridgeOverride;
27
28namespace QGBA {
29
30class ConfigOption : public QObject {
31Q_OBJECT
32
33public:
34 ConfigOption(QObject* parent = nullptr);
35
36 void connect(std::function<void(const QVariant&)>, QObject* parent = nullptr);
37
38 QAction* addValue(const QString& text, const QVariant& value, QMenu* parent = nullptr);
39 QAction* addValue(const QString& text, const char* value, QMenu* parent = nullptr);
40 QAction* addBoolean(const QString& text, QMenu* parent = nullptr);
41
42public slots:
43 void setValue(bool value);
44 void setValue(int value);
45 void setValue(unsigned value);
46 void setValue(const char* value);
47 void setValue(const QVariant& value);
48
49signals:
50 void valueChanged(const QVariant& value);
51
52private:
53 QMap<QObject*, std::function<void(const QVariant&)>> m_slots;
54 QList<QPair<QAction*, QVariant>> m_actions;
55};
56
57class ConfigController : public QObject {
58Q_OBJECT
59
60public:
61 constexpr static const char* const PORT = "qt";
62 static const int MRU_LIST_SIZE = 10;
63
64 ConfigController(QObject* parent = nullptr);
65 ~ConfigController();
66
67 const mCoreOptions* options() const { return &m_opts; }
68 bool parseArguments(mArguments* args, int argc, char* argv[], mSubParser* subparser = nullptr);
69
70 ConfigOption* addOption(const char* key);
71 void updateOption(const char* key);
72
73 QString getOption(const char* key) const;
74
75 QVariant getQtOption(const QString& key, const QString& group = QString()) const;
76
77 QList<QString> getMRU() const;
78 void setMRU(const QList<QString>& mru);
79
80 Configuration* overrides() { return mCoreConfigGetOverrides(&m_config); }
81 void saveOverride(const GBACartridgeOverride&);
82
83 Configuration* input() { return mCoreConfigGetInput(&m_config); }
84
85public slots:
86 void setOption(const char* key, bool value);
87 void setOption(const char* key, int value);
88 void setOption(const char* key, unsigned value);
89 void setOption(const char* key, const char* value);
90 void setOption(const char* key, const QVariant& value);
91 void setQtOption(const QString& key, const QVariant& value, const QString& group = QString());
92
93 void makePortable();
94 void write();
95
96private:
97 Configuration* defaults() { return &m_config.defaultsTable; }
98
99 mCoreConfig m_config;
100 mCoreOptions m_opts;
101
102 QMap<QString, ConfigOption*> m_optionSet;
103 QSettings* m_settings;
104};
105
106}
107
108#endif