all repos — mgba @ 5f62e33717f8da0b22673621253cf2e265a71603

mGBA Game Boy Advance Emulator

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 <QSettings>
 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	QVariant getQtOption(const QString& key, const QString& group = QString()) const;
 74
 75	QList<QString> getMRU() const;
 76	void setMRU(const QList<QString>& mru);
 77
 78	Configuration* overrides() { return &m_config.configTable; } // TODO: Make this not return the whole table
 79
 80public slots:
 81	void setOption(const char* key, bool value);
 82	void setOption(const char* key, int value);
 83	void setOption(const char* key, unsigned value);
 84	void setOption(const char* key, const char* value);
 85	void setOption(const char* key, const QVariant& value);
 86	void setQtOption(const QString& key, const QVariant& value, const QString& group = QString());
 87
 88	void write();
 89
 90private:
 91	Configuration* configuration() { return &m_config.configTable; }
 92	Configuration* defaults() { return &m_config.defaultsTable; }
 93
 94	friend class InputController; // TODO: Do this without friends
 95
 96	GBAConfig m_config;
 97	GBAOptions m_opts;
 98
 99	QMap<QString, ConfigOption*> m_optionSet;
100	QSettings* m_settings;
101};
102
103}
104
105#endif