Solid
powermanagement.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "powermanagement.h"
00021 #include "powermanagement_p.h"
00022
00023 #include "soliddefs_p.h"
00024
00025 #include <QtCore/QCoreApplication>
00026
00027 SOLID_GLOBAL_STATIC(Solid::PowerManagementPrivate, globalPowerManager)
00028
00029 Solid::PowerManagementPrivate::PowerManagementPrivate()
00030 : managerIface("org.freedesktop.PowerManagement",
00031 "/org/freedesktop/PowerManagement",
00032 QDBusConnection::sessionBus()),
00033 inhibitIface("org.freedesktop.PowerManagement.Inhibit",
00034 "/org/freedesktop/PowerManagement/Inhibit",
00035 QDBusConnection::sessionBus())
00036 {
00037 powerSaveStatus = managerIface.GetPowerSaveStatus();
00038
00039 if (managerIface.CanSuspend())
00040 supportedSleepStates+= Solid::PowerManagement::SuspendState;
00041 if (managerIface.CanHibernate())
00042 supportedSleepStates+= Solid::PowerManagement::HibernateState;
00043
00044 connect(&managerIface, SIGNAL(CanSuspendChanged(bool)),
00045 this, SLOT(slotCanSuspendChanged(bool)));
00046 connect(&managerIface, SIGNAL(CanHibernateChanged(bool)),
00047 this, SLOT(slotCanHibernateChanged(bool)));
00048 connect(&managerIface, SIGNAL(PowerSaveStatusChanged(bool)),
00049 this, SLOT(slotPowerSaveStatusChanged(bool)));
00050 }
00051
00052 Solid::PowerManagementPrivate::~PowerManagementPrivate()
00053 {
00054 }
00055
00056 bool Solid::PowerManagement::appShouldConserveResources()
00057 {
00058 return globalPowerManager->powerSaveStatus;
00059 }
00060
00061 QSet<Solid::PowerManagement::SleepState> Solid::PowerManagement::supportedSleepStates()
00062 {
00063 return globalPowerManager->supportedSleepStates;
00064 }
00065
00066 void Solid::PowerManagement::requestSleep(SleepState state, QObject *receiver, const char *member)
00067 {
00068 if (!globalPowerManager->supportedSleepStates.contains(state)) {
00069 return;
00070 }
00071
00072 switch (state)
00073 {
00074 case StandbyState:
00075 break;
00076 case SuspendState:
00077 globalPowerManager->managerIface.Suspend();
00078 break;
00079 case HibernateState:
00080 globalPowerManager->managerIface.Hibernate();
00081 break;
00082 }
00083 }
00084
00085 int Solid::PowerManagement::beginSuppressingSleep(const QString &reason)
00086 {
00087 QDBusReply<uint> reply = globalPowerManager->inhibitIface.Inhibit(
00088 QCoreApplication::applicationName(), reason);
00089
00090 if (reply.isValid())
00091 return reply;
00092 else
00093 return -1;
00094 }
00095
00096 bool Solid::PowerManagement::stopSuppressingSleep(int cookie)
00097 {
00098 return globalPowerManager->inhibitIface.UnInhibit(cookie).isValid();
00099 }
00100
00101 Solid::PowerManagement::Notifier *Solid::PowerManagement::notifier()
00102 {
00103 return globalPowerManager;
00104 }
00105
00106 void Solid::PowerManagementPrivate::slotCanSuspendChanged(bool newState)
00107 {
00108 if (newState) {
00109 supportedSleepStates+= Solid::PowerManagement::SuspendState;
00110 } else {
00111 supportedSleepStates-= Solid::PowerManagement::SuspendState;
00112 }
00113 }
00114
00115 void Solid::PowerManagementPrivate::slotCanHibernateChanged(bool newState)
00116 {
00117 if (newState) {
00118 supportedSleepStates+= Solid::PowerManagement::HibernateState;
00119 } else {
00120 supportedSleepStates-= Solid::PowerManagement::HibernateState;
00121 }
00122 }
00123
00124 void Solid::PowerManagementPrivate::slotPowerSaveStatusChanged(bool newState)
00125 {
00126 powerSaveStatus = newState;
00127 emit appShouldConserveResourcesChanged(powerSaveStatus);
00128 }
00129
00130 #include "powermanagement_p.moc"
00131 #include "powermanagement.moc"
00132