all repos — mgba @ 4c38f769565e8ddd7d3a8eef1a41975206c129a0

mGBA Game Boy Advance Emulator

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