From c89b1028e57a5262a12bfaafeb0a8d0b4d919c32 Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Mon, 31 Dec 2012 22:12:20 +0200 Subject: [PATCH] Replaced QtMobility BatteryInfo --- qml/CameraPage.qml | 34 -------------------- qml/main.qml | 39 ++++++++++++++++++++++- src/batteryinfo.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++ src/batteryinfo.h | 58 +++++++++++++++++++++++++++++++++ src/main.cpp | 2 ++ src/src.pro | 4 +-- 6 files changed, 178 insertions(+), 37 deletions(-) create mode 100644 src/batteryinfo.cpp create mode 100644 src/batteryinfo.h diff --git a/qml/CameraPage.qml b/qml/CameraPage.qml index 0b16370..b919e8c 100644 --- a/qml/CameraPage.qml +++ b/qml/CameraPage.qml @@ -24,7 +24,6 @@ import QtQuick 1.1 import com.nokia.meego 1.1 import QtCamera 1.0 import CameraPlus 1.0 -import QtMobility.systeminfo 1.2 Page { id: page @@ -95,37 +94,4 @@ Page { function checkDiskSpace() { return fileSystem.hasFreeSpace(fileNaming.path); } - - function checkBattery() { - // We are fine if we are connected to the charger: - if (batteryMonitor.chargingState == BatteryInfo.Charging) { - return true; - } - - // If we have enough battery then we are fine: - if (batteryMonitor.batteryStatus > BatteryInfo.BatteryCritical) { - return true; - } - - return false; - } - - BatteryInfo { - // TODO: replace this - id: batteryMonitor - monitorChargingStateChanges: cam.running - monitorBatteryStatusChanges: cam.running - - onChargingStateChanged: { - if (!checkBattery()) { - parent.batteryLow(); - } - } - - onBatteryStatusChanged: { - if (!checkBattery()) { - parent.batteryLow(); - } - } - } } diff --git a/qml/main.qml b/qml/main.qml index 01fbfa2..63a18b6 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -24,10 +24,14 @@ import QtQuick 1.1 import com.nokia.meego 1.1 import com.nokia.extras 1.1 import QtCamera 1.0 -import CameraPlus 1.0 import QtMobility.systeminfo 1.2 import QtMobility.location 1.2 +// TODO: this has to be below QtMobility.systeminfo +// We define an element called BatteryInfo which conflicts with the one defined by QtMobility +// Thus we have to be the last so our element can be used instead of the one from QtMobility +import CameraPlus 1.0 + // TODO: flash not ready (battery low or flash not ready message) // TODO: portrait/landscape // TODO: grid lines, face tracking @@ -142,6 +146,25 @@ PageStackWindow { path: fileNaming.path } + BatteryInfo { + id: batteryMonitor + active: cam.running + + function check() { + if (!checkBattery()) { + pageStack.currentPage.batteryLow(); + } + } + + onChargingChanged: { + batteryMonitor.check(); + } + + onCriticalChanged: { + batteryMonitor.check(); + } + } + function replacePage(file) { pageStack.replace(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true); } @@ -154,6 +177,20 @@ PageStackWindow { pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true); } + function checkBattery() { + // We are fine if we are connected to the charger: + if (batteryMonitor.charging) { + return true; + } + + // If we have enough battery then we are fine: + if (!batteryMonitor.critical) { + return true; + } + + return false; + } + platformStyle: PageStackWindowStyle { cornersVisible: false background: "" diff --git a/src/batteryinfo.cpp b/src/batteryinfo.cpp new file mode 100644 index 0000000..3831820 --- /dev/null +++ b/src/batteryinfo.cpp @@ -0,0 +1,78 @@ +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "batteryinfo.h" +#include +#include + +BatteryInfo::BatteryInfo(QObject *parent) : + QObject(parent), m_battery(0) { + +} + +BatteryInfo::~BatteryInfo() { + setActive(false); +} + +bool BatteryInfo::isCharging() const { + if (!m_battery) { + qmlInfo(this) << "BatteryInfo has to be activated first"; + return false; + } + + if (m_battery->getChargingState() == MeeGo::QmBattery::StateCharging) { + return true; + } + + return false; +} + +bool BatteryInfo::isCritical() const { + if (!m_battery) { + qmlInfo(this) << "BatteryInfo has to be activated first"; + return true; + } + + MeeGo::QmBattery::BatteryState state = m_battery->getBatteryState(); + + if (state == MeeGo::QmBattery::StateOK || state == MeeGo::QmBattery::StateFull) { + return false; + } + + return true; +} + +bool BatteryInfo::isActive() const { + return m_battery != 0; +} + +void BatteryInfo::setActive(bool active) { + if (isActive() == active) { + return; + } + + m_battery = new MeeGo::QmBattery(this); + QObject::connect(m_battery, SIGNAL(batteryStateChanged(MeeGo::QmBattery::BatteryState)), + this, SIGNAL(chargingChanged())); + QObject::connect(m_battery, SIGNAL(chargingStateChanged(MeeGo::QmBattery::ChargingState)), + this, SIGNAL(chargingChanged())); + + emit activeChanged(); +} diff --git a/src/batteryinfo.h b/src/batteryinfo.h new file mode 100644 index 0000000..77c3f96 --- /dev/null +++ b/src/batteryinfo.h @@ -0,0 +1,58 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef BATTERY_INFO_H +#define BATTERY_INFO_H + +#include + +namespace MeeGo { + class QmBattery; +}; + +class BatteryInfo : public QObject { + Q_OBJECT + + Q_PROPERTY(bool charging READ isCharging NOTIFY chargingChanged); + Q_PROPERTY(bool critical READ isCritical NOTIFY criticalChanged); + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged); + +public: + BatteryInfo(QObject *parent = 0); + ~BatteryInfo(); + + bool isCharging() const; + bool isCritical() const; + + bool isActive() const; + void setActive(bool active); + +signals: + void chargingChanged(); + void criticalChanged(); + void activeChanged(); + +private: + MeeGo::QmBattery *m_battery; +}; + +#endif /* BATTERY_INFO_H */ diff --git a/src/main.cpp b/src/main.cpp index dd2e44f..ff38f48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,7 @@ #include "deletehelper.h" #include "galleryhelper.h" #include "postcapturemodel.h" +#include "batteryinfo.h" static void initQuill() { // TODO: All these are hardcoded. @@ -90,6 +91,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) { qmlRegisterType("CameraPlus", 1, 0, "DeleteHelper"); qmlRegisterType("CameraPlus", 1, 0, "GalleryHelper"); qmlRegisterType("CameraPlus", 1, 0, "PostCaptureModel"); + qmlRegisterType("CameraPlus", 1, 0, "BatteryInfo"); view.setSource(QUrl("qrc:/qml/main.qml")); diff --git a/src/src.pro b/src/src.pro index 6a1427f..930a162 100644 --- a/src/src.pro +++ b/src/src.pro @@ -18,11 +18,11 @@ LIBS += -L../imports/ -limports -L../lib/ -lqtcamera SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp displaystate.cpp fsmonitor.cpp \ cameraresources.cpp compass.cpp orientation.cpp geocode.cpp mountprotector.cpp \ trackerstore.cpp focusrectangle.cpp sharehelper.cpp deletehelper.cpp galleryhelper.cpp \ - postcapturemodel.cpp + postcapturemodel.cpp batteryinfo.cpp HEADERS += settings.h filenaming.h quillitem.h displaystate.h fsmonitor.h \ cameraresources.h compass.h orientation.h geocode.h mountprotector.h \ trackerstore.h focusrectangle.h sharehelper.h deletehelper.h galleryhelper.h \ - postcapturemodel.h + postcapturemodel.h batteryinfo.h RESOURCES += ../qml/qml.qrc -- 2.25.1