diff options
author | Lorn Potter <lorn.potter@gmail.com> | 2014-11-29 10:12:41 +1000 |
---|---|---|
committer | Lorn Potter <lorn.potter@gmail.com> | 2014-12-04 08:36:07 +0100 |
commit | 32e65739c2bc690f04f9bc7ee4edeeacc3f93420 (patch) | |
tree | 57d53031a1f8f53a060478ec8b0ccfac1df660b1 | |
parent | 3a0216301ad1338126abb326e8e4c22c6ea12f40 (diff) |
Re-add BatteryInfo qml
The battery declarative class was never reinstated after the battery
class for refactored.
Also fix the upower backend to work correctly.
Task-number: QTBUG-42958
Change-Id: I4f627426f6c716a5317eb28ed85fd9da793f1940
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | examples/systeminfo/qml-battery/qml-battery.qml | 87 | ||||
-rw-r--r-- | src/imports/systeminfo/plugins.qmltypes | 204 | ||||
-rw-r--r-- | src/imports/systeminfo/qdeclarativebatteryinfo.cpp | 499 | ||||
-rw-r--r-- | src/imports/systeminfo/qdeclarativebatteryinfo_p.h | 189 | ||||
-rw-r--r-- | src/imports/systeminfo/qdeclarativedeviceinfo_p.h | 2 | ||||
-rw-r--r-- | src/imports/systeminfo/qsysteminfo.cpp | 2 | ||||
-rw-r--r-- | src/systeminfo/linux/qbatteryinfo_upower.cpp | 194 | ||||
-rw-r--r-- | src/systeminfo/linux/qbatteryinfo_upower_p.h | 4 | ||||
-rw-r--r-- | src/systeminfo/linux/qdevicekitservice_linux.cpp | 5 | ||||
-rw-r--r-- | src/systeminfo/linux/qdevicekitservice_linux_p.h | 1 |
10 files changed, 230 insertions, 957 deletions
diff --git a/examples/systeminfo/qml-battery/qml-battery.qml b/examples/systeminfo/qml-battery/qml-battery.qml index 6e0335f4..bcd6e641 100644 --- a/examples/systeminfo/qml-battery/qml-battery.qml +++ b/examples/systeminfo/qml-battery/qml-battery.qml @@ -44,8 +44,8 @@ import QtSystemInfo 5.0 import QtQuick.Window 2.0 Rectangle { - width: Screen.width - height: Screen.height + width: 640 + height: 640 MouseArea { anchors.fill: parent @@ -57,20 +57,12 @@ Rectangle { BatteryInfo { id: batinfo - monitorChargerType: true - monitorCurrentFlow: true - monitorRemainingCapacity: true - monitorRemainingChargingTime: true - monitorVoltage: true - monitorChargingState: true - monitorBatteryStatus: true - onChargerTypeChanged: { - if (type == 1) { + if (type == BatteryInfo.WallCharger) { chargertype.text = "Wall Charger" - } else if (type == 2) { + } else if (type == BatteryInfo.USBCharger) { chargertype.text = "USB Charger" - } else if (type == 3) { + } else if (type == BatteryInfo.VariableCurrentCharger) { chargertype.text = "Variable Current Charger" } else { chargertype.text = "Unknown Charger" @@ -78,79 +70,71 @@ Rectangle { } onCurrentFlowChanged: { - /* battery parameter skipped */ currentflow.text = flow + " mA" } onRemainingCapacityChanged: { - /* battery parameter skipped */ - remainingcapacity.text = capacity + getEnergyUnit() + remainingcapacity.text = capacity updateBatteryLevel() } onRemainingChargingTimeChanged: { - /* battery parameter skipped */ remainingchargingtime.text = seconds + " s" } onVoltageChanged: { - /* battery parameter skipped */ voltagetext.text = voltage + " mV" } onChargingStateChanged: { - /* battery parameter skipped */ - if (state == 1) { - chargeState.text = "Not Charging" - } else if (state == 2) { + if (state == BatteryInfo.Charging) { chargeState.text = "Charging" - } else if (state == 3) { - chargeState.text = "Discharging" + } else if (state == BatteryInfo.IdleChargingState) { + chargeState.text = "Idle Charging" + } else if (state == BatteryInfo.Discharging) { + chargeState.text = "Discharging" } else { chargeState.text = "Unknown" } } - onBatteryStatusChanged: { - /* battery parameter skipped */ - if (status == 1) { + onLevelStatusChanged: { + if (levelStatus == BatteryInfo.LevelEmpty) { batStat.text = "Empty" - } else if (status == 2) { + } else if (levelStatus == BatteryInfo.LevelLow) { batStat.text = "Low" - } else if (status == 3) { + } else if (levelStatus == BatteryInfo.LevelOk) { batStat.text = "Ok" - } else if (status == 4) { + } else if (levelStatus == BatteryInfo.LevelFull) { batStat.text = "Full" } else { batStat.text = "Unknown" } } - function getEnergyUnit() { - if (energyUnit == 1) { - return " mAh" - } else if (energyUnit == 2) { - return " mWh" - } else { - return " ???" - } + onHealthChanged: { + if (health == BatteryInfo.HealthOk) + healthState.text = "Ok" + else if (health == BatteryInfo.HealthBad) + healthState.text = "Bad" + else + healthState.text = "Unknown" } function updateBatteryLevel() { - var battery = 0 - level.text = (100/batinfo.maximumCapacity(battery)*batinfo.remainingCapacity(battery)).toFixed(1) + "%" + level.text = (100 / batinfo.maximumCapacity * batinfo.remainingCapacity).toFixed(1) + "%" } Component.onCompleted: { - var battery = 0 - onChargerTypeChanged(chargerType) - onCurrentFlowChanged(battery, currentFlow(battery)) - onRemainingCapacityChanged(battery, remainingCapacity(battery)) - onRemainingChargingTimeChanged(battery, remainingChargingTime(battery)) - onVoltageChanged(battery, voltage(battery)) - onChargingStateChanged(battery, chargingState(battery)) - onBatteryStatusChanged(battery, batteryStatus(battery)) - maximum.text = maximumCapacity(battery) + getEnergyUnit() + onChargerTypeChanged(batinfo.chargerType) + onCurrentFlowChanged(batinfo.currentFlow) + onRemainingCapacityChanged(batinfo.remainingCapacity) + onRemainingChargingTimeChanged(batinfo.remainingChargingTime) + onVoltageChanged(batinfo.voltage) + onChargingStateChanged(batinfo.chargingState) + onLevelStatusChanged(batinfo.levelStatus) + maximum.text = batinfo.maximumCapacity + onHealthChanged(batinfo.health) } } @@ -159,11 +143,13 @@ Rectangle { Text { text: "Current flow:" } Text { text: "Maximum capacity:" } Text { text: "Remaining capacity:" } - Text { text: "Battery state:" } + Text { text: "Level status:" } Text { text: "Remaining charging time:" } Text { text: "Voltage:" } Text { text: "Charge state:" } Text { text: "Charger type:" } + Text { text: "Health:" } + } Column { Text { id: level } @@ -175,6 +161,7 @@ Rectangle { Text { id: voltagetext } Text { id: chargeState } Text { id: chargertype } + Text { id: healthState } } } } diff --git a/src/imports/systeminfo/plugins.qmltypes b/src/imports/systeminfo/plugins.qmltypes index bd62dd85..858fbad9 100644 --- a/src/imports/systeminfo/plugins.qmltypes +++ b/src/imports/systeminfo/plugins.qmltypes @@ -3,11 +3,12 @@ import QtQuick.tooling 1.1 // This file describes the plugin-supplied types contained in the library. // It is used for QML tooling purposes only. // -// This file was auto-generated with the command 'qmlplugindump -notrelocatable QtSystemInfo 5.0'. +// This file was auto-generated by: +// 'qmlplugindump -notrelocatable QtSystemInfo 5.0' Module { Component { - name: "QDeclarativeBatteryInfo" + name: "QBatteryInfo" prototype: "QObject" exports: ["QtSystemInfo/BatteryInfo 5.0"] exportMetaObjectRevisions: [0] @@ -24,113 +25,99 @@ Module { name: "ChargingState" values: { "UnknownChargingState": 0, - "NotCharging": 1, - "Charging": 2, - "Discharging": 3, - "Full": 4 + "Charging": 1, + "IdleChargingState": 2, + "Discharging": 3 } } Enum { - name: "EnergyUnit" + name: "LevelStatus" values: { - "UnitUnknown": 0, - "UnitmAh": 1, - "UnitmWh": 2 + "LevelUnknown": 0, + "LevelEmpty": 1, + "LevelLow": 2, + "LevelOk": 3, + "LevelFull": 4 } } Enum { - name: "BatteryStatus" + name: "Health" values: { - "BatteryStatusUnknown": 0, - "BatteryEmpty": 1, - "BatteryLow": 2, - "BatteryOk": 3, - "BatteryFull": 4 + "HealthUnknown": 0, + "HealthOk": 1, + "HealthBad": 2 } } - Property { name: "monitorBatteryCount"; type: "bool" } - Property { name: "monitorChargerType"; type: "bool" } - Property { name: "monitorCurrentFlow"; type: "bool" } - Property { name: "monitorRemainingCapacity"; type: "bool" } - Property { name: "monitorRemainingChargingTime"; type: "bool" } - Property { name: "monitorVoltage"; type: "bool" } - Property { name: "monitorChargingState"; type: "bool" } - Property { name: "monitorBatteryStatus"; type: "bool" } Property { name: "batteryCount"; type: "int"; isReadonly: true } + Property { name: "batteryIndex"; type: "int" } + Property { name: "valid"; type: "bool"; isReadonly: true } + Property { name: "level"; type: "int"; isReadonly: true } + Property { name: "currentFlow"; type: "int"; isReadonly: true } + Property { name: "cycleCount"; type: "int"; isReadonly: true } + Property { name: "maximumCapacity"; type: "int"; isReadonly: true } + Property { name: "remainingCapacity"; type: "int"; isReadonly: true } + Property { name: "remainingChargingTime"; type: "int"; isReadonly: true } + Property { name: "voltage"; type: "int"; isReadonly: true } + Property { name: "chargingState"; type: "ChargingState"; isReadonly: true } Property { name: "chargerType"; type: "ChargerType"; isReadonly: true } - Property { name: "energyUnit"; type: "EnergyUnit"; isReadonly: true } + Property { name: "levelStatus"; type: "LevelStatus"; isReadonly: true } + Property { name: "health"; type: "Health"; isReadonly: true } + Property { name: "temperature"; type: "float"; isReadonly: true } + Signal { + name: "batteryIndexChanged" + Parameter { name: "batteryIndex"; type: "int" } + } + Signal { + name: "validChanged" + Parameter { name: "isValid"; type: "bool" } + } Signal { name: "batteryCountChanged" Parameter { name: "count"; type: "int" } } Signal { name: "chargerTypeChanged" - Parameter { name: "type"; type: "int" } + Parameter { name: "type"; type: "QBatteryInfo::ChargerType" } } Signal { name: "chargingStateChanged" - Parameter { name: "battery"; type: "int" } - Parameter { name: "state"; type: "int" } + Parameter { name: "state"; type: "QBatteryInfo::ChargingState" } + } + Signal { + name: "levelChanged" + Parameter { name: "level"; type: "int" } } Signal { name: "currentFlowChanged" - Parameter { name: "battery"; type: "int" } Parameter { name: "flow"; type: "int" } } Signal { + name: "cycleCountChanged" + Parameter { name: "cycleCount"; type: "int" } + } + Signal { name: "remainingCapacityChanged" - Parameter { name: "battery"; type: "int" } Parameter { name: "capacity"; type: "int" } } Signal { name: "remainingChargingTimeChanged" - Parameter { name: "battery"; type: "int" } Parameter { name: "seconds"; type: "int" } } Signal { name: "voltageChanged" - Parameter { name: "battery"; type: "int" } Parameter { name: "voltage"; type: "int" } } Signal { - name: "batteryStatusChanged" - Parameter { name: "battery"; type: "int" } - Parameter { name: "status"; type: "int" } - } - Method { - name: "currentFlow" - type: "int" - Parameter { name: "battery"; type: "int" } - } - Method { - name: "remainingCapacity" - type: "int" - Parameter { name: "battery"; type: "int" } - } - Method { - name: "remainingChargingTime" - type: "int" - Parameter { name: "battery"; type: "int" } + name: "levelStatusChanged" + Parameter { name: "levelStatus"; type: "QBatteryInfo::LevelStatus" } } - Method { - name: "voltage" - type: "int" - Parameter { name: "battery"; type: "int" } - } - Method { - name: "chargingState" - type: "int" - Parameter { name: "battery"; type: "int" } - } - Method { - name: "maximumCapacity" - type: "int" - Parameter { name: "battery"; type: "int" } + Signal { + name: "healthChanged" + Parameter { name: "health"; type: "QBatteryInfo::Health" } } - Method { - name: "batteryStatus" - type: "int" - Parameter { name: "battery"; type: "int" } + Signal { + name: "temperatureChanged" + Parameter { name: "temperature"; type: "float" } } } Component { @@ -219,87 +206,6 @@ Module { } } Component { - name: "QDeclarativeDeviceProfile" - prototype: "QObject" - exports: ["QtSystemInfo/DeviceProfile 5.0"] - exportMetaObjectRevisions: [0] - Enum { - name: "ProfileType" - values: { - "UnknownProfile": 0, - "SilentProfile": 1, - "NormalProfile": 2, - "VibrationProfile": 3, - "BeepProfile": 4 - } - } - Property { name: "isVibrationActivated"; type: "bool"; isReadonly: true } - Property { name: "messageRingtoneVolume"; type: "int"; isReadonly: true } - Property { name: "voiceRingtoneVolume"; type: "int"; isReadonly: true } - Property { name: "currentProfileType"; type: "ProfileType"; isReadonly: true } - Signal { name: "vibrationActivatedChanged" } - } - Component { - name: "QDeclarativeDisplayInfo" - prototype: "QObject" - exports: ["QtSystemInfo/DisplayInfo 5.0"] - exportMetaObjectRevisions: [0] - Enum { - name: "BacklightState" - values: { - "BacklightUnknown": 0, - "BacklightOff": 1, - "BacklightDimmed": 2, - "BacklightOn": 3 - } - } - Signal { - name: "backlightStateChanged" - Parameter { name: "screen"; type: "int" } - Parameter { name: "state"; type: "int" } - } - Method { - name: "brightness" - type: "int" - Parameter { name: "screen"; type: "int" } - } - Method { - name: "contrast" - type: "int" - Parameter { name: "screen"; type: "int" } - } - Method { - name: "backlightState" - type: "int" - Parameter { name: "screen"; type: "int" } - } - Method { - name: "colorDepth" - type: "int" - Parameter { name: "screen"; type: "int" } - } - Method { - name: "dpiX" - type: "int" - Parameter { name: "screen"; type: "int" } - } - Method { - name: "dpiY" - type: "int" - Parameter { name: "screen"; type: "int" } - } - Method { - name: "physicalHeight" - type: "int" - Parameter { name: "screen"; type: "int" } - } - Method { - name: "physicalWidth" - type: "int" - Parameter { name: "screen"; type: "int" } - } - } - Component { name: "QDeclarativeNetworkInfo" prototype: "QObject" exports: ["QtSystemInfo/NetworkInfo 5.0"] diff --git a/src/imports/systeminfo/qdeclarativebatteryinfo.cpp b/src/imports/systeminfo/qdeclarativebatteryinfo.cpp deleted file mode 100644 index 06ed4dc0..00000000 --- a/src/imports/systeminfo/qdeclarativebatteryinfo.cpp +++ /dev/null @@ -1,499 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtSystems module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativebatteryinfo_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmltype BatteryInfo - \instantiates QDeclarativeBatteryInfo - \inqmlmodule QtSystemInfo - \ingroup qml-systeminfo - \brief The BatteryInfo element provides various information about the battery status. -*/ - -/*! - \internal -*/ -QDeclarativeBatteryInfo::QDeclarativeBatteryInfo(QObject *parent) - : QObject(parent) - , batteryInfo(new QBatteryInfo(this)) - , isMonitorBatteryCount(false) - , isMonitorChargerType(false) - , isMonitorChargingState(false) - , isMonitorCurrentFlow(false) - , isMonitorRemainingCapacity(false) - , isMonitorRemainingChargingTime(false) - , isMonitorVoltage(false) - , isMonitorBatteryStatus(false) -{ -} - -/*! - \internal - */ -QDeclarativeBatteryInfo::~QDeclarativeBatteryInfo() -{ -} - -/*! - \qmlproperty bool BatteryInfo::monitorBatteryCount - - This property holds whether or not monitor the change of battery counts. - - \sa batteryCount - */ -bool QDeclarativeBatteryInfo::monitorBatteryCount() const -{ - return isMonitorBatteryCount; -} - -void QDeclarativeBatteryInfo::setMonitorBatteryCount(bool monitor) -{ - if (monitor != isMonitorBatteryCount) { - isMonitorBatteryCount = monitor; - if (monitor) { - connect(batteryInfo, SIGNAL(batteryCountChanged(int)), - this, SIGNAL(batteryCountChanged(int))); - } else { - disconnect(batteryInfo, SIGNAL(batteryCountChanged(int)), - this, SIGNAL(batteryCountChanged(int))); - } - emit monitorBatteryCountChanged(); - } -} - -/*! - \qmlproperty int BatteryInfo::batteryCount - - This property holds the number of batteries available, or -1 on error or the information is not - available. -*/ -int QDeclarativeBatteryInfo::batteryCount() const -{ - return batteryInfo->batteryCount(); -} - -/*! - \qmlproperty bool BatteryInfo::monitorChargerType - - This property holds whether or not monitor the change of charger type. - - \sa chargerType - */ -bool QDeclarativeBatteryInfo::monitorChargerType() const -{ - return isMonitorChargerType; -} - -void QDeclarativeBatteryInfo::setMonitorChargerType(bool monitor) -{ - if (monitor != isMonitorChargerType) { - isMonitorChargerType = monitor; - if (monitor) { - connect(batteryInfo, SIGNAL(chargerTypeChanged(QBatteryInfo::ChargerType)), - this, SLOT(_q_chargerTypeChanged(QBatteryInfo::ChargerType))); - } else { - disconnect(batteryInfo, SIGNAL(chargerTypeChanged(QBatteryInfo::ChargerType)), - this, SLOT(_q_chargerTypeChanged(QBatteryInfo::ChargerType))); - } - emit monitorChargerTypeChanged(); - } -} - -/*! - \qmlproperty enumeration BatteryInfo::chargerType - - This property holds the type of the charger. Possible values are: - \list - \li BatteryInfo.UnknownCharger - The charger type is unknown, or no charger. - \li BatteryInfo.WallCharger - Using wall (mains) charger. - \li BatteryInfo.USBCharger - Using USB charger when the system cannot differentiate the current. - \li BatteryInfo.VariableCurrentCharger - Using variable current charger such as bicycle or solar. - \endlist -*/ -QDeclarativeBatteryInfo::ChargerType QDeclarativeBatteryInfo::chargerType() const -{ - return static_cast<ChargerType>(batteryInfo->chargerType()); -} - -void QDeclarativeBatteryInfo::_q_chargerTypeChanged(QBatteryInfo::ChargerType type) -{ - emit chargerTypeChanged(static_cast<ChargerType>(type)); -} - -/*! - \qmlproperty bool BatteryInfo::monitorCurrentFlow - - This property holds whether or not monitor the flow of batteries. - - \sa onCurrentFlowChanged - */ -bool QDeclarativeBatteryInfo::monitorCurrentFlow() const -{ - return isMonitorCurrentFlow; -} - -void QDeclarativeBatteryInfo::setMonitorCurrentFlow(bool monitor) -{ - if (monitor != isMonitorCurrentFlow) { - isMonitorCurrentFlow = monitor; - if (monitor) { - connect(batteryInfo, SIGNAL(currentFlowChanged(int,int)), - this, SIGNAL(currentFlowChanged(int,int))); - } else { - disconnect(batteryInfo, SIGNAL(currentFlowChanged(int,int)), - this, SIGNAL(currentFlowChanged(int,int))); - } - emit monitorCurrentFlowChanged(); - } -} - -/*! - \qmlsignal BatteryInfo::onCurrentFlowChanged(int battery, int flow) - - This handler is called when current flow of \a battery has changed to \a flow. - Note that it won't be called unless monitorCurrentFlow is set true. - - \sa currentFlow, monitorCurrentFlow - */ - -/*! - \qmlmethod int BatteryInfo::currentFlow(int battery) - - Returns the current flow of the \a battery. - - \sa onCurrentFlowChanged -*/ -int QDeclarativeBatteryInfo::currentFlow(int battery) const -{ - return batteryInfo->currentFlow(battery); -} - -/*! - \qmlproperty bool BatteryInfo::monitorRemainingCapacity - - This property holds whether or not monitor the remaining capacity of batteries. - - \sa onRemainingCapacityChanged - */ -bool QDeclarativeBatteryInfo::monitorRemainingCapacity() const -{ - return isMonitorRemainingCapacity; -} - -void QDeclarativeBatteryInfo::setMonitorRemainingCapacity(bool monitor) -{ - if (monitor != isMonitorRemainingCapacity) { - isMonitorRemainingCapacity = monitor; - if (monitor) { - connect(batteryInfo, SIGNAL(remainingCapacityChanged(int,int)), - this, SIGNAL(remainingCapacityChanged(int,int))); - } else { - disconnect(batteryInfo, SIGNAL(remainingCapacityChanged(int,int)), - this, SIGNAL(remainingCapacityChanged(int,int))); - } - emit monitorRemainingCapacityChanged(); - } -} - -/*! - \qmlsignal BatteryInfo::onRemainingCapacityChanged(int battery, int capacity) - - This handler is called when remaining capacity of \a battery has changed to \a capacity. - Note that it won't be called unless monitorRemainingCapacity is set true. - - \sa remainingCapacity, monitorRemainingCapacity - */ - -/*! - \qmlmethod int BatteryInfo::remainingCapacity(int battery) - - Returns the remaining capacity of the \a battery. - - \sa onRemainingCapacityChanged -*/ -int QDeclarativeBatteryInfo::remainingCapacity(int battery) const -{ - return batteryInfo->remainingCapacity(battery); -} - -/*! - \qmlproperty bool BatteryInfo::monitorRemainingChargingTime - - This property holds whether or not monitor the remaining charging time of batteries. - - \sa onRemainingChargingTimeChanged - */ -bool QDeclarativeBatteryInfo::monitorRemainingChargingTime() const -{ - return isMonitorRemainingChargingTime; -} - -void QDeclarativeBatteryInfo::setMonitorRemainingChargingTime(bool monitor) -{ - if (monitor != isMonitorRemainingChargingTime) { - isMonitorRemainingChargingTime = monitor; - if (monitor) { - connect(batteryInfo, SIGNAL(remainingChargingTimeChanged(int,int)), - this, SIGNAL(remainingChargingTimeChanged(int,int))); - } else { - disconnect(batteryInfo, SIGNAL(remainingChargingTimeChanged(int,int)), - this, SIGNAL(remainingChargingTimeChanged(int,int))); - } - emit monitorRemainingChargingTimeChanged(); - } -} - -/*! - \qmlsignal BatteryInfo::onRemainingChargingTimeChanged(int battery, int seconds) - - This handler is called when remaining charging time of \a battery has changed to \a seconds. - Note that it won't be called unless monitorRemainingChargingTime is set true. - - \sa remainingChargingTime, monitorRemainingChargingTime - */ - -/*! - \qmlmethod int BatteryInfo::remainingChargingTime(int battery) - - Returns the remaining charging time of the \a battery. - - \sa onRemainingChargingTimeChanged -*/ -int QDeclarativeBatteryInfo::remainingChargingTime(int battery) const -{ - return batteryInfo->remainingChargingTime(battery); -} - -/*! - \qmlproperty bool BatteryInfo::monitorVoltage - - This property holds whether or not monitor the voltage of batteries. - - \sa onVoltageChanged - */ -bool QDeclarativeBatteryInfo::monitorVoltage() const -{ - return isMonitorVoltage; -} - -void QDeclarativeBatteryInfo::setMonitorVoltage(bool monitor) -{ - if (monitor != isMonitorVoltage) { - isMonitorVoltage = monitor; - if (monitor) { - connect(batteryInfo, SIGNAL(voltageChanged(int,int)), - this, SIGNAL(voltageChanged(int,int))); - } else { - disconnect(batteryInfo, SIGNAL(voltageChanged(int,int)), - this, SIGNAL(voltageChanged(int,int))); - } - emit monitorVoltageChanged(); - } -} - -/*! - \qmlsignal BatteryInfo::onVoltageChanged(int battery, int voltage) - - This handler is called when voltage of \a battery has changed to \a voltage. - Note that it won't be called unless monitorVoltage is set true. - - \sa voltage, monitorVoltage - */ - -/*! - \qmlmethod int BatteryInfo::voltage(int battery) - - Returns the voltage of the \a battery. - - \sa onVoltageChanged -*/ -int QDeclarativeBatteryInfo::voltage(int battery) const -{ - return batteryInfo->voltage(battery); -} - -/*! - \qmlproperty bool BatteryInfo::monitorChargingState - - This property holds whether or not monitor the change of charging state. - - \sa onChargingStateChanged - */ -bool QDeclarativeBatteryInfo::monitorChargingState() const -{ - return isMonitorChargingState; -} - -void QDeclarativeBatteryInfo::setMonitorChargingState(bool monitor) -{ - if (monitor != isMonitorChargingState) { - isMonitorChargingState = monitor; - if (monitor) { - connect(batteryInfo, SIGNAL(chargingStateChanged(int,QBatteryInfo::ChargingState)), - this, SLOT(_q_chargingStateChanged(int,QBatteryInfo::ChargingState))); - } else { - disconnect(batteryInfo, SIGNAL(chargingStateChanged(int,QBatteryInfo::ChargingState)), - this, SLOT(_q_chargingStateChanged(int,QBatteryInfo::ChargingState))); - } - emit monitorChargingStateChanged(); - } -} - -/*! - \qmlmethod ChargingState BatteryInfo::chargingState(int battery) - - Returns the charging state of the given \a battery. Possible values are: - \list - \li BatteryInfo.UnknownChargingState - The charging state is unknown or charging error occured. - \li BatteryInfo.NotCharging - The battery is not charging, i.e. too low charger power. - \li BatteryInfo.Charging - The battery is charging. - \li BatteryInfo.Discharging - The battery is discharging. - \li BatteryInfo.Full - The battery is fully charged. - \endlist - - \sa onChargingStateChanged -*/ -int QDeclarativeBatteryInfo::chargingState(int battery) const -{ - return batteryInfo->chargingState(battery); -} - -/*! - \qmlsignal BatteryInfo::onChargingStateChanged(int battery, ChargingState state) - - This handler is called when charging state of \a battery has changed to \a state. - Note that it won't be called unless monitorChargingState is set true. - - \sa chargingState, monitorChargingState - */ -void QDeclarativeBatteryInfo::_q_chargingStateChanged(int battery, QBatteryInfo::ChargingState state) -{ - emit chargingStateChanged(battery, static_cast<ChargingState>(state)); -} - -/*! - \qmlproperty enumeration BatteryInfo::energyUnit - - This property holds the energy unit used. Possible values are: - \list - \li BatteryInfo.UnitUnknown - Energy unit unknown. - \li BatteryInfo.UnitmAh - Energy described in milliamp-hour (mAh) - \li BatteryInfo.UnitmWh - Energy described in milliwatt-hour (mWh) - \endlist -*/ -QDeclarativeBatteryInfo::EnergyUnit QDeclarativeBatteryInfo::energyUnit() const -{ - return static_cast<EnergyUnit>(batteryInfo->energyUnit()); -} - -/*! - \qmlmethod int BatteryInfo::maximumCapacity(int battery) - - Returns the maximum capacity of the \a battery -*/ -int QDeclarativeBatteryInfo::maximumCapacity(int battery) const -{ - return batteryInfo->maximumCapacity(battery); -} - -/*! - \qmlproperty bool BatteryInfo::monitorBatteryStatus - - This property holds whether or not monitor the change of battery's status. - - \sa onBatteryStatusChanged - */ -bool QDeclarativeBatteryInfo::monitorBatteryStatus() const -{ - return isMonitorBatteryStatus; -} - -void QDeclarativeBatteryInfo::setMonitorBatteryStatus(bool monitor) -{ - if (monitor != isMonitorBatteryStatus) { - isMonitorBatteryStatus = monitor; - if (monitor) { - connect(batteryInfo, SIGNAL(batteryStatusChanged(int,QBatteryInfo::BatteryStatus)), - this, SLOT(_q_batteryStatusChanged(int,QBatteryInfo::BatteryStatus))); - } else { - disconnect(batteryInfo, SIGNAL(batteryStatusChanged(int,QBatteryInfo::BatteryStatus)), - this, SLOT(_q_batteryStatusChanged(int,QBatteryInfo::BatteryStatus))); - } - emit monitorBatteryStatusChanged(); - } -} - -/*! - \qmlmethod BatteryStatus BatteryInfo::batteryStatus(int battery) - - Returns the status of the given \a battery. Possible values are: - \list - \li BatteryInfo.BatteryStatusUnknown - Battery level undetermined. - \li BatteryInfo.BatteryEmpty - Battery is considered be empty and device needs to shut down. - \li BatteryInfo.BatteryLow - Battery level is low and warnings need to be issued to the user. - \li BatteryInfo.BatteryOk - Battery level is Ok. It is above "Low" but not "Full". - \li BatteryInfo.BatteryFull - Battery is fully charged. - \endlist - - \sa onBatteryStatusChanged -*/ -int QDeclarativeBatteryInfo::batteryStatus(int battery) const -{ - return batteryInfo->batteryStatus(battery); -} - -/*! - \qmlsignal BatteryInfo::onBatteryStatusChanged(int battery, BatteryStatus status) - - This handler is called when status of \a battery has changed to \a status. - Note that it won't be called unless monitorBatteryStatus is set true. - - \sa batteryStatus, monitorBatteryStatus - */ -void QDeclarativeBatteryInfo::_q_batteryStatusChanged(int battery, QBatteryInfo::BatteryStatus status) -{ - emit batteryStatusChanged(battery, static_cast<BatteryStatus>(status)); -} - -QT_END_NAMESPACE diff --git a/src/imports/systeminfo/qdeclarativebatteryinfo_p.h b/src/imports/systeminfo/qdeclarativebatteryinfo_p.h deleted file mode 100644 index 0fc104e3..00000000 --- a/src/imports/systeminfo/qdeclarativebatteryinfo_p.h +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtSystems module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QDECLARATIVEBATTERYINFO_P_H -#define QDECLARATIVEBATTERYINFO_P_H - -#include <qbatteryinfo.h> - -QT_BEGIN_NAMESPACE - -class QDeclarativeBatteryInfo : public QObject -{ - Q_OBJECT - - Q_ENUMS(ChargerType) - Q_ENUMS(ChargingState) - Q_ENUMS(EnergyUnit) - Q_ENUMS(BatteryStatus) - - Q_PROPERTY(bool monitorBatteryCount READ monitorBatteryCount WRITE setMonitorBatteryCount NOTIFY monitorBatteryCountChanged) - Q_PROPERTY(bool monitorChargerType READ monitorChargerType WRITE setMonitorChargerType NOTIFY monitorChargerTypeChanged) - Q_PROPERTY(bool monitorCurrentFlow READ monitorCurrentFlow WRITE setMonitorCurrentFlow NOTIFY monitorCurrentFlowChanged) - Q_PROPERTY(bool monitorRemainingCapacity READ monitorRemainingCapacity WRITE setMonitorRemainingCapacity NOTIFY monitorRemainingCapacityChanged) - Q_PROPERTY(bool monitorRemainingChargingTime READ monitorRemainingChargingTime WRITE setMonitorRemainingChargingTime NOTIFY monitorRemainingChargingTimeChanged) - Q_PROPERTY(bool monitorVoltage READ monitorVoltage WRITE setMonitorVoltage NOTIFY monitorVoltageChanged) - Q_PROPERTY(bool monitorChargingState READ monitorChargingState WRITE setMonitorChargingState NOTIFY monitorChargingStateChanged) - Q_PROPERTY(bool monitorBatteryStatus READ monitorBatteryStatus WRITE setMonitorBatteryStatus NOTIFY monitorBatteryStatusChanged) - - Q_PROPERTY(int batteryCount READ batteryCount NOTIFY batteryCountChanged) - Q_PROPERTY(ChargerType chargerType READ chargerType NOTIFY chargerTypeChanged) - Q_PROPERTY(EnergyUnit energyUnit READ energyUnit) - -public: - enum ChargerType { - UnknownCharger = QBatteryInfo::UnknownCharger, - WallCharger = QBatteryInfo::WallCharger, - USBCharger = QBatteryInfo::USBCharger, - VariableCurrentCharger = QBatteryInfo::VariableCurrentCharger - }; - - enum ChargingState { - UnknownChargingState = QBatteryInfo::UnknownChargingState, - NotCharging = QBatteryInfo::NotCharging, - Charging = QBatteryInfo::Charging, - Discharging = QBatteryInfo::Discharging, - Full = QBatteryInfo::Full - }; - - enum EnergyUnit { - UnitUnknown = QBatteryInfo::UnitUnknown, - UnitmAh = QBatteryInfo::UnitmAh, - UnitmWh = QBatteryInfo::UnitmWh - }; - - enum BatteryStatus { - BatteryStatusUnknown = QBatteryInfo::BatteryStatusUnknown, - BatteryEmpty = QBatteryInfo::BatteryEmpty, - BatteryLow = QBatteryInfo::BatteryLow, - BatteryOk = QBatteryInfo::BatteryOk, - BatteryFull = QBatteryInfo::BatteryFull - }; - - QDeclarativeBatteryInfo(QObject *parent = 0); - virtual ~QDeclarativeBatteryInfo(); - - bool monitorBatteryCount() const; - void setMonitorBatteryCount(bool monitor); - int batteryCount() const; - - bool monitorChargerType() const; - void setMonitorChargerType(bool monitor); - ChargerType chargerType() const; - - bool monitorCurrentFlow() const; - void setMonitorCurrentFlow(bool monitor); - Q_INVOKABLE int currentFlow(int battery) const; - - bool monitorRemainingCapacity() const; - void setMonitorRemainingCapacity(bool monitor); - Q_INVOKABLE int remainingCapacity(int battery) const; - - bool monitorRemainingChargingTime() const; - void setMonitorRemainingChargingTime(bool monitor); - Q_INVOKABLE int remainingChargingTime(int battery) const; - - bool monitorVoltage() const; - void setMonitorVoltage(bool monitor); - Q_INVOKABLE int voltage(int battery) const; - - bool monitorChargingState() const; - void setMonitorChargingState(bool monitor); - Q_INVOKABLE int chargingState(int battery) const; - - EnergyUnit energyUnit() const; - Q_INVOKABLE int maximumCapacity(int battery) const; - - bool monitorBatteryStatus() const; - void setMonitorBatteryStatus(bool monitor); - Q_INVOKABLE int batteryStatus(int battery) const; - -Q_SIGNALS: - void monitorBatteryCountChanged(); - void monitorChargerTypeChanged(); - void monitorChargingStateChanged(); - void monitorCurrentFlowChanged(); - void monitorRemainingCapacityChanged(); - void monitorRemainingChargingTimeChanged(); - void monitorVoltageChanged(); - void monitorBatteryStatusChanged(); - - void batteryCountChanged(int count); - void chargerTypeChanged(int type); - void chargingStateChanged(int battery, int state); - void currentFlowChanged(int battery, int flow); - void remainingCapacityChanged(int battery, int capacity); - void remainingChargingTimeChanged(int battery, int seconds); - void voltageChanged(int battery, int voltage); - void batteryStatusChanged(int battery, int status); - -private Q_SLOTS: - void _q_chargerTypeChanged(QBatteryInfo::ChargerType type); - void _q_chargingStateChanged(int battery, QBatteryInfo::ChargingState state); - void _q_batteryStatusChanged(int battery, QBatteryInfo::BatteryStatus status); - -private: - QBatteryInfo *batteryInfo; - - bool isMonitorBatteryCount; - bool isMonitorChargerType; - bool isMonitorChargingState; - bool isMonitorCurrentFlow; - bool isMonitorRemainingCapacity; - bool isMonitorRemainingChargingTime; - bool isMonitorVoltage; - bool isMonitorBatteryStatus; -}; - -QT_END_NAMESPACE - -#endif // QDECLARATIVEBATTERYINFO_P_H diff --git a/src/imports/systeminfo/qdeclarativedeviceinfo_p.h b/src/imports/systeminfo/qdeclarativedeviceinfo_p.h index c857cf3f..9a593bff 100644 --- a/src/imports/systeminfo/qdeclarativedeviceinfo_p.h +++ b/src/imports/systeminfo/qdeclarativedeviceinfo_p.h @@ -53,7 +53,7 @@ #ifndef QDECLARATIVEDEVICEINFO_P_H #define QDECLARATIVEDEVICEINFO_P_H -#include <qdeviceinfo.h> +#include "qdeviceinfo.h" QT_BEGIN_NAMESPACE diff --git a/src/imports/systeminfo/qsysteminfo.cpp b/src/imports/systeminfo/qsysteminfo.cpp index 93f14690..91ed0b6b 100644 --- a/src/imports/systeminfo/qsysteminfo.cpp +++ b/src/imports/systeminfo/qsysteminfo.cpp @@ -42,6 +42,7 @@ #include <QtQml/qqmlextensionplugin.h> #include <QtQml/qqml.h> +#include "qbatteryinfo.h" #include "qdeclarativedeviceinfo_p.h" #include "qdeclarativenetworkinfo_p.h" #include <qscreensaver.h> @@ -60,6 +61,7 @@ public: int major = 5; int minor = 0; + qmlRegisterType<QBatteryInfo>(uri, major, minor, "BatteryInfo"); qmlRegisterType<QDeclarativeDeviceInfo>(uri, major, minor, "DeviceInfo"); qmlRegisterType<QDeclarativeNetworkInfo>(uri, major, minor, "NetworkInfo"); qmlRegisterType<QScreenSaver>(uri, major, minor, "ScreenSaver"); diff --git a/src/systeminfo/linux/qbatteryinfo_upower.cpp b/src/systeminfo/linux/qbatteryinfo_upower.cpp index 0d5d4e12..2f18ae4c 100644 --- a/src/systeminfo/linux/qbatteryinfo_upower.cpp +++ b/src/systeminfo/linux/qbatteryinfo_upower.cpp @@ -310,6 +310,7 @@ QBatteryInfo::ChargingState QBatteryInfoPrivate::chargingState() QBatteryInfo::LevelStatus QBatteryInfoPrivate::levelStatus(int battery) { QBatteryInfo::LevelStatus stat = QBatteryInfo::LevelUnknown; + if (batteryMap.count() >= battery) { int level = batteryMap.value(battery).value(QStringLiteral("Percentage")).toInt(); if (level < 3) @@ -331,9 +332,16 @@ QBatteryInfo::LevelStatus QBatteryInfoPrivate::levelStatus() QBatteryInfo::Health QBatteryInfoPrivate::health(int battery) { - Q_UNUSED(battery) - - return QBatteryInfo::HealthUnknown; + QBatteryInfo::Health health = QBatteryInfo::HealthUnknown; + if (batteryMap.count() >= battery) { + int percent = (batteryMap.value(battery).value(QStringLiteral("EnergyFull")).toInt() *100) + / (float)( batteryMap.value(battery).value(QStringLiteral("EnergyFullDesign")).toInt()); + if (percent < 65) + health = QBatteryInfo::HealthBad; + else + health = QBatteryInfo::HealthOk; + } + return health; } QBatteryInfo::Health QBatteryInfoPrivate::health() @@ -353,38 +361,25 @@ float QBatteryInfoPrivate::temperature() return temperature(index); } -void QBatteryInfoPrivate::upowerDeviceChanged() -{ - QUPowerDeviceInterface *uPowerDevice = qobject_cast<QUPowerDeviceInterface*>(sender()); - - if (uPowerDevice->type() == 1) { -//line power - if (uPowerDevice->nativePath().contains(QStringLiteral("usb"))) - Q_EMIT chargerTypeChanged(QBatteryInfo::USBCharger); - else - Q_EMIT chargerTypeChanged(QBatteryInfo::WallCharger); - } - if (uPowerDevice->type() == 2) { -//battery - } -} void QBatteryInfoPrivate::uPowerBatteryPropertyChanged(const QString &prop, const QVariant &v) { QUPowerDeviceInterface *uPowerDevice = qobject_cast<QUPowerDeviceInterface*>(sender()); - int foundBattery = 0; - QMapIterator<int, QVariantMap> i(batteryMap); - while (i.hasNext()) { - i.next(); - if (i.value().value(QStringLiteral("NativePath")).toString() == uPowerDevice->nativePath()) { - foundBattery = i.key(); - break; + + if (uPowerDevice->type() == 2) { + QMapIterator<int, QVariantMap> i(batteryMap); + while (i.hasNext()) { + i.next(); + if (i.value().value(QStringLiteral("NativePath")).toString() == uPowerDevice->nativePath()) { + foundBattery = i.key(); + break; + } } - } - QVariantMap foundMap = batteryMap.value(foundBattery); - foundMap.insert(prop,v); - batteryMap.insert(foundBattery,foundMap); + QVariantMap foundMap = batteryMap.value(foundBattery); + foundMap.insert(prop,v); + batteryMap.insert(foundBattery,foundMap); + } if (prop == QLatin1String("Energy")) { if (foundBattery == index) @@ -396,7 +391,6 @@ void QBatteryInfoPrivate::uPowerBatteryPropertyChanged(const QString &prop, cons } else if (prop == QLatin1String("Percentage")) { int level = v.toInt(); - // Q_EMIT remainingCapacityChanged(foundBattery, level); QBatteryInfo::LevelStatus stat = QBatteryInfo::LevelUnknown; @@ -409,10 +403,8 @@ void QBatteryInfoPrivate::uPowerBatteryPropertyChanged(const QString &prop, cons else stat = QBatteryInfo::LevelFull; - // if (batteryMap.value(foundBattery).value(QStringLiteral("Percentage")).toInt() != stat) { if (foundBattery == index) Q_EMIT levelStatusChanged(stat); - // } } else if (prop == QLatin1String("Voltage")) { if (foundBattery == index) @@ -427,34 +419,37 @@ void QBatteryInfoPrivate::uPowerBatteryPropertyChanged(const QString &prop, cons if (foundBattery == index) Q_EMIT chargingStateChanged(curChargeState); } + } else if (prop == QLatin1String("Capacity")) { + QBatteryInfo::Health newHealth = health(index); + if (newHealth != healthList.value(index)) { + healthList.insert(index,newHealth); + Q_EMIT healthChanged(newHealth); + } - } else if (prop == QLatin1String("Capacity")) { - qDebug() << "Your battery just got less capacity"; } else if (prop == QLatin1String("TimeToFull")) { if (foundBattery == index) Q_EMIT remainingChargingTimeChanged(v.toInt()); - - } else if (prop == QLatin1String("Type")) { - if (uPowerDevice->isOnline()) { - QBatteryInfo::ChargerType curCharger = getChargerType(uPowerDevice->nativePath()); - if (curCharger != cType) { - cType = curCharger; - Q_EMIT chargerTypeChanged(cType); - } + } else if (prop == QLatin1String("Online")) { + QBatteryInfo::ChargerType curCharger = QBatteryInfo::UnknownCharger; + if (v.toBool()) { + curCharger = getChargerType(uPowerDevice->nativePath()); + } + if (curCharger != cType) { + cType = curCharger; + Q_EMIT chargerTypeChanged(cType); } } } QBatteryInfo::ChargerType QBatteryInfoPrivate::getChargerType(const QString &path) { - QFile charger; QBatteryInfo::ChargerType chargerType = QBatteryInfo::UnknownCharger; - charger.setFileName(path + QStringLiteral("/type")); + QFile charger; + charger.setFileName(QStringLiteral("/sys/class/power_supply/") + path + QStringLiteral("/type")); if (charger.open(QIODevice::ReadOnly)) { QString line = QString::fromLocal8Bit(charger.readAll().simplified()); if (line == QStringLiteral("USB")) { chargerType = QBatteryInfo::USBCharger; - } else if (line == QStringLiteral("Mains")) { chargerType = QBatteryInfo::WallCharger; } @@ -492,7 +487,6 @@ QBatteryInfo::ChargingState QBatteryInfoPrivate::getCurrentChargingState(int sta void QBatteryInfoPrivate::getBatteryStats() { - int batteryNumber = 0; batteryMap.clear(); QUPowerInterface *power; power = new QUPowerInterface(this); @@ -503,25 +497,94 @@ void QBatteryInfoPrivate::getBatteryStats() this,SLOT(deviceRemoved(QString))); foreach (const QDBusObjectPath &objpath, power->enumerateDevices()) { - QUPowerDeviceInterface *battery; - battery = new QUPowerDeviceInterface(objpath.path(),this); + QUPowerDeviceInterface *uPowerDevice; + uPowerDevice = new QUPowerDeviceInterface(objpath.path(),this); + connect(uPowerDevice,SIGNAL(propertyChanged(QString,QVariant)), + this,SLOT(uPowerBatteryPropertyChanged(QString,QVariant))); - if (!battery->isPowerSupply()) - continue; - if (battery->type() == 1) { //line power - cType = getChargerType(battery->nativePath()); - } - if (battery->type() == 2) { //battery power - batteryMap.insert(batteryNumber++,battery->getProperties()); + QMapIterator<QString, QVariant> i(uPowerDevice->getProperties()); + while (i.hasNext()) { + i.next(); + QString prop = i.key(); + QVariant v = i.value(); - connect(battery,SIGNAL(changed()),this,SLOT(upowerDeviceChanged())); - connect(battery,SIGNAL(propertyChanged(QString,QVariant)), - this,SLOT(uPowerBatteryPropertyChanged(QString,QVariant))); + int foundBattery = 0; + if (uPowerDevice->type() == 2) { - cState = getCurrentChargingState(battery->state()); + QMapIterator<int, QVariantMap> i(batteryMap); + while (i.hasNext()) { + i.next(); + if (i.value().value(QStringLiteral("NativePath")).toString() == uPowerDevice->nativePath()) { + foundBattery = i.key(); + break; + } + } - } //end enumerateDevices + QVariantMap foundMap = batteryMap.value(foundBattery); + foundMap.insert(prop,v); + batteryMap.insert(foundBattery,foundMap); + } + + if (prop == QLatin1String("Energy")) { + if (foundBattery == index) + Q_EMIT remainingCapacityChanged(v.toDouble() * 1000); + } else if (prop == QLatin1String("EnergyFullDesign")) { + + } else if (prop == QLatin1String("EnergyRate")) { + if (foundBattery == index) + Q_EMIT currentFlowChanged(v.toDouble() / (uPowerDevice->voltage() * 1000)); + + } else if (prop == QLatin1String("Percentage")) { + int level = v.toInt(); + + QBatteryInfo::LevelStatus stat = QBatteryInfo::LevelUnknown; + + if (level < 3) + stat = QBatteryInfo::LevelEmpty; + else if (level < 11) + stat = QBatteryInfo::LevelLow; + else if (level < 99) + stat = QBatteryInfo::LevelOk; + else + stat = QBatteryInfo::LevelFull; + + if (foundBattery == index) + Q_EMIT levelStatusChanged(stat); + + } else if (prop == QLatin1String("Voltage")) { + if (foundBattery == index) + Q_EMIT voltageChanged(v.toDouble() * 1000 ); + + } else if (prop == QLatin1String("State")) { + + QBatteryInfo::ChargingState curChargeState = getCurrentChargingState(v.toInt()); + + if (curChargeState != cState) { + cState = curChargeState; + if (foundBattery == index) + Q_EMIT chargingStateChanged(curChargeState); + } + + } else if (prop == QLatin1String("Capacity")) { + + QBatteryInfo::Health newHealth = health(index); + healthList.insert(index,newHealth); + Q_EMIT healthChanged(newHealth); + + } else if (prop == QLatin1String("TimeToFull")) { + Q_EMIT remainingChargingTimeChanged(v.toInt()); + } else if (prop == QLatin1String("Online")) { + QBatteryInfo::ChargerType curCharger = QBatteryInfo::UnknownCharger; + if (v.toBool()) { + curCharger = getChargerType(uPowerDevice->nativePath()); + if (curCharger != cType) { + cType = curCharger; + Q_EMIT chargerTypeChanged(cType); + } + } + } + } } } @@ -530,13 +593,11 @@ void QBatteryInfoPrivate::deviceAdded(const QString &path) QUPowerDeviceInterface *battery; battery = new QUPowerDeviceInterface(path,this); int batteryNumber = batteryCount(); + connect(battery,SIGNAL(propertyChanged(QString,QVariant)), + this,SLOT(uPowerBatteryPropertyChanged(QString,QVariant))); if (battery->type() == 2) { batteryMap.insert(++batteryNumber,battery->getProperties()); - connect(battery,SIGNAL(changed()),this,SLOT(upowerDeviceChanged())); - connect(battery,SIGNAL(propertyChanged(QString,QVariant)), - this,SLOT(uPowerBatteryPropertyChanged(QString,QVariant))); - } } @@ -557,11 +618,10 @@ void QBatteryInfoPrivate::deviceRemoved(const QString &path) } bool validBefore = isValid(); + disconnect(battery,SIGNAL(propertyChanged(QString,QVariant)), + this,SLOT(uPowerBatteryPropertyChanged(QString,QVariant))); if (battery->type() == 2) { batteryMap.remove(foundBattery); - disconnect(battery,SIGNAL(changed()),this,SLOT(upowerDeviceChanged())); - disconnect(battery,SIGNAL(propertyChanged(QString,QVariant)), - this,SLOT(uPowerBatteryPropertyChanged(QString,QVariant))); } bool validNow = isValid(); if (validBefore != validNow) diff --git a/src/systeminfo/linux/qbatteryinfo_upower_p.h b/src/systeminfo/linux/qbatteryinfo_upower_p.h index 8ac86ff2..d762a746 100644 --- a/src/systeminfo/linux/qbatteryinfo_upower_p.h +++ b/src/systeminfo/linux/qbatteryinfo_upower_p.h @@ -60,6 +60,7 @@ #include <QtCore/QVariantMap> #include <QtCore/QMap> #include <QtDBus/QDBusServiceWatcher> +#include "qdevicekitservice_linux_p.h" QT_BEGIN_NAMESPACE @@ -121,8 +122,8 @@ protected: QMap <int,QVariantMap> batteryMap; QBatteryInfo::ChargerType cType; QBatteryInfo::ChargingState cState; + QList <QBatteryInfo::Health> healthList; private Q_SLOTS: - void upowerDeviceChanged(); void uPowerBatteryPropertyChanged(const QString & prop, const QVariant &v); void getBatteryStats(); void deviceAdded(const QString &path); @@ -139,7 +140,6 @@ private: void initialize(); QBatteryInfo::ChargingState getCurrentChargingState(int); QBatteryInfo::ChargerType getChargerType(const QString &path); - }; QT_END_NAMESPACE diff --git a/src/systeminfo/linux/qdevicekitservice_linux.cpp b/src/systeminfo/linux/qdevicekitservice_linux.cpp index a844d2e4..ea176a28 100644 --- a/src/systeminfo/linux/qdevicekitservice_linux.cpp +++ b/src/systeminfo/linux/qdevicekitservice_linux.cpp @@ -294,4 +294,9 @@ QString QUPowerDeviceInterface::nativePath() return pMap.value(QStringLiteral("NativePath")).toString(); } +quint16 QUPowerDeviceInterface::technology() +{ + return pMap.value(QStringLiteral("Technology")).toUInt(); +} + QT_END_NAMESPACE diff --git a/src/systeminfo/linux/qdevicekitservice_linux_p.h b/src/systeminfo/linux/qdevicekitservice_linux_p.h index 06e188df..f3d46855 100644 --- a/src/systeminfo/linux/qdevicekitservice_linux_p.h +++ b/src/systeminfo/linux/qdevicekitservice_linux_p.h @@ -100,6 +100,7 @@ public: quint16 type(); qint64 timeToFull(); QString nativePath(); + quint16 technology(); QVariantMap getProperties() { return pMap; } |