dtor first
[personal-kdebase.git] / workspace / libs / solid / control / powermanager.cpp
blob1e4454575ef8efa98b4042d4ba06b87982166987
1 /* This file is part of the KDE project
2 Copyright (C) 2006-2007 Kevin Ottens <ervin@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
20 #include "powermanager.h"
21 #include "powermanager_p.h"
23 #include "soliddefs_p.h"
24 #include "managerbase_p.h"
25 #include "ifaces/powermanager.h"
27 #include <kglobal.h>
29 K_GLOBAL_STATIC(Solid::Control::PowerManagerPrivate, globalPowerManager)
31 Solid::Control::PowerManagerPrivate::PowerManagerPrivate()
33 loadBackend("Power Management", "SolidPowerManager", "Solid::Control::Ifaces::PowerManager");
35 if (managerBackend()!=0) {
36 connect(managerBackend(), SIGNAL(schemeChanged(QString)),
37 this, SIGNAL(schemeChanged(QString)));
38 connect(managerBackend(), SIGNAL(acAdapterStateChanged(int)),
39 this, SIGNAL(acAdapterStateChanged(int)));
40 connect(managerBackend(), SIGNAL(batteryStateChanged(int)),
41 this, SIGNAL(batteryStateChanged(int)));
42 connect(managerBackend(), SIGNAL(buttonPressed(int)),
43 this, SIGNAL(buttonPressed(int)));
44 connect(managerBackend(), SIGNAL(brightnessChanged(float)),
45 this, SIGNAL(brightnessChanged(float)));
46 connect(managerBackend(), SIGNAL(batteryRemainingTimeChanged(int)),
47 this, SIGNAL(batteryRemainingTimeChanged(int)));
51 Solid::Control::PowerManagerPrivate::~PowerManagerPrivate()
55 QStringList Solid::Control::PowerManager::supportedSchemes()
57 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
58 QStringList(), supportedSchemes());
61 QString Solid::Control::PowerManager::schemeDescription(const QString &schemeName)
63 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
64 QString(), schemeDescription(schemeName));
67 QString Solid::Control::PowerManager::scheme()
69 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(), QString(), scheme());
72 bool Solid::Control::PowerManager::setScheme(const QString &name)
74 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
75 false, setScheme(name));
78 Solid::Control::PowerManager::BatteryState Solid::Control::PowerManager::batteryState()
80 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
81 NoBatteryState, batteryState());
84 int Solid::Control::PowerManager::batteryChargePercent()
86 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
87 -1, batteryChargePercent());
90 int Solid::Control::PowerManager::batteryRemainingTime()
92 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
93 -1, batteryRemainingTime());
96 Solid::Control::PowerManager::AcAdapterState Solid::Control::PowerManager::acAdapterState()
98 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
99 Plugged, acAdapterState());
102 Solid::Control::PowerManager::SuspendMethods Solid::Control::PowerManager::supportedSuspendMethods()
104 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
105 UnknownSuspendMethod, supportedSuspendMethods());
108 KJob *Solid::Control::PowerManager::suspend(SuspendMethod method)
110 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
111 0, suspend(method));
114 Solid::Control::PowerManager::CpuFreqPolicies Solid::Control::PowerManager::supportedCpuFreqPolicies()
116 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
117 UnknownCpuFreqPolicy, supportedCpuFreqPolicies());
120 Solid::Control::PowerManager::CpuFreqPolicy Solid::Control::PowerManager::cpuFreqPolicy()
122 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
123 UnknownCpuFreqPolicy, cpuFreqPolicy());
126 bool Solid::Control::PowerManager::setCpuFreqPolicy(CpuFreqPolicy newPolicy)
128 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
129 false, setCpuFreqPolicy(newPolicy));
132 bool Solid::Control::PowerManager::canDisableCpu(int cpuNum)
134 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
135 false, canDisableCpu(cpuNum));
138 bool Solid::Control::PowerManager::setCpuEnabled(int cpuNum, bool enabled)
140 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
141 false, setCpuEnabled(cpuNum, enabled));
144 Solid::Control::PowerManager::BrightnessControlsList Solid::Control::PowerManager::brightnessControlsAvailable()
146 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
147 Solid::Control::PowerManager::BrightnessControlsList(), brightnessControlsAvailable());
150 bool Solid::Control::PowerManager::setBrightness(float brightness, const QString &device)
152 if(device.isEmpty())
154 Solid::Control::PowerManager::BrightnessControlsList controls = brightnessControlsAvailable();
155 if(controls.size() == 0)
157 return false;
159 else
161 foreach(const QString &device, controls.keys())
163 SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(), setBrightness(brightness, device));
165 //TODO - This should be done better, it will return true even if one of the calls returns false. SOLID_CALL does not allow us to get the return value.
166 return true;
169 else
171 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
172 false, setBrightness(brightness, device));
176 float Solid::Control::PowerManager::brightness(const QString &device)
178 if(device.isEmpty())
180 Solid::Control::PowerManager::BrightnessControlsList controls = brightnessControlsAvailable();
181 if(controls.size() == 0)
183 return false;
185 else
187 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
188 false, brightness(controls.keys().at(0)));
191 else
193 return_SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(),
194 false, brightness(device));
198 Solid::Control::PowerManager::Notifier *Solid::Control::PowerManager::notifier()
200 return globalPowerManager;
203 #include "powermanager_p.moc"
204 #include "powermanager.moc"