src/platform/qt/ConfigController.h (view raw)
1/* Copyright (c) 2013-2014 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 <QScopedPointer>
12#include <QVariant>
13
14#include <functional>
15
16extern "C" {
17#include "gba-config.h"
18#include "util/configuration.h"
19}
20
21class QAction;
22class QMenu;
23
24struct GBAArguments;
25
26namespace QGBA {
27
28class ConfigOption : public QObject {
29Q_OBJECT
30
31public:
32 ConfigOption(QObject* parent = nullptr);
33
34 void connect(std::function<void(const QVariant&)>);
35
36 QAction* addValue(const QString& text, const QVariant& value, QMenu* parent = 0);
37 QAction* addValue(const QString& text, const char* value, QMenu* parent = 0);
38 QAction* addBoolean(const QString& text, QMenu* parent = 0);
39
40public slots:
41 void setValue(bool value);
42 void setValue(int value);
43 void setValue(unsigned value);
44 void setValue(const char* value);
45 void setValue(const QVariant& value);
46
47signals:
48 void valueChanged(const QVariant& value);
49
50private:
51 std::function<void(const QVariant&)> m_slot;
52 QList<QPair<QAction*, QVariant>> m_actions;
53};
54
55class ConfigController : public QObject {
56Q_OBJECT
57
58public:
59 constexpr static const char* const PORT = "qt";
60 static const int MRU_LIST_SIZE = 10;
61
62 ConfigController(QObject* parent = nullptr);
63 ~ConfigController();
64
65 const GBAOptions* options() const { return &m_opts; }
66 bool parseArguments(GBAArguments* args, int argc, char* argv[]);
67
68 ConfigOption* addOption(const char* key);
69 void updateOption(const char* key);
70
71 QString getOption(const char* key) const;
72
73 QList<QString> getMRU() const;
74 void setMRU(const QList<QString>& mru);
75
76public slots:
77 void setOption(const char* key, bool value);
78 void setOption(const char* key, int value);
79 void setOption(const char* key, unsigned value);
80 void setOption(const char* key, const char* value);
81 void setOption(const char* key, const QVariant& value);
82
83 void write();
84
85private:
86 Configuration* configuration() { return &m_config.configTable; }
87 Configuration* defaults() { return &m_config.defaultsTable; }
88
89 friend class InputController; // TODO: Do this without friends
90
91 GBAConfig m_config;
92 GBAOptions m_opts;
93
94 QMap<QString, ConfigOption*> m_optionSet;
95};
96
97}
98
99#endif