Commit a6c2fcc8 authored by Lukáš Tinkl's avatar Lukáš Tinkl
Browse files

Add hybrid suspend method to libsolid

REVIEW: 109351
CCBUG: 302968
parent e7d9cd21
......@@ -7,12 +7,16 @@
<signal name="CanHibernateChanged">
<arg type="b" name="can_hibernate" direction="out"/>
</signal>
<signal name="CanHybridSuspendChanged">
<arg type="b" name="can_hybrid_suspend" direction="out"/>
</signal>
<signal name="PowerSaveStatusChanged">
<arg type="b" name="save_power" direction="out"/>
</signal>
<method name="Suspend"/>
<method name="Hibernate"/>
<method name="HybridSuspend"/>
<method name="CanSuspend">
<arg type="b" name="can_suspend" direction="out"/>
......@@ -20,6 +24,9 @@
<method name="CanHibernate">
<arg type="b" name="can_hibernate" direction="out"/>
</method>
<method name="CanHybridSuspend">
<arg type="b" name="can_hybrid_suspend" direction="out"/>
</method>
<method name="GetPowerSaveStatus">
<arg type="b" name="save_power" direction="out"/>
</method>
......
/*
Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
Copyright 2013 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -48,6 +49,8 @@ Solid::PowerManagementPrivate::PowerManagementPrivate()
this, SLOT(slotCanSuspendChanged(bool)));
connect(&managerIface, SIGNAL(CanHibernateChanged(bool)),
this, SLOT(slotCanHibernateChanged(bool)));
connect(&managerIface, SIGNAL(CanHybridSuspendChanged(bool)),
this, SLOT(slotCanHybridSuspendChanged(bool)));
connect(&managerIface, SIGNAL(PowerSaveStatusChanged(bool)),
this, SLOT(slotPowerSaveStatusChanged(bool)));
connect(&serviceWatcher, SIGNAL(serviceRegistered(QString)),
......@@ -94,13 +97,15 @@ void Solid::PowerManagement::requestSleep(SleepState state, QObject *receiver, c
switch (state)
{
case StandbyState:
break;
case SuspendState:
globalPowerManager->managerIface.Suspend();
break;
case HibernateState:
globalPowerManager->managerIface.Hibernate();
break;
case HybridSuspendState:
globalPowerManager->managerIface.HybridSuspend();
break;
}
}
......@@ -215,6 +220,19 @@ void Solid::PowerManagementPrivate::slotCanHibernateChanged(bool newState)
}
}
void Solid::PowerManagementPrivate::slotCanHybridSuspendChanged(bool newState)
{
if (supportedSleepStates.contains(Solid::PowerManagement::HybridSuspendState) == newState) {
return;
}
if (newState) {
supportedSleepStates+= Solid::PowerManagement::HybridSuspendState;
} else {
supportedSleepStates-= Solid::PowerManagement::HybridSuspendState;
}
}
void Solid::PowerManagementPrivate::slotPowerSaveStatusChanged(bool newState)
{
if (powerSaveStatus == newState) {
......@@ -237,6 +255,10 @@ void Solid::PowerManagementPrivate::slotServiceRegistered(const QString &service
hibernateReply.waitForFinished();
slotCanHibernateChanged(hibernateReply.isValid() ? hibernateReply.value() : false);
QDBusPendingReply<bool> hybridSuspendReply = managerIface.CanHybridSuspend();
hybridSuspendReply.waitForFinished();
slotCanHybridSuspendChanged(hybridSuspendReply.isValid() ? hybridSuspendReply.value() : false);
QDBusPendingReply<bool> saveStatusReply = managerIface.GetPowerSaveStatus();
saveStatusReply.waitForFinished();
slotPowerSaveStatusChanged(saveStatusReply.isValid() ? saveStatusReply.value() : false);
......@@ -267,6 +289,7 @@ void Solid::PowerManagementPrivate::slotServiceUnregistered(const QString &servi
// Reset the values
slotCanSuspendChanged(false);
slotCanHibernateChanged(false);
slotCanHybridSuspendChanged(false);
slotPowerSaveStatusChanged(false);
} else {
// Disconnect the signal
......
/*
Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
Copyright 2013 Lukas Tinkl <ltinkl@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -47,12 +48,16 @@ namespace Solid
* - StandbyState: Processes are stopped, some hardware is deactivated (ACPI S1)
* - SuspendState: Most devices are deactivated, only RAM is powered (ACPI S3)
* - HibernateState: State of the machine is saved to disk, and the machine is powered down (ACPI S4)
* - HybridSleepState: The contents of RAM are first copied to non-volatile storage like for regular hibernation,
* but then, instead of powering down, the computer enters sleep mode
*/
enum SleepState { StandbyState = 1, SuspendState = 2, HibernateState = 4 };
enum SleepState { StandbyState = 1, SuspendState = 2, HibernateState = 4,
/// @since 4.11
HybridSuspendState = 8 };
/**
* Retrieves a high level indication of how applications should behave according to the
* power management subsystem. For example, when on battery power, this method will return
* power management subsystem. For example, when on battery power, this method will return
* true.
*
* @return whether apps should conserve power
......@@ -64,13 +69,12 @@ namespace Solid
* Retrieves the set of suspend methods supported by the system.
*
* @return the suspend methods supported by this system
* @see Solid::PowerManager::SuspendMethod
* @see Solid::PowerManager::SuspendMethods
* @see Solid::PowerManagement::SleepState
*/
SOLID_EXPORT QSet<SleepState> supportedSleepStates();
/**
* Requests that the system goes to sleep
* Requests that the system go to sleep
*
* @param state the sleep state use
* @param receiver the object to call a slot on once the operation completes
......@@ -118,7 +122,7 @@ namespace Solid
* @param cookie The cookie acquired when requesting screen power management suppression
* @return true if the suppression was stopped, false if an invalid cookie was given
*
* @note Since 4.8, this function also inhibites screensaver
* @note Since 4.8, this function also inhibits screensaver
*
* @since 4.6
*/
......@@ -131,8 +135,7 @@ namespace Solid
/**
* This signal is emitted when the AC adapter is plugged or unplugged.
*
* @param newState the new state of the AC adapter, it's one of the
* type @see Solid::PowerManager::AcAdapterState
* @param newState whether the system runs on battery
*/
void appShouldConserveResourcesChanged(bool newState);
......
......@@ -48,6 +48,7 @@ namespace Solid
public Q_SLOTS:
void slotCanSuspendChanged(bool newState);
void slotCanHibernateChanged(bool newState);
void slotCanHybridSuspendChanged(bool newState);
void slotPowerSaveStatusChanged(bool newState);
void slotServiceRegistered(const QString &serviceName);
void slotServiceUnregistered(const QString &serviceName);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment