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

SolidModules

halsuspendjob.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2006 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 "halsuspendjob.h"
00021 
00022 #include <QtDBus/QDBusMessage>
00023 #include <QTimer>
00024 
00025 HalSuspendJob::HalSuspendJob(QDBusInterface &powermanagement,
00026                               Solid::Control::PowerManager::SuspendMethod method,
00027                               Solid::Control::PowerManager::SuspendMethods supported)
00028     : KJob(), m_halPowerManagement(powermanagement)
00029 {
00030     if (supported  & method)
00031     {
00032         switch(method)
00033         {
00034         case Solid::Control::PowerManager::ToRam:
00035             m_dbusMethod = "Suspend";
00036             m_dbusParam = 0;
00037             break;
00038         case Solid::Control::PowerManager::ToDisk:
00039             m_dbusMethod = "Hibernate";
00040             m_dbusParam = -1;
00041             break;
00042         default:
00043             break;
00044         }
00045     }
00046 }
00047 
00048 HalSuspendJob::~HalSuspendJob()
00049 {
00050 
00051 }
00052 
00053 void HalSuspendJob::start()
00054 {
00055     QTimer::singleShot(0, this, SLOT(doStart()));
00056 }
00057 
00058 void HalSuspendJob::kill(bool /*quietly */)
00059 {
00060 
00061 }
00062 
00063 void HalSuspendJob::doStart()
00064 {
00065     if (m_dbusMethod.isEmpty())
00066     {
00067         setError(1);
00068         setErrorText("Unsupported suspend method");
00069         emitResult();
00070         return;
00071     }
00072 
00073     QList<QVariant> args;
00074 
00075     if (m_dbusParam>=0)
00076     {
00077         args << m_dbusParam;
00078     }
00079 
00080     if (!m_halPowerManagement.callWithCallback(m_dbusMethod, args,
00081                                                 this, SLOT(resumeDone(const QDBusMessage &))))
00082     {
00083         setError(1);
00084         setErrorText(m_halPowerManagement.lastError().name()+": "
00085                      +m_halPowerManagement.lastError().message());
00086         emitResult();
00087     }
00088 }
00089 
00090 
00091 void HalSuspendJob::resumeDone(const QDBusMessage &reply)
00092 {
00093     if (reply.type() == QDBusMessage::ErrorMessage)
00094     {
00095         // We ignore the NoReply error, since we can timeout anyway
00096         // if the computer is suspended for too long.
00097         if (reply.errorName() != "org.freedesktop.DBus.Error.NoReply")
00098         {
00099             setError(1);
00100             setErrorText(reply.errorName()+": "+reply.arguments().at(0).toString());
00101         }
00102     }
00103 
00104     emitResult();
00105 }
00106 
00107 #include "halsuspendjob.moc"

SolidModules

Skip menu "SolidModules"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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