mirror of https://github.com/mgba-emu/mgba.git
Qt: Move configuration loading to its own class
This commit is contained in:
parent
2ddb074bda
commit
37212c1f23
|
@ -31,6 +31,7 @@ endif()
|
|||
set(SOURCE_FILES
|
||||
AudioDevice.cpp
|
||||
AudioProcessor.cpp
|
||||
ConfigController.cpp
|
||||
Display.cpp
|
||||
GBAApp.cpp
|
||||
GameController.cpp
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
#include "ConfigController.h"
|
||||
|
||||
#include "GameController.h"
|
||||
|
||||
extern "C" {
|
||||
#include "platform/commandline.h"
|
||||
}
|
||||
|
||||
using namespace QGBA;
|
||||
|
||||
ConfigController::ConfigController(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_opts()
|
||||
{
|
||||
GBAConfigInit(&m_config, PORT);
|
||||
|
||||
m_opts.audioSync = GameController::AUDIO_SYNC;
|
||||
m_opts.videoSync = GameController::VIDEO_SYNC;
|
||||
GBAConfigLoadDefaults(&m_config, &m_opts);
|
||||
GBAConfigLoad(&m_config);
|
||||
GBAConfigMap(&m_config, &m_opts);
|
||||
}
|
||||
|
||||
ConfigController::~ConfigController() {
|
||||
write();
|
||||
|
||||
GBAConfigDeinit(&m_config);
|
||||
GBAConfigFreeOpts(&m_opts);
|
||||
}
|
||||
|
||||
bool ConfigController::parseArguments(GBAArguments* args, int argc, char* argv[]) {
|
||||
return ::parseArguments(args, &m_config, argc, argv, 0);
|
||||
}
|
||||
|
||||
void ConfigController::setOption(const char* key, bool value) {
|
||||
setOption(key, (int) value);
|
||||
}
|
||||
|
||||
void ConfigController::setOption(const char* key, int value) {
|
||||
GBAConfigSetIntValue(&m_config, key, value);
|
||||
}
|
||||
|
||||
void ConfigController::setOption(const char* key, unsigned value) {
|
||||
GBAConfigSetUIntValue(&m_config, key, value);
|
||||
}
|
||||
|
||||
void ConfigController::setOption(const char* key, const char* value) {
|
||||
GBAConfigSetValue(&m_config, key, value);
|
||||
}
|
||||
|
||||
void ConfigController::write() {
|
||||
GBAConfigSave(&m_config);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef QGBA_CONFIG_CONTROLLER
|
||||
#define QGBA_CONFIG_CONTROLLER
|
||||
|
||||
#include <QObject>
|
||||
|
||||
extern "C" {
|
||||
#include "gba-config.h"
|
||||
#include "util/configuration.h"
|
||||
}
|
||||
|
||||
struct GBAArguments;
|
||||
|
||||
namespace QGBA {
|
||||
class ConfigController : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
constexpr static const char* const PORT = "qt";
|
||||
|
||||
ConfigController(QObject* parent = nullptr);
|
||||
~ConfigController();
|
||||
|
||||
const GBAOptions* options() const { return &m_opts; }
|
||||
bool parseArguments(GBAArguments* args, int argc, char* argv[]);
|
||||
|
||||
public slots:
|
||||
void setOption(const char* key, bool value);
|
||||
void setOption(const char* key, int value);
|
||||
void setOption(const char* key, unsigned value);
|
||||
void setOption(const char* key, const char* value);
|
||||
|
||||
void write();
|
||||
|
||||
private:
|
||||
GBAConfig m_config;
|
||||
GBAOptions m_opts;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -4,42 +4,30 @@
|
|||
|
||||
#include <QFileOpenEvent>
|
||||
|
||||
#define PORT "qt"
|
||||
extern "C" {
|
||||
#include "platform/commandline.h"
|
||||
}
|
||||
|
||||
using namespace QGBA;
|
||||
|
||||
GBAApp::GBAApp(int& argc, char* argv[])
|
||||
: QApplication(argc, argv)
|
||||
, m_args()
|
||||
, m_opts()
|
||||
{
|
||||
QApplication::setApplicationName(PROJECT_NAME);
|
||||
QApplication::setApplicationVersion(PROJECT_VERSION);
|
||||
|
||||
GBAConfigInit(&m_config, PORT);
|
||||
GBAConfigLoad(&m_config);
|
||||
|
||||
m_opts.audioSync = GameController::AUDIO_SYNC;
|
||||
m_opts.videoSync = GameController::VIDEO_SYNC;
|
||||
GBAConfigLoadDefaults(&m_config, &m_opts);
|
||||
|
||||
bool parsed = parseArguments(&m_args, &m_config, argc, argv, 0);
|
||||
GBAConfigMap(&m_config, &m_opts);
|
||||
m_window.setOptions(&m_opts);
|
||||
|
||||
if (parsed) {
|
||||
m_window.argumentsPassed(&m_args);
|
||||
}
|
||||
GBAArguments args = {};
|
||||
m_window.setConfig(&m_configController);
|
||||
if (m_configController.parseArguments(&args, argc, argv)) {
|
||||
m_window.argumentsPassed(&args);
|
||||
} else {
|
||||
m_window.loadConfig();
|
||||
}
|
||||
freeArguments(&args);
|
||||
|
||||
m_window.show();
|
||||
}
|
||||
|
||||
GBAApp::~GBAApp() {
|
||||
freeArguments(&m_args);
|
||||
GBAConfigFreeOpts(&m_opts);
|
||||
GBAConfigDeinit(&m_config);
|
||||
}
|
||||
|
||||
bool GBAApp::event(QEvent* event) {
|
||||
if (event->type() == QEvent::FileOpen) {
|
||||
m_window.controller()->loadGame(static_cast<QFileOpenEvent*>(event)->file());
|
||||
|
|
|
@ -3,13 +3,9 @@
|
|||
|
||||
#include <QApplication>
|
||||
|
||||
#include "ConfigController.h"
|
||||
#include "Window.h"
|
||||
|
||||
extern "C" {
|
||||
#include "platform/commandline.h"
|
||||
#include "util/configuration.h"
|
||||
}
|
||||
|
||||
namespace QGBA {
|
||||
|
||||
class GameController;
|
||||
|
@ -19,17 +15,13 @@ Q_OBJECT
|
|||
|
||||
public:
|
||||
GBAApp(int& argc, char* argv[]);
|
||||
virtual ~GBAApp();
|
||||
|
||||
protected:
|
||||
bool event(QEvent*);
|
||||
|
||||
private:
|
||||
Window m_window;
|
||||
|
||||
GBAArguments m_args;
|
||||
GBAOptions m_opts;
|
||||
GBAConfig m_config;
|
||||
ConfigController m_configController;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QMenuBar>
|
||||
#include <QStackedLayout>
|
||||
|
||||
#include "ConfigController.h"
|
||||
#include "GameController.h"
|
||||
#include "GDBController.h"
|
||||
#include "GDBWindow.h"
|
||||
|
@ -102,6 +103,8 @@ GBAKey Window::mapKey(int qtKey) {
|
|||
}
|
||||
|
||||
void Window::argumentsPassed(GBAArguments* args) {
|
||||
loadConfig();
|
||||
|
||||
if (args->patch) {
|
||||
m_controller->loadPatch(args->patch);
|
||||
}
|
||||
|
@ -111,7 +114,13 @@ void Window::argumentsPassed(GBAArguments* args) {
|
|||
}
|
||||
}
|
||||
|
||||
void Window::setOptions(GBAOptions* opts) {
|
||||
void Window::setConfig(ConfigController* config) {
|
||||
m_config = config;
|
||||
}
|
||||
|
||||
void Window::loadConfig() {
|
||||
const GBAOptions* opts = m_config->options();
|
||||
|
||||
m_logView->setLevels(opts->logLevel);
|
||||
// TODO: Have these show up as modified in the menu
|
||||
m_controller->setFrameskip(opts->frameskip);
|
||||
|
@ -135,6 +144,10 @@ void Window::setOptions(GBAOptions* opts) {
|
|||
}
|
||||
}
|
||||
|
||||
void Window::saveConfig() {
|
||||
m_config->write();
|
||||
}
|
||||
|
||||
void Window::selectROM() {
|
||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select ROM"));
|
||||
if (!filename.isEmpty()) {
|
||||
|
|
|
@ -17,6 +17,7 @@ struct GBAArguments;
|
|||
|
||||
namespace QGBA {
|
||||
|
||||
class ConfigController;
|
||||
class GameController;
|
||||
class LogView;
|
||||
class VideoView;
|
||||
|
@ -33,7 +34,7 @@ public:
|
|||
|
||||
static GBAKey mapKey(int qtKey);
|
||||
|
||||
void setOptions(GBAOptions*);
|
||||
void setConfig(ConfigController*);
|
||||
void argumentsPassed(GBAArguments*);
|
||||
|
||||
signals:
|
||||
|
@ -47,6 +48,8 @@ public slots:
|
|||
void selectBIOS();
|
||||
void selectPatch();
|
||||
void toggleFullScreen();
|
||||
void loadConfig();
|
||||
void saveConfig();
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
void openVideoWindow();
|
||||
|
@ -81,6 +84,7 @@ private:
|
|||
LoadSaveState* m_stateWindow;
|
||||
WindowBackground* m_screenWidget;
|
||||
QPixmap m_logo;
|
||||
ConfigController* m_config;
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
VideoView* m_videoView;
|
||||
|
|
Loading…
Reference in New Issue