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>
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
)
34 case Solid::Control::PowerManager::ToRam
:
35 m_dbusMethod
= "Suspend";
38 case Solid::Control::PowerManager::ToDisk
:
39 m_dbusMethod
= "Hibernate";
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())
68 setErrorText("Unsupported suspend method");
80 if (!m_halPowerManagement
.callWithCallback(m_dbusMethod
, args
,
81 this, SLOT(resumeDone(const QDBusMessage
&))))
84 setErrorText(m_halPowerManagement
.lastError().name()+": "
85 +m_halPowerManagement
.lastError().message());
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")
100 setErrorText(reply
.errorName()+": "+reply
.arguments().at(0).toString());
107 #include "halsuspendjob.moc"