Qt: Unified file opening and saving with last location
@@ -18,6 +18,7 @@ - All: Enable static linking for OS X
- All: Add --help flag for command line programs - Qt: Show version info in window title - 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;@@ -84,6 +87,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)) {
@@ -7,8 +7,7 @@ #include "SettingsView.h"
#include "AudioProcessor.h" #include "ConfigController.h" - -#include <QFileDialog> +#include "GBAApp.h" using namespace QGBA;@@ -62,7 +61,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>@@ -197,10 +195,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@@ -212,27 +206,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);@@ -242,16 +224,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); } }@@ -633,7 +607,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");