The battery percentage for low battery level is now signaled by the device

Added a field "thresholdEvent" to battery network packages.

REVIEW: 113835
This commit is contained in:
Mauro Panzeri 2013-11-14 16:32:16 +01:00 committed by Albert Vaca
parent 7e270bbc80
commit e77a2af07b
3 changed files with 25 additions and 17 deletions

View file

@ -4,6 +4,12 @@ following fields:
isCharging (boolean): If the battery of the peer device is charging
currentCharge (int): The charge % of the peer device
thresholdEvent (int) [optional when = 0, see below]:
means that a battery threshold event were fired on the remote device:
0 := no event. generally not transmitted.
1 := battery entered in low state
This is an int so in the future we'll be able to subscribe to more events.
(see BatteryPlugin.ThresholdBatteryEvent)
<TODO>
Symmetrically, it sends its own battery information in packages with the same

View file

@ -60,29 +60,23 @@ bool BatteryPlugin::receivePackage(const NetworkPackage& np)
{
bool isCharging = np.get<bool>("isCharging");
int currentCharge = np.get<int>("currentCharge");
int thresholdEvent = np.get<int>("thresholdEvent", (int)ThresholdNone);
if (batteryDbusInterface->isCharging() != currentCharge
|| batteryDbusInterface->isCharging() != isCharging) {
|| batteryDbusInterface->isCharging() != isCharging
) {
batteryDbusInterface->updateValues(isCharging, currentCharge);
}
//FIXME: Where's that 14 coming from?
//TODO: Decouple the protocol from Android
/*TODO: Look into the following android interfaces
android.intent.action.BATTERY_LOW
android.intent.action.BATTERY_OKAY
*/
if (currentCharge == 14 && !isCharging) {
if ( thresholdEvent == ThresholdBatteryLow && !isCharging ) {
KNotification* notification = new KNotification("batteryLow");
notification->setPixmap(KIcon("battery-040").pixmap(48, 48));
notification->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
notification->setTitle(i18nc("device name: low battery", "%1: low battery",device()->name()));
notification->setText(i18n("Battery at 14%"));
notification->setTitle(i18nc("device name: low battery", "%1: low battery", device()->name()));
notification->setText(i18n("Battery at %1%", currentCharge));
notification->sendEvent();
}
}
return true;
}

View file

@ -41,6 +41,14 @@ public Q_SLOTS:
virtual void connected();
private:
// Keep these values in sync with THRESHOLD* constants in
// kdeconnect-android:BatteryPlugin.java
// see README for their meaning
enum ThresholdBatteryEvent {
ThresholdNone = 0,
ThresholdBatteryLow = 1
};
BatteryDbusInterface* batteryDbusInterface;
};