cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [1/2] git commit: add ubuntu platform
Date Mon, 02 Dec 2013 22:49:25 GMT
Updated Branches:
  refs/heads/dev fcf0625da -> 1a7672d17


add ubuntu platform


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/commit/fcc108cb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/tree/fcc108cb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/diff/fcc108cb

Branch: refs/heads/dev
Commit: fcc108cb4e46a72d5e04bdf3d2da80b50cfb2deb
Parents: 92b9678
Author: Maxim Ermilov <ermilov.maxim@gmail.com>
Authored: Sun Sep 29 08:19:01 2013 +0400
Committer: Maxim Ermilov <ermilov.maxim@gmail.com>
Committed: Sun Sep 29 08:19:01 2013 +0400

----------------------------------------------------------------------
 plugin.xml             |  8 ++++-
 src/ubuntu/battery.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++
 src/ubuntu/battery.h   | 62 +++++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/fcc108cb/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index a5e6068..e0dded9 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -23,7 +23,13 @@
 
         <source-file src="src/android/BatteryListener.java" target-dir="src/org/apache/cordova/batterystatus"
/>
     </platform>
-    
+
+    <!-- ubuntu -->
+    <platform name="ubuntu">
+        <header-file src="src/ubuntu/battery.h" />
+        <source-file src="src/ubuntu/battery.cpp" />
+    </platform>
+
     <!-- ios -->
     <platform name="ios">    
         <config-file target="config.xml" parent="/*">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/fcc108cb/src/ubuntu/battery.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/battery.cpp b/src/ubuntu/battery.cpp
new file mode 100644
index 0000000..f3b8f80
--- /dev/null
+++ b/src/ubuntu/battery.cpp
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+#include <QtCore>
+
+#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)));
+}
+
+void BatteryStatus::remainingCapacityChanged(int battery, int capacity) {
+    Q_UNUSED(battery);
+    Q_UNUSED(capacity);
+
+    fireEvents();
+}
+
+void BatteryStatus::chargerTypeChanged(QBatteryInfo::ChargerType type) {
+    Q_UNUSED(type);
+
+    fireEvents();
+}
+
+void BatteryStatus::fireEvents() {
+    int fullCount = 0;
+    bool isPlugged = false;
+
+    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;
+
+        remaining += _batteryInfo.remainingCapacity(i);
+        total += _batteryInfo.maximumCapacity(i);
+    }
+
+    isPlugged = isPlugged || (_batteryInfo.batteryCount() == fullCount);
+
+    if (_scId) {
+        QVariantMap obj;
+        obj.insert("isPlugged", (int)isPlugged);
+        if (total != 0)
+          obj.insert("level", remaining * 100 / total);
+        else
+          obj.insert("level", 100);
+
+        this->callbackWithoutRemove(_scId, CordovaInternal::format(obj));
+    }
+}
+
+void BatteryStatus::start(int scId, int) {
+    _scId = scId;
+}
+
+void BatteryStatus::stop(int, int) {
+    _scId = 0;
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/fcc108cb/src/ubuntu/battery.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/battery.h b/src/ubuntu/battery.h
new file mode 100644
index 0000000..cec7856
--- /dev/null
+++ b/src/ubuntu/battery.h
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+#ifndef BATTERY_H_AAAAAAAA
+#define BATTERY_H_AAAAAAAA
+
+#include <QBatteryInfo>
+
+#include <cplugin.h>
+
+class BatteryStatus: public CPlugin {
+    Q_OBJECT
+public:
+    explicit BatteryStatus(Cordova *cordova);
+
+    virtual const QString fullName() override {
+        return BatteryStatus::fullID();
+    }
+
+    virtual const QString shortName() override {
+        return "Battery";
+    }
+
+    static const QString fullID() {
+        return "Battery";
+    }
+
+public slots:
+    void start(int scId, int ecId);
+    void stop(int scId, int ecId);
+
+private slots:
+    void remainingCapacityChanged(int battery, int capacity);
+    void chargerTypeChanged(QBatteryInfo::ChargerType type);
+    void onlineStatusChanged(bool isOnline);
+
+private:
+    void fireEvents();
+
+    QBatteryInfo _batteryInfo;
+
+    int _scId;
+};
+
+#endif


Mime
View raw message