Qt: Move ROM filter function to utils

This commit is contained in:
Vicki Pfau 2022-10-29 01:37:52 -07:00
parent c49f09dabc
commit 3b558a9509
4 changed files with 56 additions and 50 deletions

View File

@ -304,53 +304,6 @@ void Window::saveConfig() {
m_config->write();
}
QString Window::getFilters() const {
QStringList filters;
QStringList formats;
#ifdef M_CORE_GBA
QStringList gbaFormats{
"*.gba",
#if defined(USE_LIBZIP) || defined(USE_MINIZIP)
"*.zip",
#endif
#ifdef USE_LZMA
"*.7z",
#endif
#ifdef USE_ELF
"*.elf",
#endif
"*.agb",
"*.mb",
"*.rom",
"*.bin"};
formats.append(gbaFormats);
filters.append(tr("Game Boy Advance ROMs (%1)").arg(gbaFormats.join(QChar(' '))));
#endif
#ifdef M_CORE_GB
QStringList gbFormats{
"*.gb",
"*.gbc",
"*.sgb",
#if defined(USE_LIBZIP) || defined(USE_MINIZIP)
"*.zip",
#endif
#ifdef USE_LZMA
"*.7z",
#endif
"*.rom",
"*.bin"};
formats.append(gbFormats);
filters.append(tr("Game Boy ROMs (%1)").arg(gbFormats.join(QChar(' '))));
#endif
formats.removeDuplicates();
filters.prepend(tr("All ROMs (%1)").arg(formats.join(QChar(' '))));
filters.append(tr("%1 Video Logs (*.mvl)").arg(projectName));
return filters.join(";;");
}
QString Window::getFiltersArchive() const {
QStringList filters;
@ -367,7 +320,7 @@ QString Window::getFiltersArchive() const {
}
void Window::selectROM() {
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), getFilters());
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), romFilters(true));
if (!filename.isEmpty()) {
setController(m_manager->loadGame(filename), filename);
}
@ -410,7 +363,7 @@ void Window::addDirToLibrary() {
#endif
void Window::replaceROM() {
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), getFilters());
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), romFilters());
if (!filename.isEmpty()) {
m_controller->replaceGame(filename);
}

View File

@ -187,7 +187,6 @@ private:
void updateTitle(float fps = -1);
QString getFilters() const;
QString getFiltersArchive() const;
CoreManager* m_manager;

View File

@ -5,6 +5,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "utils.h"
#include <mgba/core/version.h>
#include <QCoreApplication>
#include <QObject>
namespace QGBA {
@ -59,4 +62,53 @@ bool convertAddress(const QHostAddress* input, Address* output) {
return true;
}
QString romFilters(bool includeMvl) {
QStringList filters;
QStringList formats;
#ifdef M_CORE_GBA
QStringList gbaFormats{
"*.gba",
#if defined(USE_LIBZIP) || defined(USE_MINIZIP)
"*.zip",
#endif
#ifdef USE_LZMA
"*.7z",
#endif
#ifdef USE_ELF
"*.elf",
#endif
"*.agb",
"*.mb",
"*.rom",
"*.bin"};
formats.append(gbaFormats);
filters.append(QCoreApplication::translate("QGBA", "Game Boy Advance ROMs (%1)", nullptr).arg(gbaFormats.join(QChar(' '))));
#endif
#ifdef M_CORE_GB
QStringList gbFormats{
"*.gb",
"*.gbc",
"*.sgb",
#if defined(USE_LIBZIP) || defined(USE_MINIZIP)
"*.zip",
#endif
#ifdef USE_LZMA
"*.7z",
#endif
"*.rom",
"*.bin"};
formats.append(gbFormats);
filters.append(QCoreApplication::translate("QGBA", "Game Boy ROMs (%1)", nullptr).arg(gbFormats.join(QChar(' '))));
#endif
formats.removeDuplicates();
filters.prepend(QCoreApplication::translate("QGBA", "All ROMs (%1)", nullptr).arg(formats.join(QChar(' '))));
if (includeMvl) {
filters.append(QCoreApplication::translate("QGBA", "%1 Video Logs (*.mvl)", nullptr).arg(projectName));
}
return filters.join(";;");
}
}

View File

@ -67,4 +67,6 @@ constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
}
#endif
QString romFilters(bool includeMvl = false);
}