Don't hard code application name, properly assign object owners, Qt handles delete

This commit is contained in:
Matti Viljanen 2021-04-10 04:08:50 +03:00
parent 1ae74460cf
commit 4a885c347d
No known key found for this signature in database
GPG key ID: CF32A1495158F888
5 changed files with 7 additions and 12 deletions

View file

@ -21,7 +21,7 @@ Settings::Settings(QObject *parent) : QObject(parent)
{
// Use the same file location as GUI for data exchange
if(!mySettings) {
mySettings = new QSettings("harbour-batterybuddy", "harbour-batterybuddy");
mySettings = new QSettings(appName, appName, this);
}
// Read in the values

View file

@ -68,6 +68,7 @@ public:
private:
QSettings *mySettings = nullptr;
const char* appName = APP_NAME;
// Default values
int lowAlert = 25;

View file

@ -20,7 +20,7 @@
MyNotification::MyNotification(QObject* parent) : QObject(parent)
{
notification.setAppName("Battery Buddy");
notification.setAppIcon("harbour-batterybuddy");
notification.setAppIcon(APP_NAME);
playSound = false;
sound.setAudioRole(QAudio::NotificationRole);
connect(&sound, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),

View file

@ -21,7 +21,7 @@ Settings::Settings(QObject *parent) : QObject(parent)
{
// Use the same file location as GUI for data exchange
if(!mySettings) {
mySettings = new QSettings("harbour-batterybuddy", "harbour-batterybuddy");
mySettings = new QSettings(appName, appName, this);
}
qDebug() << "Using" << mySettings->fileName();
@ -79,14 +79,7 @@ Settings::Settings(QObject *parent) : QObject(parent)
// so we must monitor it and update when it changes.
}
Settings::~Settings()
{
delete mySettings;
}
int Settings::bound(int value, int min, int max) {
return (value <= min ? min : (value >= max ? max : value));
}
Settings::~Settings() { }
bool Settings::loadInteger(const char* key, int *value, int min, int max) {
oldValue = *value;
@ -101,7 +94,7 @@ void Settings::updateConfig(QString path) {
// Use the same file location as GUI for data exchange
if(!mySettings) {
mySettings = new QSettings("harbour-batterybuddy", "harbour-batterybuddy");
mySettings = new QSettings(appName, appName, this);
}
qDebug() << "Reading values...";

View file

@ -50,6 +50,7 @@ public:
private:
QSettings* mySettings = nullptr;
QFileSystemWatcher *watcher = nullptr;
const char* appName = APP_NAME;
int oldValue;