Qt: Pause instead of interrupting when opening a file dialog, as the file dialog can spin the event loop

This commit is contained in:
Jeffrey Pfau 2016-01-22 21:00:08 -08:00
parent 6e7851f614
commit 60b4a490e2
2 changed files with 22 additions and 21 deletions

View File

@ -124,28 +124,27 @@ GBAApp* GBAApp::app() {
return g_app; return g_app;
} }
void GBAApp::interruptAll() { void GBAApp::pauseAll(QList<int>* paused) {
for (int i = 0; i < MAX_GBAS; ++i) { for (int i = 0; i < MAX_GBAS; ++i) {
if (!m_windows[i] || !m_windows[i]->controller()->isLoaded()) { if (!m_windows[i] || !m_windows[i]->controller()->isLoaded() || m_windows[i]->controller()->isPaused()) {
continue; continue;
} }
m_windows[i]->controller()->threadInterrupt(); m_windows[i]->controller()->setPaused(true);
paused->append(i);
} }
} }
void GBAApp::continueAll() { void GBAApp::continueAll(const QList<int>* paused) {
for (int i = 0; i < MAX_GBAS; ++i) { for (int i : *paused) {
if (!m_windows[i] || !m_windows[i]->controller()->isLoaded()) { m_windows[i]->controller()->setPaused(false);
continue;
}
m_windows[i]->controller()->threadContinue();
} }
} }
QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QString& filter) { QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QString& filter) {
interruptAll(); QList<int> paused;
pauseAll(&paused);
QString filename = QFileDialog::getOpenFileName(owner, title, m_configController.getQtOption("lastDirectory").toString(), filter); QString filename = QFileDialog::getOpenFileName(owner, title, m_configController.getQtOption("lastDirectory").toString(), filter);
continueAll(); continueAll(&paused);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path()); m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path());
} }
@ -153,9 +152,10 @@ QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QStr
} }
QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QString& filter) { QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QString& filter) {
interruptAll(); QList<int> paused;
pauseAll(&paused);
QString filename = QFileDialog::getSaveFileName(owner, title, m_configController.getQtOption("lastDirectory").toString(), filter); QString filename = QFileDialog::getSaveFileName(owner, title, m_configController.getQtOption("lastDirectory").toString(), filter);
continueAll(); continueAll(&paused);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path()); m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path());
} }
@ -163,9 +163,10 @@ QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QStr
} }
QString GBAApp::getOpenDirectoryName(QWidget* owner, const QString& title) { QString GBAApp::getOpenDirectoryName(QWidget* owner, const QString& title) {
interruptAll(); QList<int> paused;
pauseAll(&paused);
QString filename = QFileDialog::getExistingDirectory(owner, title, m_configController.getQtOption("lastDirectory").toString()); QString filename = QFileDialog::getExistingDirectory(owner, title, m_configController.getQtOption("lastDirectory").toString());
continueAll(); continueAll(&paused);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path()); m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path());
} }
@ -220,12 +221,13 @@ GBAApp::FileDialog::FileDialog(GBAApp* app, QWidget* parent, const QString& capt
} }
int GBAApp::FileDialog::exec() { int GBAApp::FileDialog::exec() {
m_app->interruptAll(); QList<int> paused;
m_app->pauseAll(&paused);
bool didAccept = QFileDialog::exec() == QDialog::Accepted; bool didAccept = QFileDialog::exec() == QDialog::Accepted;
QStringList filenames = selectedFiles(); QStringList filenames = selectedFiles();
if (!filenames.isEmpty()) { if (!filenames.isEmpty()) {
m_app->m_configController.setQtOption("lastDirectory", QFileInfo(filenames[0]).dir().path()); m_app->m_configController.setQtOption("lastDirectory", QFileInfo(filenames[0]).dir().path());
} }
m_app->continueAll(); m_app->continueAll(&paused);
return didAccept; return didAccept;
} }

View File

@ -44,10 +44,6 @@ public:
const NoIntroDB* gameDB() const { return m_db; } const NoIntroDB* gameDB() const { return m_db; }
bool reloadGameDB(); bool reloadGameDB();
public slots:
void interruptAll();
void continueAll();
protected: protected:
bool event(QEvent*); bool event(QEvent*);
@ -64,6 +60,9 @@ private:
Window* newWindowInternal(); Window* newWindowInternal();
void pauseAll(QList<int>* paused);
void continueAll(const QList<int>* paused);
ConfigController m_configController; ConfigController m_configController;
Window* m_windows[MAX_GBAS]; Window* m_windows[MAX_GBAS];
MultiplayerController m_multiplayer; MultiplayerController m_multiplayer;