+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
- http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
- <kcfgfile name=""/>
-
- <group name="General">
- <entry name="showRemainingTime" type="Bool">
- <default>false</default>
- </entry>
- </group>
-
-</kcfg>
// UPower seems to set the Present property false when a device is added but not probed yet
property bool isPresent: model["Plugged in"]
- property int remainingTime
-
KLocale.Locale { id: locale }
function updateSelection() {
onPaintedWidthChanged: {
if (paintedWidth > parent.width) { parent.width = paintedWidth; }
}
- // FIXME Bound to AC adapter plugged in, not battery charging, see below
- text: pluggedIn ? i18n("Time To Full:") : i18n("Time To Empty:")
- visible: remainingTimeLabel.visible
- font.pointSize: theme.smallestFont.pointSize
- color: "#99"+(theme.textColor.toString().substr(1))
- }
- Components.Label {
- height: paintedHeight
- width: parent.width
- horizontalAlignment: Text.AlignRight
- onPaintedWidthChanged: {
- if (paintedWidth > parent.width) { parent.width = paintedWidth; }
- }
text: i18n("Capacity:")
visible: capacityLabel.visible
font.pointSize: theme.smallestFont.pointSize
}
Column {
width: parent.width - labelsColumn.width - parent.spacing * 2
- Components.Label { // Remaining Time
- id: remainingTimeLabel
- height: paintedHeight
- width: parent.width
- elide: Text.ElideRight
- // FIXME Uses overall remaining time, not bound to individual battery
- text: locale.prettyFormatDuration(dialogItem.remainingTime)
- visible: showRemainingTime && model["Is Power Supply"] && model["State"] != "FullyCharged" && text != "" && dialogItem.remainingTime > 0
- font.pointSize: theme.smallestFont.pointSize
- color: "#99"+(theme.textColor.toString().substr(1))
- }
Components.Label { // Capacity
id: capacityLabel
height: paintedHeight
property alias model: batteryList.model
property bool pluggedIn
- property int remainingTime
- property bool showRemainingTime
-
property bool popupShown // somehow plasmoid.popupShowing isn't working
property int pmSwitchWidth: padding.margins.left + pmSwitch.implicitWidth + padding.margins.right
property int minimumHeight: dialogItem.actualHeight
property int maximumHeight: dialogItem.actualHeight
- property bool show_remaining_time: false
-
LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
LayoutMirroring.childrenInherit: true
Component.onCompleted: {
plasmoid.aspectRatioMode = IgnoreAspectRatio
updateLogic();
- plasmoid.addEventListener('ConfigChanged', configChanged);
plasmoid.popupEvent.connect(popupEventSlot);
}
- function configChanged() {
- show_remaining_time = plasmoid.readConfig("showRemainingTime");
- }
-
function updateLogic() {
Logic.updateCumulative();
anchors.fill: parent
focus: true
- showRemainingTime: show_remaining_time
- remainingTime: Number(pmSource.data["Battery"]["Remaining msec"])
-
pluggedIn: pmSource.data["AC Adapter"]["Plugged in"]
property int cookie1: -1
connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(QString)),
this, SLOT(deviceRemoved(QString)));
- // FIXME This check doesn't work, connect seems to always return true, hence the hack below
if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.freedesktop.PowerManagement")) {
sourceRequestEvent("PowerDevil");
-
- if (!QDBusConnection::sessionBus().connect("org.freedesktop.PowerManagement",
- "/org/freedesktop/PowerManagement",
- "org.freedesktop.PowerManagement",
- "BatteryRemainingTimeChanged", this,
- SLOT(batteryRemainingTimeChanged(qulonglong)))) {
- kDebug() << "error connecting to remaining time changes";
- }
}
}
setData("Battery", "Has Battery", !batterySources.isEmpty());
if (!batterySources.isEmpty()) {
setData("Battery", "Sources", batterySources);
- QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.PowerManagement",
- "/org/freedesktop/PowerManagement",
- "org.freedesktop.PowerManagement",
- "BatteryRemainingTimeChanged");
- QDBusPendingReply<qulonglong> reply = QDBusConnection::sessionBus().asyncCall(msg);
- QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
- QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
- this, SLOT(batteryRemainingTimeReply(QDBusPendingCallWatcher*)));
}
m_sources = basicSourceNames() + batterySources;
}
}
-void PowermanagementEngine::batteryRemainingTimeChanged(qulonglong time)
-{
- //kDebug() << "Remaining time 2:" << time;
- setData("Battery", "Remaining msec", time);
-}
-
-void PowermanagementEngine::batteryRemainingTimeReply(QDBusPendingCallWatcher *watcher)
-{
- QDBusPendingReply<qulonglong> reply = *watcher;
- if (reply.isError()) {
- kDebug() << "Error getting battery remaining time: " << reply.error().message();
- } else {
- batteryRemainingTimeChanged(reply.value());
- }
-
- watcher->deleteLater();
-}
-
K_EXPORT_PLASMA_DATAENGINE(powermanagement, PowermanagementEngine)
#include "moc_powermanagementengine.cpp"
void deviceRemoved(const QString& udi);
void deviceAdded(const QString& udi);
- void batteryRemainingTimeChanged(qulonglong time);
- void batteryRemainingTimeReply(QDBusPendingCallWatcher*);
private:
QString batteryType(const Solid::Battery *battery);