1 diff --git a/plasma/generic/dataengines/powermanagement/powermanagementengine.cpp b/plasma/generic/dataengines/powermanagement/powermanagementengine.cpp
2 index 33a6e03..f3a918a 100644
3 --- a/plasma/generic/dataengines/powermanagement/powermanagementengine.cpp
4 +++ b/plasma/generic/dataengines/powermanagement/powermanagementengine.cpp
8 #include <QtDBus/QDBusConnectionInterface>
9 +#include <QtDBus/QDBusError>
10 #include <QtDBus/QDBusInterface>
11 #include <QtDBus/QDBusMetaType>
12 #include <QtDBus/QDBusReply>
13 @@ -58,23 +59,39 @@ PowermanagementEngine::~PowermanagementEngine()
15 void PowermanagementEngine::init()
17 - connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(QString)),
18 - this, SLOT(deviceRemoved(QString)));
19 connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(QString)),
20 this, SLOT(deviceAdded(QString)));
21 + connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(QString)),
22 + this, SLOT(deviceRemoved(QString)));
24 + // FIXME This check doesn't work, connect seems to always return true, hence the hack below
25 if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.Solid.PowerManagement")) {
26 if (!QDBusConnection::sessionBus().connect("org.kde.Solid.PowerManagement",
27 - "/org/kde/Solid/PowerManagement",
28 - "org.kde.Solid.PowerManagement",
29 + "/org/kde/Solid/PowerManagement/Actions/BrightnessControl",
30 + "org.kde.Solid.PowerManagement.Actions.BrightnessControl",
31 "brightnessChanged", this,
32 SLOT(screenBrightnessChanged(int)))) {
33 kDebug() << "error connecting to Brightness changes via dbus";
36 + brightnessControlsAvailableChanged(false);
38 sourceRequestEvent("PowerDevil");
39 screenBrightnessChanged(0);
40 + brightnessControlsAvailableChanged(true);
43 + if (!QDBusConnection::sessionBus().connect("org.kde.Solid.PowerManagement",
44 + "/org/kde/Solid/PowerManagement/Actions/KeyboardBrightnessControl",
45 + "org.kde.Solid.PowerManagement.Actions.KeyboardBrightnessControl",
46 + "keyboardBrightnessChanged", this,
47 + SLOT(keyboardBrightnessChanged(int)))) {
48 + kDebug() << "error connecting to Keyboard Brightness changes via dbus";
49 + keyboardBrightnessControlsAvailableChanged(false);
51 + sourceRequestEvent("PowerDevil");
52 + keyboardBrightnessChanged(0);
53 + keyboardBrightnessControlsAvailableChanged(true);
56 if (!QDBusConnection::sessionBus().connect("org.kde.Solid.PowerManagement",
57 "/org/kde/Solid/PowerManagement",
58 "org.kde.Solid.PowerManagement",
59 @@ -114,27 +131,32 @@ bool PowermanagementEngine::sourceRequestEvent(const QString &name)
60 foreach (const Solid::Device &deviceBattery, listBattery) {
61 const Solid::Battery* battery = deviceBattery.as<Solid::Battery>();
63 - if (battery && (battery->type() == Solid::Battery::PrimaryBattery ||
64 - battery->type() == Solid::Battery::UpsBattery)) {
65 - const QString source = QString("Battery%1").arg(index++);
66 + const QString source = QString("Battery%1").arg(index++);
68 - batterySources << source;
69 - m_batterySources[deviceBattery.udi()] = source;
70 + batterySources << source;
71 + m_batterySources[deviceBattery.udi()] = source;
73 - connect(battery, SIGNAL(chargeStateChanged(int,QString)), this,
74 - SLOT(updateBatteryChargeState(int,QString)));
75 - connect(battery, SIGNAL(chargePercentChanged(int,QString)), this,
76 - SLOT(updateBatteryChargePercent(int,QString)));
77 - connect(battery, SIGNAL(plugStateChanged(bool,QString)), this,
78 - SLOT(updateBatteryPlugState(bool,QString)));
79 + connect(battery, SIGNAL(chargeStateChanged(int,QString)), this,
80 + SLOT(updateBatteryChargeState(int,QString)));
81 + connect(battery, SIGNAL(chargePercentChanged(int,QString)), this,
82 + SLOT(updateBatteryChargePercent(int,QString)));
83 + connect(battery, SIGNAL(plugStateChanged(bool,QString)), this,
84 + SLOT(updateBatteryPlugState(bool,QString)));
86 - // Set initial values
87 - updateBatteryChargeState(battery->chargeState(), deviceBattery.udi());
88 - updateBatteryChargePercent(battery->chargePercent(), deviceBattery.udi());
89 - updateBatteryPlugState(battery->isPlugged(), deviceBattery.udi());
91 + // Set initial values
92 + updateBatteryChargeState(battery->chargeState(), deviceBattery.udi());
93 + updateBatteryChargePercent(battery->chargePercent(), deviceBattery.udi());
94 + updateBatteryPlugState(battery->isPlugged(), deviceBattery.udi());
95 + updateBatteryPowerSupplyState(battery->isPowerSupply(), deviceBattery.udi());
97 + setData(source, "Vendor", deviceBattery.vendor());
98 + setData(source, "Product", deviceBattery.product());
99 + setData(source, "Capacity", battery->capacity());
100 + setData(source, "Type", batteryType(battery));
103 + updateBatteryNames();
105 setData("Battery", "Has Battery", !batterySources.isEmpty());
106 if (!batterySources.isEmpty()) {
107 setData("Battery", "Sources", batterySources);
108 @@ -180,14 +202,30 @@ bool PowermanagementEngine::sourceRequestEvent(const QString &name)
109 //kDebug() << "Sleepstate \"" << sleepstate << "\" supported.";
111 } else if (name == "PowerDevil") {
112 - QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement",
113 - "/org/kde/Solid/PowerManagement",
114 - "org.kde.Solid.PowerManagement",
116 - QDBusPendingReply<int> reply = QDBusConnection::sessionBus().asyncCall(msg);
117 - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
118 - QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
119 - this, SLOT(screenBrightnessReply(QDBusPendingCallWatcher*)));
121 + QDBusPendingReply<int> reply;
123 + if (m_brightnessControlsAvailable) {
124 + msg = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement",
125 + "/org/kde/Solid/PowerManagement/Actions/BrightnessControl",
126 + "org.kde.Solid.PowerManagement.Actions.BrightnessControl",
128 + reply = QDBusConnection::sessionBus().asyncCall(msg);
129 + QDBusPendingCallWatcher *screenWatcher = new QDBusPendingCallWatcher(reply, this);
130 + QObject::connect(screenWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
131 + this, SLOT(screenBrightnessReply(QDBusPendingCallWatcher*)));
134 + if (m_keyboardBrightnessControlsAvailable) {
135 + msg = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement",
136 + "/org/kde/Solid/PowerManagement/Actions/KeyboardBrightnessControl",
137 + "org.kde.Solid.PowerManagement.Actions.KeyboardBrightnessControl",
138 + "keyboardBrightness");
139 + reply = QDBusConnection::sessionBus().asyncCall(msg);
140 + QDBusPendingCallWatcher *keyboardWatcher = new QDBusPendingCallWatcher(reply, this);
141 + QObject::connect(keyboardWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
142 + this, SLOT(keyboardBrightnessReply(QDBusPendingCallWatcher*)));
144 //any info concerning lock screen/screensaver goes here
145 } else if (name == "UserActivity") {
146 setData("UserActivity", "IdleTime", KIdleTime::instance()->idleTime());
147 @@ -198,6 +236,37 @@ bool PowermanagementEngine::sourceRequestEvent(const QString &name)
151 +QString PowermanagementEngine::batteryType(const Solid::Battery* battery)
153 + switch(battery->type()) {
154 + case Solid::Battery::PrimaryBattery:
155 + return QLatin1String("Battery");
157 + case Solid::Battery::UpsBattery:
158 + return QLatin1String("Ups");
160 + case Solid::Battery::MonitorBattery:
161 + return QLatin1String("Monitor");
163 + case Solid::Battery::MouseBattery:
164 + return QLatin1String("Mouse");
166 + case Solid::Battery::KeyboardBattery:
167 + return QLatin1String("Keyboad");
169 + case Solid::Battery::PdaBattery:
170 + return QLatin1String("Pda");
172 + case Solid::Battery::PhoneBattery:
173 + return QLatin1String("Phone");
176 + return QLatin1String("Unknown");
179 + return QLatin1String("Unknown");
182 bool PowermanagementEngine::updateSourceEvent(const QString &source)
184 if (source == "UserActivity") {
185 @@ -243,6 +312,45 @@ void PowermanagementEngine::updateBatteryChargePercent(int newValue, const QStri
186 setData(source, "Percent", newValue);
189 +void PowermanagementEngine::updateBatteryPowerSupplyState(bool newState, const QString& udi)
191 + const QString source = m_batterySources[udi];
192 + setData(source, "Is Power Supply", newState);
195 +void PowermanagementEngine::updateBatteryNames()
197 + uint unnamedBatteries = 0;
198 + foreach (QString source, m_batterySources) {
199 + DataContainer *batteryDataContainer = containerForSource(source);
200 + if (batteryDataContainer) {
201 + const QString batteryVendor = batteryDataContainer->data()["Vendor"].toString();
202 + const QString batteryProduct = batteryDataContainer->data()["Product"].toString();
204 + // Don't show battery name for primary power supply batteries. They usually have cryptic serial number names.
205 + const QString batteryType = batteryDataContainer->data()["Type"].toString();
206 + bool batteryIsPowerSupply = batteryDataContainer->data()["Is Power Supply"].toBool();
207 + bool showBatteryName = batteryType != QLatin1String("Battery") ||
208 + (batteryType != QLatin1String("Battery") && !batteryIsPowerSupply);
210 + if (!batteryProduct.isEmpty() && batteryProduct != "Unknown Battery" && showBatteryName) {
211 + if (!batteryVendor.isEmpty()) {
212 + setData(source, "Pretty Name", QString(batteryVendor + ' ' + batteryProduct));
214 + setData(source, "Pretty Name", batteryProduct);
217 + ++unnamedBatteries;
218 + if (unnamedBatteries > 1) {
219 + setData(source, "Pretty Name", i18nc("Placeholder is the battery number", "Battery %1", unnamedBatteries));
221 + setData(source, "Pretty Name", i18n("Battery"));
228 void PowermanagementEngine::updateAcPlugState(bool newState)
230 setData("AC Adapter", "Plugged in", newState);
231 @@ -273,8 +381,7 @@ void PowermanagementEngine::deviceAdded(const QString& udi)
232 if (device.isValid()) {
233 const Solid::Battery* battery = device.as<Solid::Battery>();
235 - if (battery && (battery->type() == Solid::Battery::PrimaryBattery ||
236 - battery->type() == Solid::Battery::UpsBattery)) {
239 QStringList sourceNames(m_batterySources.values());
240 while (sourceNames.contains(QString("Battery%1").arg(index))) {
241 @@ -291,14 +398,24 @@ void PowermanagementEngine::deviceAdded(const QString& udi)
242 SLOT(updateBatteryChargePercent(int,QString)));
243 connect(battery, SIGNAL(plugStateChanged(bool,QString)), this,
244 SLOT(updateBatteryPlugState(bool,QString)));
245 + connect(battery, SIGNAL(powerSupplyStateChanged(bool,QString)), this,
246 + SLOT(updateBatteryPowerSupplyState(bool,QString)));
248 // Set initial values
249 updateBatteryChargeState(battery->chargeState(), device.udi());
250 updateBatteryChargePercent(battery->chargePercent(), device.udi());
251 updateBatteryPlugState(battery->isPlugged(), device.udi());
252 + updateBatteryPowerSupplyState(battery->isPowerSupply(), device.udi());
254 + setData(source, "Vendor", device.vendor());
255 + setData(source, "Product", device.product());
256 + setData(source, "Capacity", battery->capacity());
257 + setData(source, "Type", batteryType(battery));
259 setData("Battery", "Sources", sourceNames);
260 setData("Battery", "Has Battery", !sourceNames.isEmpty());
262 + updateBatteryNames();
266 @@ -309,6 +426,18 @@ void PowermanagementEngine::batteryRemainingTimeChanged(qulonglong time)
267 setData("Battery", "Remaining msec", time);
270 +void PowermanagementEngine::brightnessControlsAvailableChanged(bool available)
272 + setData("PowerDevil", "Screen Brightness Available", available);
273 + m_brightnessControlsAvailable = available;
276 +void PowermanagementEngine::keyboardBrightnessControlsAvailableChanged(bool available)
278 + setData("PowerDevil", "Keyboard Brightness Available", available);
279 + m_keyboardBrightnessControlsAvailable = available;
282 void PowermanagementEngine::batteryRemainingTimeReply(QDBusPendingCallWatcher *watcher)
284 QDBusPendingReply<qulonglong> reply = *watcher;
285 @@ -327,11 +456,18 @@ void PowermanagementEngine::screenBrightnessChanged(int brightness)
286 setData("PowerDevil", "Screen Brightness", brightness);
289 +void PowermanagementEngine::keyboardBrightnessChanged(int brightness)
291 + setData("PowerDevil", "Keyboard Brightness", brightness);
294 void PowermanagementEngine::screenBrightnessReply(QDBusPendingCallWatcher *watcher)
296 QDBusPendingReply<int> reply = *watcher;
297 if (reply.isError()) {
298 kDebug() << "Error getting screen brightness: " << reply.error().message();
299 + // FIXME Because the above check doesn't work, we unclaim backlight support as soon as it fails
300 + brightnessControlsAvailableChanged(false);
302 screenBrightnessChanged(reply.value());
304 @@ -339,6 +475,20 @@ void PowermanagementEngine::screenBrightnessReply(QDBusPendingCallWatcher *watch
305 watcher->deleteLater();
308 +void PowermanagementEngine::keyboardBrightnessReply(QDBusPendingCallWatcher *watcher)
310 + QDBusPendingReply<int> reply = *watcher;
311 + if (reply.isError()) {
312 + kDebug() << "Error getting keyboard brightness: " << reply.error().message();
313 + // FIXME Because the above check doesn't work, we unclaim backlight support as soon as it fails
314 + keyboardBrightnessControlsAvailableChanged(false);
316 + keyboardBrightnessChanged(reply.value());
319 + watcher->deleteLater();
322 K_EXPORT_PLASMA_DATAENGINE(powermanagement, PowermanagementEngine)
324 #include "powermanagementengine.moc"
325 diff --git a/plasma/generic/dataengines/powermanagement/powermanagementengine.h b/plasma/generic/dataengines/powermanagement/powermanagementengine.h
326 index 512bf6e..dafb6c2 100644
327 --- a/plasma/generic/dataengines/powermanagement/powermanagementengine.h
328 +++ b/plasma/generic/dataengines/powermanagement/powermanagementengine.h
329 @@ -54,21 +54,32 @@ private slots:
330 void updateBatteryChargeState(int newState, const QString& udi);
331 void updateBatteryPlugState(bool newState, const QString& udi);
332 void updateBatteryChargePercent(int newValue, const QString& udi);
333 + void updateBatteryPowerSupplyState(bool newState, const QString& udi);
334 void updateAcPlugState(bool newState);
335 + void updateBatteryNames();
337 void deviceRemoved(const QString& udi);
338 void deviceAdded(const QString& udi);
339 void batteryRemainingTimeChanged(qulonglong time);
340 void batteryRemainingTimeReply(QDBusPendingCallWatcher*);
341 void screenBrightnessChanged(int brightness);
342 + void keyboardBrightnessChanged(int brightness);
343 void screenBrightnessReply(QDBusPendingCallWatcher *watcher);
344 + void keyboardBrightnessReply(QDBusPendingCallWatcher *watcher);
345 + void brightnessControlsAvailableChanged(bool available);
346 + void keyboardBrightnessControlsAvailableChanged(bool available);
349 + QString batteryType(const Solid::Battery *battery);
350 QStringList basicSourceNames() const;
352 QStringList m_sources;
354 QHash<QString, QString> m_batterySources; // <udi, Battery0>
356 + bool m_brightnessControlsAvailable;
357 + bool m_keyboardBrightnessControlsAvailable;
362 diff --git a/plasma/generic/dataengines/powermanagement/powermanagementjob.cpp b/plasma/generic/dataengines/powermanagement/powermanagementjob.cpp
363 index 1b0b8a0..06156d9 100644
364 --- a/plasma/generic/dataengines/powermanagement/powermanagementjob.cpp
365 +++ b/plasma/generic/dataengines/powermanagement/powermanagementjob.cpp
366 @@ -94,6 +94,10 @@ void PowerManagementJob::start()
367 setScreenBrightness(parameters().value("brightness").toInt());
370 + } else if (operation == "setKeyboardBrightness") {
371 + setKeyboardBrightness(parameters().value("brightness").toInt());
376 kDebug() << "don't know what to do with " << operation;
377 @@ -103,8 +107,8 @@ void PowerManagementJob::start()
378 bool PowerManagementJob::suspend(const SuspendType &type)
380 QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement",
381 - "/org/kde/Solid/PowerManagement",
382 - "org.kde.Solid.PowerManagement",
383 + "/org/kde/Solid/PowerManagement/Actions/SuspendSession",
384 + "org.kde.Solid.PowerManagement.Actions.SuspendSession",
386 QDBusConnection::sessionBus().asyncCall(msg);
388 @@ -130,13 +134,23 @@ QString PowerManagementJob::callForType(const SuspendType &type)
389 void PowerManagementJob::setScreenBrightness(int value)
391 QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement",
392 - "/org/kde/Solid/PowerManagement",
393 - "org.kde.Solid.PowerManagement",
394 + "/org/kde/Solid/PowerManagement/Actions/BrightnessControl",
395 + "org.kde.Solid.PowerManagement.Actions.BrightnessControl",
398 QDBusConnection::sessionBus().asyncCall(msg);
401 +void PowerManagementJob::setKeyboardBrightness(int value)
403 + QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement",
404 + "/org/kde/Solid/PowerManagement/Actions/KeyboardBrightnessControl",
405 + "org.kde.Solid.PowerManagement.Actions.KeyboardBrightnessControl",
406 + "setKeyboardBrightness");
408 + QDBusConnection::sessionBus().asyncCall(msg);
411 void PowerManagementJob::requestShutDown()
413 KWorkSpace::requestShutDown();
414 diff --git a/plasma/generic/dataengines/powermanagement/powermanagementjob.h b/plasma/generic/dataengines/powermanagement/powermanagementjob.h
415 index 3b974ab..c1c7bf4 100644
416 --- a/plasma/generic/dataengines/powermanagement/powermanagementjob.h
417 +++ b/plasma/generic/dataengines/powermanagement/powermanagementjob.h
420 * Copyright 2011 Sebastian Kügler <sebas@kde.org>
423 * This program is free software; you can redistribute it and/or modify
424 * it under the terms of the GNU Library General Public License version 2 as
425 * published by the Free Software Foundation
426 @@ -41,6 +41,7 @@ class PowerManagementJob : public Plasma::ServiceJob
427 void requestShutDown();
428 QString callForType(const SuspendType &type);
429 void setScreenBrightness(int value);
430 + void setKeyboardBrightness(int value);
433 #endif // POWERMANAGEMENTJOB_H
434 diff --git a/plasma/generic/dataengines/powermanagement/powermanagementservice.operations b/plasma/generic/dataengines/powermanagement/powermanagementservice.operations
435 index 533c00a..c9abbf9 100644
436 --- a/plasma/generic/dataengines/powermanagement/powermanagementservice.operations
437 +++ b/plasma/generic/dataengines/powermanagement/powermanagementservice.operations
439 <label>The value of the screen brightness</label>
442 + <group name="setKeyboardBrightness">
443 + <entry name="brightness" type="Int">
444 + <label>The value of the keyboard brightness</label>
448 diff --git a/plasma/generic/applets/batterymonitor/contents/code/logic.js b/plasma/generic/applets/batterymonitor/contents/code/logic.js
449 index 974694a..9bd618d 100644
450 --- a/plasma/generic/applets/batterymonitor/contents/code/logic.js
451 +++ b/plasma/generic/applets/batterymonitor/contents/code/logic.js
453 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
459 function updateCumulative() {
463 + var plugged = false;
464 for (var i=0; i<batteries.count; i++) {
465 var b = batteries.get(i);
466 + if (!b["Is Power Supply"]) {
469 if (b["Plugged in"]) {
473 if (b["State"] != "NoCharge") {
479 - if (batteries.count > 0) {
480 - batteries.cumulativePercent = Math.round(sum/batteries.count);
482 + batteries.cumulativePercent = Math.round(sum/count);
484 - batteries.cumulativePercent = 0;
485 + // We don't have any power supply batteries
486 + // Use the lowest value from any battery
487 + if (batteries.count > 0) {
488 + var b = lowestBattery();
489 + batteries.cumulativePercent = b["Percent"];
491 + batteries.cumulativePercent = 0;
494 + batteries.cumulativePluggedin = plugged;
495 batteries.allCharged = charged;
498 -function stringForState(batteryData) {
499 - var pluggedIn = batteryData["Plugged in"];
500 - var percent = batteryData["Percent"];
501 - var state = batteryData["State"];
504 - if (state == "NoCharge") {
505 - return i18n("<b>%1% (charged)</b>", percent);
506 - } else if (state == "Discharging") {
507 - return i18n("<b>%1% (discharging)</b>", percent);
509 - return i18n("<b>%1% (charging)</b>", percent);
510 +function plasmoidStatus() {
511 + var status = "PassiveStatus";
512 + if (batteries.cumulativePluggedin) {
513 + if (batteries.cumulativePercent <= 10) {
514 + status = "NeedsAttentionStatus";
515 + } else if (!batteries.allCharged) {
516 + status = "ActiveStatus";
518 + } else if (batteries.count > 0) { // in case your mouse gets low
519 + if (batteries.cumulativePercent && batteries.cumulativePercent <= 10) {
520 + status = "NeedsAttentionStatus";
524 - return i18nc("Battery is not plugged in", "<b>Not present</b>");
528 -function updateTooltip() {
530 - for (var i=0; i<batteries.count; i++) {
531 - if (batteries.count == 1) {
532 - text += i18n("Battery:");
537 +function lowestBattery() {
538 + if (batteries.count == 0) {
542 - text += i18nc("tooltip: placeholder is the battery ID", "Battery %1:", i+1);
543 + var lowestPercent = 100;
545 + for(var i=0; i<batteries.count; i++) {
546 + var b = batteries.get(i);
547 + if (b["Percent"] && b["Percent"] < lowestPercent) {
548 + lowestPercent = b["Percent"];
556 - text += stringForState(pmSource.data["Battery"+i]);
557 +function stringForBatteryState(batteryData) {
558 + if (batteryData["Plugged in"]) {
559 + switch(batteryData["State"]) {
560 + case "NoCharge": return i18n("Not Charging");
561 + case "Discharging": return i18n("Discharging");
562 + case "FullyCharged": return i18n("Fully Charged");
563 + default: return i18n("Charging");
566 + return i18nc("Battery is currently not present in the bay","Not present");
570 +function iconForBattery(batteryData,pluggedIn) {
571 + switch(batteryData["Type"]) {
573 + return "video-display";
575 + return "input-mouse";
577 + return "input-keyboard";
582 + default: // Primary and UPS
583 + p = batteryData["Percent"];
586 + } else if (p >= 70) {
588 + } else if (p >= 50) {
590 + } else if (p >= 30) {
592 + } else if (p >= 10) {
600 + if (pluggedIn && batteryData["Is Power Supply"]) {
601 + return "battery-charging-" + fill;
604 + return "dialog-warning"
606 + return "battery-" + fill;
611 +function updateTooltip() {
614 + if (batteries.count == 0) {
615 + image = "battery-missing";
616 + text = i18n("No Batteries Available");
618 + var hasPowerSupply = false;
620 + text = "<table style='white-space: nowrap'>";
621 + for(var i=0; i<batteries.count; i++) {
622 + var b = batteries.get(i);
624 + text += "<td align='right'>" + i18nc("Placeholder is battery name", "%1:", b["Pretty Name"]) + " </td>";
625 + text += "<td>" + i18nc("Placeholder is battery percentage", "%1%", b["Percent"]) + "</td>";
628 - if (pmSource.data["AC Adapter"]) {
629 - text += i18nc("tooltip", "AC Adapter:") + " ";
630 - text += pmSource.data["AC Adapter"]["Plugged in"] ? i18nc("tooltip", "<b>Plugged in</b>") : i18nc("tooltip", "<b>Not plugged in</b>");
631 + if (b["Is Power Supply"]) { hasPowerSupply = true; }
633 + text += "</table>";
635 + if (hasPowerSupply) {
637 + b["Percent"] = batteries.cumulativePercent;
638 + image = iconForBattery(b, pmSource.data["AC Adapter"]["Plugged in"] ? true : false);
640 + var b = lowestBattery();
641 + image = iconForBattery(b, false);
644 batteries.tooltipText = text;
645 + batteries.tooltipImage = image;
648 function updateBrightness() {
649 @@ -94,16 +179,26 @@ function updateBrightness() {
652 dialogItem.disableBrightnessUpdate = true;
653 - dialogItem.screenBrightness = pmSource.data["PowerDevil"]["Screen Brightness"];
654 + if (pmSource.data["PowerDevil"]["Screen Brightness"]) {
655 + dialogItem.screenBrightness = pmSource.data["PowerDevil"]["Screen Brightness"];
657 + if (pmSource.data["PowerDevil"]["Keyboard Brightness"]) {
658 + dialogItem.keyboardBrightness = pmSource.data["PowerDevil"]["Keyboard Brightness"];
660 dialogItem.disableBrightnessUpdate = false;
663 -function callForType(type) {
665 - return "suspendToRam";
666 - } else if (type == disk) {
667 - return "suspendToDisk";
669 +// TODO: give translated and formatted string with KGlobal::locale()->prettyFormatDuration(msec);
670 +function formatDuration(msec) {
671 + if (msec == 0 || msec === undefined)
674 + var time = new Date(msec);
675 + var hours = time.getUTCHours();
676 + var minutes = time.getUTCMinutes();
678 - return "suspendHybrid";
680 + if (hours > 0) str += i18np("1 hour ", "%1 hours ", hours);
681 + if (minutes > 0) str += i18np("1 minute", "%1 minutes", minutes);
684 diff --git a/plasma/generic/applets/batterymonitor/contents/code/platform.js b/plasma/generic/applets/batterymonitor/contents/code/platform.js
685 deleted file mode 100644
686 index 59af3af..0000000
687 --- a/plasma/generic/applets/batterymonitor/contents/code/platform.js
691 -function shouldOfferSuspend(pmSource) {
692 - return pmSource.data["Sleep States"]["Suspend"];
695 -function shouldOfferHibernate(pmSource) {
696 - return pmSource.data["Sleep States"]["Hibernate"];
699 diff --git a/plasma/generic/applets/batterymonitor/contents/config/main.xml b/plasma/generic/applets/batterymonitor/contents/config/main.xml
700 index fc31b3e..5e9e31d 100644
701 --- a/plasma/generic/applets/batterymonitor/contents/config/main.xml
702 +++ b/plasma/generic/applets/batterymonitor/contents/config/main.xml
706 <group name="General">
707 - <entry name="showBatteryString" type="Bool">
708 - <default>false</default>
710 - <entry name="showMultipleBatteries" type="Bool">
711 - <default>false</default>
713 <entry name="showRemainingTime" type="Bool">
714 <default>false</default>
716 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/AcAdapterItem.qml b/plasma/generic/applets/batterymonitor/contents/ui/AcAdapterItem.qml
718 index 0000000..c2216f8
720 +++ b/plasma/generic/applets/batterymonitor/contents/ui/AcAdapterItem.qml
723 + * Copyright 2012-2013 Daniel Nicoletti <dantti12@gmail.com>
724 + * Copyright 2013 Kai Uwe Broulik <kde@privat.broulik.de>
726 + * This program is free software; you can redistribute it and/or modify
727 + * it under the terms of the GNU Library General Public License as
728 + * published by the Free Software Foundation; either version 2 or
729 + * (at your option) any later version.
731 + * This program is distributed in the hope that it will be useful,
732 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
733 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
734 + * GNU General Public License for more details
736 + * You should have received a copy of the GNU Library General Public
737 + * License along with this program; if not, write to the
738 + * Free Software Foundation, Inc.,
739 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
743 +import org.kde.plasma.core 0.1 as PlasmaCore
744 +import org.kde.plasma.components 0.1 as Components
745 +import org.kde.qtextracomponents 0.1
750 + width: parent.width
751 + height: acIcon.height + padding.margins.top + padding.margins.bottom
753 + property bool pluggedIn
754 + property bool showTime
755 + property string remainingString
759 + width: theme.iconSizes.dialog
763 + topMargin: padding.margins.top
765 + leftMargin: padding.margins.left
768 + icon: pluggedIn ? QIcon("battery-charging-low") : QIcon("battery-low")
778 + height: paintedHeight
779 + text: i18n("AC Adapter")
785 + top: showTime ? acLabel.top : undefined
786 + bottom: showTime ? undefined : acIcon.bottom
787 + left: showTime ? acLabel.right : acIcon.right
788 + leftMargin: showTime ? 3 : 6
790 + height: paintedHeight
791 + text: pluggedIn ? i18n("Plugged In") : i18n("Not Plugged In")
792 + color: "#77"+(theme.textColor.toString().substr(1))
798 + bottom: acIcon.bottom
802 + height: paintedHeight
804 + text: pluggedIn ? i18n("Time remaining until full: %1", remainingString) : i18n("Time remaining until empty: %1", remainingString)
805 + color: "#77"+(theme.textColor.toString().substr(1))
809 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/BatteryIcon.qml b/plasma/generic/applets/batterymonitor/contents/ui/BatteryIcon.qml
810 index 080ab51..6a49d34 100644
811 --- a/plasma/generic/applets/batterymonitor/contents/ui/BatteryIcon.qml
812 +++ b/plasma/generic/applets/batterymonitor/contents/ui/BatteryIcon.qml
813 @@ -21,15 +21,13 @@ import QtQuick 1.1
814 import org.kde.plasma.core 0.1 as PlasmaCore
818 - property bool monochrome
819 property bool hasBattery
821 property bool pluggedIn
826 - imagePath: monochrome ? "icons/battery" : "widgets/battery-oxygen"
827 + imagePath: "icons/battery"
831 @@ -39,25 +37,55 @@ Item {
838 elementId: hasBattery ? fillElement(percent) : "Unavailable"
839 - visible: percent>10 || !hasBattery
840 + visible: elementId != ""
843 function fillElement(p) {
846 - } else if (p >= 70) {
848 - } else if (p >= 50) {
850 - } else if (p > 20) {
852 - } else if (p >= 10) {
854 + // We switched from having steps of 20 for the battery percentage to a more accurate
855 + // step of 10. This means we break other and older themes.
856 + // If the Fill10 element is not found, it is likely that the theme doesn't support
857 + // that and we use the older method of obtaining the fill element.
858 + if (!svg.hasElement("Fill10")) {
861 + } else if (p >= 70) {
863 + } else if (p >= 50) {
865 + } else if (p > 20) {
867 + } else if (p >= 10) {
874 + } else if (p >= 85) {
876 + } else if (p >= 75) {
878 + } else if (p >= 65) {
880 + } else if (p >= 55) {
882 + } else if (p >= 45) {
884 + } else if (p >= 35) {
886 + } else if (p >= 25) {
888 + } else if (p >= 15) {
890 + } else if (p >= 5) {
899 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/BatteryItem.qml b/plasma/generic/applets/batterymonitor/contents/ui/BatteryItem.qml
901 index 0000000..81779ff
903 +++ b/plasma/generic/applets/batterymonitor/contents/ui/BatteryItem.qml
906 + * Copyright 2012-2013 Daniel Nicoletti <dantti12@gmail.com>
907 + * Copyright 2013 Kai Uwe Broulik <kde@privat.broulik.de>
909 + * This program is free software; you can redistribute it and/or modify
910 + * it under the terms of the GNU Library General Public License as
911 + * published by the Free Software Foundation; either version 2 or
912 + * (at your option) any later version.
914 + * This program is distributed in the hope that it will be useful,
915 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
916 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
917 + * GNU General Public License for more details
919 + * You should have received a copy of the GNU Library General Public
920 + * License along with this program; if not, write to the
921 + * Free Software Foundation, Inc.,
922 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
926 +import org.kde.plasma.core 0.1 as PlasmaCore
927 +import org.kde.plasma.components 0.1 as Components
928 +import org.kde.qtextracomponents 0.1
929 +import "plasmapackage:/code/logic.js" as Logic
934 + width: batteryColumn.width
935 + height: expanded ? batteryInfos.height + padding.margins.top + padding.margins.bottom * 2 + actionRow.height
936 + : batteryInfos.height + padding.margins.top + padding.margins.bottom
938 + Behavior on height { PropertyAnimation {} }
940 + property bool highlight
941 + property bool expanded
942 + property bool showChargeAnimation
944 + property bool isPresent: !model["Is Power Supply"] || model["Plugged in"]
946 + function updateSelection() {
947 + var containsMouse = mouseArea.containsMouse;
949 + if (highlight || expanded && containsMouse) {
950 + padding.opacity = 1;
951 + } else if (expanded) {
952 + padding.opacity = 0.8;
953 + } else if (containsMouse) {
954 + padding.opacity = 0.65;
956 + padding.opacity = 0;
960 + PlasmaCore.FrameSvgItem {
962 + imagePath: "widgets/viewitem"
965 + Behavior on opacity { PropertyAnimation {} }
966 + anchors.fill: parent
971 + anchors.fill: parent
973 + onEntered: updateSelection()
974 + onExited: updateSelection()
980 + batteryItem.forceActiveFocus();
988 + height: Math.max(batteryIcon.height, batteryNameLabel.height + batteryPercentBar.height)
992 + topMargin: padding.margins.top
994 + leftMargin: padding.margins.left
995 + right: parent.right
996 + rightMargin: padding.margins.right
1001 + width: theme.iconSizes.dialog
1004 + verticalCenter: parent.verticalCenter
1007 + icon: QIcon(Logic.iconForBattery(model,pluggedIn))
1010 + SequentialAnimation {
1011 + id: chargeAnimation
1012 + running: showChargeAnimation && model["State"] == "Charging"
1013 + alwaysRunToEnd: true
1014 + loops: Animation.Infinite
1017 + target: batteryIcon
1018 + properties: "opacity"
1022 + easing.type: Easing.InCubic
1025 + target: batteryIcon
1026 + properties: "opacity"
1030 + easing.type: Easing.OutCubic
1034 + Components.Label {
1035 + id: batteryNameLabel
1037 + verticalCenter: isPresent ? undefined : batteryIcon.verticalCenter
1038 + top: isPresent ? parent.top : undefined
1039 + left: batteryIcon.right
1042 + height: paintedHeight
1043 + elide: Text.ElideRight
1044 + text: model["Pretty Name"]
1047 + Components.Label {
1048 + id: batteryStatusLabel
1050 + top: batteryNameLabel.top
1051 + left: batteryNameLabel.right
1054 + text: Logic.stringForBatteryState(model)
1055 + height: paintedHeight
1056 + visible: model["Is Power Supply"]
1057 + color: "#77"+(theme.textColor.toString().substr(1))
1060 + Components.ProgressBar {
1061 + id: batteryPercentBar
1063 + bottom: parent.bottom
1064 + left: batteryIcon.right
1066 + right: batteryPercent.left
1071 + visible: isPresent
1072 + value: parseInt(model["Percent"])
1075 + Components.Label {
1076 + id: batteryPercent
1078 + verticalCenter: batteryPercentBar.verticalCenter
1079 + right: parent.right
1081 + visible: isPresent
1082 + text: i18nc("Placeholder is battery percentage", "%1%", model["Percent"])
1088 + opacity: expanded ? 1 : 0
1089 + width: parent.width
1091 + top: batteryInfos.bottom
1092 + topMargin: padding.margins.bottom
1094 + leftMargin: padding.margins.left
1095 + right: parent.right
1096 + rightMargin: padding.margins.right
1097 + bottomMargin: padding.margins.bottom
1100 + Behavior on opacity { PropertyAnimation {} }
1102 + PlasmaCore.SvgItem {
1103 + svg: PlasmaCore.Svg {
1105 + imagePath: "widgets/line"
1107 + elementId: "horizontal-line"
1108 + height: lineSvg.elementSize("horizontal-line").height
1109 + width: parent.width
1114 + width: parent.width
1119 + Components.Label {
1120 + height: paintedHeight
1121 + width: parent.width
1122 + horizontalAlignment: Text.AlignRight
1123 + onPaintedWidthChanged: {
1124 + if (paintedWidth > parent.width) { parent.width = paintedWidth; }
1126 + text: model["State"] == "Charging" ? i18n("Time To Full:") : i18n("Time To Empty:")
1127 + visible: remainingTimeLabel.visible
1128 + font.pointSize: theme.smallestFont.pointSize
1129 + color: "#99"+(theme.textColor.toString().substr(1))
1131 + Components.Label {
1132 + height: paintedHeight
1133 + width: parent.width
1134 + horizontalAlignment: Text.AlignRight
1135 + onPaintedWidthChanged: {
1136 + if (paintedWidth > parent.width) { parent.width = paintedWidth; }
1138 + text: i18n("Capacity:")
1139 + visible: capacityLabel.visible
1140 + font.pointSize: theme.smallestFont.pointSize
1141 + color: "#99"+(theme.textColor.toString().substr(1))
1143 + Components.Label {
1144 + height: paintedHeight
1145 + width: parent.width
1146 + horizontalAlignment: Text.AlignRight
1147 + onPaintedWidthChanged: {
1148 + if (paintedWidth > parent.width) { parent.width = paintedWidth; }
1150 + text: i18n("Vendor:")
1151 + visible: vendorLabel.visible
1152 + font.pointSize: theme.smallestFont.pointSize
1153 + color: "#99"+(theme.textColor.toString().substr(1))
1155 + Components.Label {
1156 + height: paintedHeight
1157 + width: parent.width
1158 + horizontalAlignment: Text.AlignRight
1159 + onPaintedWidthChanged: {
1160 + if (paintedWidth > parent.width) { parent.width = paintedWidth; }
1162 + text: i18n("Model:")
1163 + visible: modelLabel.visible
1164 + font.pointSize: theme.smallestFont.pointSize
1165 + color: "#99"+(theme.textColor.toString().substr(1))
1169 + width: parent.width - labelsColumn.width - parent.spacing * 2
1170 + Components.Label { // Remaining Time
1171 + id: remainingTimeLabel
1172 + height: paintedHeight
1173 + width: parent.width
1174 + elide: Text.ElideRight
1175 + text: Logic.formatDuration(model["Remaining Time"])
1176 + visible: showRemainingTime && model["Is Power Supply"] && model["State"] != "NoCharge" && text
1177 + font.pointSize: theme.smallestFont.pointSize
1178 + color: "#99"+(theme.textColor.toString().substr(1))
1180 + Components.Label { // Capacity
1182 + height: paintedHeight
1183 + width: parent.width
1184 + elide: Text.ElideRight
1185 + text: i18nc("Placeholder is battery capacity", "%1%", model["Capacity"])
1186 + visible: model["Capacity"] != "" && model["Capacity"] !== undefined
1187 + font.pointSize: theme.smallestFont.pointSize
1188 + color: "#99"+(theme.textColor.toString().substr(1))
1190 + Components.Label { // Vendor
1192 + height: paintedHeight
1193 + width: parent.width
1194 + elide: Text.ElideRight
1195 + text: model["Vendor"]
1196 + visible: model["Vendor"] != "" && model["Vendor"] !== undefined
1197 + font.pointSize: theme.smallestFont.pointSize
1198 + color: "#99"+(theme.textColor.toString().substr(1))
1200 + Components.Label { // Model
1202 + height: paintedHeight
1203 + width: parent.width
1204 + elide: Text.ElideRight
1205 + text: model["Product"]
1206 + visible: model["Product"] != "" && model["Product"] !== undefined
1207 + font.pointSize: theme.smallestFont.pointSize
1208 + color: "#99"+(theme.textColor.toString().substr(1))
1215 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/BrightnessItem.qml b/plasma/generic/applets/batterymonitor/contents/ui/BrightnessItem.qml
1216 new file mode 100644
1217 index 0000000..34c596c
1219 +++ b/plasma/generic/applets/batterymonitor/contents/ui/BrightnessItem.qml
1222 + * Copyright 2012-2013 Daniel Nicoletti <dantti12@gmail.com>
1223 + * Copyright 2013 Kai Uwe Broulik <kde@privat.broulik.de>
1225 + * This program is free software; you can redistribute it and/or modify
1226 + * it under the terms of the GNU Library General Public License as
1227 + * published by the Free Software Foundation; either version 2 or
1228 + * (at your option) any later version.
1230 + * This program is distributed in the hope that it will be useful,
1231 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1232 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1233 + * GNU General Public License for more details
1235 + * You should have received a copy of the GNU Library General Public
1236 + * License along with this program; if not, write to the
1237 + * Free Software Foundation, Inc.,
1238 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1242 +import org.kde.plasma.core 0.1 as PlasmaCore
1243 +import org.kde.plasma.components 0.1 as Components
1244 +import org.kde.qtextracomponents 0.1
1247 + id: brightnessItem
1249 + width: parent.width
1250 + height: Math.max(brightnessIcon.height, brightnessLabel.height + brightnessSlider.height) + padding.margins.top + padding.margins.bottom
1252 + property alias icon: brightnessIcon.icon
1253 + property alias label: brightnessLabel.text
1254 + property alias value: brightnessSlider.value
1256 + signal changed(int screenBrightness)
1259 + id: brightnessIcon
1260 + width: theme.iconSizes.dialog
1263 + verticalCenter: parent.verticalCenter
1264 + topMargin: padding.margins.top
1265 + bottomMargin: padding.margins.bottom
1267 + leftMargin: padding.margins.left
1271 + Components.Label {
1272 + id: brightnessLabel
1275 + topMargin: padding.margins.top
1276 + left: brightnessIcon.right
1279 + height: paintedHeight
1282 + Components.Slider {
1283 + id: brightnessSlider
1285 + bottom: parent.bottom
1286 + bottomMargin: padding.margins.bottom
1287 + left: brightnessIcon.right
1288 + right: brightnessPercent.left
1295 + onValueChanged: changed(value)
1298 + Components.Label {
1299 + id: brightnessPercent
1301 + right: parent.right
1302 + rightMargin: padding.margins.right
1303 + verticalCenter: brightnessSlider.verticalCenter
1305 + height: paintedHeight
1306 + text: i18nc("Placeholder is brightness percentage", "%1%", brightnessSlider.value)
1310 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/CompactRepresentation.qml b/plasma/generic/applets/batterymonitor/contents/ui/CompactRepresentation.qml
1311 new file mode 100644
1312 index 0000000..e9dc772
1314 +++ b/plasma/generic/applets/batterymonitor/contents/ui/CompactRepresentation.qml
1317 +* Copyright 2011 Sebastian Kügler <sebas@kde.org>
1318 +* Copyright 2011 Viranch Mehta <viranch.mehta@gmail.com>
1319 +* Copyright 2013 Kai Uwe Broulik <kde@privat.broulik.de>
1321 +* This program is free software; you can redistribute it and/or modify
1322 +* it under the terms of the GNU Library General Public License as
1323 +* published by the Free Software Foundation; either version 2 or
1324 +* (at your option) any later version.
1326 +* This program is distributed in the hope that it will be useful,
1327 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
1328 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1329 +* GNU General Public License for more details
1331 +* You should have received a copy of the GNU Library General Public
1332 +* License along with this program; if not, write to the
1333 +* Free Software Foundation, Inc.,
1334 +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1338 +import org.kde.plasma.core 0.1 as PlasmaCore
1339 +import org.kde.plasma.components 0.1 as Components
1340 +import "plasmapackage:/code/logic.js" as Logic
1345 + property int minimumWidth
1346 + property int minimumHeight
1348 + property bool hasBattery
1350 + property QtObject pmSource
1351 + property QtObject batteries
1353 + property bool singleBattery
1355 + model: singleBattery ? 1 : batteries
1357 + anchors.fill: parent
1358 + orientation: ListView.Horizontal
1359 + interactive: false
1361 + function isConstrained() {
1362 + return (plasmoid.formFactor == Vertical || plasmoid.formFactor == Horizontal);
1365 + Component.onCompleted: {
1366 + if (!isConstrained()) {
1367 + minimumHeight = theme.iconSizes.dialog;
1368 + minimumWidth = minimumHeight * view.count;
1370 + // NOTE: Keep in sync with systray
1371 + minimumHeight = 24;
1372 + minimumWidth = 24;
1377 + id: batteryContainer
1379 + property bool hasBattery: view.singleBattery ? batteries.count : model["Plugged in"]
1380 + property int percent: view.singleBattery ? batteries.cumulativePercent : model["Percent"]
1381 + property bool pluggedIn: pmSource.data["AC Adapter"]["Plugged in"]
1383 + width: view.width/view.count
1384 + height: view.height
1386 + property real iconSize: Math.min(width, height)
1389 + anchors.fill: parent
1393 + anchors.centerIn: isConstrained() ? parent : undefined
1394 + anchors.horizontalCenter: isConstrained() ? undefined : parent.horizontalCenter
1395 + hasBattery: batteryContainer.hasBattery
1396 + percent: batteryContainer.percent
1397 + pluggedIn: batteryContainer.pluggedIn
1398 + height: isConstrained() ? batteryContainer.iconSize : batteryContainer.iconSize - batteryLabel.height
1402 + Components.Label {
1404 + width: parent.width
1405 + height: paintedHeight
1406 + horizontalAlignment: Text.AlignHCenter
1407 + text: i18nc("battery percentage below battery icon", "%1%", percent)
1408 + font.pixelSize: Math.max(batteryContainer.iconSize/8, 10)
1409 + visible: !isConstrained()
1416 + anchors.fill: parent
1417 + hoverEnabled: true
1418 + onClicked: plasmoid.togglePopup()
1420 + PlasmaCore.ToolTip {
1423 + image: batteries.tooltipImage
1424 + subText: batteries.tooltipText
1428 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml b/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml
1429 index 76fb1ce..4f46834 100644
1430 --- a/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml
1431 +++ b/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml
1434 * Copyright 2011 Viranch Mehta <viranch.mehta@gmail.com>
1435 + * Copyright 2013 Kai Uwe Broulik <kde@privat.broulik.de>
1437 * This program is free software; you can redistribute it and/or modify
1438 * it under the terms of the GNU Library General Public License as
1439 @@ -18,176 +19,106 @@
1443 +import org.kde.plasma.core 0.1 as PlasmaCore
1444 import org.kde.plasma.components 0.1 as Components
1445 +import org.kde.qtextracomponents 0.1
1446 import "plasmapackage:/code/logic.js" as Logic
1450 - width: childrenRect.width+24
1451 - height: childrenRect.height+24
1452 + property int actualHeight: batteryColumn.implicitHeight + settingsColumn.height + separator.height + 10 // 10 = separator margins
1454 - property alias model: batteryLabels.model
1455 - property alias hasBattery: batteryIcon.hasBattery
1456 - property alias percent: batteryIcon.percent
1457 + property alias model: batteryList.model
1458 property bool pluggedIn
1459 + property bool showRemainingTime
1461 + property bool popupShown // somehow plasmoid.popupShowing isn't working
1463 + property bool isBrightnessAvailable
1464 property alias screenBrightness: brightnessSlider.value
1465 - property int remainingMsec
1466 - property alias showSuspendButton: suspendButton.visible
1467 - property alias showHibernateButton: hibernateButton.visible
1469 + property bool isKeyboardBrightnessAvailable
1470 + property alias keyboardBrightness: keyboardBrightnessSlider.value
1472 - signal suspendClicked(int type)
1473 signal brightnessChanged(int screenBrightness)
1474 + signal keyboardBrightnessChanged(int keyboardBrightness)
1475 signal powermanagementChanged(bool checked)
1477 + PlasmaCore.FrameSvgItem {
1479 + imagePath: "widgets/viewitem"
1489 + width: parent.width
1496 - model: dialog.model
1497 - Components.Label {
1498 - text: model.count>1 ? i18nc("Placeholder is the battery ID", "Battery %1:", index+1) : i18n("Battery:")
1499 - width: labels.width
1500 - horizontalAlignment: Text.AlignRight
1504 - Components.Label {
1505 - text: i18n("AC Adapter:")
1506 - anchors.right: parent.right
1507 - anchors.bottomMargin: 12
1510 - Components.Label {
1511 - text: i18nc("Label for remaining time", "Time Remaining:")
1512 - visible: remainingTime.visible
1513 - anchors.right: parent.right
1516 - Components.Label {
1517 - text: i18nc("Label for power management inhibition", "Power management enabled:")
1518 - anchors.right: parent.right
1519 + right: parent.right
1520 + top: plasmoid.location == BottomEdge ? parent.top : undefined
1521 + bottom: plasmoid.location == BottomEdge ? undefined : parent.bottom
1524 - Components.Label {
1525 - text: i18n("Screen Brightness:")
1526 - anchors.right: parent.right
1529 + delegate: BatteryItem { showChargeAnimation: popupShown }
1538 - left: labels.right
1541 + id: settingsColumn
1543 + width: parent.width
1554 - Components.Label {
1555 - text: Logic.stringForState(model)
1556 - font.weight: Font.Bold
1560 - Components.Label {
1561 - text: dialog.pluggedIn ? i18n("Plugged in") : i18n("Not plugged in")
1562 - font.weight: Font.Bold
1563 - anchors.bottomMargin: 12
1566 - Components.Label {
1568 - text: formatDuration(remainingMsec);
1569 - font.weight: Font.Bold
1577 - width: upperValues.width + batteryIcon.width * 2
1581 - Components.CheckBox {
1583 - onClicked: powermanagementChanged(checked)
1587 - Components.Slider {
1588 - id: brightnessSlider
1589 - width: lowerValues.width
1593 - onValueChanged: brightnessChanged(value)
1597 + right: parent.right
1598 + top: plasmoid.location == BottomEdge ? undefined : parent.top
1599 + bottom: plasmoid.location == BottomEdge ? parent.bottom : undefined
1603 - // TODO: give translated and formatted string with KGlobal::locale()->prettyFormatDuration(msec);
1604 - function formatDuration(msec) {
1608 - var time = new Date(msec);
1609 - var hours = time.getUTCHours();
1610 - var minutes = time.getUTCMinutes();
1612 - if (hours > 0) str += i18np("1 hour ", "%1 hours ", hours);
1613 - if (minutes > 0) str += i18np("1 minute", "%1 minutes", minutes);
1617 + id: brightnessSlider
1618 + icon: QIcon("video-display")
1619 + label: i18n("Display Brightness")
1620 + visible: isBrightnessAvailable
1621 + onChanged: brightnessChanged(value)
1625 - top: values.bottom
1627 - right: values.right
1630 - Components.ToolButton {
1632 - iconSource: "system-suspend"
1633 - text: i18nc("Suspend the computer to RAM; translation should be short", "Sleep")
1634 - onClicked: suspendClicked(Logic.ram)
1636 + id: keyboardBrightnessSlider
1637 + icon: QIcon("input-keyboard")
1638 + label: i18n("Keyboard Brightness")
1639 + visible: isKeyboardBrightnessAvailable
1640 + onChanged: keyboardBrightnessChanged(value)
1643 - Components.ToolButton {
1644 - id: hibernateButton
1645 - iconSource: "system-suspend-hibernate"
1646 - text: i18nc("Suspend the computer to disk; translation should be short", "Hibernate")
1647 - onClicked: suspendClicked(Logic.disk)
1648 + PowerManagementItem {
1650 + onEnabledChanged: powermanagementChanged(enabled)
1657 - pluggedIn: dialog.pluggedIn
1658 + PlasmaCore.SvgItem {
1660 + svg: PlasmaCore.Svg {
1662 + imagePath: "widgets/line"
1664 + elementId: "horizontal-line"
1665 + height: lineSvg.elementSize("horizontal-line").height
1666 + width: parent.width
1669 - right: values.right
1671 + top: plasmoid.location == BottomEdge ? undefined : settingsColumn.bottom
1672 + bottom: plasmoid.location == BottomEdge ? settingsColumn.top : undefined
1673 + leftMargin: padding.margins.left
1674 + rightMargin: padding.margins.right
1679 - height: hibernateButton.height * 2
1682 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/PowerManagementItem.qml b/plasma/generic/applets/batterymonitor/contents/ui/PowerManagementItem.qml
1683 new file mode 100644
1684 index 0000000..c82a86d
1686 +++ b/plasma/generic/applets/batterymonitor/contents/ui/PowerManagementItem.qml
1689 + * Copyright 2012-2013 Daniel Nicoletti <dantti12@gmail.com>
1690 + * Copyright 2013 Kai Uwe Broulik <kde@privat.broulik.de>
1692 + * This program is free software; you can redistribute it and/or modify
1693 + * it under the terms of the GNU Library General Public License as
1694 + * published by the Free Software Foundation; either version 2 or
1695 + * (at your option) any later version.
1697 + * This program is distributed in the hope that it will be useful,
1698 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1699 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1700 + * GNU General Public License for more details
1702 + * You should have received a copy of the GNU Library General Public
1703 + * License along with this program; if not, write to the
1704 + * Free Software Foundation, Inc.,
1705 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1709 +import org.kde.plasma.core 0.1 as PlasmaCore
1710 +import org.kde.plasma.components 0.1 as Components
1711 +import org.kde.qtextracomponents 0.1
1714 + id: brightnessItem
1716 + width: parent.width
1717 + height: Math.max(pmCheckBox.height, pmLabel.height) + padding.margins.top + padding.margins.bottom
1719 + property alias enabled: pmCheckBox.checked
1721 + signal enabledChanged(bool checked)
1723 + Components.CheckBox {
1726 + verticalCenter: parent.verticalCenter
1728 + leftMargin: padding.margins.left + (theme.iconSizes.dialog - width)
1729 + topMargin: padding.margins.top
1730 + bottomMargin: padding.margins.bottom
1733 + onCheckedChanged: enabledChanged(checked)
1736 + Components.Label {
1739 + verticalCenter: pmCheckBox.verticalCenter
1740 + left: pmCheckBox.right
1743 + height: paintedHeight
1744 + text: i18n("Enable Power Management")
1748 + anchors.fill: parent
1750 + onReleased: pmCheckBox.released();
1751 + onPressed: pmCheckBox.forceActiveFocus();
1755 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/ScrollableListView.qml b/plasma/generic/applets/batterymonitor/contents/ui/ScrollableListView.qml
1756 new file mode 100644
1757 index 0000000..c3cb818
1759 +++ b/plasma/generic/applets/batterymonitor/contents/ui/ScrollableListView.qml
1762 + * Copyright 2012 Daniel Nicoletti <dantti12@gmail.com>
1764 + * This program is free software; you can redistribute it and/or modify
1765 + * it under the terms of the GNU Library General Public License as
1766 + * published by the Free Software Foundation; either version 2 or
1767 + * (at your option) any later version.
1769 + * This program is distributed in the hope that it will be useful,
1770 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1771 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1772 + * GNU General Public License for more details
1774 + * You should have received a copy of the GNU Library General Public
1775 + * License along with this program; if not, write to the
1776 + * Free Software Foundation, Inc.,
1777 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1781 +import org.kde.plasma.core 0.1 as PlasmaCore
1782 +import org.kde.plasma.components 0.1 as Components
1783 +import org.kde.qtextracomponents 0.1
1786 + property alias delegate: list.delegate
1787 + property alias model: list.model
1788 + property alias view: list
1789 + property alias interactive: list.interactive
1790 + property alias currentIndex: list.currentIndex
1791 + signal countChanged()
1793 + Component.onCompleted: {
1794 + list.countChanged.connect(countChanged)
1803 + right: scrollBar.visible ? scrollBar.left : parent.right
1805 + bottom: parent.bottom
1807 + boundsBehavior: Flickable.StopAtBounds
1809 + Components.ScrollBar {
1811 + flickableItem: list
1813 + right: parent.right
1815 + bottom: list.bottom
1819 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml b/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml
1820 index a5e1c13..f082c38 100644
1821 --- a/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml
1822 +++ b/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml
1825 * Copyright 2011 Sebastian Kügler <sebas@kde.org>
1826 * Copyright 2011 Viranch Mehta <viranch.mehta@gmail.com>
1827 + * Copyright 2013 Kai Uwe Broulik <kde@privat.broulik.de>
1829 * This program is free software; you can redistribute it and/or modify
1830 * it under the terms of the GNU Library General Public License as
1831 @@ -21,128 +22,40 @@
1833 import org.kde.plasma.core 0.1 as PlasmaCore
1834 import "plasmapackage:/code/logic.js" as Logic
1835 -import "plasmapackage:/code/platform.js" as Platform
1839 - property int minimumWidth: dialogItem.width
1840 - property int minimumHeight: dialogItem.height
1841 + property int minimumWidth: theme.iconSizes.dialog * 9
1842 + property int minimumHeight: dialogItem.actualHeight
1843 + property int maximumHeight: dialogItem.actualHeight
1845 property bool show_remaining_time: false
1847 + PlasmaCore.Theme { id: theme }
1849 Component.onCompleted: {
1850 + plasmoid.aspectRatioMode = IgnoreAspectRatio
1851 Logic.updateCumulative();
1852 + plasmoid.status = Logic.plasmoidStatus();
1853 Logic.updateTooltip();
1854 Logic.updateBrightness();
1855 plasmoid.addEventListener('ConfigChanged', configChanged);
1856 + plasmoid.popupEvent.connect(popupEventSlot);
1859 function configChanged() {
1860 show_remaining_time = plasmoid.readConfig("showRemainingTime");
1863 - property Component compactRepresentation: Component {
1867 - property int minimumWidth
1868 - property int minimumHeight
1870 - property bool showOverlay: false
1871 - property bool showMultipleBatteries: false
1872 - property bool hasBattery: pmSource.data["Battery"]["Has Battery"]
1874 - property QtObject pmSource: plasmoid.rootItem.pmSource
1875 - property QtObject batteries: plasmoid.rootItem.batteries
1877 - property bool singleBattery: isConstrained() || !showMultipleBatteries || !hasBattery
1879 - model: singleBattery ? 1 : batteries
1881 - PlasmaCore.Theme { id: theme }
1883 - anchors.fill: parent
1884 - orientation: ListView.Horizontal
1886 - function isConstrained() {
1887 - return (plasmoid.formFactor == Vertical || plasmoid.formFactor == Horizontal);
1890 - Component.onCompleted: {
1891 - if (!isConstrained()) {
1892 - minimumWidth = 32;
1893 - minimumHeight = 32;
1895 - plasmoid.addEventListener('ConfigChanged', configChanged);
1898 - function configChanged() {
1899 - showOverlay = plasmoid.readConfig("showBatteryString");
1900 - showMultipleBatteries = plasmoid.readConfig("showMultipleBatteries");
1904 - id: batteryContainer
1906 - property bool hasBattery: view.singleBattery ? batteries.cumulativePluggedin : model["Plugged in"]
1907 - property int percent: view.singleBattery ? batteries.cumulativePercent : model["Percent"]
1908 - property bool pluggedIn: pmSource.data["AC Adapter"]["Plugged in"]
1910 - width: view.width/view.count
1911 - height: view.height
1913 - property real size: Math.min(width, height)
1918 - hasBattery: parent.hasBattery
1919 - percent: parent.percent
1920 - pluggedIn: parent.pluggedIn
1921 - width: size; height: size
1922 - anchors.centerIn: parent
1927 - // should be 40 when size is 90
1928 - width: Math.max(parent.size*4/9, 35)
1930 - anchors.centerIn: parent
1931 - color: theme.backgroundColor
1932 - border.color: "grey"
1935 - opacity: hasBattery ? (showOverlay ? 0.7 : (isConstrained() ? 0 : mouseArea.containsMouse*0.7)) : 0
1937 - Behavior on opacity { NumberAnimation { duration: 100 } }
1942 - text: i18nc("overlay on the battery, needs to be really tiny", "%1%", percent);
1943 - color: theme.textColor
1944 - font.pixelSize: Math.max(parent.size/8, 11)
1945 - anchors.centerIn: labelRect
1946 - // keep the opacity 1 when labelRect.opacity=0.7
1947 - opacity: labelRect.opacity/0.7
1953 - anchors.fill: parent
1954 - hoverEnabled: true
1955 - onClicked: plasmoid.togglePopup()
1956 + function popupEventSlot(popped) {
1957 + dialogItem.popupShown = popped;
1960 - PlasmaCore.ToolTip {
1964 - subText: batteries.tooltipText
1968 + property Component compactRepresentation: CompactRepresentation {
1969 + hasBattery: pmSource.data["Battery"]["Has Battery"]
1970 + pmSource: plasmoid.rootItem.pmSource
1971 + batteries: plasmoid.rootItem.batteries
1972 + singleBattery: isConstrained() || !hasBattery
1975 property QtObject pmSource: PlasmaCore.DataSource {
1976 @@ -150,12 +63,14 @@ Item {
1977 engine: "powermanagement"
1978 connectedSources: sources
1980 + Logic.updateCumulative();
1981 + plasmoid.status = Logic.plasmoidStatus();
1982 Logic.updateTooltip();
1983 Logic.updateBrightness();
1986 if (source == "Battery0") {
1987 - disconnectSource(source);
1988 + disconnectSource(source);
1989 connectSource(source);
1992 @@ -173,44 +88,31 @@ Item {
1995 Logic.updateCumulative();
1997 - var status = "PassiveStatus";
1998 - if (batteries.cumulativePluggedin) {
1999 - if (batteries.cumulativePercent <= 10) {
2000 - status = "NeedsAttentionStatus";
2001 - } else if (!batteries.allCharged) {
2002 - status = "ActiveStatus";
2005 - plasmoid.status = status;
2006 + plasmoid.status = Logic.plasmoidStatus();
2009 property int cumulativePercent
2010 - property bool cumulativePluggedin: count > 0
2011 + property bool cumulativePluggedin
2012 // true --> all batteries charged
2013 // false --> one of the batteries charging/discharging
2014 property bool allCharged
2015 property string tooltipText
2016 + property string tooltipImage
2021 property bool disableBrightnessUpdate: false
2023 - hasBattery: batteries.cumulativePluggedin
2024 - percent: batteries.cumulativePercent
2025 + anchors.fill: parent
2027 + isBrightnessAvailable: pmSource.data["PowerDevil"]["Screen Brightness Available"] ? true : false
2028 + isKeyboardBrightnessAvailable: pmSource.data["PowerDevil"]["Keyboard Brightness Available"] ? true : false
2030 + showRemainingTime: show_remaining_time
2032 pluggedIn: pmSource.data["AC Adapter"]["Plugged in"]
2033 - remainingMsec: parent.show_remaining_time ? Number(pmSource.data["Battery"]["Remaining msec"]) : 0
2034 - showSuspendButton: Platform.shouldOfferSuspend(pmSource)
2035 - showHibernateButton: Platform.shouldOfferHibernate(pmSource)
2037 - onSuspendClicked: {
2038 - plasmoid.togglePopup();
2039 - service = pmSource.serviceForSource("PowerDevil");
2040 - var operationName = Logic.callForType(type);
2041 - operation = service.operationDescription(operationName);
2042 - service.startOperationCall(operation);
2044 onBrightnessChanged: {
2045 if (disableBrightnessUpdate) {
2047 @@ -220,6 +122,15 @@ Item {
2048 operation.brightness = screenBrightness;
2049 service.startOperationCall(operation);
2051 + onKeyboardBrightnessChanged: {
2052 + if (disableBrightnessUpdate) {
2055 + service = pmSource.serviceForSource("PowerDevil");
2056 + operation = service.operationDescription("setKeyboardBrightness");
2057 + operation.brightness = keyboardBrightness;
2058 + service.startOperationCall(operation);
2060 property int cookie1: -1
2061 property int cookie2: -1
2062 onPowermanagementChanged: {
2063 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/config.ui b/plasma/generic/applets/batterymonitor/contents/ui/config.ui
2064 deleted file mode 100644
2065 index 3df38e2..0000000
2066 --- a/plasma/generic/applets/batterymonitor/contents/ui/config.ui
2069 -<?xml version="1.0" encoding="UTF-8"?>
2071 - <class>batteryConfig</class>
2072 - <widget class="QWidget" name="batteryConfig">
2073 - <property name="geometry">
2077 - <width>247</width>
2078 - <height>73</height>
2081 - <property name="windowTitle">
2082 - <string>Configure Battery Monitor</string>
2084 - <layout class="QVBoxLayout" name="verticalLayout">
2086 - <widget class="QCheckBox" name="kcfg_showBatteryString">
2087 - <property name="toolTip">
2090 - <property name="text">
2091 - <string>Show charge &information</string>
2096 - <widget class="QCheckBox" name="kcfg_showMultipleBatteries">
2097 - <property name="toolTip">
2100 - <property name="text">
2101 - <string>Show the state for &each battery present</string>
2106 - <spacer name="verticalSpacer">
2107 - <property name="orientation">
2108 - <enum>Qt::Vertical</enum>
2110 - <property name="sizeHint" stdset="0">
2113 - <height>15</height>
2123 diff --git a/plasma/generic/applets/batterymonitor/metadata.desktop b/plasma/generic/applets/batterymonitor/metadata.desktop
2124 index cd8f1a2..2b70e2c 100644
2125 --- a/plasma/generic/applets/batterymonitor/metadata.desktop
2126 +++ b/plasma/generic/applets/batterymonitor/metadata.desktop
2127 @@ -159,7 +159,6 @@ Comment[zh_CN]=查看电池电源的状态
2128 Comment[zh_TW]=查看您的電池的電力狀態
2130 Keywords=Power Management;Battery;System;Energy;
2131 -Keywords[bs]=Upravljanje napajenjem, Baterija, Sistem, Energija
2132 Keywords[ca]=Sistema de gestió d'energia;Bateria;Sistema;Energia;
2133 Keywords[cs]=Správa napájení;Baterie;Systém;Energie;
2134 Keywords[da]=Strømstyring;battery;system;energi;
2135 @@ -167,17 +166,16 @@ Keywords[de]=Energieverwaltungssystem;Akku;System;Energie;
2136 Keywords[el]=Διαχείριση ισχύος·Μπαταρία·Σύστημα·Ενέργεια·
2137 Keywords[es]=Gestión de energía;Batería;Sistema;Energía;
2138 Keywords[fi]=Virranhallinta;Akku;Järjestelmä;Virransäästö;
2139 -Keywords[fr]=Gestion de l'énergie, Batterie, Système, Énergie,
2140 -Keywords[gl]=Power Management;Battery;System;Energy;xestión da enerxía;batería;sistema;
2141 +Keywords[fr]=Gestion de l'énergie, Batterie, Système, Énergie,
2142 Keywords[hu]=Energiakezelés;Akkumulátor;Rendszer;Energia;
2143 -Keywords[ia]=Gestion de energia; Batteria;Systema; Energia;
2144 -Keywords[it]=Gestione energetica;Batteria;Sistema;Energia;
2145 +Keywords[ia]=Gestion de energia;Batteria;Systema; Energia;
2146 Keywords[kk]=Power Management;Battery;System;Energy;
2147 Keywords[lt]=Energijos valdymas,Baterija,Sistema,Energija,akumuliatorius;
2148 Keywords[mr]=वीज व्यवस्थापन; बॅटरी; प्रणाली; ऊर्जा;
2149 Keywords[nb]=Strømstyring; Batteri; System; Energi;
2150 Keywords[nl]=Energiebeheer;Batterij;Accu;Systeem;Energie;
2151 -Keywords[pl]=Zarządzanie energią;bateria;system;energia;
2152 +Keywords[pa]=ਪਾਵਰ ਪਰਬੰਧ;ਬੈਟਰੀ;ਸਿਸਟਮ;ਊਰਜਾ;
2153 +Keywords[pl]=Zarządzanie Energią;Bateria;System;Energia
2154 Keywords[pt]=Gestão de Energia;Bateria;Sistema;Energia;
2155 Keywords[pt_BR]=Gerenciamento de energia;Bateria;Sistema;Energia;
2156 Keywords[ru]=Power Management;Battery;System;Energy;управление питанием;батарея;система;энергия;энергопотребление
2157 @@ -198,17 +196,17 @@ Type=Service
2158 X-KDE-ServiceTypes=Plasma/Applet,Plasma/PopupApplet
2160 X-Plasma-API=declarativeappletscript
2161 -X-Plasma-DefaultSize=100,100
2162 +X-Plasma-DefaultSize=450,300
2163 X-Plasma-MainScript=ui/batterymonitor.qml
2164 X-Plasma-ConfigPlugins=powerdevilprofilesconfig,powerdevilactivitiesconfig,powerdevilglobalconfig
2165 X-Plasma-NotificationArea=true
2167 -X-KDE-PluginInfo-Author=Sebastian Kügler
2168 +X-KDE-PluginInfo-Author=Sebastian Kügler, Kai Uwe Broulik
2169 X-KDE-PluginInfo-Category=System Information
2170 -X-KDE-PluginInfo-Email=sebas@kde.org
2171 +X-KDE-PluginInfo-Email=sebas@kde.org, kde@privat.broulik.de
2172 X-KDE-PluginInfo-License=GPL
2173 X-KDE-PluginInfo-Name=battery
2174 -X-KDE-PluginInfo-Version=1.0
2175 +X-KDE-PluginInfo-Version=2.0
2176 X-KDE-PluginInfo-Website=http://vizZzion.org
2177 X-KDE-PluginInfo-Depends=
2178 X-KDE-PluginInfo-EnabledByDefault=true
2179 diff --git a/plasma/generic/applets/batterymonitor/platformcontents/touch/code/platform.js b/plasma/generic/applets/batterymonitor/platformcontents/touch/code/platform.js
2180 deleted file mode 100644
2181 index aa57ab8..0000000
2182 --- a/plasma/generic/applets/batterymonitor/platformcontents/touch/code/platform.js
2186 -function shouldOfferSuspend() {
2190 -function shouldOfferHibernate() {