12,925
回編集
(→画面のロック) |
(→ハイバネート) |
||
228行目: | 228行目: | ||
== ハイバネート == | == ハイバネート == | ||
* GNOME Power Managementコマンドを実行する場合 | |||
<syntaxhighlight lang="c++"> | <syntaxhighlight lang="c++"> | ||
#include <QProcess> | |||
void Converter::hibernate() | void Converter::hibernate() | ||
{ | { | ||
// GNOME Power Management コマンドを試行 | |||
if (QProcess::startDetached("gnome-power-cmd.sh hibernate") || | |||
QProcess::startDetached("gnome-power-cmd hibernate")) { | |||
qInfo() << "Hibernation initiated via GNOME Power Management."; | |||
return; | |||
} | |||
qWarning() << "GNOME Power Management commands failed. Trying DBus methods."; | |||
} | |||
</syntaxhighlight> | |||
<br> | |||
* D-Busを使用する場合 | |||
<syntaxhighlight lang="c++"> | |||
#include <QDBusInterface> | |||
#include <QDBusReply> | |||
#include <QDebug> | |||
void Converter::hibernate() | |||
{ | |||
// HAL (Hardware Abstraction Layer) を試行 | |||
QDBusInterface halPower("org.freedesktop.Hal", | |||
"/org/freedesktop/Hal/devices/computer", | |||
"org.freedesktop.Hal.Device.SystemPowerManagement", | |||
QDBusConnection::systemBus()); | |||
if (halPower.isValid()) { | |||
QDBusReply<void> reply = halPower.call("Hibernate"); | |||
if (reply.isValid()) { | |||
qInfo() << "Hibernation initiated via HAL."; | |||
return; | |||
} | } | ||
qWarning() << "HAL hibernation failed:" << reply.error().message(); | |||
} | |||
else { | |||
qWarning() << "Failed to connect to HAL power management."; | |||
} | } | ||
// DeviceKit Powerを試行 | |||
QDBusInterface dkPower("org.freedesktop.DeviceKit.Power", | |||
"/org/freedesktop/DeviceKit/Power", | |||
"org.freedesktop.DeviceKit.Power", | |||
QDBusConnection::systemBus()); | |||
if (dkPower.isValid()) { | |||
QDBusReply<void> reply = dkPower.call("Hibernate"); | |||
if (reply.isValid()) { | |||
qInfo() << "Hibernation initiated via DeviceKit Power."; | |||
return; | |||
} | } | ||
qWarning() << "DeviceKit Power hibernation failed:" << reply.error().message(); | |||
} | } | ||
else { | |||
qWarning() << "Failed to connect to DeviceKit Power."; | |||
} | |||
qCritical() << "All hibernation methods failed."; | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |