diff --git a/mythtv/programs/mythfrontend/exitprompt.cpp b/mythtv/programs/mythfrontend/exitprompt.cpp index 52776b74e31..63043afc439 100644 --- a/mythtv/programs/mythfrontend/exitprompt.cpp +++ b/mythtv/programs/mythfrontend/exitprompt.cpp @@ -15,8 +15,9 @@ ExitPrompter::ExitPrompter() : m_power(MythPower::AcquireRelease(this, true)) { - m_haltCommand = gCoreContext->GetSetting("HaltCommand",""); - m_rebootCommand = gCoreContext->GetSetting("RebootCommand",""); + m_haltCommand = gCoreContext->GetSetting("HaltCommand", ""); + m_rebootCommand = gCoreContext->GetSetting("RebootCommand", ""); + m_suspendCommand = gCoreContext->GetSetting("SuspendCommand", ""); } ExitPrompter::~ExitPrompter() @@ -101,6 +102,18 @@ void ExitPrompter::DoSuspend(bool Confirmed) if (!Confirmed) return; + // Use user specified command if it exists + if (!m_suspendCommand.isEmpty()) + { + uint ret = myth_system(m_suspendCommand); + if (ret == GENERIC_EXIT_OK) + return; + + LOG(VB_GENERAL, LOG_ERR, + "User defined SuspendCommand failed, falling back to " + "alternative methods."); + } + if (m_power && m_power->IsFeatureSupported(MythPower::FeatureSuspend)) m_power->RequestFeature(MythPower::FeatureSuspend); } @@ -131,13 +144,13 @@ void ExitPrompter::HandleExit() bool haveshutdown = !m_haltCommand.isEmpty(); bool havereboot = !m_rebootCommand.isEmpty(); - bool havesuspend = false; + bool havesuspend = !m_suspendCommand.isEmpty(); if (m_power) { havereboot |= m_power->IsFeatureSupported(MythPower::FeatureRestart); haveshutdown |= m_power->IsFeatureSupported(MythPower::FeatureShutdown); - havesuspend = m_power->IsFeatureSupported(MythPower::FeatureSuspend); + havesuspend |= m_power->IsFeatureSupported(MythPower::FeatureSuspend); } switch (gCoreContext->GetNumSetting("OverrideExitMenu", 0)) diff --git a/mythtv/programs/mythfrontend/exitprompt.h b/mythtv/programs/mythfrontend/exitprompt.h index 078d356a8ef..423455d8815 100644 --- a/mythtv/programs/mythfrontend/exitprompt.h +++ b/mythtv/programs/mythfrontend/exitprompt.h @@ -25,4 +25,5 @@ class ExitPrompter : public QObject MythPower* m_power { nullptr }; QString m_haltCommand; QString m_rebootCommand; + QString m_suspendCommand; }; diff --git a/mythtv/programs/mythfrontend/globalsettings.cpp b/mythtv/programs/mythfrontend/globalsettings.cpp index 5d2f59a31ff..96fcf1b401a 100644 --- a/mythtv/programs/mythfrontend/globalsettings.cpp +++ b/mythtv/programs/mythfrontend/globalsettings.cpp @@ -1912,7 +1912,7 @@ static HostSpinBoxSetting *FrontendIdleTimeout() return gs; } -static HostComboBoxSetting *OverrideExitMenu() +static HostComboBoxSetting *OverrideExitMenu(MythPower *Power) { auto *gc = new HostComboBoxSetting("OverrideExitMenu"); @@ -1932,12 +1932,11 @@ static HostComboBoxSetting *OverrideExitMenu() QString helptext = MainGeneralSettings::tr("By default, only remote frontends are shown " "the shutdown option on the exit menu. Here " - "you can force specific shutdown and reboot " + "you can force specific shutdown, reboot and suspend " "options to be displayed."); - MythPower* power = MythPower::AcquireRelease(gc, true); - if (power) + if (Power) { - QStringList supported = power->GetFeatureList(); + QStringList supported = Power->GetFeatureList(); if (!supported.isEmpty()) { helptext.prepend(MainGeneralSettings::tr( @@ -1948,46 +1947,68 @@ static HostComboBoxSetting *OverrideExitMenu() { helptext.append(MainGeneralSettings::tr( " This system appears to have no power options available. Try " - "setting the Halt/Reboot commands below.")); + "setting the Halt/Reboot/Suspend commands below.")); } - MythPower::AcquireRelease(gc, false); } gc->setHelpText(helptext); return gc; } -static HostTextEditSetting *RebootCommand() +static HostTextEditSetting *RebootCommand(MythPower *Power) { auto *ge = new HostTextEditSetting("RebootCommand"); - ge->setLabel(MainGeneralSettings::tr("Reboot command")); - ge->setValue(""); - - ge->setHelpText(MainGeneralSettings::tr("Optional. Script to run if you " - "select the reboot option from the " - "exit menu, if the option is " - "displayed. You must configure an " - "exit key to display the exit " - "menu.")); + QString help = MainGeneralSettings::tr( + "Optional. Script to run if you select the reboot option from the " + "exit menu, if the option is displayed. You must configure an " + "exit key to display the exit menu."); + if (Power && Power->IsFeatureSupported(MythPower::FeatureRestart)) + { + help.append(MainGeneralSettings::tr( + " Note: This system appears to support reboot without using this setting.")); + } + ge->setHelpText(help); return ge; } -static HostTextEditSetting *HaltCommand() +static HostTextEditSetting *SuspendCommand(MythPower *Power) { - auto *ge = new HostTextEditSetting("HaltCommand"); + auto *suspend = new HostTextEditSetting("SuspendCommand"); + suspend->setLabel(MainGeneralSettings::tr("Suspend command")); + suspend->setValue(""); + QString help = MainGeneralSettings::tr( + "Optional: Script to run if you select the suspend option from the " + "exit menu, if the option is displayed."); - ge->setLabel(MainGeneralSettings::tr("Halt command")); + if (Power && Power->IsFeatureSupported(MythPower::FeatureSuspend)) + { + help.append(MainGeneralSettings::tr( + " Note: This system appears to support suspend without using this setting.")); + } + suspend->setHelpText(help); + return suspend; +} +static HostTextEditSetting *HaltCommand(MythPower *Power) +{ + auto *ge = new HostTextEditSetting("HaltCommand"); + ge->setLabel(MainGeneralSettings::tr("Halt command")); ge->setValue(""); + QString help = MainGeneralSettings::tr("Optional. Script to run if you " + "select the shutdown option from " + "the exit menu, if the option is " + "displayed. You must configure an " + "exit key to display the exit " + "menu."); + if (Power && Power->IsFeatureSupported(MythPower::FeatureShutdown)) + { + help.append(MainGeneralSettings::tr( + " Note: This system appears to support shutdown without using this setting.")); + } - ge->setHelpText(MainGeneralSettings::tr("Optional. Script to run if you " - "select the shutdown option from " - "the exit menu, if the option is " - "displayed. You must configure an " - "exit key to display the exit " - "menu.")); + ge->setHelpText(help); return ge; } @@ -3915,26 +3936,33 @@ class ShutDownRebootSetting : public GroupSetting { public: ShutDownRebootSetting(); + private slots: - void childChanged(StandardSetting * /*setting*/) override; // StandardSetting + void childChanged(StandardSetting*) override; + private: - StandardSetting *m_overrideExitMenu {nullptr}; - StandardSetting *m_haltCommand {nullptr}; - StandardSetting *m_rebootCommand {nullptr}; + StandardSetting *m_overrideExitMenu { nullptr }; + StandardSetting *m_haltCommand { nullptr }; + StandardSetting *m_rebootCommand { nullptr }; + StandardSetting *m_suspendCommand { nullptr }; }; ShutDownRebootSetting::ShutDownRebootSetting() { setLabel(MainGeneralSettings::tr("Shutdown/Reboot Settings")); addChild(FrontendIdleTimeout()); - addChild(m_overrideExitMenu = OverrideExitMenu()); - addChild(m_haltCommand = HaltCommand()); - addChild(m_rebootCommand = RebootCommand()); + auto *power = MythPower::AcquireRelease(this, true); + addChild(m_overrideExitMenu = OverrideExitMenu(power)); + addChild(m_haltCommand = HaltCommand(power)); + addChild(m_rebootCommand = RebootCommand(power)); + addChild(m_suspendCommand = SuspendCommand(power)); + if (power) + MythPower::AcquireRelease(this, false); connect(m_overrideExitMenu,SIGNAL(valueChanged(StandardSetting *)), SLOT(childChanged(StandardSetting *))); } -void ShutDownRebootSetting::childChanged(StandardSetting * /*setting*/) +void ShutDownRebootSetting::childChanged(StandardSetting*) { switch (m_overrideExitMenu->getValue().toInt()) { @@ -3942,21 +3970,31 @@ void ShutDownRebootSetting::childChanged(StandardSetting * /*setting*/) case 4: m_haltCommand->setEnabled(true); m_rebootCommand->setEnabled(false); + m_suspendCommand->setEnabled(false); break; case 3: case 6: m_haltCommand->setEnabled(true); m_rebootCommand->setEnabled(true); + m_suspendCommand->setEnabled(false); break; case 5: m_haltCommand->setEnabled(false); m_rebootCommand->setEnabled(true); + m_suspendCommand->setEnabled(false); + break; + case 8: + case 9: + m_suspendCommand->setEnabled(true); + m_haltCommand->setEnabled(false); + m_rebootCommand->setEnabled(false); break; case 0: case 1: default: m_haltCommand->setEnabled(false); m_rebootCommand->setEnabled(false); + m_suspendCommand->setEnabled(false); break; } }