all repos — mgba @ b8fe87324f8987db99ede4b3332a9ea781726e85

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