DolphinQt: Properly handle quit events.

* Confirm stopping emulation when the window is closing, not just the "Stop" button
 * Don't resume if we were already paused when we got the quit event
 * Shutdown the core at the end of main() so we don't crash on exit
 * Miscellaneous other logic cleanups related to this
This commit is contained in:
waddlesplash
2015-09-12 13:10:38 -04:00
parent 436f1133dd
commit 831d8ef13f
4 changed files with 23 additions and 19 deletions

View File

@ -60,6 +60,7 @@ int main(int argc, char* argv[])
int retcode = app.exec(); int retcode = app.exec();
delete g_main_window; delete g_main_window;
Core::Shutdown();
UICommon::Shutdown(); UICommon::Shutdown();
return retcode; return retcode;
} }

View File

@ -4,6 +4,7 @@
#include <memory> #include <memory>
#include <QActionGroup> #include <QActionGroup>
#include <QCloseEvent>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
@ -62,7 +63,9 @@ DMainWindow::DMainWindow(QWidget* parent_widget)
StartGame(filename); StartGame(filename);
}); });
connect(m_ui->actionBrowse, &QAction::triggered, this, &DMainWindow::OnBrowse); connect(m_ui->actionBrowse, &QAction::triggered, this, &DMainWindow::OnBrowse);
connect(m_ui->actionExit, &QAction::triggered, this, &DMainWindow::OnExit); connect(m_ui->actionExit, &QAction::triggered, this, [&]() {
close();
});
connect(m_ui->actionListView, &QAction::triggered, this, &DMainWindow::OnGameListStyleChanged); connect(m_ui->actionListView, &QAction::triggered, this, &DMainWindow::OnGameListStyleChanged);
connect(m_ui->actionTreeView, &QAction::triggered, this, &DMainWindow::OnGameListStyleChanged); connect(m_ui->actionTreeView, &QAction::triggered, this, &DMainWindow::OnGameListStyleChanged);
@ -110,7 +113,10 @@ DMainWindow::~DMainWindow()
void DMainWindow::closeEvent(QCloseEvent* ce) void DMainWindow::closeEvent(QCloseEvent* ce)
{ {
Stop(); if (!OnStop())
ce->ignore();
else
QMainWindow::closeEvent(ce);
} }
// Emulation // Emulation
@ -231,14 +237,6 @@ void DMainWindow::OnBrowse()
m_game_tracker->ScanForGames(); m_game_tracker->ScanForGames();
} }
void DMainWindow::OnExit()
{
close();
if (Core::GetState() == Core::CORE_UNINITIALIZED || m_isStopping)
return;
Stop();
}
void DMainWindow::OnPlay() void DMainWindow::OnPlay()
{ {
if (Core::GetState() != Core::CORE_UNINITIALIZED) if (Core::GetState() != Core::CORE_UNINITIALIZED)
@ -262,9 +260,17 @@ bool DMainWindow::OnStop()
// Ask for confirmation in case the user accidentally clicked Stop / Escape // Ask for confirmation in case the user accidentally clicked Stop / Escape
if (SConfig::GetInstance().bConfirmStop) if (SConfig::GetInstance().bConfirmStop)
{ {
// Pause emulation // Pause emulation if it isn't already
Core::SetState(Core::CORE_PAUSE); bool wasPaused = false;
emit CoreStateChanged(Core::CORE_PAUSE); if (Core::GetState() == Core::CORE_PAUSE)
{
wasPaused = true;
}
else
{
Core::SetState(Core::CORE_PAUSE);
emit CoreStateChanged(Core::CORE_PAUSE);
}
QMessageBox::StandardButton ret = QMessageBox::question(m_render_widget.get(), tr("Please confirm..."), QMessageBox::StandardButton ret = QMessageBox::question(m_render_widget.get(), tr("Please confirm..."),
tr("Do you want to stop the current emulation?"), tr("Do you want to stop the current emulation?"),
@ -272,7 +278,8 @@ bool DMainWindow::OnStop()
if (ret == QMessageBox::No) if (ret == QMessageBox::No)
{ {
DoStartPause(); if (!wasPaused)
DoStartPause();
return false; return false;
} }
} }

View File

@ -44,7 +44,6 @@ private slots:
// Main toolbar // Main toolbar
void OnBrowse(); void OnBrowse();
void OnExit();
void OnPlay(); void OnPlay();
void OnReset(); void OnReset();

View File

@ -19,10 +19,7 @@ protected:
void mousePressEvent(QMouseEvent*) override {} void mousePressEvent(QMouseEvent*) override {}
void paintEvent(QPaintEvent*) override {} void paintEvent(QPaintEvent*) override {}
private slots: private:
void closeEvent(QCloseEvent* e) override; void closeEvent(QCloseEvent* e) override;
signals:
void Closed();
}; };