diff --git a/application/src/battery.cpp b/application/src/battery.cpp index ddf06b6..1f69dfb 100644 --- a/application/src/battery.cpp +++ b/application/src/battery.cpp @@ -21,6 +21,7 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO { settings = newSettings; logger = newLogger; + const QString notFound = "not found"; QStringList filenames; @@ -34,8 +35,7 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO } } - if(chargeFile) logL("Battery charge file: " + chargeFile->fileName()); - else logL("Battery charge file: not found!"); + logL("Battery charge file: " + (chargeFile ? chargeFile->fileName() : notFound)); // Number: battery/charging current, e.g. -1450000 (-145mA) filenames.clear(); @@ -49,8 +49,7 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO } } - if(currentFile) logL("Charging/discharging current file: " + currentFile->fileName()); - else logL("Charging/discharging current file: not found!"); + logL("Charging/discharging current file: " + (currentFile ? currentFile->fileName() : notFound)); // String: charging, discharging, full, empty, unknown (others?) filenames.clear(); @@ -64,8 +63,7 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO } } - if(stateFile) logL("Status file: " + stateFile->fileName()); - else logL("Status file: not found!"); + logL("Status file: " + (stateFile ? stateFile->fileName() : notFound)); // Number: 0 or 1 filenames.clear(); @@ -79,8 +77,7 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO } } - if(chargerConnectedFile) logL("Charger status file: " + chargerConnectedFile->fileName()); - else logL("Charger status file: not found!"); + logL("Charger status file: " + (chargerConnectedFile ? chargerConnectedFile->fileName() : notFound)); // Number: temperature filenames.clear(); @@ -94,8 +91,7 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO } } - if(temperatureFile) logL("Battery temperature file: " + temperatureFile->fileName()); - else logL("Battery temperature file: not found!"); + logL("Battery temperature file: " + (temperatureFile ? temperatureFile->fileName() : notFound)); // String: health state filenames.clear(); @@ -108,8 +104,7 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO } } - if(healthFile) logL("Battery health file: " + healthFile->fileName()); - else logL("Battery health file: not found!"); + logL("Battery health file: " + (healthFile ? healthFile->fileName() : notFound)); // Charger control file filenames.clear(); @@ -143,11 +138,10 @@ Battery::Battery(Settings* newSettings, Logger* newLogger, QObject* parent) : QO chargingEnabledFile = Q_NULLPTR; } } - else if(!QSysInfo::machineHostName().contains("SailfishEmul")) { - logL("Charger control file not found!"); + else { + logL("Charger control file: " + notFound); logL("Please contact the developer with your device model!"); } - else logL("Charger control file: not found!"); updateData(); } @@ -221,9 +215,9 @@ void Battery::updateData() } } -int Battery::getCharge(){ return charge; } +int Battery::getCharge() { return charge; } -int Battery::getCurrent(){ return current; } +int Battery::getCurrent() { return current; } int Battery::getMaxChargeCurrent() { return maxChargeCurrent; } diff --git a/application/src/settings.cpp b/application/src/settings.cpp index 44677f6..197f3be 100644 --- a/application/src/settings.cpp +++ b/application/src/settings.cpp @@ -84,9 +84,9 @@ QString Settings::getLogFilename() { return logFilename; } QString Settings::getNotificationTitle() { return notificationTitle; } QString Settings::getNotificationLowText() { return notificationLowText; } QString Settings::getNotificationHighText() { return notificationHighText; } -QString Settings::getNotificationHealthTitle() { return notificationHealthTitle; } -QString Settings::getNotificationHealthWarnText() { return notificationHealthWarnText; } -QString Settings::getNotificationHealthCritText() { return notificationHealthCritText; } +QString Settings::getNotificationHealthTitle() { return notificationHealthTitle; } +QString Settings::getNotificationHealthWarnText() { return notificationHealthWarnText; } +QString Settings::getNotificationHealthCritText() { return notificationHealthCritText; } int Settings::getLogLevel() { return logLevel; } void Settings::setLowAlert(const int newLimit) { diff --git a/service/src/battery.cpp b/service/src/battery.cpp index e60ffb3..56b5e62 100644 --- a/service/src/battery.cpp +++ b/service/src/battery.cpp @@ -21,6 +21,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb { logger = newLogger; settings = new Settings(logger, this); + const QString notFound = "not found"; // Read log level from config - if not already set if(!loglevelSet) { @@ -45,8 +46,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb } } - if(chargeFile) logL("Battery charge file: " + chargeFile->fileName()); - else logL("Battery charge file: not found!"); + logL("Battery charge file: " + (chargeFile ? chargeFile->fileName() : notFound)); // Charging/discharging current in microamps, e.g. -1450000 (-145mA) filenames.clear(); @@ -60,8 +60,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb } } - if(currentFile) logL("Charging/discharging current file: " + currentFile->fileName()); - else logL("Charging/discharging current file: not found!"); + logL("Charging/discharging current file: " + (currentFile ? currentFile->fileName() : notFound)); // Maximum charge current in microamps, e.g. 3500000 (3500mA) filenames.clear(); @@ -91,7 +90,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb } } else { - logL("Max charge current file: not found!"); + logL("Max charge current file: " + notFound); } settings->setMaxSupportedChargeCurrent(maxSupportedChargeCurrent); @@ -107,8 +106,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb } } - if(stateFile) logL("Status file: " + stateFile->fileName()); - else logL("Status file: not found!"); + logL("Status file: " + (stateFile ? stateFile->fileName() : notFound)); // Charger connected, bool (number): 0 or 1 filenames.clear(); @@ -122,8 +120,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb } } - if(chargerConnectedFile) logL("Charger status file: " + chargerConnectedFile->fileName()); - else logL("Charger status file: not found!"); + logL("Charger status file: " + (chargerConnectedFile ? chargerConnectedFile->fileName() : notFound)); // Number: temperature filenames.clear(); @@ -137,8 +134,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb } } - if(temperatureFile) logL("Battery temperature file: " + temperatureFile->fileName()); - else logL("Battery temperature file: not found!"); + logL("Battery temperature file: " + (temperatureFile ? temperatureFile->fileName() : notFound)); // String: health state filenames.clear(); @@ -151,8 +147,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb } } - if(healthFile) logL("Battery health file: " + healthFile->fileName()); - else logL("Battery health file: not found!"); + logL("Battery health file: " + (healthFile ? healthFile->fileName() : notFound)); // Charger control file filenames.clear(); @@ -186,11 +181,10 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QCoreApplication *app, QOb chargingEnabledFile = Q_NULLPTR; } } - else if(!QSysInfo::machineHostName().contains("SailfishEmul")) { + else { logL("Charger control file not found!"); logL("Please contact the developer with your device model!"); } - else logL("Charger control file: not found!"); connect(settings, SIGNAL(resetTimers()), this, SLOT(resetTimers())); connect(settings, SIGNAL(setMaxChargeCurrent(int)), this, SLOT(setMaxChargeCurrent(int)));