2019-01-06 00:40:22 +03:00
|
|
|
/**
|
|
|
|
* Battery Buddy, a Sailfish application to prolong battery lifetime
|
|
|
|
*
|
2020-03-21 04:27:09 +03:00
|
|
|
* Copyright (C) 2019-2020 Matti Viljanen
|
2019-01-06 00:40:22 +03:00
|
|
|
*
|
|
|
|
* Battery Buddy is free software: you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Battery Buddy 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 General Public License for more details. You should have received a copy of the GNU
|
2020-03-24 11:02:30 +03:00
|
|
|
* General Public License along with Battery Buddy. If not, see <http://www.gnu.org/licenses/>.
|
2019-01-06 00:40:22 +03:00
|
|
|
*
|
|
|
|
* Author: Matti Viljanen
|
|
|
|
*/
|
2022-03-20 21:16:24 +03:00
|
|
|
import QtQuick 2.6
|
2019-01-05 16:49:35 +03:00
|
|
|
import Sailfish.Silica 1.0
|
2019-01-29 02:23:53 +03:00
|
|
|
import "../components"
|
2019-01-05 16:49:35 +03:00
|
|
|
|
|
|
|
Page {
|
|
|
|
id: page
|
2020-03-21 17:03:07 +03:00
|
|
|
allowedOrientations: Orientation.Portrait | Orientation.Landscape | Orientation.LandscapeInverted
|
2019-01-09 01:59:23 +03:00
|
|
|
property variant statusText: {
|
|
|
|
"idle": qsTr("idle", "Charger plugged in, not using nor charging battery"),
|
|
|
|
"discharging": qsTr("discharging", "Charger not plugged in, battery discharging"),
|
|
|
|
"charging": qsTr("charging", "Charger plugged in and battery charging"),
|
2020-03-20 21:49:28 +03:00
|
|
|
"full": qsTr("full", "Battery fully charged"),
|
|
|
|
"empty": qsTr("empty", "Battery fully depleted"),
|
2019-01-09 01:59:23 +03:00
|
|
|
"unknown": qsTr("unknown", "Battery not detected, or faulty, or something")
|
|
|
|
}
|
2021-05-02 11:23:58 +03:00
|
|
|
property variant healthText: {
|
|
|
|
"good": qsTr("Good", "Battery is OK"),
|
|
|
|
"warm": qsTr("Warm", "Battery is warm"),
|
|
|
|
"overheat": qsTr("Overheated", "Battery is very hot"),
|
2021-05-02 22:14:29 +03:00
|
|
|
"cool": qsTr("Cool", "Battery is cool"),
|
|
|
|
"cold": qsTr("Cold", "Battery is very cold"),
|
2021-05-22 22:58:05 +03:00
|
|
|
"unknown": qsTr("unknown", "Battery not detected, or faulty, or something")
|
2021-05-02 11:23:58 +03:00
|
|
|
}
|
2020-06-14 13:10:30 +03:00
|
|
|
property bool serviceRunning: true
|
2019-01-05 16:49:35 +03:00
|
|
|
|
2022-03-20 20:26:57 +03:00
|
|
|
SystemdUserService {
|
|
|
|
id: batteryService
|
|
|
|
serviceName: 'harbour-batterybuddy.service'
|
|
|
|
}
|
|
|
|
|
2020-06-14 11:57:09 +03:00
|
|
|
Timer {
|
|
|
|
id: startupTimer
|
2020-11-15 23:19:13 +03:00
|
|
|
interval: 1
|
2020-06-14 11:57:09 +03:00
|
|
|
repeat: false
|
|
|
|
running: true
|
|
|
|
onTriggered: {
|
2021-04-17 22:01:19 +03:00
|
|
|
if(logger.debug) logger.log("Startup timer started")
|
2020-03-21 04:25:26 +03:00
|
|
|
pageStack.pushAttached(Qt.resolvedUrl("SettingsPage.qml"))
|
2019-01-29 02:25:16 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-05 16:49:35 +03:00
|
|
|
|
|
|
|
// To enable PullDownMenu, place our content in a SilicaFlickable
|
|
|
|
SilicaFlickable {
|
2019-01-08 21:06:08 +03:00
|
|
|
id: mainFlickable
|
2019-01-05 16:49:35 +03:00
|
|
|
anchors.fill: parent
|
2020-03-21 17:03:07 +03:00
|
|
|
contentHeight: flow.height + Theme.horizontalPageMargin
|
2019-01-05 16:49:35 +03:00
|
|
|
|
2019-01-08 21:06:08 +03:00
|
|
|
VerticalScrollDecorator { flickable: mainFlickable }
|
|
|
|
|
2019-01-05 21:16:04 +03:00
|
|
|
PullDownMenu {
|
2019-01-06 00:37:44 +03:00
|
|
|
MenuItem {
|
2019-01-06 12:34:26 +03:00
|
|
|
text: qsTr("Background", "More to read, background information...")
|
2019-01-06 00:37:44 +03:00
|
|
|
onClicked: pageStack.push(Qt.resolvedUrl("InfoPage.qml"))
|
|
|
|
}
|
2019-01-05 21:16:04 +03:00
|
|
|
}
|
|
|
|
|
2019-01-05 16:49:35 +03:00
|
|
|
// Place our content in a Column. The PageHeader is always placed at the top
|
|
|
|
// of the page, followed by our content.
|
2020-03-21 17:03:07 +03:00
|
|
|
Flow {
|
|
|
|
id: flow
|
|
|
|
anchors {
|
|
|
|
top: parent.top
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
}
|
|
|
|
height: header.height + Math.max(columnOne.heigh, columnTwo.height)
|
2019-01-05 16:49:35 +03:00
|
|
|
|
|
|
|
PageHeader {
|
2020-03-21 17:03:07 +03:00
|
|
|
id: header
|
2019-01-05 18:15:32 +03:00
|
|
|
title: qsTr("Battery Buddy")
|
|
|
|
}
|
2019-01-29 02:23:53 +03:00
|
|
|
Column {
|
2020-03-21 17:03:07 +03:00
|
|
|
id: columnOne
|
|
|
|
width: isPortrait ? parent.width : parent.width / 2
|
|
|
|
spacing: Theme.paddingLarge
|
2019-01-29 02:23:53 +03:00
|
|
|
|
2020-03-21 17:03:07 +03:00
|
|
|
Label {
|
|
|
|
x: Theme.paddingLarge
|
|
|
|
text: qsTr("Battery status")
|
|
|
|
color: Theme.highlightColor
|
2019-01-29 02:23:53 +03:00
|
|
|
}
|
2020-03-21 17:03:07 +03:00
|
|
|
Item {
|
|
|
|
width: parent.width
|
|
|
|
// Rotation: width <==> height
|
|
|
|
height: batteryGraph.width
|
|
|
|
BatteryGraph {
|
|
|
|
id: batteryGraph
|
|
|
|
transformOrigin: Item.Center
|
|
|
|
rotation: 90
|
|
|
|
width: parent.width * 0.2
|
|
|
|
anchors.centerIn: parent
|
|
|
|
}
|
2019-01-29 02:23:53 +03:00
|
|
|
}
|
2020-03-21 17:03:07 +03:00
|
|
|
// Detail column
|
|
|
|
Column {
|
|
|
|
width: parent.width
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
MyDetailItem {
|
|
|
|
label: qsTr("Charge:")
|
|
|
|
value: battery.charge + "%"
|
|
|
|
}
|
2020-11-15 23:28:00 +03:00
|
|
|
MyDetailItem {
|
|
|
|
label: qsTr("Current:")
|
|
|
|
value: Math.floor(battery.current / 1000) + " mA"
|
|
|
|
}
|
|
|
|
|
2020-03-21 17:03:07 +03:00
|
|
|
MyDetailItem {
|
|
|
|
label: qsTr("Charger connected:")
|
|
|
|
value: battery.chargerConnected ? qsTr("yes") : qsTr("no")
|
|
|
|
}
|
|
|
|
MyDetailItem {
|
|
|
|
label: qsTr("State:")
|
|
|
|
value: statusText[battery.state]
|
|
|
|
}
|
2021-05-02 11:23:58 +03:00
|
|
|
MyDetailItem {
|
|
|
|
label: qsTr("Health:")
|
|
|
|
value: healthText[battery.health]
|
2021-05-23 14:25:24 +03:00
|
|
|
visible: value !== "unknown"
|
2021-05-02 11:23:58 +03:00
|
|
|
}
|
|
|
|
MyDetailItem {
|
|
|
|
label: qsTr("Temperature:")
|
2021-05-22 23:02:25 +03:00
|
|
|
value: battery.temperature === 0x7FFFFFFF ? healthText["unknown"] : formatTemperature(battery.temperature)
|
2021-05-23 14:25:24 +03:00
|
|
|
visible: battery.temperature !== 0x7FFFFFFF
|
2021-05-22 23:02:25 +03:00
|
|
|
|
|
|
|
function formatTemperature(temp) {
|
|
|
|
if(Qt.locale().measurementSystem === Locale.ImperialUSSystem) {
|
|
|
|
return Math.floor((battery.temperature / 10) * 1.8 + 32) + " °F"
|
|
|
|
}
|
|
|
|
return Math.floor(battery.temperature / 10) + " °C"
|
|
|
|
}
|
2021-05-02 11:23:58 +03:00
|
|
|
}
|
2019-01-29 02:23:53 +03:00
|
|
|
}
|
2019-01-06 00:42:57 +03:00
|
|
|
}
|
2020-03-21 17:03:07 +03:00
|
|
|
Column {
|
|
|
|
id: columnTwo
|
|
|
|
width: isPortrait ? parent.width : parent.width / 2
|
|
|
|
spacing: Theme.paddingMedium
|
|
|
|
Label {
|
|
|
|
x: Theme.paddingLarge
|
2020-06-12 01:04:11 +03:00
|
|
|
text: qsTr("Background service")
|
2020-03-21 17:03:07 +03:00
|
|
|
color: Theme.highlightColor
|
|
|
|
}
|
|
|
|
Label {
|
|
|
|
x: Theme.paddingLarge*2
|
|
|
|
width: parent.width - x*2;
|
|
|
|
wrapMode: Text.Wrap
|
2020-06-12 01:04:11 +03:00
|
|
|
text: qsTr("If notifications misbehave or there are problems with charger control, restarting the background service should help.")
|
2020-03-21 17:03:07 +03:00
|
|
|
color: Theme.primaryColor
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
2020-03-21 04:22:47 +03:00
|
|
|
}
|
2020-03-21 17:03:07 +03:00
|
|
|
Row {
|
|
|
|
anchors {
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
}
|
2020-06-12 01:04:11 +03:00
|
|
|
height: daemonStartButton.height
|
2020-03-21 04:22:47 +03:00
|
|
|
|
2020-03-21 17:03:07 +03:00
|
|
|
Column {
|
|
|
|
width: parent.width / 2
|
|
|
|
Button {
|
2020-06-12 01:04:11 +03:00
|
|
|
id: daemonStartButton
|
2020-03-21 17:03:07 +03:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2020-06-12 01:04:11 +03:00
|
|
|
text: qsTr("Start")
|
2022-03-20 20:26:57 +03:00
|
|
|
onClicked: batteryService.startService()
|
|
|
|
enabled: batteryService.serviceState !== "active"
|
2020-03-21 05:03:40 +03:00
|
|
|
}
|
2020-03-21 04:22:47 +03:00
|
|
|
}
|
2020-03-21 17:03:07 +03:00
|
|
|
Column {
|
|
|
|
width: parent.width / 2
|
|
|
|
Button {
|
2020-06-12 01:04:11 +03:00
|
|
|
id: daemonStopButton
|
2020-03-21 17:03:07 +03:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2020-06-12 01:04:11 +03:00
|
|
|
text: qsTr("Stop")
|
2022-03-20 20:26:57 +03:00
|
|
|
onClicked: batteryService.stopService()
|
|
|
|
enabled: batteryService.serviceState === "active"
|
2020-03-21 05:03:40 +03:00
|
|
|
}
|
2020-03-21 04:22:47 +03:00
|
|
|
}
|
|
|
|
}
|
2020-03-21 17:03:07 +03:00
|
|
|
Label {
|
|
|
|
x: Theme.paddingLarge*2
|
|
|
|
width: parent.width - x*2;
|
|
|
|
wrapMode: Text.Wrap
|
2020-04-26 21:58:42 +03:00
|
|
|
text: qsTr("You can close Battery Buddy when you are done, notifications and charger control will continue working in the background.")
|
2020-03-21 17:03:07 +03:00
|
|
|
color: Theme.primaryColor
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
|
|
}
|
2019-01-06 00:42:57 +03:00
|
|
|
}
|
2019-01-05 16:49:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|