mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 20:44:15 +00:00
Set power state to idle when deconstructing class
This commit is contained in:
parent
0f862fcf9f
commit
d357cdd5f9
@ -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)
|
||||
|
||||
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()
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -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…
x
Reference in New Issue
Block a user