all repos — mgba @ 67f8197493dd3f978b96f69ad1eabfc1d674de69

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