lay base for keeping config in sync across multiple instances
This commit is contained in:
parent
2bf0eb7ead
commit
24ca1a5fdb
|
@ -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)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue