Qt: Handle saving input settings better
Jeffrey Pfau jeffrey@endrift.com
Tue, 21 Apr 2015 21:06:26 -0700
6 files changed,
21 insertions(+),
9 deletions(-)
M
src/gba/input.c
→
src/gba/input.c
@@ -505,9 +505,12 @@ const char* GBAInputGetCustomValue(const struct Configuration* config, uint32_t type, const char* key, const char* profile) {
char sectionName[SECTION_NAME_MAX]; if (profile) { snprintf(sectionName, SECTION_NAME_MAX, "input-profile.%s", profile); - } else { - _makeSectionName(sectionName, SECTION_NAME_MAX, type); + const char* value = ConfigurationGetValue(config, sectionName, key); + if (value) { + return value; + } } + _makeSectionName(sectionName, SECTION_NAME_MAX, type); return ConfigurationGetValue(config, sectionName, key); }@@ -515,8 +518,8 @@ void GBAInputSetCustomValue(struct Configuration* config, uint32_t type, const char* key, const char* value, const char* profile) {
char sectionName[SECTION_NAME_MAX]; if (profile) { snprintf(sectionName, SECTION_NAME_MAX, "input-profile.%s", profile); - } else { - _makeSectionName(sectionName, SECTION_NAME_MAX, type); + ConfigurationSetValue(config, sectionName, key, value); } + _makeSectionName(sectionName, SECTION_NAME_MAX, type); ConfigurationSetValue(config, sectionName, key, value); }
M
src/platform/qt/ConfigController.cpp
→
src/platform/qt/ConfigController.cpp
@@ -120,8 +120,6 @@ GBAConfigMap(&m_config, &m_opts);
} ConfigController::~ConfigController() { - write(); - GBAConfigDeinit(&m_config); GBAConfigFreeOpts(&m_opts); }
M
src/platform/qt/InputController.cpp
→
src/platform/qt/InputController.cpp
@@ -108,13 +108,20 @@ recalibrateAxes();
#endif } -void InputController::saveConfiguration(uint32_t type) { - GBAInputMapSave(&m_inputMap, type, m_config->input()); +void InputController::saveConfiguration() { + saveConfiguration(KEYBOARD); #ifdef BUILD_SDL + saveConfiguration(SDL_BINDING_BUTTON); + saveProfile(SDL_BINDING_BUTTON, profileForType(SDL_BINDING_BUTTON)); if (m_playerAttached) { GBASDLPlayerSaveConfig(&m_sdlPlayer, m_config->input()); } + m_config->write(); #endif +} + +void InputController::saveConfiguration(uint32_t type) { + GBAInputMapSave(&m_inputMap, type, m_config->input()); m_config->write(); }
M
src/platform/qt/InputController.h
→
src/platform/qt/InputController.h
@@ -36,9 +36,10 @@ InputController(int playerId = 0, QObject* parent = nullptr);
~InputController(); void setConfiguration(ConfigController* config); + void saveConfiguration(); void loadConfiguration(uint32_t type); void loadProfile(uint32_t type, const QString& profile); - void saveConfiguration(uint32_t type = KEYBOARD); + void saveConfiguration(uint32_t type); void saveProfile(uint32_t type, const QString& profile); const char* profileForType(uint32_t type);
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -197,6 +197,7 @@ m_inputController.setConfiguration(m_config);
} void Window::saveConfig() { + m_inputController.saveConfiguration(); m_config->write(); }@@ -411,6 +412,7 @@
void Window::closeEvent(QCloseEvent* event) { emit shutdown(); m_config->setQtOption("windowPos", pos()); + saveConfig(); QMainWindow::closeEvent(event); }