[
https://issues.apache.org/jira/browse/CB-11256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16291440#comment-16291440
]
ASF GitHub Bot commented on CB-11256:
-------------------------------------
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:
[email protected]
> QBattery API changes break the Ubuntu battery plugin support code
> -----------------------------------------------------------------
>
> Key: CB-11256
> URL: https://issues.apache.org/jira/browse/CB-11256
> Project: Apache Cordova
> Issue Type: Bug
> Components: cordova-ubuntu
> Reporter: David Barth
> Assignee: David Barth
> Labels: triaged
>
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]