~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to powerdevil/daemon/powerdevilfdoconnector.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008 by Kevin Ottens <ervin@kde.org>                    *
 
3
 *   Copyright (C) 2008-2010 by Dario Freddi <drf@kde.org>                 *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 **************************************************************************/
 
20
 
 
21
#include "powerdevilfdoconnector.h"
 
22
 
 
23
#include "powerdevilcore.h"
 
24
 
 
25
#include "powermanagementfdoadaptor.h"
 
26
#include "powermanagementinhibitadaptor.h"
 
27
 
 
28
namespace PowerDevil {
 
29
 
 
30
FdoConnector::FdoConnector(PowerDevil::Core *parent)
 
31
        : QObject(parent), m_core(parent)
 
32
{
 
33
    new PowerManagementFdoAdaptor(this);
 
34
    new PowerManagementInhibitAdaptor(this);
 
35
 
 
36
    QDBusConnection c = QDBusConnection::sessionBus();
 
37
 
 
38
    c.registerService("org.freedesktop.PowerManagement");
 
39
    c.registerObject("/org/freedesktop/PowerManagement", this);
 
40
 
 
41
    c.registerService("org.freedesktop.PowerManagement.Inhibit");
 
42
    c.registerObject("/org/freedesktop/PowerManagement/Inhibit", this);
 
43
 
 
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)));
 
48
}
 
49
 
 
50
bool FdoConnector::CanHibernate()
 
51
{
 
52
    return m_core->backend()->supportedSuspendMethods() & PowerDevil::BackendInterface::ToDisk;
 
53
}
 
54
 
 
55
bool FdoConnector::CanSuspend()
 
56
{
 
57
    return m_core->backend()->supportedSuspendMethods() & PowerDevil::BackendInterface::ToRam;
 
58
}
 
59
 
 
60
bool FdoConnector::GetPowerSaveStatus()
 
61
{
 
62
    return m_core->backend()->acAdapterState() == PowerDevil::BackendInterface::Unplugged;
 
63
}
 
64
 
 
65
void FdoConnector::Suspend()
 
66
{
 
67
    m_core->suspendToRam();
 
68
}
 
69
 
 
70
void FdoConnector::Hibernate()
 
71
{
 
72
    m_core->suspendToDisk();
 
73
}
 
74
 
 
75
bool FdoConnector::HasInhibit()
 
76
{
 
77
    return PolicyAgent::instance()->requirePolicyCheck(PolicyAgent::InterruptSession) != PolicyAgent::None;
 
78
}
 
79
 
 
80
int FdoConnector::Inhibit(const QString &application, const QString &reason)
 
81
{
 
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());
 
87
    } else {
 
88
        return PolicyAgent::instance()->AddInhibition((uint)PolicyAgent::InterruptSession, application, reason);
 
89
    }
 
90
}
 
91
 
 
92
void FdoConnector::UnInhibit(int cookie)
 
93
{
 
94
    PolicyAgent::instance()->ReleaseInhibition(cookie);
 
95
}
 
96
 
 
97
void FdoConnector::ForceUnInhibitAll()
 
98
{
 
99
    PolicyAgent::instance()->releaseAllInhibitions();
 
100
}
 
101
 
 
102
void FdoConnector::onAcAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState newstate)
 
103
{
 
104
    emit PowerSaveStatusChanged(newstate == PowerDevil::BackendInterface::Unplugged);
 
105
}
 
106
 
 
107
void FdoConnector::onUnavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies newpolicies)
 
108
{
 
109
    emit HasInhibitChanged(newpolicies & PowerDevil::PolicyAgent::InterruptSession);
 
110
}
 
111
 
 
112
}
 
113
 
 
114
#include "powerdevilfdoconnector.moc"