From 02b3f4052424f467b01eda327f4e05d79f9bba38 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sat, 21 Mar 2020 05:02:04 +0200 Subject: [PATCH] Increase debug log verbosity --- harbour-batterybuddy.pro | 2 + src/harbour-batterybuddy.cpp | 3 ++ src/settings.cpp | 101 ++++++++++++++++++++++++++++++++--- src/settings.h | 35 ++++++------ 4 files changed, 116 insertions(+), 25 deletions(-) diff --git a/harbour-batterybuddy.pro b/harbour-batterybuddy.pro index 7682bd5..703ee21 100644 --- a/harbour-batterybuddy.pro +++ b/harbour-batterybuddy.pro @@ -14,6 +14,8 @@ TARGET = harbour-batterybuddy CONFIG += sailfishapp sailfishapp_i18n +#DEFINES += QT_NO_DEBUG_OUTPUT + HEADERS += \ src/battery.h \ src/settings.h diff --git a/src/harbour-batterybuddy.cpp b/src/harbour-batterybuddy.cpp index 870b315..ff6db05 100644 --- a/src/harbour-batterybuddy.cpp +++ b/src/harbour-batterybuddy.cpp @@ -48,6 +48,9 @@ int main(int argc, char *argv[]) QGuiApplication* app = SailfishApp::application(argc, argv); QQuickView* view = SailfishApp::createView(); + qDebug() << "Application name:" << app->applicationName(); + qDebug() << "Organization name:" << app->organizationName(); + Settings* settings = new Settings(); Battery* battery = new Battery(settings); diff --git a/src/settings.cpp b/src/settings.cpp index f8cadf7..179a7c9 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -45,16 +45,96 @@ Settings::Settings(QObject *parent) : QObject(parent) Settings::~Settings() { - mySettings.setValue(sLowAlert, QByteArray::number(lowAlert)); - mySettings.setValue(sHighAlert, QByteArray::number(highAlert)); - mySettings.setValue(sInterval, QByteArray::number(interval)); - mySettings.setValue(sLimitEnabled, QByteArray::number(limitEnabled)); - mySettings.setValue(sNotificationsEnabled, QByteArray::number(notificationsEnabled)); - mySettings.setValue(sLowLimit, QByteArray::number(lowLimit)); - mySettings.setValue(sHighLimit, QByteArray::number(highLimit)); - qInfo() << "Settings saved"; + saveInteger(sLowAlert, &lowAlert); + saveInteger(sHighAlert, &highAlert); + saveInteger(sInterval, &interval); + saveInteger(sLimitEnabled, &limitEnabled); + saveInteger(sNotificationsEnabled, ¬ificationsEnabled); + saveInteger(sLowLimit, &lowLimit); + saveInteger(sHighLimit, &highLimit); + mySettings.sync(); + qInfo() << "Settings saved:" << mySettings.status() == QSettings::NoError; } +int Settings::getLowAlert() { + return lowAlert; +} + +int Settings::getHighAlert() { + return highAlert; +} + +int Settings::getInterval() { + return interval; +} + +int Settings::getLowLimit() { + return lowLimit; +} + +int Settings::getHighLimit() { + return highLimit; +} + +bool Settings::getLimitEnabled() { + return limitEnabled == 1; +} + +bool Settings::getNotificationsEnabled() { + return notificationsEnabled == 1; +} + +QString Settings::getLowAlertFile() { + return lowAlertFile; +} + +QString Settings::getHighAlertFile() { + return highAlertFile; +} + +void Settings::setLowAlert(int newLimit) { + lowAlert = newLimit; + emit lowAlertChanged(); + qDebug() << "Change" << sLowAlert << newLimit; +} + +void Settings::setHighAlert(int newLimit) { + highAlert = newLimit; + emit highAlertChanged(); + qDebug() << "Change" << sHighAlert << newLimit; +} + +void Settings::setInterval(int newInterval) { + interval = newInterval; + emit intervalChanged(); + qDebug() << "Change" << sInterval << newInterval; +} + +void Settings::setLowLimit(int newLimit) { + lowLimit = newLimit; + emit lowLimitChanged(); + qDebug() << "Change" << sLowLimit << newLimit; +} + +void Settings::setHighLimit(int newLimit) { + highLimit = newLimit; + emit highLimitChanged(); + qDebug() << "Change" << sHighLimit << newLimit; +} + +void Settings::setLimitEnabled(bool newEnabled) { + limitEnabled = (newEnabled ? 1 : 0); + emit limitEnabledChanged(); + qDebug() << "Change" << sLimitEnabled << newEnabled; +} + +void Settings::setNotificationsEnabled(bool newEnabled) { + notificationsEnabled = (newEnabled ? 1 : 0); + emit notificationsEnabledChanged(); + qDebug() << "Change" << sNotificationsEnabled << newEnabled; +} + + int Settings::bound(int value, int min, int max) { return (value <= min ? min : (value >= max ? max : value)); } @@ -63,3 +143,8 @@ void Settings::loadInteger(const char* key, int *value, int min, int max) { *value = bound(mySettings.value(key, *value).toInt(), min, max); qInfo() << "Loaded" << key << *value; } + +void Settings::saveInteger(const char* key, int *value) { + mySettings.setValue(key, QByteArray::number(*value)); + qInfo() << "Saved" << key << *value; +} diff --git a/src/settings.h b/src/settings.h index 911e484..fb19c23 100644 --- a/src/settings.h +++ b/src/settings.h @@ -39,23 +39,23 @@ public: Settings(QObject* parent = nullptr); ~Settings(); - int getLowAlert() { return lowAlert; } - int getHighAlert() { return highAlert; } - int getInterval() { return interval; } - int getLowLimit() { return lowLimit; } - int getHighLimit() { return highLimit; } - bool getLimitEnabled() { return limitEnabled == 1; } - bool getNotificationsEnabled() { return notificationsEnabled == 1; } - QString getLowAlertFile() { return lowAlertFile; } - QString getHighAlertFile() { return highAlertFile;} + int getLowAlert(); + int getHighAlert(); + int getInterval(); + int getLowLimit(); + int getHighLimit(); + bool getLimitEnabled(); + bool getNotificationsEnabled(); + QString getLowAlertFile(); + QString getHighAlertFile(); - void setLowAlert(int newLimit) { lowAlert = newLimit; emit lowAlertChanged(); } - void setHighAlert(int newLimit) { highAlert = newLimit; emit highAlertChanged(); } - void setInterval(int newInterval) { interval = newInterval; emit intervalChanged(); } - void setLowLimit(int newLimit) { lowLimit = newLimit; emit lowLimitChanged(); } - void setHighLimit(int newLimit) { highLimit = newLimit; emit highLimitChanged(); } - void setLimitEnabled(bool newEnabled) { limitEnabled = (newEnabled ? 1 : 0); emit limitEnabledChanged(); } - void setNotificationsEnabled(bool newEnabled) { notificationsEnabled = (newEnabled ? 1 : 0); emit notificationsEnabledChanged(); } + 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); private: @@ -84,7 +84,8 @@ private: const char* sHighAlertFile = "highAlertFile"; int bound(int value, int min, int max); - void loadInteger(const char *key, int* value, int min, int max); + void loadInteger(const char *key, int *value, int min, int max); + void saveInteger(const char *key, int *value); signals: int lowAlertChanged();