Hi,
as discussed in IRC (with Kevin). See attached patch for the battery related
stuff in kdelibs/solid (note: didn't compile the patch).
The other device information as e.g. remainingTime and chargingRate (and maybe
more) should then go into a extended battery class/object.
Danny
Index: battery.cpp
===================================================================
--- battery.cpp (Revision 659745)
+++ battery.cpp (Arbeitskopie)
@@ -31,6 +31,9 @@
connect(backendObject, SIGNAL(chargeStateChanged(int)),
this, SIGNAL(chargeStateChanged(int)));
+
+ connect(backendObject, SIGNAL(pluggingStateChanged(bool)),
+ this, SIGNAL(pluggingStateChanged(bool)));
}
Solid::Battery::~Battery()
@@ -56,10 +59,10 @@
return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), QString(), chargeLevelUnit());
}
-int Solid::Battery::charge(LevelType type) const
+int Solid::Battery::chargeInfo(LevelType type) const
{
Q_D(const Battery);
- return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), 0, charge(type));
+ return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), 0, chargeInfo(type));
}
int Solid::Battery::chargePercent() const
Index: battery.h
===================================================================
--- battery.h (Revision 659745)
+++ battery.h (Arbeitskopie)
@@ -38,7 +38,7 @@
Q_PROPERTY(bool plugged READ isPlugged)
Q_PROPERTY(BatteryType type READ type)
Q_PROPERTY(QString chargeLevelUnit READ chargeLevelUnit)
- Q_PROPERTY(int charge READ charge)
+ Q_PROPERTY(int chargeInfo READ chargeInfo)
Q_PROPERTY(int chargePercent READ chargePercent)
Q_PROPERTY(QString voltageUnit READ voltageUnit)
Q_PROPERTY(int voltage READ voltage)
@@ -78,7 +78,8 @@
/**
* This enum type defines charge state of a battery
*
- * - NoCharge : Battery charge is stable, not charging or discharging
+ * - NoCharge : Battery charge is stable, not charging or discharging or
+ * the state is Unknown
* - Charging : Battery is charging
* - Discharging : Battery is discharging
*/
@@ -145,7 +146,7 @@
* @return the requested charge level
* @see Solid::Battery::LevelType
*/
- int charge(LevelType type = CurrentLevel) const;
+ int chargeInfo(LevelType type = CurrentLevel) const;
/**
* Retrieves the current charge level of the battery normalised
@@ -209,6 +209,14 @@
* @see Solid::Battery::ChargeState
*/
void chargeStateChanged(int newState);
+
+ /**
+ * This signal is emitted if the battery get plugged in/out of the
+ * battery bay.
+ *
+ * @param newState the new plugging state of the battery, type is boolean
+ */
+ void pluggingStateChanged(bool newState);
};
}
Index: ifaces/battery.h
===================================================================
--- ifaces/battery.h (Revision 659745)
+++ ifaces/battery.h (Arbeitskopie)
@@ -75,7 +75,7 @@
* @return the requested charge level
* @see Solid::Battery::LevelType
*/
- virtual int charge(Solid::Battery::LevelType type = Solid::Battery::CurrentLevel) const = 0;
+ virtual int chargeInfo(Solid::Battery::LevelType type = Solid::Battery::CurrentLevel) const = 0;
/**
* Retrieves the current charge level of the battery normalised
@@ -86,7 +86,6 @@
virtual int chargePercent() const = 0;
-
/**
* Retrieves the physical unit used by the voltage values
* (for example mV).
@@ -140,6 +139,15 @@
* @see Solid::Battery::ChargeState
*/
virtual void chargeStateChanged(int newState) = 0;
+
+ /**
+ * This signal is emitted if the battery get plugged in/out of the
+ * battery bay.
+ *
+ * @param newState the new plugging state of the battery, type is boolean
+ */
+ virtual void pluggingStateChanged(bool newState);
+
};
}
}
Index: backends/hal/halbattery.cpp
===================================================================
--- backends/hal/halbattery.cpp (Revision 659745)
+++ backends/hal/halbattery.cpp (Arbeitskopie)
@@ -80,7 +80,7 @@
return m_device->property("battery.charge_level.unit").toString();
}
-int Battery::charge(Solid::Battery::LevelType type) const
+int Battery::chargeInfo(Solid::Battery::LevelType type) const
{
switch(type)
{
@@ -150,6 +150,11 @@
{
emit chargeStateChanged(chargeState());
}
+ else if ( changes.contains( "battery.present" ) )
+ {
+ emit pluggingStateChanged( isPlugged() );
+ }
+
}
#include "backends/hal/halbattery.moc"
Index: backends/hal/halbattery.h
===================================================================
--- backends/hal/halbattery.h (Revision 659745)
+++ backends/hal/halbattery.h (Arbeitskopie)
@@ -36,7 +36,7 @@
virtual Solid::Battery::BatteryType type() const;
virtual QString chargeLevelUnit() const;
- virtual int charge(Solid::Battery::LevelType type = Solid::Battery::CurrentLevel) const;
+ virtual int chargeInfo(Solid::Battery::LevelType type = Solid::Battery::CurrentLevel) const;
virtual int chargePercent() const;
virtual QString voltageUnit() const;
@@ -48,6 +48,7 @@
Q_SIGNALS:
void chargePercentChanged(int value);
void chargeStateChanged(int newState);
+ void pluggingStateChanged( bool newState );
private Q_SLOTS:
void slotPropertyChanged(const QMap<QString,int> &changes);
_______________________________________________
Kde-hardware-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-hardware-devel