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-06 00:38:41 +03:00
|
|
|
#ifndef SETTINGS_H
|
|
|
|
#define SETTINGS_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2019-01-06 17:39:33 +03:00
|
|
|
#include <QSettings>
|
2020-03-21 02:17:15 +03:00
|
|
|
#include <QDebug>
|
2019-01-06 00:38:41 +03:00
|
|
|
|
|
|
|
class Settings : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-03-20 21:57:06 +03:00
|
|
|
Q_PROPERTY(int lowAlert READ getLowAlert WRITE setLowAlert NOTIFY lowAlertChanged)
|
|
|
|
Q_PROPERTY(int highAlert READ getHighAlert WRITE setHighAlert NOTIFY highAlertChanged)
|
|
|
|
Q_PROPERTY(int interval READ getInterval WRITE setInterval NOTIFY intervalChanged)
|
|
|
|
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)
|
2020-03-21 04:22:47 +03:00
|
|
|
Q_PROPERTY(bool notificationsEnabled READ getNotificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged)
|
2020-03-20 21:57:06 +03:00
|
|
|
Q_PROPERTY(QString lowAlertFile READ getLowAlertFile NOTIFY lowAlertFileChanged)
|
|
|
|
Q_PROPERTY(QString highAlertFile READ getHighAlertFile NOTIFY highAlertFileChanged)
|
2019-01-06 00:38:41 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
Settings(QObject* parent = nullptr);
|
|
|
|
~Settings();
|
|
|
|
|
2020-03-21 06:02:04 +03:00
|
|
|
int getLowAlert();
|
|
|
|
int getHighAlert();
|
|
|
|
int getInterval();
|
|
|
|
int getLowLimit();
|
|
|
|
int getHighLimit();
|
|
|
|
bool getLimitEnabled();
|
|
|
|
bool getNotificationsEnabled();
|
|
|
|
QString getLowAlertFile();
|
|
|
|
QString getHighAlertFile();
|
2020-03-20 21:57:06 +03:00
|
|
|
|
2020-03-21 06:02:04 +03:00
|
|
|
void setLowAlert(int newLimit);
|
|
|
|
void setHighAlert(int newLimit);
|
|
|
|
void setInterval(int newInterval);
|
|
|
|
void setLowLimit(int newLimit);
|
|
|
|
void setHighLimit(int newLimit);
|
|
|
|
void setLimitEnabled(bool newEnabled);
|
|
|
|
void setNotificationsEnabled(bool newEnabled);
|
2020-03-20 21:57:06 +03:00
|
|
|
|
2019-01-06 00:38:41 +03:00
|
|
|
|
|
|
|
private:
|
2019-01-08 21:19:54 +03:00
|
|
|
QSettings mySettings;
|
|
|
|
|
2019-01-06 17:39:33 +03:00
|
|
|
// Default values
|
2020-03-20 21:57:06 +03:00
|
|
|
int lowAlert = 25;
|
|
|
|
int highAlert = 75;
|
2019-01-29 02:11:32 +03:00
|
|
|
int interval = 60;
|
2020-03-21 02:17:15 +03:00
|
|
|
int limitEnabled = 0; // Converted to boolean for QML
|
2020-03-21 04:22:47 +03:00
|
|
|
int notificationsEnabled = 1; // Converted to boolean for QML
|
2020-03-20 21:57:06 +03:00
|
|
|
int lowLimit = 65;
|
|
|
|
int highLimit = 70;
|
2019-01-06 17:39:33 +03:00
|
|
|
QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav";
|
|
|
|
QString highAlertFile = "/usr/share/sounds/jolla-ambient/stereo/positive_confirmation.wav";
|
2019-01-06 00:38:41 +03:00
|
|
|
|
2020-03-20 21:57:06 +03:00
|
|
|
// To avoid repeating the same string over and over and over...
|
|
|
|
const char* sLowAlert = "lowAlert";
|
|
|
|
const char* sHighAlert = "highAlert";
|
|
|
|
const char* sInterval = "interval";
|
|
|
|
const char* sLimitEnabled = "limitEnabled";
|
2020-03-21 04:22:47 +03:00
|
|
|
const char* sNotificationsEnabled = "notificationsEnabled";
|
2020-03-20 21:57:06 +03:00
|
|
|
const char* sLowLimit = "lowLimit";
|
|
|
|
const char* sHighLimit = "highLimit";
|
|
|
|
const char* sLowAlertFile = "lowAlertFile";
|
|
|
|
const char* sHighAlertFile = "highAlertFile";
|
|
|
|
|
2020-03-21 02:17:15 +03:00
|
|
|
int bound(int value, int min, int max);
|
2020-03-21 06:02:04 +03:00
|
|
|
void loadInteger(const char *key, int *value, int min, int max);
|
|
|
|
void saveInteger(const char *key, int *value);
|
2020-03-21 02:17:15 +03:00
|
|
|
|
2019-01-06 00:38:41 +03:00
|
|
|
signals:
|
2020-03-20 21:57:06 +03:00
|
|
|
int lowAlertChanged();
|
|
|
|
int highAlertChanged();
|
2019-01-29 02:11:32 +03:00
|
|
|
int intervalChanged();
|
2020-03-20 18:26:29 +03:00
|
|
|
bool limitEnabledChanged();
|
2020-03-21 04:22:47 +03:00
|
|
|
bool notificationsEnabledChanged();
|
2020-03-20 21:57:06 +03:00
|
|
|
int lowLimitChanged();
|
|
|
|
int highLimitChanged();
|
|
|
|
QString lowAlertFileChanged();
|
|
|
|
QString highAlertFileChanged();
|
2019-01-06 00:38:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SETTINGS_H
|