Qt: Use filters for the forwarder file types

This commit is contained in:
Vicki Pfau 2022-11-04 06:38:50 -07:00
parent b48c7a1887
commit 91e62b8e72
3 changed files with 23 additions and 2 deletions

View File

@ -73,6 +73,17 @@ QString ForwarderGenerator::systemName(ForwarderGenerator::System system) {
return {};
}
QString ForwarderGenerator::systemHumanName(ForwarderGenerator::System system) {
switch (system) {
case ForwarderGenerator::System::N3DS:
return tr("3DS");
case ForwarderGenerator::System::VITA:
return tr("Vita");
}
return {};
}
QString ForwarderGenerator::base36(const QByteArray& bytes, int length) {
static const char* alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
QString buffer(length, 'X');

View File

@ -40,11 +40,13 @@ public:
virtual QList<QPair<QString, QSize>> imageTypes() const = 0;
virtual System system() const = 0;
QString systemName() const { return systemName(system()); }
QString systemHumanName() const { return systemHumanName(system()); }
virtual QString extension() const = 0;
virtual QStringList externalTools() const { return {}; }
static QString systemName(System);
static QString systemHumanName(System);
virtual void rebuild(const QString& source, const QString& target) = 0;

View File

@ -151,10 +151,18 @@ void ForwarderView::setSystem(ForwarderGenerator::System system) {
void ForwarderView::connectBrowseButton(QAbstractButton* button, QLineEdit* lineEdit, const QString& title, bool save, const QString& filter) {
connect(button, &QAbstractButton::clicked, lineEdit, [this, lineEdit, save, title, filter]() {
QString filename;
QString usedFilter = filter;
if (filter.isEmpty()) {
// Use the forwarder type, if selected
ForwarderGenerator* generator = m_controller.generator();
if (generator) {
usedFilter = tr("%1 installable package (*.%2)").arg(generator->systemHumanName()).arg(generator->extension());
}
}
if (save) {
filename = GBAApp::app()->getSaveFileName(this, title, filter);
filename = GBAApp::app()->getSaveFileName(this, title, usedFilter);
} else {
filename = GBAApp::app()->getOpenFileName(this, title, filter);
filename = GBAApp::app()->getOpenFileName(this, title, usedFilter);
}
if (filename.isEmpty()) {
return;