Skip to content

Commit

Permalink
GlobalSettings: Add suspend command setting
Browse files Browse the repository at this point in the history
- and extend the help text to hint to the user that the various extra
settings may not be needed
  • Loading branch information
mark-kendall committed Jan 27, 2020
1 parent ee66508 commit 7238608
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 38 deletions.
21 changes: 17 additions & 4 deletions mythtv/programs/mythfrontend/exitprompt.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions mythtv/programs/mythfrontend/exitprompt.h
Expand Up @@ -25,4 +25,5 @@ class ExitPrompter : public QObject
MythPower* m_power { nullptr };
QString m_haltCommand;
QString m_rebootCommand;
QString m_suspendCommand;
};
106 changes: 72 additions & 34 deletions mythtv/programs/mythfrontend/globalsettings.cpp
Expand Up @@ -1912,7 +1912,7 @@ static HostSpinBoxSetting *FrontendIdleTimeout()
return gs;
}

static HostComboBoxSetting *OverrideExitMenu()
static HostComboBoxSetting *OverrideExitMenu(MythPower *Power)
{
auto *gc = new HostComboBoxSetting("OverrideExitMenu");

Expand All @@ -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(
Expand All @@ -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;
}

Expand Down Expand Up @@ -3915,48 +3936,65 @@ 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())
{
case 2:
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;
}
}
Expand Down

0 comments on commit 7238608

Please sign in to comment.