lay base for keeping config in sync across multiple instances

This commit is contained in:
Arisotura 2024-10-27 10:02:57 +01:00
parent 2bf0eb7ead
commit 24ca1a5fdb
6 changed files with 73 additions and 16 deletions

View File

@ -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, ...) void EmuInstance::osdAddMessage(unsigned int color, const char* fmt, ...)
{ {
if (fmt == nullptr) if (fmt == nullptr)

View File

@ -21,6 +21,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "main.h"
#include "NDS.h" #include "NDS.h"
#include "EmuThread.h" #include "EmuThread.h"
#include "Window.h" #include "Window.h"
@ -91,6 +92,8 @@ public:
Config::Table& getGlobalConfig() { return globalCfg; } Config::Table& getGlobalConfig() { return globalCfg; }
Config::Table& getLocalConfig() { return localCfg; } Config::Table& getLocalConfig() { return localCfg; }
void updateConfigInfo(int kind);
std::string instanceFileSuffix(); std::string instanceFileSuffix();
void createWindow(); void createWindow();

View File

@ -271,7 +271,8 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
setStyleSheet("QMenuBar::item { padding: 4px 8px; }"); setStyleSheet("QMenuBar::item { padding: 4px 8px; }");
#endif #endif
hasMenu = (!parent); //hasMenu = (!parent);
hasMenu = true;
if (hasMenu) if (hasMenu)
{ {
@ -288,15 +289,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
actOpenROMArchive->setShortcut(QKeySequence(Qt::Key_O | Qt::CTRL | Qt::SHIFT));*/ actOpenROMArchive->setShortcut(QKeySequence(Qt::Key_O | Qt::CTRL | Qt::SHIFT));*/
recentMenu = menu->addMenu("Open recent"); recentMenu = menu->addMenu("Open recent");
Config::Array recentROMs = globalCfg.GetArray("RecentROM"); loadRecentFilesMenu(true);
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();
//actBootFirmware = menu->addAction("Launch DS menu"); //actBootFirmware = menu->addAction("Launch DS menu");
actBootFirmware = menu->addAction("Boot firmware"); actBootFirmware = menu->addAction("Boot firmware");
@ -1280,12 +1273,23 @@ void MainWindow::onClearRecentFiles()
updateRecentFilesMenu(); updateRecentFilesMenu();
} }
void MainWindow::updateRecentFilesMenu() void MainWindow::loadRecentFilesMenu(bool loadcfg)
{ {
recentMenu->clear(); if (loadcfg)
{
recentFileList.clear();
Config::Array recentroms = globalCfg.GetArray("RecentROM"); Config::Array recentROMs = globalCfg.GetArray("RecentROM");
recentroms.Clear(); 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) 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)); QAction *actRecentFile_i = recentMenu->addAction(QString("%1. %2").arg(i+1).arg(item_display));
actRecentFile_i->setData(item_full); actRecentFile_i->setData(item_full);
connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile); connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile);
recentroms.SetQString(i, recentFileList.at(i));
} }
while (recentFileList.size() > 10) while (recentFileList.size() > 10)
@ -1330,8 +1332,24 @@ void MainWindow::updateRecentFilesMenu()
if (recentFileList.empty()) if (recentFileList.empty())
actClearRecentList->setEnabled(false); 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(); Config::Save();
loadRecentFilesMenu(false);
updateConfigInfoAll(Config_RecentFiles, emuInstance->getInstanceID());
} }
void MainWindow::onClickRecentFile() void MainWindow::onClickRecentFile()

View File

@ -134,6 +134,8 @@ public:
// called when the MP interface is changed // called when the MP interface is changed
void updateMPInterface(melonDS::MPInterfaceType type); void updateMPInterface(melonDS::MPInterfaceType type);
void loadRecentFilesMenu(bool loadcfg);
protected: protected:
void keyPressEvent(QKeyEvent* event) override; void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override;

View File

@ -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() void pathInit()
{ {
// First, check for the portable directory next to the executable. // First, check for the portable directory next to the executable.

View File

@ -31,6 +31,11 @@
#include "ScreenLayout.h" #include "ScreenLayout.h"
#include "MPInterface.h" #include "MPInterface.h"
enum
{
Config_RecentFiles,
};
class MelonApplication : public QApplication class MelonApplication : public QApplication
{ {
Q_OBJECT Q_OBJECT
@ -50,6 +55,8 @@ void deleteEmuInstance(int id);
void deleteAllEmuInstances(int first = 0); void deleteAllEmuInstances(int first = 0);
int numEmuInstances(); int numEmuInstances();
void updateConfigInfoAll(int kind, int sourceinst);
void setMPInterface(melonDS::MPInterfaceType type); void setMPInterface(melonDS::MPInterfaceType type);
#endif // MAIN_H #endif // MAIN_H