2019-01-29 02:11:32 +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-29 02:11:32 +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-29 02:11:32 +03:00
*
* Author: Matti Viljanen
* /
2021-04-09 23:27:20 +03:00
import QtQuick 2.2
2019-01-29 02:11:32 +03:00
import Sailfish . Silica 1.0
2020-03-20 23:57:59 +03:00
import "../components"
2019-01-29 02:11:32 +03:00
Page {
id: settingsPage
2020-03-21 17:03:07 +03:00
allowedOrientations: Orientation . Portrait | Orientation . Landscape | Orientation . LandscapeInverted
2019-01-29 02:11:32 +03:00
2022-03-20 20:26:57 +03:00
SystemdUserService {
id: batteryService
serviceName: 'harbour-batterybuddy.service'
onServiceMaskedChanged: {
daemonEnabledSwitch . busy = false
}
2020-06-14 13:09:14 +03:00
}
2021-04-09 23:25:43 +03:00
//////////////////////////////////////////////////
//
// TIMERS AND PROCESSES
//
//////////////////////////////////////////////////
2020-06-14 13:09:14 +03:00
Timer {
id: startupTimer
interval: 100
repeat: false
running: true
onTriggered: {
autoStopCharging . checked = settings . limitEnabled
highLimitSlider . value = settings . highLimit
lowLimitSlider . value = settings . lowLimit
highAlertSlider . value = settings . highAlert
2021-05-02 12:33:45 +03:00
healthSelector . currentIndex = settings . healthAlert
2020-06-14 13:09:14 +03:00
lowAlertSlider . value = settings . lowAlert
2021-07-25 20:54:27 +03:00
highIntervalCombo . currentIndex = settings . highNotificationsInterval
lowIntervalCombo . currentIndex = settings . lowNotificationsInterval
healthIntervalCombo . currentIndex = settings . healthNotificationsInterval
2021-04-17 22:01:19 +03:00
if ( logger . debug ) logger . log ( "SettingsPage values updated" )
2022-03-20 20:26:57 +03:00
batteryService . queryEnabled ( )
2020-06-14 13:09:14 +03:00
}
2020-03-21 14:12:45 +03:00
}
2021-04-09 23:25:43 +03:00
//////////////////////////////////////////////////
//
// MAIN CONTENT
//
//////////////////////////////////////////////////
2020-03-20 18:26:29 +03:00
SilicaFlickable {
anchors.fill: parent
2020-03-21 17:03:07 +03:00
contentHeight: flow . height + Theme . horizontalPageMargin
2019-01-29 02:11:32 +03:00
2020-03-21 04:25:26 +03:00
PullDownMenu {
2021-04-17 23:38:34 +03:00
MenuItem {
text: qsTr ( "View log" )
onClicked: pageStack . push ( Qt . resolvedUrl ( "LogPage.qml" ) )
}
2020-03-21 04:25:26 +03:00
MenuItem {
text: qsTr ( "About" , "About this application" )
onClicked: pageStack . push ( Qt . resolvedUrl ( "AboutPage.qml" ) )
}
}
2020-03-21 17:03:07 +03:00
Flow {
id: flow
2020-03-20 18:26:29 +03:00
anchors {
2020-03-21 17:03:07 +03:00
top: parent . top
2020-03-20 18:26:29 +03:00
left: parent . left
right: parent . right
}
2020-03-21 17:03:07 +03:00
height: header . height + Math . max ( columnOne . heigh , columnTwo . height )
2020-03-20 18:26:29 +03:00
2020-03-21 17:03:07 +03:00
PageHeader {
id: header
title: qsTr ( "Settings" )
2020-03-20 18:26:29 +03:00
}
2021-04-09 23:25:43 +03:00
//////////////////////////////////////////////////
//
// THE LEFT/TOP COLUMN
//
//////////////////////////////////////////////////
2020-03-21 17:03:07 +03:00
Column {
id: columnOne
width: isPortrait ? parent.width : parent . width / 2
spacing: Theme . paddingMedium
2020-06-14 19:22:41 +03:00
Label {
x: Theme . paddingLarge
text: qsTr ( "Background service" )
color: Theme . highlightColor
}
TextSwitch {
id: daemonEnabledSwitch
text: qsTr ( "Start background service at startup" )
2022-03-20 20:26:57 +03:00
checked: batteryService . serviceMasked === "loaded"
2020-06-14 19:22:41 +03:00
onClicked: {
2022-03-20 20:26:57 +03:00
if ( checked )
batteryService . enableService ( )
else
batteryService . disableService ( )
2020-06-14 19:22:41 +03:00
busy = true
}
}
2020-03-21 17:03:07 +03:00
Label {
x: Theme . paddingLarge
text: qsTr ( "Charging settings" )
color: Theme . highlightColor
2020-03-20 21:57:06 +03:00
}
2020-06-14 19:22:41 +03:00
Label {
text: qsTr ( "This option disables charging automatically when the battery has charged above the pausing percentage and enables it again when the battery has depleted below the resuming percentage." )
anchors {
left: parent . left
right: parent . right
leftMargin: Theme . horizontalPageMargin * 2
rightMargin: Theme . horizontalPageMargin
}
color: Theme . primaryColor
font.pixelSize: Theme . fontSizeExtraSmall
wrapMode: Text . Wrap
}
2020-03-21 17:03:07 +03:00
TextSwitch {
id: autoStopCharging
text: qsTr ( "Automatic charging control" )
onCheckedChanged: settings . limitEnabled = checked
2020-03-20 21:57:06 +03:00
}
2020-03-21 17:03:07 +03:00
2021-04-10 01:31:03 +03:00
SectionHeader { text: qsTr ( "Pause charging limit" ) }
MySlider {
2020-03-21 17:03:07 +03:00
id: highLimitSlider
2021-04-10 01:42:08 +03:00
minimumValue: 6
maximumValue: 100
2020-03-21 17:03:07 +03:00
stepSize: 1
valueText: value + "%"
onValueChanged: {
if ( lowLimitSlider . value >= value )
lowLimitSlider . value = value - 1
}
2021-04-10 01:31:03 +03:00
onReleased: save ( )
function save ( ) {
2020-04-26 18:23:35 +03:00
settings . lowLimit = lowLimitSlider . value
settings . highLimit = value
}
2020-03-20 18:26:29 +03:00
}
2021-04-10 01:31:03 +03:00
AdjustmentButtons {
targetSlider: highLimitSlider
smallChange: 1
largeChange: 5
}
SectionHeader { text: qsTr ( "Resume charging limit" ) }
MySlider {
2020-03-21 17:03:07 +03:00
id: lowLimitSlider
2021-04-10 01:42:08 +03:00
minimumValue: 5
maximumValue: 99
2020-03-21 17:03:07 +03:00
stepSize: 1
valueText: value + "%"
onValueChanged: {
if ( highLimitSlider . value <= value )
highLimitSlider . value = value + 1
}
2021-04-10 01:31:03 +03:00
onReleased: save ( )
function save ( ) {
2020-04-26 18:23:35 +03:00
settings . lowLimit = value
settings . highLimit = highLimitSlider . value
}
2020-03-20 18:26:29 +03:00
}
2021-04-10 01:31:03 +03:00
AdjustmentButtons {
targetSlider: lowLimitSlider
smallChange: 1
largeChange: 5
}
2020-03-20 18:26:29 +03:00
}
2021-04-09 23:25:43 +03:00
//////////////////////////////////////////////////
//
// THE RIGHT/BOTTOM COLUMN
//
//////////////////////////////////////////////////
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
text: qsTr ( "Notification settings" )
color: Theme . highlightColor
}
2020-06-14 19:22:41 +03:00
Label {
text: qsTr ( "Display visual and audible notifications about reached battery charge levels, when the battery charge is below or above desired percentage." )
anchors {
left: parent . left
right: parent . right
leftMargin: Theme . horizontalPageMargin * 2
rightMargin: Theme . horizontalPageMargin
}
color: Theme . primaryColor
font.pixelSize: Theme . fontSizeExtraSmall
wrapMode: Text . Wrap
}
2021-04-10 01:31:03 +03:00
SectionHeader { text: qsTr ( "Battery full notification" ) }
MySlider {
2020-03-21 17:03:07 +03:00
id: highAlertSlider
2021-04-10 01:42:08 +03:00
minimumValue: 6
2020-03-21 17:03:07 +03:00
maximumValue: 100
stepSize: 1
valueText: value + "%"
onValueChanged: {
if ( lowAlertSlider . value >= value )
lowAlertSlider . value = value - 1
}
2021-04-10 01:31:03 +03:00
onReleased: save ( )
function save ( ) {
2020-04-26 18:23:35 +03:00
settings . lowAlert = lowAlertSlider . value
settings . highAlert = value
}
2020-03-21 17:03:07 +03:00
}
2021-04-10 01:31:03 +03:00
AdjustmentButtons {
targetSlider: highAlertSlider
smallChange: 1
largeChange: 5
}
SectionHeader { text: qsTr ( "Battery low notification" ) }
MySlider {
2020-03-21 17:03:07 +03:00
id: lowAlertSlider
2021-04-10 01:42:08 +03:00
minimumValue: 5
2020-03-21 17:03:07 +03:00
maximumValue: 99
stepSize: 1
valueText: value + "%"
onValueChanged: {
if ( highAlertSlider . value <= value )
highAlertSlider . value = value + 1
}
2021-04-10 01:31:03 +03:00
onReleased: save ( )
function save ( ) {
2020-04-26 18:23:35 +03:00
settings . lowAlert = value
settings . highAlert = highAlertSlider . value
}
2020-03-21 17:03:07 +03:00
}
2021-04-10 01:31:03 +03:00
AdjustmentButtons {
targetSlider: lowAlertSlider
smallChange: 1
largeChange: 5
}
SectionHeader { text: qsTr ( "Battery high notification interval" ) }
2021-07-25 20:54:27 +03:00
ComboBox {
id: highIntervalCombo
label: qsTr ( "Battery high notification interval" )
menu: ContextMenu {
Repeater {
model: frequencyNames
MenuItem {
enabled: index > 0
visible: index > 0
text: modelData
onClicked: {
highIntervalCombo . currentIndex = index
highIntervalCombo . save ( )
}
}
}
2020-11-30 23:41:09 +03:00
}
2021-04-10 01:31:03 +03:00
function save ( ) {
2021-07-25 20:54:27 +03:00
settings . highNotificationsInterval = currentIndex
2021-04-10 01:31:03 +03:00
}
}
SectionHeader { text: qsTr ( "Battery low notification interval" ) }
2021-07-25 20:54:27 +03:00
ComboBox {
id: lowIntervalCombo
label: qsTr ( "Battery low notification interval" )
menu: ContextMenu {
Repeater {
model: frequencyNames
MenuItem {
enabled: index > 0
visible: index > 0
text: modelData
onClicked: {
lowIntervalCombo . currentIndex = index
lowIntervalCombo . save ( )
}
}
}
2020-11-30 23:41:09 +03:00
}
2021-04-10 01:31:03 +03:00
function save ( ) {
2021-07-25 20:54:27 +03:00
settings . lowNotificationsInterval = currentIndex
2021-04-10 01:31:03 +03:00
}
}
2021-05-02 12:33:45 +03:00
Label {
x: Theme . paddingLarge
2021-05-23 00:03:19 +03:00
text: qsTr ( "Health notification settings" )
2021-05-02 12:33:45 +03:00
color: Theme . highlightColor
}
Label {
2021-05-02 22:14:29 +03:00
text: qsTr ( "Display visual and audible notifications when the battery status exceeds safe values.<br />This usually means high (or low) temperature but can include other parameters depending on the hardware." )
2021-05-02 12:33:45 +03:00
anchors {
left: parent . left
right: parent . right
leftMargin: Theme . horizontalPageMargin * 2
rightMargin: Theme . horizontalPageMargin
}
color: Theme . primaryColor
font.pixelSize: Theme . fontSizeExtraSmall
wrapMode: Text . Wrap
}
2021-05-23 00:03:19 +03:00
SectionHeader { text: qsTr ( "Battery health notification" ) }
2021-05-02 13:33:32 +03:00
2021-05-02 12:33:45 +03:00
ComboBox {
id: healthSelector
width: parent . width
2022-03-19 22:14:37 +03:00
label: qsTr ( "Notification threshold" )
2021-05-02 12:33:45 +03:00
currentIndex: settings . healthAlert
menu: ContextMenu {
2021-05-02 18:18:25 +03:00
MenuItem { text: qsTr ( "Never" ) }
2021-05-02 12:33:45 +03:00
MenuItem { text: qsTr ( "Warning" ) }
MenuItem { text: qsTr ( "Critical" ) }
2021-05-02 13:33:32 +03:00
}
2021-05-02 12:33:45 +03:00
onValueChanged: save ( )
function save ( ) {
settings . healthAlert = healthSelector . currentIndex
2021-05-02 13:33:32 +03:00
}
}
2021-05-02 18:18:25 +03:00
SectionHeader { text: qsTr ( "Health notification interval" ) }
2021-05-02 13:33:32 +03:00
2021-07-25 20:54:27 +03:00
ComboBox {
id: healthIntervalCombo
label: qsTr ( "Health notification interval" )
menu: ContextMenu {
Repeater {
model: frequencyNames
MenuItem {
enabled: index > 0
visible: index > 0
text: modelData
onClicked: {
healthIntervalCombo . currentIndex = index
healthIntervalCombo . save ( )
}
}
}
2021-05-02 13:33:32 +03:00
}
function save ( ) {
2021-07-25 20:54:27 +03:00
settings . healthNotificationsInterval = currentIndex
2021-05-02 13:33:32 +03:00
}
}
2020-03-21 04:22:47 +03:00
}
2019-01-29 02:11:32 +03:00
}
}
}