2019-01-06 00:40:22 +03:00
|
|
|
/**
|
|
|
|
* Battery Buddy, a Sailfish application to prolong battery lifetime
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Matti Viljanen
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* General Public License along with CarBudget. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Matti Viljanen
|
|
|
|
*/
|
2019-01-05 16:49:35 +03:00
|
|
|
import QtQuick 2.0
|
2019-01-05 23:02:01 +03:00
|
|
|
import QtMultimedia 5.6
|
2019-01-05 16:49:35 +03:00
|
|
|
import Sailfish.Silica 1.0
|
2019-01-06 01:28:43 +03:00
|
|
|
import Nemo.Notifications 1.0
|
2019-01-29 02:23:53 +03:00
|
|
|
import "../components"
|
2019-01-05 16:49:35 +03:00
|
|
|
|
|
|
|
Page {
|
|
|
|
id: page
|
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"),
|
|
|
|
"unknown": qsTr("unknown", "Battery not detected, or faulty, or something")
|
|
|
|
}
|
2019-01-05 16:49:35 +03:00
|
|
|
|
2019-01-29 02:25:16 +03:00
|
|
|
onStatusChanged: {
|
|
|
|
if(status == PageStatus.Activating) {
|
|
|
|
alertTimer.interval = settings.interval * 1000;
|
|
|
|
}
|
|
|
|
}
|
2019-01-05 16:49:35 +03:00
|
|
|
|
2019-02-10 21:30:11 +03:00
|
|
|
SoundEffect {
|
2019-01-05 23:02:01 +03:00
|
|
|
id: alertLow
|
2019-01-29 02:28:44 +03:00
|
|
|
volume: 0.6
|
2019-01-05 23:02:01 +03:00
|
|
|
source: settings.lowAlertFile
|
2019-02-10 21:30:11 +03:00
|
|
|
|
2019-01-05 23:02:01 +03:00
|
|
|
}
|
|
|
|
|
2019-02-10 21:30:11 +03:00
|
|
|
SoundEffect {
|
2019-01-05 23:02:01 +03:00
|
|
|
id: alertHigh
|
2019-01-29 02:28:44 +03:00
|
|
|
volume: 0.6
|
2019-01-05 23:02:01 +03:00
|
|
|
source: settings.highAlertFile
|
|
|
|
}
|
|
|
|
|
2019-01-06 01:28:43 +03:00
|
|
|
Notification {
|
|
|
|
id: notification
|
2019-01-06 12:34:04 +03:00
|
|
|
property bool test: false
|
2019-01-06 01:28:43 +03:00
|
|
|
appName: qsTr("Battery Buddy")
|
|
|
|
appIcon: "/usr/share/icons/hicolor/128x128/apps/harbour-batterybuddy.png"
|
|
|
|
summary: qsTr("Battery charge", "Battery charge 20%") +" "+ battery.charge + "%"
|
2019-01-06 12:34:04 +03:00
|
|
|
body: test ? qsTr("This is a test.") : battery.charging ? qsTr("Please disconnect the charger.") : qsTr("Please connect the charger.")
|
2019-01-06 01:28:43 +03:00
|
|
|
previewSummary: summary
|
|
|
|
previewBody: body
|
2019-01-29 02:28:44 +03:00
|
|
|
urgency: Notification.Critical
|
2019-02-11 15:03:00 +03:00
|
|
|
function republish() {
|
|
|
|
if(replacesId > 0)
|
|
|
|
close()
|
|
|
|
publish()
|
|
|
|
}
|
|
|
|
function republishTest() {
|
|
|
|
test = true
|
|
|
|
republish()
|
|
|
|
test = false
|
|
|
|
}
|
2019-01-06 01:28:43 +03:00
|
|
|
}
|
|
|
|
|
2019-01-05 23:02:01 +03:00
|
|
|
Timer {
|
2019-01-29 02:25:16 +03:00
|
|
|
id: alertTimer
|
|
|
|
interval: settings.interval * 1000 // sec -> msec
|
2019-01-05 23:02:01 +03:00
|
|
|
running: true
|
|
|
|
repeat: true
|
|
|
|
onTriggered: {
|
2019-01-08 21:21:21 +03:00
|
|
|
if(battery.charge <= settings.lowerLimit && battery.state === "discharging") {
|
2019-01-05 23:02:01 +03:00
|
|
|
alertLow.play()
|
2019-02-11 15:03:00 +03:00
|
|
|
notification.republish()
|
2019-01-06 01:28:43 +03:00
|
|
|
}
|
2019-01-08 21:21:21 +03:00
|
|
|
else if(battery.charge >= settings.upperLimit &&
|
|
|
|
(battery.state === "charging" && battery.charging === true) || (battery.state === "idle" && battery.charging === false)) {
|
2019-01-06 12:31:48 +03:00
|
|
|
alertHigh.play()
|
2019-02-11 15:03:00 +03:00
|
|
|
notification.republish()
|
2019-01-06 01:28:43 +03:00
|
|
|
}
|
2019-02-11 15:03:00 +03:00
|
|
|
else if(notification.replacesId > 0) {
|
2019-01-06 01:28:43 +03:00
|
|
|
notification.close()
|
2019-02-11 15:03:00 +03:00
|
|
|
}
|
2019-01-05 23:02:01 +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
|
|
|
|
contentHeight: column.height
|
|
|
|
|
2019-01-08 21:06:08 +03:00
|
|
|
VerticalScrollDecorator { flickable: mainFlickable }
|
|
|
|
|
2019-01-05 21:16:04 +03:00
|
|
|
PullDownMenu {
|
|
|
|
MenuItem {
|
2019-01-06 12:34:26 +03:00
|
|
|
text: qsTr("About", "About this application")
|
2019-01-05 21:16:04 +03:00
|
|
|
onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
|
|
|
|
}
|
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-29 02:25:16 +03:00
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Settings")
|
|
|
|
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.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.
|
|
|
|
Column {
|
|
|
|
id: column
|
|
|
|
|
|
|
|
width: page.width
|
|
|
|
spacing: Theme.paddingLarge
|
|
|
|
PageHeader {
|
2019-01-05 18:15:32 +03:00
|
|
|
title: qsTr("Battery Buddy")
|
|
|
|
}
|
2019-01-06 00:42:57 +03:00
|
|
|
Label {
|
|
|
|
x: Theme.paddingLarge
|
|
|
|
text: qsTr("Battery status")
|
|
|
|
color: Theme.highlightColor
|
2019-01-05 16:49:35 +03:00
|
|
|
}
|
2019-01-29 02:27:30 +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-06 00:42:57 +03:00
|
|
|
}
|
2019-01-29 02:23:53 +03:00
|
|
|
// Detail column
|
|
|
|
Column {
|
|
|
|
width: parent.width
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
MyDetailItem {
|
|
|
|
label: qsTr("Charge:")
|
|
|
|
value: battery.charge + "%"
|
|
|
|
}
|
|
|
|
MyDetailItem {
|
|
|
|
label: qsTr("Charging:")
|
|
|
|
value: battery.charging ? qsTr("yes") : qsTr("no")
|
|
|
|
}
|
|
|
|
MyDetailItem {
|
|
|
|
label: qsTr("State:")
|
|
|
|
value: statusText[battery.state]
|
|
|
|
}
|
2019-01-06 00:42:57 +03:00
|
|
|
}
|
|
|
|
Label {
|
|
|
|
x: Theme.paddingLarge*2
|
|
|
|
width: parent.width - x*2;
|
|
|
|
wrapMode: Text.Wrap
|
2019-01-29 02:25:16 +03:00
|
|
|
text: qsTr("Please leave Battery Buddy running in the background in order to receive alerts.")
|
2019-01-06 00:42:57 +03:00
|
|
|
color: Theme.primaryColor
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
2019-01-05 16:49:35 +03:00
|
|
|
}
|
2019-01-06 00:42:57 +03:00
|
|
|
Label {
|
|
|
|
x: Theme.paddingLarge
|
|
|
|
text: qsTr("Alert tests")
|
|
|
|
color: Theme.highlightColor
|
|
|
|
}
|
|
|
|
Label {
|
|
|
|
x: Theme.paddingLarge*2
|
|
|
|
width: parent.width - x*2;
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
text: qsTr("Click the buttons to test the sound and notification.")
|
|
|
|
color: Theme.primaryColor
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
|
|
}
|
|
|
|
Item {
|
|
|
|
width: parent.width
|
|
|
|
height: lowButton.height
|
|
|
|
anchors.left: parent.left
|
|
|
|
Item {
|
|
|
|
width: parent.width / 2
|
|
|
|
height: lowButton.height
|
|
|
|
Button {
|
|
|
|
id: lowButton
|
2019-02-11 15:03:00 +03:00
|
|
|
anchors.centerIn: parent
|
2019-01-06 12:34:04 +03:00
|
|
|
text: qsTr("Discharged")
|
2019-01-06 01:28:43 +03:00
|
|
|
onClicked: {
|
|
|
|
alertLow.play()
|
2019-02-11 15:03:00 +03:00
|
|
|
notification.republishTest()
|
2019-01-06 01:28:43 +03:00
|
|
|
}
|
2019-01-06 00:42:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Item {
|
|
|
|
anchors.right: parent.right
|
|
|
|
width: parent.width / 2
|
|
|
|
height: lowButton.height
|
|
|
|
Button {
|
2019-01-06 12:34:04 +03:00
|
|
|
text: qsTr("Charged")
|
2019-02-11 15:03:00 +03:00
|
|
|
anchors.centerIn: parent
|
2019-01-06 01:28:43 +03:00
|
|
|
onClicked: {
|
|
|
|
alertHigh.play()
|
2019-02-11 15:03:00 +03:00
|
|
|
notification.republishTest()
|
2019-01-06 01:28:43 +03:00
|
|
|
}
|
2019-01-06 00:42:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Item {
|
|
|
|
width: parent.width
|
|
|
|
height: Theme.paddingLarge
|
|
|
|
}
|
2019-01-05 16:49:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|