mirror of https://github.com/mgba-emu/mgba.git
Qt: Unified file opening and saving with last location
This commit is contained in:
parent
0378fa229d
commit
bbac206364
1
CHANGES
1
CHANGES
|
@ -47,6 +47,7 @@ Misc:
|
||||||
- All: Enable static linking for Windows
|
- All: Enable static linking for Windows
|
||||||
- All: Enable static linking for OS X
|
- All: Enable static linking for OS X
|
||||||
- Qt: Migrate multiplayer window handling into GBAApp
|
- Qt: Migrate multiplayer window handling into GBAApp
|
||||||
|
- Qt: Unified file opening and saving with last location
|
||||||
|
|
||||||
0.2.1: (2015-05-13)
|
0.2.1: (2015-05-13)
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "CheatsView.h"
|
#include "CheatsView.h"
|
||||||
|
|
||||||
|
#include "GBAApp.h"
|
||||||
#include "GameController.h"
|
#include "GameController.h"
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QFileDialog>
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "gba/cheats.h"
|
#include "gba/cheats.h"
|
||||||
|
@ -64,14 +64,14 @@ bool CheatsView::eventFilter(QObject* object, QEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatsView::load() {
|
void CheatsView::load() {
|
||||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select cheats file"));
|
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select cheats file"));
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_model.loadFile(filename);
|
m_model.loadFile(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatsView::save() {
|
void CheatsView::save() {
|
||||||
QString filename = QFileDialog::getSaveFileName(this, tr("Select cheats file"));
|
QString filename = GBAApp::app()->getSaveFileName(this, tr("Select cheats file"));
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_model.saveFile(filename);
|
m_model.saveFile(filename);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include "GameController.h"
|
#include "GameController.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QFileOpenEvent>
|
#include <QFileOpenEvent>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -22,6 +24,7 @@ GBAApp* g_app = nullptr;
|
||||||
|
|
||||||
GBAApp::GBAApp(int& argc, char* argv[])
|
GBAApp::GBAApp(int& argc, char* argv[])
|
||||||
: QApplication(argc, argv)
|
: QApplication(argc, argv)
|
||||||
|
, m_windows{}
|
||||||
{
|
{
|
||||||
g_app = this;
|
g_app = this;
|
||||||
|
|
||||||
|
@ -85,6 +88,44 @@ Window* GBAApp::newWindow() {
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window* GBAApp::newWindow() {
|
GBAApp* GBAApp::app() {
|
||||||
return g_app->newWindowInternal();
|
return g_app;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GBAApp::interruptAll() {
|
||||||
|
for (int i = 0; i < MAX_GBAS; ++i) {
|
||||||
|
if (!m_windows[i] || !m_windows[i]->controller()->isLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
m_windows[i]->controller()->threadInterrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GBAApp::continueAll() {
|
||||||
|
for (int i = 0; i < MAX_GBAS; ++i) {
|
||||||
|
if (!m_windows[i] || !m_windows[i]->controller()->isLoaded()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
m_windows[i]->controller()->threadContinue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QString& filter) {
|
||||||
|
interruptAll();
|
||||||
|
QString filename = QFileDialog::getOpenFileName(owner, title, m_configController.getQtOption("lastDirectory").toString(), filter);
|
||||||
|
continueAll();
|
||||||
|
if (!filename.isEmpty()) {
|
||||||
|
m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path());
|
||||||
|
}
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QString& filter) {
|
||||||
|
interruptAll();
|
||||||
|
QString filename = QFileDialog::getSaveFileName(owner, title, m_configController.getQtOption("lastDirectory").toString(), filter);
|
||||||
|
continueAll();
|
||||||
|
if (!filename.isEmpty()) {
|
||||||
|
m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path());
|
||||||
|
}
|
||||||
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,16 @@ Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GBAApp(int& argc, char* argv[]);
|
GBAApp(int& argc, char* argv[]);
|
||||||
|
static GBAApp* app();
|
||||||
|
|
||||||
static Window* newWindow();
|
Window* newWindow();
|
||||||
|
|
||||||
|
QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = QString());
|
||||||
|
QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = QString());
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void interruptAll();
|
||||||
|
void continueAll();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent*);
|
bool event(QEvent*);
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
#ifdef USE_MAGICK
|
#ifdef USE_MAGICK
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include "GBAApp.h"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
@ -48,7 +49,7 @@ void GIFView::stopRecording() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GIFView::selectFile() {
|
void GIFView::selectFile() {
|
||||||
QString filename = QFileDialog::getSaveFileName(this, tr("Select output file"));
|
QString filename = GBAApp::app()->getSaveFileName(this, tr("Select output file"), tr("Graphics Interchange Format (*.gif)"));
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_ui.filename->setText(filename);
|
m_ui.filename->setText(filename);
|
||||||
if (!ImageMagickGIFEncoderIsOpen(&m_encoder)) {
|
if (!ImageMagickGIFEncoderIsOpen(&m_encoder)) {
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "PaletteView.h"
|
#include "PaletteView.h"
|
||||||
|
|
||||||
|
#include "GBAApp.h"
|
||||||
#include "VFileDevice.h"
|
#include "VFileDevice.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -83,7 +83,7 @@ void PaletteView::exportPalette(int start, int length) {
|
||||||
length = 512 - start;
|
length = 512 - start;
|
||||||
}
|
}
|
||||||
m_controller->threadInterrupt();
|
m_controller->threadInterrupt();
|
||||||
QString filename = QFileDialog::getSaveFileName(this, tr("Export palette"), QString(), tr("Windows PAL (*.pal);;Adobe Color Table (*.act)"));
|
QString filename = GBAApp::app()->getSaveFileName(this, tr("Export palette"), tr("Windows PAL (*.pal)"));
|
||||||
if (filename.isNull()) {
|
if (filename.isNull()) {
|
||||||
m_controller->threadContinue();
|
m_controller->threadContinue();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
|
|
||||||
#include "AudioProcessor.h"
|
#include "AudioProcessor.h"
|
||||||
#include "ConfigController.h"
|
#include "ConfigController.h"
|
||||||
|
#include "GBAApp.h"
|
||||||
#include <QFileDialog>
|
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
|
||||||
|
@ -65,7 +64,7 @@ SettingsView::SettingsView(ConfigController* controller, QWidget* parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsView::selectBios() {
|
void SettingsView::selectBios() {
|
||||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select BIOS"));
|
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_ui.bios->setText(filename);
|
m_ui.bios->setText(filename);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include "GBAApp.h"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
@ -212,7 +213,7 @@ void VideoView::stopRecording() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoView::selectFile() {
|
void VideoView::selectFile() {
|
||||||
QString filename = QFileDialog::getSaveFileName(this, tr("Select output file"));
|
QString filename = GBAApp::app()->getSaveFileName(this, tr("Select output file"));
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_ui.filename->setText(filename);
|
m_ui.filename->setText(filename);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
@ -216,10 +214,6 @@ void Window::saveConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::selectROM() {
|
void Window::selectROM() {
|
||||||
bool doPause = m_controller->isLoaded() && !m_controller->isPaused();
|
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(true);
|
|
||||||
}
|
|
||||||
QStringList formats{
|
QStringList formats{
|
||||||
"*.gba",
|
"*.gba",
|
||||||
#ifdef USE_LIBZIP
|
#ifdef USE_LIBZIP
|
||||||
|
@ -231,27 +225,15 @@ void Window::selectROM() {
|
||||||
"*.rom",
|
"*.rom",
|
||||||
"*.bin"};
|
"*.bin"};
|
||||||
QString filter = tr("Game Boy Advance ROMs (%1)").arg(formats.join(QChar(' ')));
|
QString filter = tr("Game Boy Advance ROMs (%1)").arg(formats.join(QChar(' ')));
|
||||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select ROM"), m_config->getQtOption("lastDirectory").toString(), filter);
|
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), filter);
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(false);
|
|
||||||
}
|
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path());
|
|
||||||
m_controller->loadGame(filename);
|
m_controller->loadGame(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::selectBIOS() {
|
void Window::selectBIOS() {
|
||||||
bool doPause = m_controller->isLoaded() && !m_controller->isPaused();
|
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(true);
|
|
||||||
}
|
|
||||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select BIOS"), m_config->getQtOption("lastDirectory").toString());
|
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(false);
|
|
||||||
}
|
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path());
|
|
||||||
m_config->setOption("bios", filename);
|
m_config->setOption("bios", filename);
|
||||||
m_config->updateOption("bios");
|
m_config->updateOption("bios");
|
||||||
m_config->setOption("useBios", true);
|
m_config->setOption("useBios", true);
|
||||||
|
@ -261,16 +243,8 @@ void Window::selectBIOS() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::selectPatch() {
|
void Window::selectPatch() {
|
||||||
bool doPause = m_controller->isLoaded() && !m_controller->isPaused();
|
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select patch"), tr("Patches (*.ips *.ups *.bps)"));
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(true);
|
|
||||||
}
|
|
||||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select patch"), m_config->getQtOption("lastDirectory").toString(), tr("Patches (*.ips *.ups *.bps)"));
|
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(false);
|
|
||||||
}
|
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path());
|
|
||||||
m_controller->loadPatch(filename);
|
m_controller->loadPatch(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,31 +256,15 @@ void Window::openView(QWidget* widget) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::importSharkport() {
|
void Window::importSharkport() {
|
||||||
bool doPause = m_controller->isLoaded() && !m_controller->isPaused();
|
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select save"), tr("GameShark saves (*.sps *.xps)"));
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(true);
|
|
||||||
}
|
|
||||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select save"), m_config->getQtOption("lastDirectory").toString(), tr("GameShark saves (*.sps *.xps)"));
|
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(false);
|
|
||||||
}
|
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path());
|
|
||||||
m_controller->importSharkport(filename);
|
m_controller->importSharkport(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::exportSharkport() {
|
void Window::exportSharkport() {
|
||||||
bool doPause = m_controller->isLoaded() && !m_controller->isPaused();
|
QString filename = GBAApp::app()->getSaveFileName(this, tr("Select save"), tr("GameShark saves (*.sps *.xps)"));
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(true);
|
|
||||||
}
|
|
||||||
QString filename = QFileDialog::getSaveFileName(this, tr("Select save"), m_config->getQtOption("lastDirectory").toString(), tr("GameShark saves (*.sps *.xps)"));
|
|
||||||
if (doPause) {
|
|
||||||
m_controller->setPaused(false);
|
|
||||||
}
|
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path());
|
|
||||||
m_controller->exportSharkport(filename);
|
m_controller->exportSharkport(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -713,7 +671,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
QAction* multiWindow = new QAction(tr("New multiplayer window"), fileMenu);
|
QAction* multiWindow = new QAction(tr("New multiplayer window"), fileMenu);
|
||||||
connect(multiWindow, &QAction::triggered, [this]() {
|
connect(multiWindow, &QAction::triggered, [this]() {
|
||||||
GBAApp::newWindow();
|
GBAApp::app()->newWindow();
|
||||||
});
|
});
|
||||||
addControlledAction(fileMenu, multiWindow, "multiWindow");
|
addControlledAction(fileMenu, multiWindow, "multiWindow");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue