• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Solid

powermanagement.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 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 Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
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 

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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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