Move sliders to Settings page, add alert interval setting

This commit is contained in:
Matti Viljanen 2019-01-29 01:11:32 +02:00
parent 1548b17916
commit c7ba509bc7
No known key found for this signature in database
GPG key ID: CF32A1495158F888
3 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,80 @@
/**
* 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
*/
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: settingsPage
anchors.fill: parent
PageHeader {
id: header
title: qsTr("Settings")
}
Column {
anchors.top: header.bottom
width: parent.width
spacing: Theme.paddingMedium
Label {
x: Theme.paddingLarge
text: qsTr("Alert settings")
color: Theme.highlightColor
}
Label {
x: Theme.paddingLarge*2
width: parent.width - x*2;
wrapMode: Text.Wrap
text: qsTr("Set the maximum and minimum target charge levels.")
color: Theme.primaryColor
font.pixelSize: Theme.fontSizeSmall
}
Slider {
width: parent.width
label: qsTr("Charging limit")
minimumValue: 60
maximumValue: 99
stepSize: 1
value: settings.upperLimit
valueText: value + "%"
onValueChanged: settings.upperLimit = value
}
Slider {
width: parent.width
label: qsTr("Discharging limit")
minimumValue: 10
maximumValue: 40
stepSize: 1
value: settings.lowerLimit
valueText: value + "%"
onValueChanged: settings.lowerLimit = value
}
Slider {
width: parent.width
label: qsTr("Alert interval")
minimumValue: 60
maximumValue: 600
stepSize: 10
value: settings.interval
valueText: Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
onValueChanged: settings.interval = value
}
}
}

View file

@ -34,18 +34,28 @@ Settings::Settings(QObject *parent) : QObject(parent)
emit upperLimitChanged();
}
}
if(mySettings.contains("interval")) {
tempValue = mySettings.value("interval").toInt();
if(tempValue >= 60 && tempValue <= 600) {
interval = tempValue;
emit intervalChanged();
}
}
}
Settings::~Settings()
{
mySettings.setValue("lowerLimit", QByteArray::number(lowerLimit));
mySettings.setValue("upperLimit", QByteArray::number(upperLimit));
mySettings.setValue("interval", QByteArray::number(interval));
}
int Settings::getLowerLimit() { return lowerLimit; }
int Settings::getUpperLimit() { return upperLimit; }
int Settings::getInterval() { return interval; }
QString Settings::getLowAlert() { return lowAlertFile; }
QString Settings::getHighAlert() { return highAlertFile; }
@ -53,3 +63,5 @@ QString Settings::getHighAlert() { return highAlertFile; }
void Settings::setLowerLimit(int newLimit) { lowerLimit = newLimit; }
void Settings::setUpperLimit(int newLimit) { upperLimit = newLimit; }
void Settings::setInterval(int newInterval) { interval = newInterval; }

View file

@ -26,6 +26,7 @@ class Settings : public QObject
Q_OBJECT
Q_PROPERTY(int lowerLimit READ getLowerLimit WRITE setLowerLimit NOTIFY lowerLimitChanged)
Q_PROPERTY(int upperLimit READ getUpperLimit WRITE setUpperLimit NOTIFY upperLimitChanged)
Q_PROPERTY(int interval READ getInterval WRITE setInterval NOTIFY intervalChanged)
Q_PROPERTY(QString lowAlertFile READ getLowAlert NOTIFY lowAlertChanged)
Q_PROPERTY(QString highAlertFile READ getHighAlert NOTIFY highAlertChanged)
@ -36,10 +37,12 @@ public:
// QML-exposed stuff
int getLowerLimit();
int getUpperLimit();
int getInterval();
QString getLowAlert();
QString getHighAlert();
void setLowerLimit(int newLimit);
void setUpperLimit(int newLimit);
void setInterval(int newInterval);
private:
QSettings mySettings;
@ -47,12 +50,14 @@ private:
// Default values
int lowerLimit = 25;
int upperLimit = 75;
int interval = 60;
QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav";
QString highAlertFile = "/usr/share/sounds/jolla-ambient/stereo/positive_confirmation.wav";
signals:
int lowerLimitChanged();
int upperLimitChanged();
int intervalChanged();
QString lowAlertChanged();
QString highAlertChanged();
};