From 24ca1a5fdbd6f8c2a64966b2417eae678ab95c91 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 27 Oct 2024 10:02:57 +0100 Subject: [PATCH] lay base for keeping config in sync across multiple instances --- src/frontend/qt_sdl/EmuInstance.cpp | 15 +++++++++ src/frontend/qt_sdl/EmuInstance.h | 3 ++ src/frontend/qt_sdl/Window.cpp | 50 ++++++++++++++++++++--------- src/frontend/qt_sdl/Window.h | 2 ++ src/frontend/qt_sdl/main.cpp | 12 +++++++ src/frontend/qt_sdl/main.h | 7 ++++ 6 files changed, 73 insertions(+), 16 deletions(-) diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index 09f6a2bc..7fc73670 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -241,6 +241,21 @@ void EmuInstance::deleteAllWindows() } +void EmuInstance::updateConfigInfo(int kind) +{ + switch (kind) + { + case Config_RecentFiles: + for (int i = 0; i < kMaxWindows; i++) + { + if (windowList[i]) + windowList[i]->loadRecentFilesMenu(true); + } + break; + } +} + + void EmuInstance::osdAddMessage(unsigned int color, const char* fmt, ...) { if (fmt == nullptr) diff --git a/src/frontend/qt_sdl/EmuInstance.h b/src/frontend/qt_sdl/EmuInstance.h index 8022867a..a7ecddf8 100644 --- a/src/frontend/qt_sdl/EmuInstance.h +++ b/src/frontend/qt_sdl/EmuInstance.h @@ -21,6 +21,7 @@ #include +#include "main.h" #include "NDS.h" #include "EmuThread.h" #include "Window.h" @@ -91,6 +92,8 @@ public: Config::Table& getGlobalConfig() { return globalCfg; } Config::Table& getLocalConfig() { return localCfg; } + void updateConfigInfo(int kind); + std::string instanceFileSuffix(); void createWindow(); diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 3ba9ada5..b44fed7a 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -271,7 +271,8 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) : setStyleSheet("QMenuBar::item { padding: 4px 8px; }"); #endif - hasMenu = (!parent); + //hasMenu = (!parent); + hasMenu = true; if (hasMenu) { @@ -288,15 +289,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) : actOpenROMArchive->setShortcut(QKeySequence(Qt::Key_O | Qt::CTRL | Qt::SHIFT));*/ recentMenu = menu->addMenu("Open recent"); - Config::Array recentROMs = globalCfg.GetArray("RecentROM"); - int numrecent = std::min(kMaxRecentROMs, (int) recentROMs.Size()); - for (int i = 0; i < numrecent; ++i) - { - std::string item = recentROMs.GetString(i); - if (!item.empty()) - recentFileList.push_back(QString::fromStdString(item)); - } - updateRecentFilesMenu(); + loadRecentFilesMenu(true); //actBootFirmware = menu->addAction("Launch DS menu"); actBootFirmware = menu->addAction("Boot firmware"); @@ -1280,12 +1273,23 @@ void MainWindow::onClearRecentFiles() updateRecentFilesMenu(); } -void MainWindow::updateRecentFilesMenu() +void MainWindow::loadRecentFilesMenu(bool loadcfg) { - recentMenu->clear(); + if (loadcfg) + { + recentFileList.clear(); - Config::Array recentroms = globalCfg.GetArray("RecentROM"); - recentroms.Clear(); + Config::Array recentROMs = globalCfg.GetArray("RecentROM"); + int numrecent = std::min(kMaxRecentROMs, (int) recentROMs.Size()); + for (int i = 0; i < numrecent; ++i) + { + std::string item = recentROMs.GetString(i); + if (!item.empty()) + recentFileList.push_back(QString::fromStdString(item)); + } + } + + recentMenu->clear(); for (int i = 0; i < recentFileList.size(); ++i) { @@ -1316,8 +1320,6 @@ void MainWindow::updateRecentFilesMenu() QAction *actRecentFile_i = recentMenu->addAction(QString("%1. %2").arg(i+1).arg(item_display)); actRecentFile_i->setData(item_full); connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile); - - recentroms.SetQString(i, recentFileList.at(i)); } while (recentFileList.size() > 10) @@ -1330,8 +1332,24 @@ void MainWindow::updateRecentFilesMenu() if (recentFileList.empty()) actClearRecentList->setEnabled(false); +} + +void MainWindow::updateRecentFilesMenu() +{ + Config::Array recentroms = globalCfg.GetArray("RecentROM"); + recentroms.Clear(); + + for (int i = 0; i < recentFileList.size(); ++i) + { + if (i >= kMaxRecentROMs) break; + + recentroms.SetQString(i, recentFileList.at(i)); + } Config::Save(); + loadRecentFilesMenu(false); + + updateConfigInfoAll(Config_RecentFiles, emuInstance->getInstanceID()); } void MainWindow::onClickRecentFile() diff --git a/src/frontend/qt_sdl/Window.h b/src/frontend/qt_sdl/Window.h index 17575b53..a344c1e3 100644 --- a/src/frontend/qt_sdl/Window.h +++ b/src/frontend/qt_sdl/Window.h @@ -134,6 +134,8 @@ public: // called when the MP interface is changed void updateMPInterface(melonDS::MPInterfaceType type); + void loadRecentFilesMenu(bool loadcfg); + protected: void keyPressEvent(QKeyEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index e63c8a9b..a4cc965e 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -168,6 +168,18 @@ int numEmuInstances() } +void updateConfigInfoAll(int kind, int sourceinst) +{ + for (int i = 0; i < kMaxEmuInstances; i++) + { + if (i == sourceinst) continue; + if (!emuInstances[i]) continue; + + emuInstances[i]->updateConfigInfo(kind); + } +} + + void pathInit() { // First, check for the portable directory next to the executable. diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 77cdf4ee..b247d1fd 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -31,6 +31,11 @@ #include "ScreenLayout.h" #include "MPInterface.h" +enum +{ + Config_RecentFiles, +}; + class MelonApplication : public QApplication { Q_OBJECT @@ -50,6 +55,8 @@ void deleteEmuInstance(int id); void deleteAllEmuInstances(int first = 0); int numEmuInstances(); +void updateConfigInfoAll(int kind, int sourceinst); + void setMPInterface(melonDS::MPInterfaceType type); #endif // MAIN_H