mirror of https://github.com/snes9xgit/snes9x.git
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:
parent
794b4fdc72
commit
55724eba1d
|
@ -642,6 +642,11 @@ QString EmuApplication::iconPrefix()
|
||||||
return blackicons;
|
return blackicons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string EmuApplication::getContentFolder()
|
||||||
|
{
|
||||||
|
return core->getContentFolder();
|
||||||
|
}
|
||||||
|
|
||||||
void EmuThread::runOnThread(std::function<void()> func, bool blocking)
|
void EmuThread::runOnThread(std::function<void()> func, bool blocking)
|
||||||
{
|
{
|
||||||
if (QThread::currentThread() != this)
|
if (QThread::currentThread() != this)
|
||||||
|
|
|
@ -85,6 +85,7 @@ struct EmuApplication
|
||||||
void stopThread();
|
void stopThread();
|
||||||
bool isCoreActive();
|
bool isCoreActive();
|
||||||
QString iconPrefix();
|
QString iconPrefix();
|
||||||
|
std::string getContentFolder();
|
||||||
|
|
||||||
std::vector<std::tuple<bool, std::string, std::string>> getCheatList();
|
std::vector<std::tuple<bool, std::string, std::string>> getCheatList();
|
||||||
void disableAllCheats();
|
void disableAllCheats();
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "EmuConfig.hpp"
|
#include "EmuConfig.hpp"
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
|
||||||
FoldersPanel::FoldersPanel(EmuApplication *app_)
|
FoldersPanel::FoldersPanel(EmuApplication *app_)
|
||||||
: app(app_)
|
: app(app_)
|
||||||
|
@ -29,17 +30,6 @@ void FoldersPanel::connectEntry(QComboBox *combo, QLineEdit *lineEdit, QPushButt
|
||||||
this->refreshEntry(combo, lineEdit, browse, location, folder);
|
this->refreshEntry(combo, lineEdit, browse, location, folder);
|
||||||
app->updateSettings();
|
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()
|
void FoldersPanel::refreshData()
|
||||||
|
@ -53,18 +43,56 @@ void FoldersPanel::refreshData()
|
||||||
|
|
||||||
void FoldersPanel::refreshEntry(QComboBox *combo, QLineEdit *lineEdit, QPushButton *browse, int *location, std::string *folder)
|
void FoldersPanel::refreshEntry(QComboBox *combo, QLineEdit *lineEdit, QPushButton *browse, int *location, std::string *folder)
|
||||||
{
|
{
|
||||||
|
QString rom_dir;
|
||||||
bool custom = (*location == EmuConfig::eCustomDirectory);
|
bool custom = (*location == EmuConfig::eCustomDirectory);
|
||||||
combo->setCurrentIndex(*location);
|
combo->setCurrentIndex(*location);
|
||||||
if (custom)
|
if (custom)
|
||||||
|
{
|
||||||
lineEdit->setText(QString::fromUtf8(*folder));
|
lineEdit->setText(QString::fromUtf8(*folder));
|
||||||
|
}
|
||||||
else if (*location == EmuConfig::eConfigDirectory)
|
else if (*location == EmuConfig::eConfigDirectory)
|
||||||
|
{
|
||||||
lineEdit->setText(tr("Config folder is %1").arg(app->config->findConfigDir().c_str()));
|
lineEdit->setText(tr("Config folder is %1").arg(app->config->findConfigDir().c_str()));
|
||||||
else
|
} else
|
||||||
lineEdit->clear();
|
{
|
||||||
|
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);
|
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)
|
void FoldersPanel::showEvent(QShowEvent *event)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "Snes9xController.hpp"
|
#include "Snes9xController.hpp"
|
||||||
#include "EmuConfig.hpp"
|
#include "EmuConfig.hpp"
|
||||||
#include "SoftwareScalers.hpp"
|
#include "SoftwareScalers.hpp"
|
||||||
|
#include "fscompat.h"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
namespace fs = std::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);
|
return S9xModifyCheatGroup(index, name, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Snes9xController::getContentFolder()
|
||||||
|
{
|
||||||
|
return S9xGetDirectory(ROMFILENAME_DIR);
|
||||||
|
}
|
|
@ -46,6 +46,7 @@ class Snes9xController
|
||||||
int tryImportCheats(std::string filename);
|
int tryImportCheats(std::string filename);
|
||||||
std::string validateCheat(std::string code);
|
std::string validateCheat(std::string code);
|
||||||
int modifyCheat(int index, std::string name, std::string code);
|
int modifyCheat(int index, std::string name, std::string code);
|
||||||
|
std::string getContentFolder();
|
||||||
|
|
||||||
std::string getStateFolder();
|
std::string getStateFolder();
|
||||||
std::string config_folder;
|
std::string config_folder;
|
||||||
|
|
Loading…
Reference in New Issue