You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2017/12/14 19:36:52 UTC

[GitHub] maverickmishra closed pull request #38: CB-11256: (ubuntu) Qt API change breaks the battery plugin

maverickmishra closed pull request #38: CB-11256: (ubuntu) Qt API change breaks the battery plugin
URL: https://github.com/apache/cordova-plugin-battery-status/pull/38
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/ubuntu/battery.cpp b/src/ubuntu/battery.cpp
index f3b8f80..3e22580 100644
--- a/src/ubuntu/battery.cpp
+++ b/src/ubuntu/battery.cpp
@@ -22,20 +22,38 @@
 
 #include "battery.h"
 
-BatteryStatus::BatteryStatus(Cordova *cordova) : CPlugin(cordova) {
-    _scId = 0;
-
-    connect(&_batteryInfo, SIGNAL(remainingCapacityChanged(int,int)), this, SLOT(remainingCapacityChanged(int,int)));
-    connect(&_batteryInfo, SIGNAL(chargerTypeChanged(QBatteryInfo::ChargerType)), this, SLOT(chargerTypeChanged(QBatteryInfo::ChargerType)));
+BatteryStatus::BatteryStatus(Cordova *cordova)
+        : CPlugin(cordova),
+          _scId(0) {
+
+    connect(&_batteryInfo,
+            SIGNAL(remainingCapacityChanged(int)),
+            this,
+            SLOT(remainingCapacityChanged(int)));
+
+    connect(&_batteryInfo,
+            SIGNAL(batteryCountChanged(int)),
+            this,
+            SLOT(batteryCountChanged(int)));
+
+    connect(&_batteryInfo,
+            SIGNAL(chargerTypeChanged(QBatteryInfo::ChargerType)),
+            this,
+            SLOT(chargerTypeChanged(QBatteryInfo::ChargerType)));
 }
 
-void BatteryStatus::remainingCapacityChanged(int battery, int capacity) {
-    Q_UNUSED(battery);
+void BatteryStatus::remainingCapacityChanged(int capacity) {
     Q_UNUSED(capacity);
 
     fireEvents();
 }
 
+void BatteryStatus::batteryCountChanged(int count) {
+    Q_UNUSED(count);
+
+    fireEvents();
+}
+
 void BatteryStatus::chargerTypeChanged(QBatteryInfo::ChargerType type) {
     Q_UNUSED(type);
 
@@ -48,11 +66,15 @@ void BatteryStatus::fireEvents() {
 
     int remaining = 0, total = 0;
     for (int i = 0; i < _batteryInfo.batteryCount(); i++) {
-        isPlugged = (_batteryInfo.chargingState(i) == QBatteryInfo::Charging) || isPlugged;
-        fullCount += _batteryInfo.chargingState(i) == QBatteryInfo::Full;
+        QBatteryInfo bi(i);
+
+        if (bi.isValid()) {
+          isPlugged = (bi.chargingState() == QBatteryInfo::Charging) || isPlugged;
+          fullCount += bi.chargingState() == QBatteryInfo::LevelFull;
 
-        remaining += _batteryInfo.remainingCapacity(i);
-        total += _batteryInfo.maximumCapacity(i);
+          remaining += bi.remainingCapacity();
+          total += bi.maximumCapacity();
+        }
     }
 
     isPlugged = isPlugged || (_batteryInfo.batteryCount() == fullCount);
diff --git a/src/ubuntu/battery.h b/src/ubuntu/battery.h
index cec7856..2e58b40 100644
--- a/src/ubuntu/battery.h
+++ b/src/ubuntu/battery.h
@@ -25,6 +25,7 @@
 
 #include <cplugin.h>
 
+
 class BatteryStatus: public CPlugin {
     Q_OBJECT
 public:
@@ -47,15 +48,14 @@ public slots:
     void stop(int scId, int ecId);
 
 private slots:
-    void remainingCapacityChanged(int battery, int capacity);
+    void remainingCapacityChanged(int capacity);
+    void batteryCountChanged(int count);
     void chargerTypeChanged(QBatteryInfo::ChargerType type);
-    void onlineStatusChanged(bool isOnline);
 
 private:
     void fireEvents();
 
     QBatteryInfo _batteryInfo;
-
     int _scId;
 };
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org