SolidModules
halsuspendjob.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 )
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
00096
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"