all repos — mgba @ 91fd2c6b4768fbeb58c74d2f119e7d55685a9800

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
 18#include <mgba/core/config.h>
 19#include <mgba-util/configuration.h>
 20#include "feature/commandline.h"
 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	QString getOption(const QString& key) const;
 75
 76	QVariant getQtOption(const QString& key, const QString& group = QString()) const;
 77
 78	QList<QString> getMRU() const;
 79	void setMRU(const QList<QString>& mru);
 80
 81	Configuration* overrides() { return mCoreConfigGetOverrides(&m_config); }
 82	void saveOverride(const Override&);
 83
 84	Configuration* input() { return mCoreConfigGetInput(&m_config); }
 85
 86	const mCoreConfig* config() { return &m_config; }
 87
 88	static const QString& configDir();
 89
 90public slots:
 91	void setOption(const char* key, bool value);
 92	void setOption(const char* key, int value);
 93	void setOption(const char* key, unsigned value);
 94	void setOption(const char* key, const char* value);
 95	void setOption(const char* key, const QVariant& value);
 96	void setQtOption(const QString& key, const QVariant& value, const QString& group = QString());
 97
 98	void makePortable();
 99	void write();
100
101private:
102	Configuration* defaults() { return &m_config.defaultsTable; }
103
104	mCoreConfig m_config;
105	mCoreOptions m_opts;
106
107	QMap<QString, ConfigOption*> m_optionSet;
108	QSettings* m_settings;
109	static QString s_configDir;
110};
111
112}
113
114#endif