diff --git a/qt/src/EmuApplication.cpp b/qt/src/EmuApplication.cpp index b6c4a5e6..1a2bb8fb 100644 --- a/qt/src/EmuApplication.cpp +++ b/qt/src/EmuApplication.cpp @@ -642,6 +642,11 @@ QString EmuApplication::iconPrefix() return blackicons; } +std::string EmuApplication::getContentFolder() +{ + return core->getContentFolder(); +} + void EmuThread::runOnThread(std::function func, bool blocking) { if (QThread::currentThread() != this) diff --git a/qt/src/EmuApplication.hpp b/qt/src/EmuApplication.hpp index d23ac9e5..0936fb82 100644 --- a/qt/src/EmuApplication.hpp +++ b/qt/src/EmuApplication.hpp @@ -85,6 +85,7 @@ struct EmuApplication void stopThread(); bool isCoreActive(); QString iconPrefix(); + std::string getContentFolder(); std::vector> getCheatList(); void disableAllCheats(); diff --git a/qt/src/FoldersPanel.cpp b/qt/src/FoldersPanel.cpp index 8e3f3c0a..01c01047 100644 --- a/qt/src/FoldersPanel.cpp +++ b/qt/src/FoldersPanel.cpp @@ -3,6 +3,7 @@ #include "EmuConfig.hpp" #include #include +#include FoldersPanel::FoldersPanel(EmuApplication *app_) : app(app_) @@ -29,17 +30,6 @@ void FoldersPanel::connectEntry(QComboBox *combo, QLineEdit *lineEdit, QPushButt this->refreshEntry(combo, lineEdit, browse, location, folder); app->updateSettings(); }); - - QObject::connect(browse, &QPushButton::pressed, [=] { - QFileDialog dialog(this, tr("Select a Folder")); - dialog.setFileMode(QFileDialog::Directory); - dialog.setDirectory(QString::fromUtf8(*folder)); - if (!dialog.exec()) - return; - *folder = dialog.selectedFiles().at(0).toUtf8(); - lineEdit->setText(QString::fromUtf8(*folder)); - app->updateSettings(); - }); } void FoldersPanel::refreshData() @@ -53,18 +43,56 @@ void FoldersPanel::refreshData() void FoldersPanel::refreshEntry(QComboBox *combo, QLineEdit *lineEdit, QPushButton *browse, int *location, std::string *folder) { + QString rom_dir; bool custom = (*location == EmuConfig::eCustomDirectory); combo->setCurrentIndex(*location); if (custom) + { lineEdit->setText(QString::fromUtf8(*folder)); + } else if (*location == EmuConfig::eConfigDirectory) + { lineEdit->setText(tr("Config folder is %1").arg(app->config->findConfigDir().c_str())); - else - lineEdit->clear(); + } else + { + rom_dir = QString::fromStdString(app->getContentFolder()); + if (rom_dir.isEmpty()) + rom_dir = QString::fromStdString(app->config->last_rom_folder); + + lineEdit->setText("ROM Folder: " + rom_dir); + } lineEdit->setEnabled(custom); - browse->setEnabled(custom); + browse->disconnect(); + if (custom) + { + browse->setText(tr("Browse...")); + QObject::connect(browse, &QPushButton::pressed, [=] { + QFileDialog dialog(this, tr("Select a Folder")); + dialog.setFileMode(QFileDialog::Directory); + dialog.setDirectory(QString::fromUtf8(*folder)); + if (!dialog.exec()) + return; + *folder = dialog.selectedFiles().at(0).toUtf8(); + lineEdit->setText(QString::fromStdString(*folder)); + app->updateSettings(); + }); + } + else + { + QString dir{}; + if (*location == EmuConfig::eConfigDirectory) + dir = app->config->findConfigDir().c_str(); + else if (*location == EmuConfig::eROMDirectory) + dir = rom_dir; + + QObject::connect(browse, &QPushButton::pressed, [dir] { + QDesktopServices::openUrl(QUrl::fromLocalFile(dir)); + }); + lineEdit->setEnabled(custom); + browse->setText(tr("Open Folder...")); + } } void FoldersPanel::showEvent(QShowEvent *event) diff --git a/qt/src/Snes9xController.cpp b/qt/src/Snes9xController.cpp index c006066f..40562bed 100644 --- a/qt/src/Snes9xController.cpp +++ b/qt/src/Snes9xController.cpp @@ -1,6 +1,7 @@ #include "Snes9xController.hpp" #include "EmuConfig.hpp" #include "SoftwareScalers.hpp" +#include "fscompat.h" #include namespace fs = std::filesystem; @@ -855,3 +856,8 @@ int Snes9xController::modifyCheat(int index, std::string name, std::string code) { return S9xModifyCheatGroup(index, name, code); } + +std::string Snes9xController::getContentFolder() +{ + return S9xGetDirectory(ROMFILENAME_DIR); +} \ No newline at end of file diff --git a/qt/src/Snes9xController.hpp b/qt/src/Snes9xController.hpp index c69b681a..83814fa6 100644 --- a/qt/src/Snes9xController.hpp +++ b/qt/src/Snes9xController.hpp @@ -46,6 +46,7 @@ class Snes9xController int tryImportCheats(std::string filename); std::string validateCheat(std::string code); int modifyCheat(int index, std::string name, std::string code); + std::string getContentFolder(); std::string getStateFolder(); std::string config_folder;