Qt: Unified file opening and saving with last location
@@ -47,6 +47,7 @@ - GBA: GBARewind now returns how many states it has rewound
- All: Enable static linking for Windows - All: Enable static linking for OS X - Qt: Migrate multiplayer window handling into GBAApp + - Qt: Unified file opening and saving with last location 0.2.1: (2015-05-13) Bugfixes:
@@ -5,10 +5,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "CheatsView.h" +#include "GBAApp.h" #include "GameController.h" #include <QClipboard> -#include <QFileDialog> extern "C" { #include "gba/cheats.h"@@ -64,14 +64,14 @@ return false;
} 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()) { m_model.loadFile(filename); } } 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()) { m_model.saveFile(filename); }
@@ -9,6 +9,8 @@ #include "AudioProcessor.h"
#include "GameController.h" #include "Window.h" +#include <QFileDialog> +#include <QFileInfo> #include <QFileOpenEvent> extern "C" {@@ -22,6 +24,7 @@ GBAApp* g_app = nullptr;
GBAApp::GBAApp(int& argc, char* argv[]) : QApplication(argc, argv) + , m_windows{} { g_app = this;@@ -85,6 +88,44 @@ #endif
return w; } -Window* GBAApp::newWindow() { - return g_app->newWindowInternal(); +GBAApp* GBAApp::app() { + 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: GBAApp(int& argc, char* argv[]); + static GBAApp* app(); + + Window* newWindow(); - static 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: bool event(QEvent*);
@@ -7,7 +7,8 @@ #include "GIFView.h"
#ifdef USE_MAGICK -#include <QFileDialog> +#include "GBAApp.h" + #include <QMap> using namespace QGBA;@@ -48,7 +49,7 @@ m_ui.start->setEnabled(true);
} 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()) { m_ui.filename->setText(filename); if (!ImageMagickGIFEncoderIsOpen(&m_encoder)) {
@@ -5,9 +5,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "PaletteView.h" +#include "GBAApp.h" #include "VFileDevice.h" -#include <QFileDialog> #include <QFontDatabase> extern "C" {@@ -83,7 +83,7 @@ if (start + length > 512) {
length = 512 - start; } 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()) { m_controller->threadContinue(); return;
@@ -7,8 +7,7 @@ #include "SettingsView.h"
#include "AudioProcessor.h" #include "ConfigController.h" - -#include <QFileDialog> +#include "GBAApp.h" using namespace QGBA;@@ -65,7 +64,7 @@ connect(m_ui.buttonBox, SIGNAL(accepted()), this, SLOT(updateConfig()));
} void SettingsView::selectBios() { - QString filename = QFileDialog::getOpenFileName(this, tr("Select BIOS")); + QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS")); if (!filename.isEmpty()) { m_ui.bios->setText(filename); }
@@ -7,7 +7,8 @@ #include "VideoView.h"
#ifdef USE_FFMPEG -#include <QFileDialog> +#include "GBAApp.h" + #include <QMap> using namespace QGBA;@@ -212,7 +213,7 @@ validateSettings();
} 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()) { m_ui.filename->setText(filename); }
@@ -5,8 +5,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "Window.h" -#include <QFileDialog> -#include <QFileInfo> #include <QKeyEvent> #include <QKeySequence> #include <QMenuBar>@@ -216,10 +214,6 @@ m_config->write();
} void Window::selectROM() { - bool doPause = m_controller->isLoaded() && !m_controller->isPaused(); - if (doPause) { - m_controller->setPaused(true); - } QStringList formats{ "*.gba", #ifdef USE_LIBZIP@@ -231,27 +225,15 @@ #endif
"*.rom", "*.bin"}; 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); - if (doPause) { - m_controller->setPaused(false); - } + QString filename = GBAApp::app()->getOpenFileName(this, tr("Select ROM"), filter); if (!filename.isEmpty()) { - m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path()); m_controller->loadGame(filename); } } void Window::selectBIOS() { - bool doPause = m_controller->isLoaded() && !m_controller->isPaused(); - 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); - } + QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS")); if (!filename.isEmpty()) { - m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path()); m_config->setOption("bios", filename); m_config->updateOption("bios"); m_config->setOption("useBios", true);@@ -261,16 +243,8 @@ }
} void Window::selectPatch() { - bool doPause = m_controller->isLoaded() && !m_controller->isPaused(); - 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); - } + QString filename = GBAApp::app()->getOpenFileName(this, tr("Select patch"), tr("Patches (*.ips *.ups *.bps)")); if (!filename.isEmpty()) { - m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path()); m_controller->loadPatch(filename); } }@@ -282,31 +256,15 @@ widget->show();
} void Window::importSharkport() { - bool doPause = m_controller->isLoaded() && !m_controller->isPaused(); - 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); - } + QString filename = GBAApp::app()->getOpenFileName(this, tr("Select save"), tr("GameShark saves (*.sps *.xps)")); if (!filename.isEmpty()) { - m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path()); m_controller->importSharkport(filename); } } void Window::exportSharkport() { - bool doPause = m_controller->isLoaded() && !m_controller->isPaused(); - 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); - } + QString filename = GBAApp::app()->getSaveFileName(this, tr("Select save"), tr("GameShark saves (*.sps *.xps)")); if (!filename.isEmpty()) { - m_config->setQtOption("lastDirectory", QFileInfo(filename).dir().path()); m_controller->exportSharkport(filename); } }@@ -713,7 +671,7 @@
fileMenu->addSeparator(); QAction* multiWindow = new QAction(tr("New multiplayer window"), fileMenu); connect(multiWindow, &QAction::triggered, [this]() { - GBAApp::newWindow(); + GBAApp::app()->newWindow(); }); addControlledAction(fileMenu, multiWindow, "multiWindow");