add more spacing
[personal-kdebase.git] / workspace / solid / hal / halsuspendjob.cpp
blobec891667054118e5bc5a925a6a2a545245476c86
1 /* This file is part of the KDE project
2 Copyright (C) 2006 Kevin Ottens <ervin@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
20 #include "halsuspendjob.h"
22 #include <QtDBus/QDBusMessage>
23 #include <QTimer>
25 HalSuspendJob::HalSuspendJob(QDBusInterface &powermanagement,
26 Solid::Control::PowerManager::SuspendMethod method,
27 Solid::Control::PowerManager::SuspendMethods supported)
28 : KJob(), m_halPowerManagement(powermanagement)
30 if (supported & method)
32 switch(method)
34 case Solid::Control::PowerManager::ToRam:
35 m_dbusMethod = "Suspend";
36 m_dbusParam = 0;
37 break;
38 case Solid::Control::PowerManager::ToDisk:
39 m_dbusMethod = "Hibernate";
40 m_dbusParam = -1;
41 break;
42 default:
43 break;
48 HalSuspendJob::~HalSuspendJob()
53 void HalSuspendJob::start()
55 QTimer::singleShot(0, this, SLOT(doStart()));
58 void HalSuspendJob::kill(bool /*quietly */)
63 void HalSuspendJob::doStart()
65 if (m_dbusMethod.isEmpty())
67 setError(1);
68 setErrorText("Unsupported suspend method");
69 emitResult();
70 return;
73 QList<QVariant> args;
75 if (m_dbusParam>=0)
77 args << m_dbusParam;
80 if (!m_halPowerManagement.callWithCallback(m_dbusMethod, args,
81 this, SLOT(resumeDone(const QDBusMessage &))))
83 setError(1);
84 setErrorText(m_halPowerManagement.lastError().name()+": "
85 +m_halPowerManagement.lastError().message());
86 emitResult();
91 void HalSuspendJob::resumeDone(const QDBusMessage &reply)
93 if (reply.type() == QDBusMessage::ErrorMessage)
95 // We ignore the NoReply error, since we can timeout anyway
96 // if the computer is suspended for too long.
97 if (reply.errorName() != "org.freedesktop.DBus.Error.NoReply")
99 setError(1);
100 setErrorText(reply.errorName()+": "+reply.arguments().at(0).toString());
104 emitResult();
107 #include "halsuspendjob.moc"