|
|
@ -45,21 +45,28 @@ PowerManagementInhibitor::PowerManagementInhibitor(QObject *parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
delete m_busInterface; |
|
|
|
delete m_busInterface; |
|
|
|
|
|
|
|
|
|
|
|
m_busInterface = new QDBusInterface(u"org.freedesktop.PowerManagement"_s, u"/org/freedesktop/PowerManagement/Inhibit"_s |
|
|
|
m_busInterface = new QDBusInterface(u"org.freedesktop.login1"_s, u"/org/freedesktop/login1"_s |
|
|
|
, u"org.freedesktop.PowerManagement.Inhibit"_s, QDBusConnection::sessionBus(), this); |
|
|
|
, u"org.freedesktop.login1.Manager"_s, QDBusConnection::systemBus(), this); |
|
|
|
m_manager = ManagerType::Freedesktop; |
|
|
|
m_manager = ManagerType::Systemd; |
|
|
|
if (!m_busInterface->isValid()) |
|
|
|
if (!m_busInterface->isValid()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
delete m_busInterface; |
|
|
|
delete m_busInterface; |
|
|
|
m_busInterface = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_state = Error; |
|
|
|
m_busInterface = new QDBusInterface(u"org.freedesktop.PowerManagement"_s, u"/org/freedesktop/PowerManagement/Inhibit"_s |
|
|
|
|
|
|
|
, u"org.freedesktop.PowerManagement.Inhibit"_s, QDBusConnection::sessionBus(), this); |
|
|
|
|
|
|
|
m_manager = ManagerType::Freedesktop; |
|
|
|
|
|
|
|
if (!m_busInterface->isValid()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
delete m_busInterface; |
|
|
|
|
|
|
|
m_busInterface = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (m_busInterface) |
|
|
|
if (m_busInterface) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_busInterface->setTimeout(1000); |
|
|
|
m_busInterface->setTimeout(1000); |
|
|
|
|
|
|
|
m_state = Idle; |
|
|
|
LogMsg(tr("Power management found suitable D-Bus interface. Interface: %1").arg(m_busInterface->interface())); |
|
|
|
LogMsg(tr("Power management found suitable D-Bus interface. Interface: %1").arg(m_busInterface->interface())); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
@ -77,6 +84,13 @@ void PowerManagementInhibitor::requestIdle() |
|
|
|
m_state = RequestIdle; |
|
|
|
m_state = RequestIdle; |
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Requesting idle"); |
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Requesting idle"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_manager == ManagerType::Systemd) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QDBusUnixFileDescriptor dummy; |
|
|
|
|
|
|
|
m_fd.swap(dummy); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const QString method = (m_manager == ManagerType::Gnome) |
|
|
|
const QString method = (m_manager == ManagerType::Gnome) |
|
|
|
? u"Uninhibit"_s |
|
|
|
? u"Uninhibit"_s |
|
|
|
: u"UnInhibit"_s; |
|
|
|
: u"UnInhibit"_s; |
|
|
@ -95,9 +109,21 @@ void PowerManagementInhibitor::requestBusy() |
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Requesting busy"); |
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Requesting busy"); |
|
|
|
|
|
|
|
|
|
|
|
const QString message = u"Active torrents are currently present"_s; |
|
|
|
const QString message = u"Active torrents are currently present"_s; |
|
|
|
const auto args = (m_manager == ManagerType::Gnome) |
|
|
|
|
|
|
|
? QList<QVariant> {u"qBittorrent"_s, 0u, message, 4u} |
|
|
|
QList<QVariant> args; |
|
|
|
: QList<QVariant> {u"qBittorrent"_s, message}; |
|
|
|
switch (m_manager) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case ManagerType::Freedesktop: |
|
|
|
|
|
|
|
args = {u"qBittorrent"_s, message}; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case ManagerType::Gnome: |
|
|
|
|
|
|
|
args = {u"qBittorrent"_s, 0u, message, 4u}; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case ManagerType::Systemd: |
|
|
|
|
|
|
|
args = {u"sleep"_s, u"qBittorrent"_s, message, u"block"_s}; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const QDBusPendingCall pcall = m_busInterface->asyncCallWithArgumentList(u"Inhibit"_s, args); |
|
|
|
const QDBusPendingCall pcall = m_busInterface->asyncCallWithArgumentList(u"Inhibit"_s, args); |
|
|
|
const auto *watcher = new QDBusPendingCallWatcher(pcall, this); |
|
|
|
const auto *watcher = new QDBusPendingCallWatcher(pcall, this); |
|
|
|
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); |
|
|
|
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); |
|
|
@ -128,22 +154,45 @@ void PowerManagementInhibitor::onAsyncReply(QDBusPendingCallWatcher *call) |
|
|
|
} |
|
|
|
} |
|
|
|
else if (m_state == RequestBusy) |
|
|
|
else if (m_state == RequestBusy) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const QDBusPendingReply<quint32> reply = *call; |
|
|
|
if (m_manager == ManagerType::Systemd) |
|
|
|
|
|
|
|
|
|
|
|
if (reply.isError()) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); |
|
|
|
const QDBusPendingReply<QDBusUnixFileDescriptor> reply = *call; |
|
|
|
LogMsg(tr("Power management error. Action: %1. Error: %2").arg(u"RequestBusy"_s |
|
|
|
|
|
|
|
, reply.error().message()), Log::WARNING); |
|
|
|
if (reply.isError()) |
|
|
|
m_state = Error; |
|
|
|
{ |
|
|
|
|
|
|
|
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); |
|
|
|
|
|
|
|
LogMsg(tr("Power management error. Action: %1. Error: %2").arg(u"RequestBusy"_s |
|
|
|
|
|
|
|
, reply.error().message()), Log::WARNING); |
|
|
|
|
|
|
|
m_state = Error; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_state = Busy; |
|
|
|
|
|
|
|
m_fd = reply.value(); |
|
|
|
|
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie); |
|
|
|
|
|
|
|
if (m_intendedState == Idle) |
|
|
|
|
|
|
|
requestIdle(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_state = Busy; |
|
|
|
const QDBusPendingReply<quint32> reply = *call; |
|
|
|
m_cookie = reply.value(); |
|
|
|
|
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie); |
|
|
|
if (reply.isError()) |
|
|
|
if (m_intendedState == Idle) |
|
|
|
{ |
|
|
|
requestIdle(); |
|
|
|
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); |
|
|
|
|
|
|
|
LogMsg(tr("Power management error. Action: %1. Error: %2").arg(u"RequestBusy"_s |
|
|
|
|
|
|
|
, reply.error().message()), Log::WARNING); |
|
|
|
|
|
|
|
m_state = Error; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_state = Busy; |
|
|
|
|
|
|
|
m_cookie = reply.value(); |
|
|
|
|
|
|
|
qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie); |
|
|
|
|
|
|
|
if (m_intendedState == Idle) |
|
|
|
|
|
|
|
requestIdle(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|