mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-12 16:23:07 -07:00
Use ConsoleKit to shutdown the system instead of HAL (deprecated)
use UPower to suspend the system instead of HAL (deprecated) Rewrote computer shutdown/suspend code to avoid data loss
This commit is contained in:
parent
eaac9180e5
commit
c63503aaa6
3 changed files with 21 additions and 11 deletions
17
src/misc.cpp
17
src/misc.cpp
|
@ -209,13 +209,16 @@ long long misc::freeDiskSpaceOnPath(QString path) {
|
||||||
#ifndef DISABLE_GUI
|
#ifndef DISABLE_GUI
|
||||||
void misc::shutdownComputer(bool sleep) {
|
void misc::shutdownComputer(bool sleep) {
|
||||||
#if defined(Q_WS_X11) && defined(QT_DBUS_LIB)
|
#if defined(Q_WS_X11) && defined(QT_DBUS_LIB)
|
||||||
// Use dbus to power off the system
|
// Use dbus to power off / suspend the system
|
||||||
// dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
|
if(sleep) {
|
||||||
QDBusInterface computer("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus());
|
QDBusInterface upowerIface("org.freedesktop.UPower", "/org/freedesktop/UPower",
|
||||||
if(sleep)
|
"org.freedesktop.UPower", QDBusConnection::systemBus());
|
||||||
computer.call("Suspend", 5);
|
upowerIface.call("Suspend");
|
||||||
else
|
} else {
|
||||||
computer.call("Shutdown");
|
QDBusInterface consolekitIface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager",
|
||||||
|
"org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus());
|
||||||
|
consolekitIface.call("Stop");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef Q_WS_MAC
|
#ifdef Q_WS_MAC
|
||||||
AEEventID EventToSend;
|
AEEventID EventToSend;
|
||||||
|
|
|
@ -95,7 +95,7 @@ QBtSession::QBtSession()
|
||||||
#ifndef DISABLE_GUI
|
#ifndef DISABLE_GUI
|
||||||
, geoipDBLoaded(false), resolve_countries(false)
|
, geoipDBLoaded(false), resolve_countries(false)
|
||||||
#endif
|
#endif
|
||||||
, m_tracker(0)
|
, m_tracker(0), m_shutdownAct(NO_SHUTDOWN)
|
||||||
{
|
{
|
||||||
BigRatioTimer = new QTimer(this);
|
BigRatioTimer = new QTimer(this);
|
||||||
BigRatioTimer->setInterval(10000);
|
BigRatioTimer->setInterval(10000);
|
||||||
|
@ -182,6 +182,10 @@ QBtSession::~QBtSession() {
|
||||||
qDebug("Deleting the session");
|
qDebug("Deleting the session");
|
||||||
delete s;
|
delete s;
|
||||||
qDebug("BTSession destructor OUT");
|
qDebug("BTSession destructor OUT");
|
||||||
|
if(m_shutdownAct != NO_SHUTDOWN) {
|
||||||
|
qDebug() << "Sending computer shutdown/suspend signal...";
|
||||||
|
misc::shutdownComputer(m_shutdownAct == SUSPEND_COMPUTER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QBtSession::preAllocateAllFiles(bool b) {
|
void QBtSession::preAllocateAllFiles(bool b) {
|
||||||
|
@ -2112,9 +2116,10 @@ void QBtSession::readAlerts() {
|
||||||
qDebug("Saving fast resume data");
|
qDebug("Saving fast resume data");
|
||||||
saveFastResumeData();
|
saveFastResumeData();
|
||||||
// Make sure preferences are synced before exiting
|
// Make sure preferences are synced before exiting
|
||||||
pref.sync();
|
if(suspend)
|
||||||
qDebug("Sending computer shutdown/suspend signal");
|
m_shutdownAct = SUSPEND_COMPUTER;
|
||||||
misc::shutdownComputer(suspend);
|
else
|
||||||
|
m_shutdownAct = SHUTDOWN_COMPUTER;
|
||||||
}
|
}
|
||||||
qDebug("Exiting the application");
|
qDebug("Exiting the application");
|
||||||
qApp->exit();
|
qApp->exit();
|
||||||
|
|
|
@ -69,6 +69,7 @@ public:
|
||||||
private:
|
private:
|
||||||
explicit QBtSession();
|
explicit QBtSession();
|
||||||
static QBtSession* m_instance;
|
static QBtSession* m_instance;
|
||||||
|
enum shutDownAction { NO_SHUTDOWN, SHUTDOWN_COMPUTER, SUSPEND_COMPUTER };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QBtSession* instance();
|
static QBtSession* instance();
|
||||||
|
@ -267,6 +268,7 @@ private:
|
||||||
// Tracker
|
// Tracker
|
||||||
QPointer<QTracker> m_tracker;
|
QPointer<QTracker> m_tracker;
|
||||||
TorrentSpeedMonitor *m_speedMonitor;
|
TorrentSpeedMonitor *m_speedMonitor;
|
||||||
|
shutDownAction m_shutdownAct;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue