Web lists-archives.org

Remaining battery time in solid




Hello,

There is a bug requesting remainind time to be displayed at the battery
widget. (http://bugs.kde.org/show_bug.cgi?id=158781) As it seems this
isn't supplied by solid I did a try at adding it.
I've just copied all the charcePercent functions to remainingTime
functions and used the hal-call I found in the source of the guidance
powermanger. I'm not sure what the do with the fakehw backend though.

I've attached a patchfile based of the KDE 4.0 branch (within the
kdelibs/solid/solid directory). (As this is the first time I tryed
things with solid I'm not sure I didn't forget anything)

Stas Verberkt
Index: battery.cpp
===================================================================
--- battery.cpp	(revision 805950)
+++ battery.cpp	(working copy)
@@ -59,6 +59,12 @@ int Solid::Battery::chargePercent() cons
     return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), 0, chargePercent());
 }
 
+int Solid::Battery::remainingTime() const
+{
+    Q_D(const Battery);
+    return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), 0, remainingTime());
+}
+
 bool Solid::Battery::isRechargeable() const
 {
     Q_D(const Battery);
Index: battery.h
===================================================================
--- battery.h	(revision 805950)
+++ battery.h	(working copy)
@@ -123,6 +123,13 @@ namespace Solid
          */
         int chargePercent() const;
 
+        /**
+         * Retrieves the remaining time of the battery power,
+         * or the remaining time to charge.
+         *
+         * @return the remaining time in seconds
+         */
+        int remainingTime() const;
 
 
         /**
Index: ifaces/battery.h
===================================================================
--- ifaces/battery.h	(revision 805950)
+++ ifaces/battery.h	(working copy)
@@ -65,6 +65,15 @@ namespace Ifaces
          */
         virtual int chargePercent() const = 0;
 
+        /**
+         * Retrieves the remaining time of the battery power,
+         * or the remaining time to charge.
+         *
+         * @return the remaining time in seconds
+         */
+        virtual int remainingTime() const = 0;
+
+
 
         /**
          * Indicates if the battery is rechargeable.
Index: backends/hal/halbattery.cpp
===================================================================
--- backends/hal/halbattery.cpp	(revision 805950)
+++ backends/hal/halbattery.cpp	(working copy)
@@ -82,6 +82,11 @@ int Battery::chargePercent() const
     return m_device->property("battery.charge_level.percentage").toInt();
 }
 
+int Battery::remainingTime() const
+{
+    return m_device->property("battery.remaining_time").toInt();
+}
+
 bool Battery::isRechargeable() const
 {
     return m_device->property("battery.is_rechargeable").toBool();
Index: backends/hal/halbattery.h
===================================================================
--- backends/hal/halbattery.h	(revision 805950)
+++ backends/hal/halbattery.h	(working copy)
@@ -42,6 +42,7 @@ public:
     virtual Solid::Battery::BatteryType type() const;
 
     virtual int chargePercent() const;
+    virtual int remainingTime() const;
 
     virtual bool isRechargeable() const;
     virtual Solid::Battery::ChargeState chargeState() const;
Index: backends/fakehw/fakebattery.h
===================================================================
--- backends/fakehw/fakebattery.h	(revision 805950)
+++ backends/fakehw/fakebattery.h	(working copy)
@@ -43,6 +43,7 @@ public Q_SLOTS:
     virtual Solid::Battery::BatteryType type() const;
 
     virtual int chargePercent() const;
+    virtual int remainingTime() const;
 
     virtual bool isRechargeable() const;
     virtual Solid::Battery::ChargeState chargeState() const;
Index: backends/fakehw/fakebattery.cpp
===================================================================
--- backends/fakehw/fakebattery.cpp	(revision 805950)
+++ backends/fakehw/fakebattery.cpp	(working copy)
@@ -84,6 +84,11 @@ int FakeBattery::chargePercent() const
     return percent;
 }
 
+int FakeBattery::remainingTime() const
+{
+    return 0;
+}
+
 bool FakeBattery::isRechargeable() const
 {
     return fakeDevice()->property("isRechargeable").toBool();
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<