1
/***************************************************************************
2
* Copyright (C) 2008 by Kevin Ottens <ervin@kde.org> *
3
* Copyright (C) 2008-2010 by Dario Freddi <drf@kde.org> *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
19
**************************************************************************/
21
#include "powerdevilfdoconnector.h"
23
#include "powerdevilcore.h"
25
#include "powermanagementfdoadaptor.h"
26
#include "powermanagementinhibitadaptor.h"
28
namespace PowerDevil {
30
FdoConnector::FdoConnector(PowerDevil::Core *parent)
31
: QObject(parent), m_core(parent)
33
new PowerManagementFdoAdaptor(this);
34
new PowerManagementInhibitAdaptor(this);
36
QDBusConnection c = QDBusConnection::sessionBus();
38
c.registerService("org.freedesktop.PowerManagement");
39
c.registerObject("/org/freedesktop/PowerManagement", this);
41
c.registerService("org.freedesktop.PowerManagement.Inhibit");
42
c.registerObject("/org/freedesktop/PowerManagement/Inhibit", this);
44
connect(m_core->backend(), SIGNAL(acAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState)),
45
this, SLOT(onAcAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState)));
46
connect(PolicyAgent::instance(), SIGNAL(unavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies)),
47
this, SLOT(onUnavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies)));
50
bool FdoConnector::CanHibernate()
52
return m_core->backend()->supportedSuspendMethods() & PowerDevil::BackendInterface::ToDisk;
55
bool FdoConnector::CanSuspend()
57
return m_core->backend()->supportedSuspendMethods() & PowerDevil::BackendInterface::ToRam;
60
bool FdoConnector::GetPowerSaveStatus()
62
return m_core->backend()->acAdapterState() == PowerDevil::BackendInterface::Unplugged;
65
void FdoConnector::Suspend()
67
m_core->suspendToRam();
70
void FdoConnector::Hibernate()
72
m_core->suspendToDisk();
75
bool FdoConnector::HasInhibit()
77
return PolicyAgent::instance()->requirePolicyCheck(PolicyAgent::InterruptSession) != PolicyAgent::None;
80
int FdoConnector::Inhibit(const QString &application, const QString &reason)
82
// Inhibit here means we cannot interrupt the session.
83
// If we've been called from DBus, use PolicyAgent's service watching system
84
if (calledFromDBus()) {
85
return PolicyAgent::instance()->addInhibitionWithExplicitDBusService((uint)PolicyAgent::InterruptSession,
86
application, reason, message().service());
88
return PolicyAgent::instance()->AddInhibition((uint)PolicyAgent::InterruptSession, application, reason);
92
void FdoConnector::UnInhibit(int cookie)
94
PolicyAgent::instance()->ReleaseInhibition(cookie);
97
void FdoConnector::ForceUnInhibitAll()
99
PolicyAgent::instance()->releaseAllInhibitions();
102
void FdoConnector::onAcAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState newstate)
104
emit PowerSaveStatusChanged(newstate == PowerDevil::BackendInterface::Unplugged);
107
void FdoConnector::onUnavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies newpolicies)
109
emit HasInhibitChanged(newpolicies & PowerDevil::PolicyAgent::InterruptSession);
114
#include "powerdevilfdoconnector.moc"