all repos — mgba @ fa884d071ecaa3e05ff20b45a67bf9500dd3d6b6

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
 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 Override&);
 82
 83	Configuration* input() { return mCoreConfigGetInput(&m_config); }
 84
 85	const mCoreConfig* config() { return &m_config; }
 86
 87public slots:
 88	void setOption(const char* key, bool value);
 89	void setOption(const char* key, int value);
 90	void setOption(const char* key, unsigned value);
 91	void setOption(const char* key, const char* value);
 92	void setOption(const char* key, const QVariant& value);
 93	void setQtOption(const QString& key, const QVariant& value, const QString& group = QString());
 94
 95	void makePortable();
 96	void write();
 97
 98private:
 99	Configuration* defaults() { return &m_config.defaultsTable; }
100
101	mCoreConfig m_config;
102	mCoreOptions m_opts;
103
104	QMap<QString, ConfigOption*> m_optionSet;
105	QSettings* m_settings;
106};
107
108}
109
110#endif