• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Solid

powermanagement.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) version 3, or any
00008     later version accepted by the membership of KDE e.V. (or its
00009     successor approved by the membership of KDE e.V.), which shall
00010     act as a proxy defined in Section 6 of version 3 of the license.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "powermanagement.h"
00022 #include "powermanagement_p.h"
00023 
00024 #include "soliddefs_p.h"
00025 
00026 #include <QtCore/QCoreApplication>
00027 
00028 SOLID_GLOBAL_STATIC(Solid::PowerManagementPrivate, globalPowerManager)
00029 
00030 Solid::PowerManagementPrivate::PowerManagementPrivate()
00031     : managerIface("org.freedesktop.PowerManagement",
00032                    "/org/freedesktop/PowerManagement",
00033                    QDBusConnection::sessionBus()),
00034       policyAgentIface("org.kde.Solid.PowerManagement.PolicyAgent",
00035                        "/org/kde/Solid/PowerManagement/PolicyAgent",
00036                        QDBusConnection::sessionBus()),
00037       inhibitIface("org.freedesktop.PowerManagement.Inhibit",
00038                    "/org/freedesktop/PowerManagement/Inhibit",
00039                    QDBusConnection::sessionBus())
00040 {
00041     powerSaveStatus = managerIface.GetPowerSaveStatus();
00042 
00043     if (managerIface.CanSuspend())
00044         supportedSleepStates+= Solid::PowerManagement::SuspendState;
00045     if (managerIface.CanHibernate())
00046         supportedSleepStates+= Solid::PowerManagement::HibernateState;
00047 
00048     connect(&managerIface, SIGNAL(CanSuspendChanged(bool)),
00049             this, SLOT(slotCanSuspendChanged(bool)));
00050     connect(&managerIface, SIGNAL(CanHibernateChanged(bool)),
00051             this, SLOT(slotCanHibernateChanged(bool)));
00052     connect(&managerIface, SIGNAL(PowerSaveStatusChanged(bool)),
00053             this, SLOT(slotPowerSaveStatusChanged(bool)));
00054 }
00055 
00056 Solid::PowerManagementPrivate::~PowerManagementPrivate()
00057 {
00058 }
00059 
00060 Solid::PowerManagement::Notifier::Notifier()
00061 {
00062 }
00063 
00064 bool Solid::PowerManagement::appShouldConserveResources()
00065 {
00066     return globalPowerManager->powerSaveStatus;
00067 }
00068 
00069 QSet<Solid::PowerManagement::SleepState> Solid::PowerManagement::supportedSleepStates()
00070 {
00071     return globalPowerManager->supportedSleepStates;
00072 }
00073 
00074 void Solid::PowerManagement::requestSleep(SleepState state, QObject *receiver, const char *member)
00075 {
00076     Q_UNUSED(receiver)
00077     Q_UNUSED(member)
00078 
00079     if (!globalPowerManager->supportedSleepStates.contains(state)) {
00080         return;
00081     }
00082 
00083     switch (state)
00084     {
00085     case StandbyState:
00086         break;
00087     case SuspendState:
00088         globalPowerManager->managerIface.Suspend();
00089         break;
00090     case HibernateState:
00091         globalPowerManager->managerIface.Hibernate();
00092         break;
00093     }
00094 }
00095 
00096 int Solid::PowerManagement::beginSuppressingSleep(const QString &reason)
00097 {
00098     QDBusReply<uint> reply;
00099     if (globalPowerManager->policyAgentIface.isValid()) {
00100         reply = globalPowerManager->policyAgentIface.AddInhibition(
00101             (uint)PowerManagementPrivate::InterruptSession,
00102             QCoreApplication::applicationName(), reason);
00103     } else {
00104         // Fallback to the fd.o Inhibit interface
00105         reply = globalPowerManager->inhibitIface.Inhibit(QCoreApplication::applicationName(), reason);
00106     }
00107 
00108     if (reply.isValid())
00109         return reply;
00110     else
00111         return -1;
00112 }
00113 
00114 bool Solid::PowerManagement::stopSuppressingSleep(int cookie)
00115 {
00116     if (globalPowerManager->policyAgentIface.isValid()) {
00117         return globalPowerManager->policyAgentIface.ReleaseInhibition(cookie).isValid();
00118     } else {
00119         // Fallback to the fd.o Inhibit interface
00120         return globalPowerManager->inhibitIface.UnInhibit(cookie).isValid();
00121     }
00122 }
00123 
00124 int Solid::PowerManagement::beginSuppressingScreenPowerManagement(const QString& reason)
00125 {
00126     if (globalPowerManager->policyAgentIface.isValid()) {
00127         QDBusReply<uint> reply = globalPowerManager->policyAgentIface.AddInhibition(
00128             (uint)PowerManagementPrivate::ChangeScreenSettings,
00129             QCoreApplication::applicationName(), reason);
00130 
00131         if (reply.isValid())
00132             return reply;
00133         else
00134             return -1;
00135     } else {
00136         // No way to fallback on something, hence return failure
00137         return -1;
00138     }
00139 }
00140 
00141 bool Solid::PowerManagement::stopSuppressingScreenPowerManagement(int cookie)
00142 {
00143     if (globalPowerManager->policyAgentIface.isValid()) {
00144         return globalPowerManager->policyAgentIface.ReleaseInhibition(cookie).isValid();
00145     } else {
00146         // No way to fallback on something, hence return failure
00147         return false;
00148     }
00149 }
00150 
00151 Solid::PowerManagement::Notifier *Solid::PowerManagement::notifier()
00152 {
00153     return globalPowerManager;
00154 }
00155 
00156 void Solid::PowerManagementPrivate::slotCanSuspendChanged(bool newState)
00157 {
00158     if (newState) {
00159         supportedSleepStates+= Solid::PowerManagement::SuspendState;
00160     } else {
00161         supportedSleepStates-= Solid::PowerManagement::SuspendState;
00162     }
00163 }
00164 
00165 void Solid::PowerManagementPrivate::slotCanHibernateChanged(bool newState)
00166 {
00167     if (newState) {
00168         supportedSleepStates+= Solid::PowerManagement::HibernateState;
00169     } else {
00170         supportedSleepStates-= Solid::PowerManagement::HibernateState;
00171     }
00172 }
00173 
00174 void Solid::PowerManagementPrivate::slotPowerSaveStatusChanged(bool newState)
00175 {
00176     powerSaveStatus = newState;
00177     emit appShouldConserveResourcesChanged(powerSaveStatus);
00178 }
00179 
00180 #include "powermanagement_p.moc"
00181 #include "powermanagement.moc"
00182 

Solid

Skip menu "Solid"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal