From e77a2af07bec550d8ce025693003d8b04613b31f Mon Sep 17 00:00:00 2001 From: Mauro Panzeri Date: Thu, 14 Nov 2013 16:32:16 +0100 Subject: [PATCH] The battery percentage for low battery level is now signaled by the device Added a field "thresholdEvent" to battery network packages. REVIEW: 113835 --- kded/plugins/battery/README | 6 ++++++ kded/plugins/battery/batteryplugin.cpp | 28 ++++++++++---------------- kded/plugins/battery/batteryplugin.h | 8 ++++++++ 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/kded/plugins/battery/README b/kded/plugins/battery/README index b7f1ddde1..8812ba1a1 100644 --- a/kded/plugins/battery/README +++ b/kded/plugins/battery/README @@ -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) Symmetrically, it sends its own battery information in packages with the same diff --git a/kded/plugins/battery/batteryplugin.cpp b/kded/plugins/battery/batteryplugin.cpp index 2f5314a35..074acdf8e 100644 --- a/kded/plugins/battery/batteryplugin.cpp +++ b/kded/plugins/battery/batteryplugin.cpp @@ -60,27 +60,21 @@ bool BatteryPlugin::receivePackage(const NetworkPackage& np) { bool isCharging = np.get("isCharging"); int currentCharge = np.get("currentCharge"); + int thresholdEvent = np.get("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) { - 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->sendEvent(); - } - + 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 %1%", currentCharge)); + notification->sendEvent(); } return true; diff --git a/kded/plugins/battery/batteryplugin.h b/kded/plugins/battery/batteryplugin.h index 3288980f3..0902913fd 100644 --- a/kded/plugins/battery/batteryplugin.h +++ b/kded/plugins/battery/batteryplugin.h @@ -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; };