Qt: Add shutdown without saving menu option

This commit is contained in:
Connor McLaughlin 2021-01-08 23:42:17 +10:00
parent 6a04803502
commit b0398f5aa7
10 changed files with 43 additions and 5 deletions

View file

@ -374,6 +374,10 @@ void AndroidHostInterface::EmulationThreadEntryPoint(jobject emulation_activity,
EmulationThreadLoop(); EmulationThreadLoop();
thread_env->CallVoidMethod(m_emulation_activity_object, s_EmulationActivity_method_onEmulationStopped); thread_env->CallVoidMethod(m_emulation_activity_object, s_EmulationActivity_method_onEmulationStopped);
if (g_settings.save_state_on_exit)
SaveResumeSaveState();
PowerOffSystem(); PowerOffSystem();
DestroyImGuiContext(); DestroyImGuiContext();
thread_env->DeleteGlobalRef(m_emulation_activity_object); thread_env->DeleteGlobalRef(m_emulation_activity_object);

View file

@ -810,6 +810,7 @@ void MainWindow::updateEmulationActions(bool starting, bool running)
m_ui.actionResumeLastState->setDisabled(starting || running); m_ui.actionResumeLastState->setDisabled(starting || running);
m_ui.actionPowerOff->setDisabled(starting || !running); m_ui.actionPowerOff->setDisabled(starting || !running);
m_ui.actionPowerOffWithoutSaving->setDisabled(starting || !running);
m_ui.actionReset->setDisabled(starting || !running); m_ui.actionReset->setDisabled(starting || !running);
m_ui.actionPause->setDisabled(starting || !running); m_ui.actionPause->setDisabled(starting || !running);
m_ui.actionChangeDisc->setDisabled(starting || !running); m_ui.actionChangeDisc->setDisabled(starting || !running);
@ -926,6 +927,8 @@ void MainWindow::connectSignals()
connect(m_ui.actionAddGameDirectory, &QAction::triggered, connect(m_ui.actionAddGameDirectory, &QAction::triggered,
[this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); }); [this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); });
connect(m_ui.actionPowerOff, &QAction::triggered, m_host_interface, &QtHostInterface::powerOffSystem); connect(m_ui.actionPowerOff, &QAction::triggered, m_host_interface, &QtHostInterface::powerOffSystem);
connect(m_ui.actionPowerOffWithoutSaving, &QAction::triggered, m_host_interface,
&QtHostInterface::powerOffSystemWithoutSaving);
connect(m_ui.actionReset, &QAction::triggered, m_host_interface, &QtHostInterface::resetSystem); connect(m_ui.actionReset, &QAction::triggered, m_host_interface, &QtHostInterface::resetSystem);
connect(m_ui.actionPause, &QAction::toggled, [this](bool active) { m_host_interface->pauseSystem(active); }); connect(m_ui.actionPause, &QAction::toggled, [this](bool active) { m_host_interface->pauseSystem(active); });
connect(m_ui.actionScreenshot, &QAction::triggered, m_host_interface, &QtHostInterface::saveScreenshot); connect(m_ui.actionScreenshot, &QAction::triggered, m_host_interface, &QtHostInterface::saveScreenshot);

View file

@ -87,6 +87,7 @@
<addaction name="actionResumeLastState"/> <addaction name="actionResumeLastState"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionPowerOff"/> <addaction name="actionPowerOff"/>
<addaction name="actionPowerOffWithoutSaving"/>
<addaction name="actionReset"/> <addaction name="actionReset"/>
<addaction name="actionPause"/> <addaction name="actionPause"/>
<addaction name="menuChangeDisc"/> <addaction name="menuChangeDisc"/>
@ -790,6 +791,15 @@
<string>Open Data Directory...</string> <string>Open Data Directory...</string>
</property> </property>
</action> </action>
<action name="actionPowerOffWithoutSaving">
<property name="icon">
<iconset resource="resources/resources.qrc">
<normaloff>:/icons/process-stop.png</normaloff>:/icons/process-stop.png</iconset>
</property>
<property name="text">
<string>Power Off &amp;Without Saving</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="resources/resources.qrc"/> <include location="resources/resources.qrc"/>

View file

@ -808,6 +808,20 @@ void QtHostInterface::powerOffSystem()
return; return;
} }
if (g_settings.save_state_on_exit)
SaveResumeSaveState();
PowerOffSystem();
}
void QtHostInterface::powerOffSystemWithoutSaving()
{
if (!isOnWorkerThread())
{
QMetaObject::invokeMethod(this, "powerOffSystemWithoutSaving", Qt::QueuedConnection);
return;
}
PowerOffSystem(); PowerOffSystem();
} }

View file

@ -154,6 +154,7 @@ public Q_SLOTS:
void resumeSystemFromState(const QString& filename, bool boot_on_failure); void resumeSystemFromState(const QString& filename, bool boot_on_failure);
void resumeSystemFromMostRecentState(); void resumeSystemFromMostRecentState();
void powerOffSystem(); void powerOffSystem();
void powerOffSystemWithoutSaving();
void synchronousPowerOffSystem(); void synchronousPowerOffSystem();
void resetSystem(); void resetSystem();
void pauseSystem(bool paused, bool wait_until_paused = false); void pauseSystem(bool paused, bool wait_until_paused = false);

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View file

@ -92,6 +92,8 @@
<file>icons/preferences-desktop-keyboard-shortcuts@2x.png</file> <file>icons/preferences-desktop-keyboard-shortcuts@2x.png</file>
<file>icons/preferences-system.png</file> <file>icons/preferences-system.png</file>
<file>icons/preferences-system@2x.png</file> <file>icons/preferences-system@2x.png</file>
<file>icons/process-stop.png</file>
<file>icons/process-stop@2x.png</file>
<file>icons/software-update-available.png</file> <file>icons/software-update-available.png</file>
<file>icons/software-update-available@2x.png</file> <file>icons/software-update-available@2x.png</file>
<file>icons/star-0.png</file> <file>icons/star-0.png</file>

View file

@ -673,7 +673,11 @@ void SDLHostInterface::DrawMainMenuBar()
if (ImGui::MenuItem("Power Off", nullptr, false, system_enabled)) if (ImGui::MenuItem("Power Off", nullptr, false, system_enabled))
{ {
RunLater([this]() { DestroySystem(); }); RunLater([this]() {
if (g_settings.save_state_on_exit)
SaveResumeSaveState();
PowerOffSystem();
});
ClearImGuiFocus(); ClearImGuiFocus();
} }

View file

@ -174,9 +174,6 @@ void CommonHostInterface::PowerOffSystem()
if (System::IsShutdown()) if (System::IsShutdown())
return; return;
if (g_settings.save_state_on_exit)
SaveResumeSaveState();
HostInterface::PowerOffSystem(); HostInterface::PowerOffSystem();
if (InBatchMode()) if (InBatchMode())
@ -1489,6 +1486,9 @@ void CommonHostInterface::RegisterGeneralHotkeys()
} }
} }
if (g_settings.save_state_on_exit)
SaveResumeSaveState();
PowerOffSystem(); PowerOffSystem();
} }
}); });