mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2025-01-08 11:11:51 +00:00
GUI: add separate actions for hibernation/sleeping instead of just suspending
This commit is contained in:
parent
ddb5c21083
commit
a8f880b216
6
NEWS.md
6
NEWS.md
@ -8,9 +8,9 @@
|
||||
queue completion.
|
||||
* MKVToolNix GUI: implemented several built-in actions that can be executed
|
||||
either on special events or once via the "watch jobs" tool. These are:
|
||||
playing an audio file (implemented for all operating systems); suspending
|
||||
and shutting down the computer (only implemented for Windows and for Linux
|
||||
systems using systemd).
|
||||
playing an audio file (implemented for all operating systems); hibernating,
|
||||
sleeping and shutting down the computer (only implemented for Windows and
|
||||
for Linux systems using systemd).
|
||||
|
||||
## Bug fixes
|
||||
|
||||
|
@ -104,8 +104,11 @@ ProgramRunner::run(Util::Settings::RunProgramForEvent forEvent,
|
||||
else if (runConfig->m_type == Util::Settings::RunProgramType::ShutDownComputer)
|
||||
shutDownComputer(*runConfig);
|
||||
|
||||
else if (runConfig->m_type == Util::Settings::RunProgramType::SuspendComputer)
|
||||
suspendComputer(*runConfig);
|
||||
else if (runConfig->m_type == Util::Settings::RunProgramType::HibernateComputer)
|
||||
hibernateComputer(*runConfig);
|
||||
|
||||
else if (runConfig->m_type == Util::Settings::RunProgramType::SleepComputer)
|
||||
sleepComputer(*runConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,7 +218,12 @@ ProgramRunner::shutDownComputer(Util::Settings::RunProgramConfig &/* config */)
|
||||
}
|
||||
|
||||
void
|
||||
ProgramRunner::suspendComputer(Util::Settings::RunProgramConfig &/* config */) {
|
||||
ProgramRunner::hibernateComputer(Util::Settings::RunProgramConfig &/* config */) {
|
||||
// Not supported in an OS-agnostic way.
|
||||
}
|
||||
|
||||
void
|
||||
ProgramRunner::sleepComputer(Util::Settings::RunProgramConfig &/* config */) {
|
||||
// Not supported in an OS-agnostic way.
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,8 @@ protected:
|
||||
virtual void executeProgram(Util::Settings::RunProgramConfig &config, std::function<void(VariableMap &)> const &setupVariables, VariableMap const &generalVariables);
|
||||
virtual void playAudioFile(Util::Settings::RunProgramConfig &config);
|
||||
virtual void shutDownComputer(Util::Settings::RunProgramConfig &config);
|
||||
virtual void suspendComputer(Util::Settings::RunProgramConfig &config);
|
||||
virtual void hibernateComputer(Util::Settings::RunProgramConfig &config);
|
||||
virtual void sleepComputer(Util::Settings::RunProgramConfig &config);
|
||||
|
||||
public:
|
||||
static std::unique_ptr<ProgramRunner> create();
|
||||
|
@ -24,7 +24,7 @@ LinuxProgramRunner::isRunProgramTypeSupported(Util::Settings::RunProgramType typ
|
||||
if (ProgramRunner::isRunProgramTypeSupported(type))
|
||||
return true;
|
||||
|
||||
return mtx::included_in(type, Util::Settings::RunProgramType::ShutDownComputer, Util::Settings::RunProgramType::SuspendComputer);
|
||||
return mtx::included_in(type, Util::Settings::RunProgramType::ShutDownComputer, Util::Settings::RunProgramType::HibernateComputer, Util::Settings::RunProgramType::SleepComputer);
|
||||
}
|
||||
|
||||
void
|
||||
@ -40,15 +40,24 @@ LinuxProgramRunner::shutDownComputer(Util::Settings::RunProgramConfig &) {
|
||||
}
|
||||
|
||||
void
|
||||
LinuxProgramRunner::suspendComputer(Util::Settings::RunProgramConfig &) {
|
||||
qDebug() << "LinuxProgramRunner::suspendComputer: about to shut down the computer via systemctl";
|
||||
LinuxProgramRunner::hibernateOrSleepComputer(bool hibernate) {
|
||||
auto action = Q(hibernate ? "hibernate" : "suspend");
|
||||
qDebug() << "LinuxProgramRunner::hibernateOrSleepComputer: about to" << action << "the computer via systemctl";
|
||||
|
||||
auto result = QProcess::execute("systemctl suspend");
|
||||
auto result = QProcess::execute(Q("systemctl %1").arg(action));
|
||||
|
||||
if (result == 0)
|
||||
return;
|
||||
if (result != 0)
|
||||
qDebug() << "LinuxProgramRunner::hibernateOrSleepComputer: 'systemctl" << action << "' failed:" << result;
|
||||
}
|
||||
|
||||
qDebug() << "LinuxProgramRunner::suspendComputer: 'systemctl poweroff' failed:" << result;
|
||||
void
|
||||
LinuxProgramRunner::hibernateComputer(Util::Settings::RunProgramConfig &) {
|
||||
hibernateOrSleepComputer(true);
|
||||
}
|
||||
|
||||
void
|
||||
LinuxProgramRunner::sleepComputer(Util::Settings::RunProgramConfig &) {
|
||||
hibernateOrSleepComputer(false);
|
||||
}
|
||||
|
||||
}}}
|
||||
|
@ -22,7 +22,9 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void shutDownComputer(Util::Settings::RunProgramConfig &config) override;
|
||||
virtual void suspendComputer(Util::Settings::RunProgramConfig &config) override;
|
||||
virtual void hibernateComputer(Util::Settings::RunProgramConfig &config) override;
|
||||
virtual void sleepComputer(Util::Settings::RunProgramConfig &config) override;
|
||||
virtual void hibernateOrSleepComputer(bool hibernate);
|
||||
};
|
||||
|
||||
}}}
|
||||
|
@ -28,7 +28,7 @@ WindowsProgramRunner::isRunProgramTypeSupported(Util::Settings::RunProgramType t
|
||||
if (ProgramRunner::isRunProgramTypeSupported(type))
|
||||
return true;
|
||||
|
||||
return mtx::included_in(type, Util::Settings::RunProgramType::ShutDownComputer, Util::Settings::RunProgramType::SuspendComputer);
|
||||
return mtx::included_in(type, Util::Settings::RunProgramType::ShutDownComputer, Util::Settings::RunProgramType::HibernateComputer, Util::Settings::RunProgramType::SleepComputer);
|
||||
}
|
||||
|
||||
void
|
||||
@ -68,22 +68,27 @@ WindowsProgramRunner::shutDownComputer(Util::Settings::RunProgramConfig &) {
|
||||
}
|
||||
|
||||
void
|
||||
WindowsProgramRunner::suspendComputer(Util::Settings::RunProgramConfig &) {
|
||||
qDebug() << "WindowsProgramRunner::suspendComputer: about to hibernate";
|
||||
WindowsProgramRunner::hibernateOrSleepComputer(bool hibernate) {
|
||||
auto action = Q(hibernate ? "hibernate" : "sleep");
|
||||
qDebug() << "WindowsProgramRunner::hibernateOrSleepComputer: about to" << action;
|
||||
|
||||
addShutdownNamePrivilege();
|
||||
|
||||
if (SetSuspendState(true, false, false))
|
||||
if (SetSuspendState(hibernate, false, false))
|
||||
return;
|
||||
|
||||
auto error = GetLastError();
|
||||
qDebug() << "WindowsProgramRunner::suspendComputer: hibernate failed, about to sleep; error:" << error << Q(mtx::sys::format_windows_message(error));
|
||||
qDebug() << "WindowsProgramRunner::hibernateOrSleepComputer:" << action << "failed; error:" << error << Q(mtx::sys::format_windows_message(error));
|
||||
}
|
||||
|
||||
if (SetSuspendState(false, false, false))
|
||||
return;
|
||||
void
|
||||
WindowsProgramRunner::hibernateComputer(Util::Settings::RunProgramConfig &) {
|
||||
hibernateOrSleepComputer(true);
|
||||
}
|
||||
|
||||
error = GetLastError();
|
||||
qDebug() << "WindowsProgramRunner::suspendComputer: sleep failed, too. Not trying anything else. Error:" << error << Q(mtx::sys::format_windows_message(error));
|
||||
void
|
||||
WindowsProgramRunner::sleepComputer(Util::Settings::RunProgramConfig &) {
|
||||
hibernateOrSleepComputer(false);
|
||||
}
|
||||
|
||||
QString
|
||||
|
@ -22,7 +22,9 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void shutDownComputer(Util::Settings::RunProgramConfig &config) override;
|
||||
virtual void suspendComputer(Util::Settings::RunProgramConfig &config) override;
|
||||
virtual void hibernateComputer(Util::Settings::RunProgramConfig &config) override;
|
||||
virtual void sleepComputer(Util::Settings::RunProgramConfig &config) override;
|
||||
virtual void hibernateOrSleepComputer(bool hibernate);
|
||||
virtual void addShutdownNamePrivilege();
|
||||
};
|
||||
|
||||
|
@ -195,12 +195,14 @@ PrefsRunProgramWidget::setupTypeControl(Util::Settings::RunProgramConfig const &
|
||||
addItemIfSupported(QY("Execute a program"), Util::Settings::RunProgramType::ExecuteProgram);
|
||||
addItemIfSupported(QY("Play an audio file"), Util::Settings::RunProgramType::PlayAudioFile);
|
||||
addItemIfSupported(QY("Shut down the computer"), Util::Settings::RunProgramType::ShutDownComputer);
|
||||
addItemIfSupported(QY("Suspend the computer"), Util::Settings::RunProgramType::SuspendComputer);
|
||||
addItemIfSupported(QY("Hibernate the computer"), Util::Settings::RunProgramType::HibernateComputer);
|
||||
addItemIfSupported(QY("Sleep the computer"), Util::Settings::RunProgramType::SleepComputer);
|
||||
|
||||
d->pagesByType[Util::Settings::RunProgramType::ExecuteProgram] = d->ui->executeProgramTypePage;
|
||||
d->pagesByType[Util::Settings::RunProgramType::PlayAudioFile] = d->ui->playAudioFileTypePage;
|
||||
d->pagesByType[Util::Settings::RunProgramType::ShutDownComputer] = d->ui->emptyTypePage;
|
||||
d->pagesByType[Util::Settings::RunProgramType::SuspendComputer] = d->ui->emptyTypePage;
|
||||
d->pagesByType[Util::Settings::RunProgramType::ExecuteProgram] = d->ui->executeProgramTypePage;
|
||||
d->pagesByType[Util::Settings::RunProgramType::PlayAudioFile] = d->ui->playAudioFileTypePage;
|
||||
d->pagesByType[Util::Settings::RunProgramType::ShutDownComputer] = d->ui->emptyTypePage;
|
||||
d->pagesByType[Util::Settings::RunProgramType::HibernateComputer] = d->ui->emptyTypePage;
|
||||
d->pagesByType[Util::Settings::RunProgramType::SleepComputer] = d->ui->emptyTypePage;
|
||||
|
||||
showPageForType(cfg.m_type);
|
||||
|
||||
|
@ -51,11 +51,12 @@ Settings::RunProgramConfig::name()
|
||||
if (!m_name.isEmpty())
|
||||
return m_name;
|
||||
|
||||
return m_type == RunProgramType::ExecuteProgram ? nameForExternalProgram()
|
||||
: m_type == RunProgramType::PlayAudioFile ? nameForPlayAudioFile()
|
||||
: m_type == RunProgramType::ShutDownComputer ? QY("Shut down the computer")
|
||||
: m_type == RunProgramType::SuspendComputer ? QY("Suspend the computer")
|
||||
: Q("unknown");
|
||||
return m_type == RunProgramType::ExecuteProgram ? nameForExternalProgram()
|
||||
: m_type == RunProgramType::PlayAudioFile ? nameForPlayAudioFile()
|
||||
: m_type == RunProgramType::ShutDownComputer ? QY("Shut down the computer")
|
||||
: m_type == RunProgramType::HibernateComputer ? QY("Hibernate the computer")
|
||||
: m_type == RunProgramType::SleepComputer ? QY("Sleep the computer")
|
||||
: Q("unknown");
|
||||
}
|
||||
|
||||
QString
|
||||
@ -420,7 +421,8 @@ Settings::addDefaultRunProgramConfigurations(QSettings ®) {
|
||||
auto numConfigurationsBefore = m_runProgramConfigurations.count();
|
||||
|
||||
addDefaultRunProgramConfigurationForType(reg, RunProgramType::PlayAudioFile, [](RunProgramConfig &cfg) { cfg.m_audioFile = App::programRunner().defaultAudioFileName(); });
|
||||
addDefaultRunProgramConfigurationForType(reg, RunProgramType::SuspendComputer);
|
||||
addDefaultRunProgramConfigurationForType(reg, RunProgramType::SleepComputer);
|
||||
addDefaultRunProgramConfigurationForType(reg, RunProgramType::HibernateComputer);
|
||||
addDefaultRunProgramConfigurationForType(reg, RunProgramType::ShutDownComputer);
|
||||
|
||||
if (numConfigurationsBefore != m_runProgramConfigurations.count())
|
||||
|
@ -26,7 +26,8 @@ public:
|
||||
ExecuteProgram,
|
||||
PlayAudioFile,
|
||||
ShutDownComputer,
|
||||
SuspendComputer,
|
||||
HibernateComputer,
|
||||
SleepComputer,
|
||||
Max,
|
||||
Default = ExecuteProgram,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user