Qt: Change browse button to "Open Folder" button when location isn't custom.

Enables quick access to the ROM directory or the config directory.
This commit is contained in:
BearOso 2024-05-25 12:04:58 -05:00
parent 794b4fdc72
commit 55724eba1d
5 changed files with 55 additions and 14 deletions

View File

@ -642,6 +642,11 @@ QString EmuApplication::iconPrefix()
return blackicons;
}
std::string EmuApplication::getContentFolder()
{
return core->getContentFolder();
}
void EmuThread::runOnThread(std::function<void()> func, bool blocking)
{
if (QThread::currentThread() != this)

View File

@ -85,6 +85,7 @@ struct EmuApplication
void stopThread();
bool isCoreActive();
QString iconPrefix();
std::string getContentFolder();
std::vector<std::tuple<bool, std::string, std::string>> getCheatList();
void disableAllCheats();

View File

@ -3,6 +3,7 @@
#include "EmuConfig.hpp"
#include <QSpinBox>
#include <QFileDialog>
#include <QDesktopServices>
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)

View File

@ -1,6 +1,7 @@
#include "Snes9xController.hpp"
#include "EmuConfig.hpp"
#include "SoftwareScalers.hpp"
#include "fscompat.h"
#include <filesystem>
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);
}

View File

@ -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;