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
|
|
|
|
* 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
|
2020-03-20 17:16:30 +03:00
|
|
|
import QtMultimedia 5.6
|
2019-01-05 16:49:35 +03:00
|
|
|
import Sailfish.Silica 1.0
|
2020-03-20 17:16:30 +03:00
|
|
|
import Nemo.Notifications 1.0
|
2019-01-05 16:49:35 +03:00
|
|
|
import "pages"
|
|
|
|
|
|
|
|
ApplicationWindow
|
|
|
|
{
|
2020-03-20 17:16:30 +03:00
|
|
|
SoundEffect {
|
|
|
|
id: alertLow
|
|
|
|
volume: 0.6
|
|
|
|
source: settings.lowAlertFile
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundEffect {
|
|
|
|
id: alertHigh
|
|
|
|
volume: 0.6
|
|
|
|
source: settings.highAlertFile
|
|
|
|
}
|
|
|
|
|
|
|
|
Notification {
|
|
|
|
id: notification
|
|
|
|
property bool test: false
|
|
|
|
appName: qsTr("Battery Buddy")
|
|
|
|
appIcon: "/usr/share/icons/hicolor/128x128/apps/harbour-batterybuddy.png"
|
|
|
|
summary: qsTr("Battery charge", "Battery charge 20%") +" "+ battery.charge + "%"
|
|
|
|
body: test ? qsTr("This is a test.") : battery.charging ? qsTr("Please disconnect the charger.") : qsTr("Please connect the charger.")
|
|
|
|
previewSummary: summary
|
|
|
|
previewBody: body
|
|
|
|
urgency: Notification.Critical
|
|
|
|
function republish() {
|
|
|
|
if(replacesId > 0)
|
|
|
|
close()
|
|
|
|
publish()
|
|
|
|
}
|
|
|
|
function republishTest() {
|
|
|
|
test = true
|
|
|
|
republish()
|
|
|
|
test = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: alertTimer
|
2020-03-21 04:22:47 +03:00
|
|
|
interval: settings.interval * 1000
|
|
|
|
running: settings.notificationsEnabled
|
2020-03-20 17:16:30 +03:00
|
|
|
repeat: true
|
|
|
|
onTriggered: {
|
|
|
|
if(battery.charge <= settings.lowerLimit && battery.state === "discharging") {
|
|
|
|
alertLow.play()
|
|
|
|
notification.republish()
|
|
|
|
}
|
|
|
|
else if(battery.charge >= settings.upperLimit &&
|
|
|
|
(battery.state === "charging" && battery.charging === true) || (battery.state === "idle" && battery.charging === false)) {
|
|
|
|
alertHigh.play()
|
|
|
|
notification.republish()
|
|
|
|
}
|
|
|
|
else if(notification.replacesId > 0) {
|
|
|
|
notification.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 18:15:32 +03:00
|
|
|
initialPage: Component { MainPage { } }
|
2019-01-05 16:49:35 +03:00
|
|
|
cover: Qt.resolvedUrl("cover/CoverPage.qml")
|
|
|
|
allowedOrientations: defaultAllowedOrientations
|
|
|
|
}
|