Skip to content

Commit

Permalink
Qt: Change browse button to "Open Folder" button when location isn't …
Browse files Browse the repository at this point in the history
…custom.

Enables quick access to the ROM directory or the config directory.
  • Loading branch information
bearoso committed May 25, 2024
1 parent 794b4fd commit 55724eb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
5 changes: 5 additions & 0 deletions qt/src/EmuApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions qt/src/EmuApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
56 changes: 42 additions & 14 deletions qt/src/FoldersPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "EmuConfig.hpp"
#include <QSpinBox>
#include <QFileDialog>
#include <QDesktopServices>

FoldersPanel::FoldersPanel(EmuApplication *app_)
: app(app_)
Expand All @@ -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()
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions qt/src/Snes9xController.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Snes9xController.hpp"
#include "EmuConfig.hpp"
#include "SoftwareScalers.hpp"
#include "fscompat.h"
#include <filesystem>
namespace fs = std::filesystem;

Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions qt/src/Snes9xController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 55724eb

Please sign in to comment.