Browse Source

Set power state to idle when deconstructing class

adaptive-webui-19844
Chocobo1 1 year ago
parent
commit
d357cdd5f9
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 23
      src/gui/powermanagement/powermanagement.cpp
  2. 4
      src/gui/powermanagement/powermanagement.h

23
src/gui/powermanagement/powermanagement.cpp

@ -44,10 +44,15 @@ @@ -44,10 +44,15 @@
PowerManagement::PowerManagement(QObject *parent)
: QObject(parent)
{
#ifdef QBT_USES_DBUS
m_inhibitor = new PowerManagementInhibitor(this);
, m_inhibitor {new PowerManagementInhibitor(this)}
#endif
{
}
PowerManagement::~PowerManagement()
{
setIdle();
}
void PowerManagement::setActivityState(const bool busy)
@ -60,15 +65,16 @@ void PowerManagement::setActivityState(const bool busy) @@ -60,15 +65,16 @@ void PowerManagement::setActivityState(const bool busy)
void PowerManagement::setBusy()
{
if (m_busy) return;
if (m_busy)
return;
m_busy = true;
#ifdef Q_OS_WIN
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
::SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
#elif defined(QBT_USES_DBUS)
m_inhibitor->requestBusy();
#elif defined(Q_OS_MACOS)
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn
const IOReturn success = ::IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn
, tr("qBittorrent is active").toCFString(), &m_assertionID);
if (success != kIOReturnSuccess)
m_busy = false;
@ -77,14 +83,15 @@ void PowerManagement::setBusy() @@ -77,14 +83,15 @@ void PowerManagement::setBusy()
void PowerManagement::setIdle()
{
if (!m_busy) return;
if (!m_busy)
return;
m_busy = false;
#ifdef Q_OS_WIN
SetThreadExecutionState(ES_CONTINUOUS);
::SetThreadExecutionState(ES_CONTINUOUS);
#elif defined(QBT_USES_DBUS)
m_inhibitor->requestIdle();
#elif defined(Q_OS_MACOS)
IOPMAssertionRelease(m_assertionID);
::IOPMAssertionRelease(m_assertionID);
#endif
}

4
src/gui/powermanagement/powermanagement.h

@ -40,14 +40,14 @@ @@ -40,14 +40,14 @@
class PowerManagementInhibitor;
#endif
class PowerManagement : public QObject
class PowerManagement final : public QObject
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(PowerManagement)
public:
PowerManagement(QObject *parent = nullptr);
virtual ~PowerManagement() = default;
~PowerManagement() override;
void setActivityState(bool busy);

Loading…
Cancel
Save