prepare settings for health alert

This commit is contained in:
Peter G. (nephros) 2021-05-02 12:33:32 +02:00
parent ce994a0d1e
commit 93fa677a6f
3 changed files with 102 additions and 14 deletions

View file

@ -43,9 +43,11 @@ Page {
highLimitSlider.value = settings.highLimit
lowLimitSlider.value = settings.lowLimit
highAlertSlider.value = settings.highAlert
healthAlertSlider.value = settings.healthAlert
lowAlertSlider.value = settings.lowAlert
highIntervalSlider.value = settings.highNotificationsInterval
lowIntervalSlider.value = settings.lowNotificationsInterval
healthIntervalSlider.value = settings.healthNotificationsInterval
if(logger.debug) logger.log("SettingsPage values updated")
daemonCheck.start()
}
@ -365,6 +367,59 @@ Page {
smallChange: 10
largeChange: 60
}
SectionHeader { text: qsTr("Battery health notification") }
MySlider {
id: healthAlertSlider
minimumValue: 0
maximumValue: 2
stepSize: 1
onValueChanged: {
if(healthAlertSlider.value <= value)
healthAlertSlider.value = value + 1
}
valueText: {
if (value === 0)
return "None"
if (value === 1)
return "Warning"
if (value === 2)
return "Critical"
}
onReleased: save()
function save(){
settings.healthAlert = value
}
}
SectionHeader { text: qsTr("Battery health warning interval") }
MySlider {
id: healthIntervalSlider
minimumValue: 50
maximumValue: 610
stepSize: 10
valueText: updateValueText()
onValueChanged: updateValueText()
function updateValueText() {
if(value == 50)
return qsTr("Once")
if(value == 610)
return qsTr("Never")
return Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
}
onReleased: save()
function save() {
settings.healthNotificationsInterval = value
}
}
AdjustmentButtons {
targetSlider: healthIntervalSlider
smallChange: 10
largeChange: 60
}
}
}
}

View file

@ -58,17 +58,21 @@ Settings::~Settings()
// Getters condensed.
int Settings::getLowAlert() { return lowAlert; }
int Settings::getHighAlert() { return highAlert; }
int Settings::getHealthAlert() { return healthAlert; }
int Settings::getHighNotificationsInterval() { return highNotificationsInterval; }
int Settings::getLowNotificationsInterval() { return lowNotificationsInterval; }
int Settings::getHealthNotificationsInterval() { return healthNotificationsInterval; }
int Settings::getLowLimit() { return lowLimit; }
int Settings::getHighLimit() { return highLimit; }
bool Settings::getLimitEnabled() { return limitEnabled == 1; }
QString Settings::getLowAlertFile() { return lowAlertFile; }
QString Settings::getHighAlertFile() { return highAlertFile; }
QString Settings::getHealthAlertFile() { return healthAlertFile; }
QString Settings::getLogFilename() { return logFilename; }
QString Settings::getNotificationTitle() { return notificationTitle; }
QString Settings::getNotificationLowText() { return notificationLowText; }
QString Settings::getNotificationHighText() { return notificationHighText; }
QString Settings::getNotificationHealthText() { return notificationHealthText; }
int Settings::getLogLevel() { return logLevel; }
void Settings::setLowAlert(const int newLimit) {
@ -83,6 +87,12 @@ void Settings::setHighAlert(const int newLimit) {
}
}
void Settings::setHealthAlert(const int newLimit) {
if(saveInteger(sHealthAlert, newLimit, healthAlert)) {
emit healthAlertChanged(healthAlert);
}
}
void Settings::setHighNotificationsInterval(const int newInterval) {
if(saveInteger(sHighNotificationsInterval, newInterval, highNotificationsInterval)) {
emit highNotificationsIntervalChanged(highNotificationsInterval);

View file

@ -27,16 +27,20 @@ class Settings : public QObject
Q_OBJECT
Q_PROPERTY(int highAlert READ getHighAlert WRITE setHighAlert NOTIFY highAlertChanged)
Q_PROPERTY(int lowAlert READ getLowAlert WRITE setLowAlert NOTIFY lowAlertChanged)
Q_PROPERTY(int healthAlert READ getHealthAlert WRITE setHealthAlert NOTIFY healthAlertChanged)
Q_PROPERTY(int highNotificationsInterval READ getHighNotificationsInterval WRITE setHighNotificationsInterval NOTIFY highNotificationsIntervalChanged)
Q_PROPERTY(int lowNotificationsInterval READ getLowNotificationsInterval WRITE setLowNotificationsInterval NOTIFY lowNotificationsIntervalChanged)
Q_PROPERTY(int healthNotificationsInterval READ getHealthNotificationsInterval WRITE setHealthNotificationsInterval NOTIFY healthNotificationsIntervalChanged)
Q_PROPERTY(int highLimit READ getHighLimit WRITE setHighLimit NOTIFY highLimitChanged)
Q_PROPERTY(int lowLimit READ getLowLimit WRITE setLowLimit NOTIFY lowLimitChanged)
Q_PROPERTY(bool limitEnabled READ getLimitEnabled WRITE setLimitEnabled NOTIFY limitEnabledChanged)
Q_PROPERTY(QString highAlertFile READ getHighAlertFile NOTIFY highAlertFileChanged)
Q_PROPERTY(QString lowAlertFile READ getLowAlertFile NOTIFY lowAlertFileChanged)
Q_PROPERTY(QString healthAlertFile READ getHealthAlertFile NOTIFY healthAlertFileChanged)
Q_PROPERTY(QString notificationTitle READ getNotificationTitle WRITE setNotificationTitle NOTIFY notificationTitleChanged)
Q_PROPERTY(QString notificationLowText READ getNotificationLowText WRITE setNotificationLowText NOTIFY notificationLowTextChanged)
Q_PROPERTY(QString notificationHighText READ getNotificationHighText WRITE setNotificationHighText NOTIFY notificationHighTextChanged)
Q_PROPERTY(QString notificationHealthText READ getNotificationHealthText WRITE setNotificationHealthText NOTIFY notificationHealthTextChanged)
Q_PROPERTY(QString logFilename READ getLogFilename NOTIFY logFilenameChanged)
Q_PROPERTY(int logLevel READ getLogLevel WRITE setLogLevel NOTIFY logLevelChanged)
@ -46,29 +50,36 @@ public:
int getLowAlert();
int getHighAlert();
int getHealthAlert();
int getHighNotificationsInterval();
int getLowNotificationsInterval();
int getHealthNotificationsInterval();
int getLowLimit();
int getHighLimit();
bool getLimitEnabled();
QString getLowAlertFile();
QString getHighAlertFile();
QString getHealthAlertFile();
QString getNotificationTitle();
QString getNotificationLowText();
QString getNotificationHighText();
QString getNotificationHealthText();
QString getLogFilename();
int getLogLevel();
void setLowAlert(const int newLimit);
void setHighAlert(const int newLimit);
void setHealthAlert(const int newLimit);
void setHighNotificationsInterval(const int newInterval);
void setLowNotificationsInterval(const int newInterval);
void setHealthNotificationsInterval(const int newInterval);
void setLowLimit(const int newLimit);
void setHighLimit(const int newLimit);
void setLimitEnabled(const bool newEnabled);
void setNotificationTitle(const QString newText);
void setNotificationLowText(const QString newText);
void setNotificationHighText(const QString newText);
void setNotificationHealthText(const QString newText);
void setLogLevel(const int newLogLevel);
private:
@ -79,32 +90,40 @@ private:
// Default values
int lowAlert = 25;
int highAlert = 75;
int healthAlert = 1; // warn
int highNotificationsInterval = 60;
int lowNotificationsInterval = 60;
int healthNotificationsInterval = 60;
int limitEnabled = 1; // Converted to boolean for QML
int lowLimit = 65;
int highLimit = 70;
QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav";
QString highAlertFile = "/usr/share/sounds/jolla-ambient/stereo/positive_confirmation.wav";
QString healthAlertFile = lowAlertFile;
QString notificationTitle;
QString notificationLowText;
QString notificationHighText;
QString notificationHealthText;
QString logFilename;
int logLevel;
// To avoid repeating the same string over and over and over...
const char* sLowAlert = "lowAlert";
const char* sHighAlert = "highAlert";
const char* sHealthAlert = "healthAlert";
const char* sHighNotificationsInterval = "highNotificationsInterval";
const char* sLowNotificationsInterval = "lowNotificationsInterval";
const char* sHealthNotificationsInterval = "healthNotificationsInterval";
const char* sLimitEnabled = "limitEnabled";
const char* sLowLimit = "lowLimit";
const char* sHighLimit = "highLimit";
const char* sLowAlertFile = "lowAlertFile";
const char* sHighAlertFile = "highAlertFile";
const char* sHealthAlertFile = "healthAlertFile";
const char* sNotificationTitle = "notificationTitle";
const char* sNotificationLowText = "notificationLowText";
const char* sNotificationHighText = "notificationHighText";
const char* sNotificationHealthText = "notificationHealthText";
const char* sLogFilename = "logFilename";
const char* sLogLevel = "logLevel";
@ -117,16 +136,20 @@ private:
signals:
void lowAlertChanged(int);
void highAlertChanged(int);
void healthAlertChanged(int);
void highNotificationsIntervalChanged(int);
void lowNotificationsIntervalChanged(int);
void healthNotificationsIntervalChanged(int);
void limitEnabledChanged(bool);
void lowLimitChanged(int);
void highLimitChanged(int);
void lowAlertFileChanged(QString);
void highAlertFileChanged(QString);
void healthAlertFileChanged(QString);
void notificationTitleChanged(QString);
void notificationLowTextChanged(QString);
void notificationHighTextChanged(QString);
void notificationHealthTextChanged(QString);
void logFilenameChanged(QString);
void logLevelChanged(int);
};