1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
/***************************************************************************
* Copyright (C) 2010 by Dario Freddi <drf@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "powerdevilbackendinterface.h"
#include "powerdevilscreenbrightnesslogic.h"
#include "powerdevilkeyboardbrightnesslogic.h"
#include "powerdevil_debug.h"
#include <QDebug>
namespace PowerDevil
{
class BackendInterface::Private
{
public:
Private() : acAdapterState(UnknownAcAdapterState), batteryState(NoBatteryState), batteryRemainingTime(0),
isReady(false), isError(false), isLidClosed(false), isLidPresent(false) {}
~Private() {}
AcAdapterState acAdapterState;
BatteryState batteryState;
qulonglong batteryRemainingTime;
QHash< BrightnessControlType, BrightnessLogic* > brightnessLogic;
BrightnessControlsList brightnessControlsAvailable;
Capabilities capabilities;
SuspendMethods suspendMethods;
QString errorString;
bool isReady;
bool isError;
bool isLidClosed;
bool isLidPresent;
QHash< QString, uint > capacities;
};
BackendInterface::BackendInterface(QObject* parent)
: QObject(parent)
, d(new Private)
{
d->brightnessLogic[Screen] = new ScreenBrightnessLogic();
d->brightnessLogic[Keyboard] = new KeyboardBrightnessLogic();
}
BackendInterface::~BackendInterface()
{
delete d->brightnessLogic[Keyboard];
delete d->brightnessLogic[Screen];
delete d;
}
BackendInterface::AcAdapterState BackendInterface::acAdapterState() const
{
return d->acAdapterState;
}
qulonglong BackendInterface::batteryRemainingTime() const
{
return d->batteryRemainingTime;
}
BackendInterface::BatteryState BackendInterface::batteryState() const
{
return d->batteryState;
}
void BackendInterface::setBrightness(int brightness, BackendInterface::BrightnessControlType type)
{
if (type == Screen) {
qCDebug(POWERDEVIL) << "set screen brightness: " << brightness;
} else {
qCDebug(POWERDEVIL) << "set kbd backlight: " << brightness;
}
d->brightnessLogic.value(type)->setValue(brightness);
}
int BackendInterface::brightness(BackendInterface::BrightnessControlType type) const
{
return d->brightnessLogic.value(type)->value();
}
int BackendInterface::brightnessMax(BackendInterface::BrightnessControlType type) const
{
return d->brightnessLogic.value(type)->valueMax();
}
int BackendInterface::brightnessSteps(BackendInterface::BrightnessControlType type) const
{
BrightnessLogic *logic = d->brightnessLogic.value(type);
logic->setValueMax(brightnessMax(type));
return logic->steps();
}
BackendInterface::BrightnessControlsList BackendInterface::brightnessControlsAvailable() const
{
return d->brightnessControlsAvailable;
}
QHash< QString, uint > BackendInterface::capacities() const
{
return d->capacities;
}
BackendInterface::SuspendMethods BackendInterface::supportedSuspendMethods() const
{
return d->suspendMethods;
}
bool BackendInterface::isLidClosed() const
{
return d->isLidClosed;
}
bool BackendInterface::isLidPresent() const
{
return d->isLidPresent;
}
void BackendInterface::setLidPresent(bool present)
{
d->isLidPresent = present;
}
void BackendInterface::setAcAdapterState(PowerDevil::BackendInterface::AcAdapterState state)
{
d->acAdapterState = state;
Q_EMIT acAdapterStateChanged(state);
}
void BackendInterface::setBackendHasError(const QString& errorDetails)
{
Q_UNUSED(errorDetails)
}
void BackendInterface::setBackendIsReady(BrightnessControlsList availableBrightnessControls,
BackendInterface::SuspendMethods supportedSuspendMethods)
{
d->brightnessControlsAvailable = availableBrightnessControls;
d->suspendMethods = supportedSuspendMethods;
d->isReady = true;
Q_EMIT backendReady();
}
void BackendInterface::setBatteryRemainingTime(qulonglong time)
{
if (d->batteryRemainingTime != time) {
d->batteryRemainingTime = time;
Q_EMIT batteryRemainingTimeChanged(time);
}
}
void BackendInterface::setBatteryState(PowerDevil::BackendInterface::BatteryState state)
{
d->batteryState = state;
Q_EMIT batteryStateChanged(state);
}
void BackendInterface::setButtonPressed(PowerDevil::BackendInterface::ButtonType type)
{
if (type == LidClose && !d->isLidClosed) {
d->isLidClosed = true;
Q_EMIT lidClosedChanged(true);
} else if (type == LidOpen && d->isLidClosed) {
d->isLidClosed = false;
Q_EMIT lidClosedChanged(false);
}
Q_EMIT buttonPressed(type);
}
void BackendInterface::setCapacityForBattery(const QString& batteryId, uint percent)
{
d->capacities.insert(batteryId, percent);
}
void BackendInterface::onBrightnessChanged(BrightnessControlType type, int value, int valueMax)
{
BrightnessLogic *logic = d->brightnessLogic.value(type);
logic->setValueMax(valueMax);
logic->setValue(value);
Q_EMIT brightnessChanged(logic->info(), type);
}
BackendInterface::Capabilities BackendInterface::capabilities() const
{
return d->capabilities;
}
void BackendInterface::setCapabilities(BackendInterface::Capabilities capabilities)
{
d->capabilities = capabilities;
}
int BackendInterface::calculateNextStep(int value, int valueMax, BrightnessControlType type, BrightnessLogic::BrightnessKeyType keyType)
{
BrightnessLogic *logic = d->brightnessLogic.value(type);
logic->setValueMax(valueMax);
logic->setValue(value);
return logic->action(keyType);
}
}
|