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

« back to all changes in this revision

Viewing changes to powerdevil/daemon/powerdevilbackendinterface.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) 2010 by Dario Freddi <drf@kde.org>                      *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program is distributed in the hope that it will be useful,       *
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 
18
 ***************************************************************************/
 
19
 
 
20
#include "powerdevilbackendinterface.h"
 
21
 
 
22
namespace PowerDevil
 
23
{
 
24
 
 
25
class BackendInterface::Private
 
26
{
 
27
public:
 
28
    Private() : isReady(false), isError(false), isLidClosed(false) {}
 
29
    ~Private() {}
 
30
 
 
31
    AcAdapterState acAdapterState;
 
32
    qulonglong batteryRemainingTime;
 
33
    BatteryState batteryState;
 
34
    QHash< BrightnessControlType, float > brightness;
 
35
    BrightnessControlsList brightnessControlsAvailable;
 
36
    Capabilities capabilities;
 
37
    SuspendMethods suspendMethods;
 
38
    QString errorString;
 
39
    bool isReady;
 
40
    bool isError;
 
41
    bool isLidClosed;
 
42
    QHash< QString, uint > capacities;
 
43
    QList< RecallNotice > recallNotices;
 
44
};
 
45
 
 
46
BackendInterface::BackendInterface(QObject* parent)
 
47
    : QObject(parent)
 
48
    , d(new Private)
 
49
{
 
50
}
 
51
 
 
52
BackendInterface::~BackendInterface()
 
53
{
 
54
    delete d;
 
55
}
 
56
 
 
57
BackendInterface::AcAdapterState BackendInterface::acAdapterState() const
 
58
{
 
59
    return d->acAdapterState;
 
60
}
 
61
 
 
62
qulonglong BackendInterface::batteryRemainingTime() const
 
63
{
 
64
    return d->batteryRemainingTime;
 
65
}
 
66
 
 
67
BackendInterface::BatteryState BackendInterface::batteryState() const
 
68
{
 
69
    return d->batteryState;
 
70
}
 
71
 
 
72
float BackendInterface::brightness(BackendInterface::BrightnessControlType type) const
 
73
{
 
74
    return d->brightness[type];
 
75
}
 
76
 
 
77
BackendInterface::BrightnessControlsList BackendInterface::brightnessControlsAvailable() const
 
78
{
 
79
    return d->brightnessControlsAvailable;
 
80
}
 
81
 
 
82
QHash< QString, uint > BackendInterface::capacities() const
 
83
{
 
84
    return d->capacities;
 
85
}
 
86
 
 
87
QList< BackendInterface::RecallNotice > BackendInterface::recallNotices() const
 
88
{
 
89
    return d->recallNotices;
 
90
}
 
91
 
 
92
BackendInterface::SuspendMethods BackendInterface::supportedSuspendMethods() const
 
93
{
 
94
    return d->suspendMethods;
 
95
}
 
96
 
 
97
bool BackendInterface::isLidClosed() const
 
98
{
 
99
    return d->isLidClosed;
 
100
}
 
101
 
 
102
void BackendInterface::setAcAdapterState(PowerDevil::BackendInterface::AcAdapterState state)
 
103
{
 
104
    d->acAdapterState = state;
 
105
    emit acAdapterStateChanged(state);
 
106
}
 
107
 
 
108
void BackendInterface::setBackendHasError(const QString& errorDetails)
 
109
{
 
110
    Q_UNUSED(errorDetails)
 
111
}
 
112
 
 
113
void BackendInterface::setBackendIsReady(BrightnessControlsList availableBrightnessControls,
 
114
                                         BackendInterface::SuspendMethods supportedSuspendMethods)
 
115
{
 
116
    d->brightnessControlsAvailable = availableBrightnessControls;
 
117
    d->suspendMethods = supportedSuspendMethods;
 
118
    d->isReady = true;
 
119
 
 
120
    emit backendReady();
 
121
}
 
122
 
 
123
void BackendInterface::setBatteryRemainingTime(qulonglong time)
 
124
{
 
125
    d->batteryRemainingTime = time;
 
126
    emit batteryRemainingTimeChanged(time);
 
127
}
 
128
 
 
129
void BackendInterface::setBatteryState(PowerDevil::BackendInterface::BatteryState state)
 
130
{
 
131
    d->batteryState = state;
 
132
    emit batteryStateChanged(state);
 
133
}
 
134
 
 
135
void BackendInterface::setButtonPressed(PowerDevil::BackendInterface::ButtonType type)
 
136
{
 
137
    if (type == LidClose) {
 
138
        d->isLidClosed = true;
 
139
    } else if (type == LidOpen) {
 
140
        d->isLidClosed = false;
 
141
    }
 
142
    emit buttonPressed(type);
 
143
}
 
144
 
 
145
void BackendInterface::setCapacityForBattery(const QString& batteryId, uint percent)
 
146
{
 
147
    d->capacities.insert(batteryId, percent);
 
148
}
 
149
 
 
150
void BackendInterface::setRecallNotices(const QList< BackendInterface::RecallNotice >& notices)
 
151
{
 
152
    d->recallNotices = notices;
 
153
}
 
154
 
 
155
void BackendInterface::onBrightnessChanged(BackendInterface::BrightnessControlType device, float brightness)
 
156
{
 
157
    d->brightness[device] = brightness;
 
158
    emit brightnessChanged(brightness, device);
 
159
}
 
160
 
 
161
void BackendInterface::setResumeFromSuspend()
 
162
{
 
163
    emit resumeFromSuspend();
 
164
}
 
165
 
 
166
BackendInterface::Capabilities BackendInterface::capabilities() const
 
167
{
 
168
    return d->capabilities;
 
169
}
 
170
 
 
171
void BackendInterface::setCapabilities(BackendInterface::Capabilities capabilities)
 
172
{
 
173
    d->capabilities = capabilities;
 
174
}
 
175
 
 
176
}
 
177
 
 
178
#include "powerdevilbackendinterface.moc"