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 <QtDBus/QDBusReply>
26
#include <KConfigGroup>
28
HalSuspendJob::HalSuspendJob(QDBusInterface &powermanagement, QDBusInterface &computer,
29
PowerDevil::BackendInterface::SuspendMethod method,
30
PowerDevil::BackendInterface::SuspendMethods supported)
31
: KJob(), m_halPowerManagement(powermanagement), m_halComputer(computer)
33
if (supported & method)
35
QDBusReply<bool> reply;
39
case PowerDevil::BackendInterface::ToRam:
40
reply = m_halComputer.call("GetPropertyBoolean", "power_management.can_suspend_hybrid");
44
bool can_hybrid = reply;
47
// Temporary: let's check if system is configured to use Hybrid suspend. Default is no.
48
KConfig sconf("suspendpreferencesrc");
49
KConfigGroup group(&sconf, "Preferences");
50
if (group.readEntry("use_hybrid", false)) {
51
m_dbusMethod = "SuspendHybrid";
53
m_dbusMethod = "Suspend";
58
m_dbusMethod = "Suspend";
63
m_dbusMethod = "Suspend";
67
case PowerDevil::BackendInterface::ToDisk:
68
m_dbusMethod = "Hibernate";
77
HalSuspendJob::~HalSuspendJob()
82
void HalSuspendJob::start()
84
QTimer::singleShot(0, this, SLOT(doStart()));
87
void HalSuspendJob::kill(bool /*quietly */)
92
void HalSuspendJob::doStart()
94
if (m_dbusMethod.isEmpty())
97
setErrorText("Unsupported suspend method");
102
QList<QVariant> args;
109
if (!m_halPowerManagement.callWithCallback(m_dbusMethod, args,
110
this, SLOT(resumeDone(const QDBusMessage &))))
113
setErrorText(m_halPowerManagement.lastError().name()+": "
114
+m_halPowerManagement.lastError().message());
120
void HalSuspendJob::resumeDone(const QDBusMessage &reply)
122
if (reply.type() == QDBusMessage::ErrorMessage)
124
// We ignore the NoReply error, since we can timeout anyway
125
// if the computer is suspended for too long.
126
if (reply.errorName() != "org.freedesktop.DBus.Error.NoReply")
129
setErrorText(reply.errorName()+": "+reply.arguments().at(0).toString());
136
#include "halsuspendjob.moc"