mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Set power state to idle when deconstructing class
This commit is contained in:
parent
0f862fcf9f
commit
d357cdd5f9
2 changed files with 17 additions and 10 deletions
|
@ -44,10 +44,15 @@
|
||||||
|
|
||||||
PowerManagement::PowerManagement(QObject *parent)
|
PowerManagement::PowerManagement(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
|
||||||
#ifdef QBT_USES_DBUS
|
#ifdef QBT_USES_DBUS
|
||||||
m_inhibitor = new PowerManagementInhibitor(this);
|
, m_inhibitor {new PowerManagementInhibitor(this)}
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PowerManagement::~PowerManagement()
|
||||||
|
{
|
||||||
|
setIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerManagement::setActivityState(const bool busy)
|
void PowerManagement::setActivityState(const bool busy)
|
||||||
|
@ -60,15 +65,16 @@ void PowerManagement::setActivityState(const bool busy)
|
||||||
|
|
||||||
void PowerManagement::setBusy()
|
void PowerManagement::setBusy()
|
||||||
{
|
{
|
||||||
if (m_busy) return;
|
if (m_busy)
|
||||||
|
return;
|
||||||
m_busy = true;
|
m_busy = true;
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
|
::SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
|
||||||
#elif defined(QBT_USES_DBUS)
|
#elif defined(QBT_USES_DBUS)
|
||||||
m_inhibitor->requestBusy();
|
m_inhibitor->requestBusy();
|
||||||
#elif defined(Q_OS_MACOS)
|
#elif defined(Q_OS_MACOS)
|
||||||
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn
|
const IOReturn success = ::IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn
|
||||||
, tr("qBittorrent is active").toCFString(), &m_assertionID);
|
, tr("qBittorrent is active").toCFString(), &m_assertionID);
|
||||||
if (success != kIOReturnSuccess)
|
if (success != kIOReturnSuccess)
|
||||||
m_busy = false;
|
m_busy = false;
|
||||||
|
@ -77,14 +83,15 @@ void PowerManagement::setBusy()
|
||||||
|
|
||||||
void PowerManagement::setIdle()
|
void PowerManagement::setIdle()
|
||||||
{
|
{
|
||||||
if (!m_busy) return;
|
if (!m_busy)
|
||||||
|
return;
|
||||||
m_busy = false;
|
m_busy = false;
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
SetThreadExecutionState(ES_CONTINUOUS);
|
::SetThreadExecutionState(ES_CONTINUOUS);
|
||||||
#elif defined(QBT_USES_DBUS)
|
#elif defined(QBT_USES_DBUS)
|
||||||
m_inhibitor->requestIdle();
|
m_inhibitor->requestIdle();
|
||||||
#elif defined(Q_OS_MACOS)
|
#elif defined(Q_OS_MACOS)
|
||||||
IOPMAssertionRelease(m_assertionID);
|
::IOPMAssertionRelease(m_assertionID);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,14 +40,14 @@
|
||||||
class PowerManagementInhibitor;
|
class PowerManagementInhibitor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class PowerManagement : public QObject
|
class PowerManagement final : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DISABLE_COPY_MOVE(PowerManagement)
|
Q_DISABLE_COPY_MOVE(PowerManagement)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PowerManagement(QObject *parent = nullptr);
|
PowerManagement(QObject *parent = nullptr);
|
||||||
virtual ~PowerManagement() = default;
|
~PowerManagement() override;
|
||||||
|
|
||||||
void setActivityState(bool busy);
|
void setActivityState(bool busy);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue