From b5cc5a2cf7abc4da07cf52f8d4c39eea2cff3968 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 24 May 2024 11:41:51 +0200 Subject: [PATCH] port some small fry to the new config system. --- src/frontend/qt_sdl/Config.cpp | 18 ++++++------------ src/frontend/qt_sdl/Config.h | 6 ++---- src/frontend/qt_sdl/ROMInfoDialog.cpp | 4 ++-- src/frontend/qt_sdl/Window.cpp | 26 +++++++++++++++----------- src/frontend/qt_sdl/Window.h | 2 ++ 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/frontend/qt_sdl/Config.cpp b/src/frontend/qt_sdl/Config.cpp index dc121336..a578266d 100644 --- a/src/frontend/qt_sdl/Config.cpp +++ b/src/frontend/qt_sdl/Config.cpp @@ -85,18 +85,6 @@ bool DirectLAN; bool SavestateRelocSRAM; -int AudioInterp; -int AudioBitDepth; -int AudioVolume; -bool DSiVolumeSync; -int MicInputType; -std::string MicDevice; -std::string MicWavPath; - -std::string LastROMFolder; - -std::string RecentROMList[10]; - std::string SaveFilePath; std::string SavestatePath; std::string CheatFilePath; @@ -411,6 +399,12 @@ size_t Array::Size() return Data.size(); } +void Array::Clear() +{ + toml::array newarray; + Data = newarray; +} + Array Array::GetArray(const int id) { while (Data.size() < id+1) diff --git a/src/frontend/qt_sdl/Config.h b/src/frontend/qt_sdl/Config.h index 7d45bf37..8f8857a3 100644 --- a/src/frontend/qt_sdl/Config.h +++ b/src/frontend/qt_sdl/Config.h @@ -78,6 +78,8 @@ public: size_t Size(); + void Clear(); + Array GetArray(const int id); int GetInt(const int id); @@ -197,10 +199,6 @@ extern bool DirectLAN; extern bool SavestateRelocSRAM; -extern std::string LastROMFolder; - -extern std::string RecentROMList[10]; - extern std::string SaveFilePath; extern std::string SavestatePath; extern std::string CheatFilePath; diff --git a/src/frontend/qt_sdl/ROMInfoDialog.cpp b/src/frontend/qt_sdl/ROMInfoDialog.cpp index 82e27efd..acc2e768 100644 --- a/src/frontend/qt_sdl/ROMInfoDialog.cpp +++ b/src/frontend/qt_sdl/ROMInfoDialog.cpp @@ -139,7 +139,7 @@ void ROMInfoDialog::on_saveIconButton_clicked() { QString filename = QFileDialog::getSaveFileName(this, "Save Icon", - QString::fromStdString(Config::LastROMFolder), + emuInstance->getGlobalConfig().GetQString("LastROMFolder"), "PNG Images (*.png)"); if (filename.isEmpty()) return; @@ -151,7 +151,7 @@ void ROMInfoDialog::on_saveAnimatedIconButton_clicked() { QString filename = QFileDialog::getSaveFileName(this, "Save Animated Icon", - QString::fromStdString(Config::LastROMFolder), + emuInstance->getGlobalConfig().GetQString("LastROMFolder"), "GIF Images (*.gif)"); if (filename.isEmpty()) return; diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 54240198..2dc01255 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -251,9 +251,11 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) : actOpenROMArchive->setShortcut(QKeySequence(Qt::Key_O | Qt::CTRL | Qt::SHIFT));*/ recentMenu = menu->addMenu("Open recent"); - for (int i = 0; i < 10; ++i) + Config::Array recentROMs = globalCfg.GetArray("RecentROM"); + int numrecent = std::min(kMaxRecentROMs, (int)recentROMs.Size()); + for (int i = 0; i < numrecent; ++i) { - std::string item = Config::RecentROMList[i]; + std::string item = recentROMs.GetString(i); if (!item.empty()) recentFileList.push_back(QString::fromStdString(item)); } @@ -1154,13 +1156,13 @@ QStringList MainWindow::pickROM(bool gba) const QString filename = QFileDialog::getOpenFileName( this, "Open " + console + " ROM", - QString::fromStdString(Config::LastROMFolder), + globalCfg.GetQString("LastROMFolder"), "All supported files (*" + allROMs + ")" + extraFilters ); if (filename.isEmpty()) return {}; - Config::LastROMFolder = QFileInfo(filename).dir().path().toStdString(); + globalCfg.SetQString("LastROMFolder", QFileInfo(filename).dir().path()); return splitArchivePath(filename, false); } @@ -1223,8 +1225,7 @@ void MainWindow::onOpenFile() void MainWindow::onClearRecentFiles() { recentFileList.clear(); - for (int i = 0; i < 10; i++) - Config::RecentROMList[i] = ""; + globalCfg.GetArray("RecentROM").Clear(); updateRecentFilesMenu(); } @@ -1232,9 +1233,12 @@ void MainWindow::updateRecentFilesMenu() { recentMenu->clear(); + Config::Array recentroms = globalCfg.GetArray("RecentROM"); + recentroms.Clear(); + for (int i = 0; i < recentFileList.size(); ++i) { - if (i >= 10) break; + if (i >= kMaxRecentROMs) break; QString item_full = recentFileList.at(i); QString item_display = item_full; @@ -1262,7 +1266,7 @@ void MainWindow::updateRecentFilesMenu() actRecentFile_i->setData(item_full); connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile); - Config::RecentROMList[i] = recentFileList.at(i).toStdString(); + recentroms.SetQString(i, recentFileList.at(i)); } while (recentFileList.size() > 10) @@ -1435,7 +1439,7 @@ void MainWindow::onSaveState() // TODO: specific 'last directory' for savestate files? QString qfilename = QFileDialog::getSaveFileName(this, "Save state", - QString::fromStdString(Config::LastROMFolder), + globalCfg.GetQString("LastROMFolder"), "melonDS savestates (*.mln);;Any file (*.*)"); if (qfilename.isEmpty()) { @@ -1477,7 +1481,7 @@ void MainWindow::onLoadState() // TODO: specific 'last directory' for savestate files? QString qfilename = QFileDialog::getOpenFileName(this, "Load state", - QString::fromStdString(Config::LastROMFolder), + globalCfg.GetQString("LastROMFolder"), "melonDS savestates (*.ml*);;Any file (*.*)"); if (qfilename.isEmpty()) { @@ -1526,7 +1530,7 @@ void MainWindow::onImportSavefile() emuThread->emuPause(); QString path = QFileDialog::getOpenFileName(this, "Select savefile", - QString::fromStdString(Config::LastROMFolder), + globalCfg.GetQString("LastROMFolder"), "Savefiles (*.sav *.bin *.dsv);;Any file (*.*)"); if (path.isEmpty()) diff --git a/src/frontend/qt_sdl/Window.h b/src/frontend/qt_sdl/Window.h index 85d7778d..c334c262 100644 --- a/src/frontend/qt_sdl/Window.h +++ b/src/frontend/qt_sdl/Window.h @@ -40,6 +40,8 @@ class EmuInstance; class EmuThread; +const int kMaxRecentROMs = 10; + /* class WindowBase : public QMainWindow {