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;
}
void GBAApp::interruptAll() {
void GBAApp::pauseAll(QList<int>* paused) {
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;
}
m_windows[i]->controller()->threadInterrupt();
m_windows[i]->controller()->setPaused(true);
paused->append(i);
}
}
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();
void GBAApp::continueAll(const QList<int>* paused) {
for (int i : *paused) {
m_windows[i]->controller()->setPaused(false);
}
}
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);
continueAll();
continueAll(&paused);
if (!filename.isEmpty()) {
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) {
interruptAll();
QList<int> paused;
pauseAll(&paused);
QString filename = QFileDialog::getSaveFileName(owner, title, m_configController.getQtOption("lastDirectory").toString(), filter);
continueAll();
continueAll(&paused);
if (!filename.isEmpty()) {
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) {
interruptAll();
QList<int> paused;
pauseAll(&paused);
QString filename = QFileDialog::getExistingDirectory(owner, title, m_configController.getQtOption("lastDirectory").toString());
continueAll();
continueAll(&paused);
if (!filename.isEmpty()) {
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() {
m_app->interruptAll();
QList<int> paused;
m_app->pauseAll(&paused);
bool didAccept = QFileDialog::exec() == QDialog::Accepted;
QStringList filenames = selectedFiles();
if (!filenames.isEmpty()) {
m_app->m_configController.setQtOption("lastDirectory", QFileInfo(filenames[0]).dir().path());
}
m_app->continueAll();
m_app->continueAll(&paused);
return didAccept;
}

View File

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