Don't hard code application name, properly assign object owners, Qt handles delete
This commit is contained in:
parent
1ae74460cf
commit
4a885c347d
5 changed files with 7 additions and 12 deletions
|
@ -21,7 +21,7 @@ Settings::Settings(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
// Use the same file location as GUI for data exchange
|
// Use the same file location as GUI for data exchange
|
||||||
if(!mySettings) {
|
if(!mySettings) {
|
||||||
mySettings = new QSettings("harbour-batterybuddy", "harbour-batterybuddy");
|
mySettings = new QSettings(appName, appName, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read in the values
|
// Read in the values
|
||||||
|
|
|
@ -68,6 +68,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSettings *mySettings = nullptr;
|
QSettings *mySettings = nullptr;
|
||||||
|
const char* appName = APP_NAME;
|
||||||
|
|
||||||
// Default values
|
// Default values
|
||||||
int lowAlert = 25;
|
int lowAlert = 25;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
MyNotification::MyNotification(QObject* parent) : QObject(parent)
|
MyNotification::MyNotification(QObject* parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
notification.setAppName("Battery Buddy");
|
notification.setAppName("Battery Buddy");
|
||||||
notification.setAppIcon("harbour-batterybuddy");
|
notification.setAppIcon(APP_NAME);
|
||||||
playSound = false;
|
playSound = false;
|
||||||
sound.setAudioRole(QAudio::NotificationRole);
|
sound.setAudioRole(QAudio::NotificationRole);
|
||||||
connect(&sound, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
|
connect(&sound, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
|
||||||
|
|
|
@ -21,7 +21,7 @@ Settings::Settings(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
// Use the same file location as GUI for data exchange
|
// Use the same file location as GUI for data exchange
|
||||||
if(!mySettings) {
|
if(!mySettings) {
|
||||||
mySettings = new QSettings("harbour-batterybuddy", "harbour-batterybuddy");
|
mySettings = new QSettings(appName, appName, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Using" << mySettings->fileName();
|
qDebug() << "Using" << mySettings->fileName();
|
||||||
|
@ -79,14 +79,7 @@ Settings::Settings(QObject *parent) : QObject(parent)
|
||||||
// so we must monitor it and update when it changes.
|
// so we must monitor it and update when it changes.
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::~Settings()
|
Settings::~Settings() { }
|
||||||
{
|
|
||||||
delete mySettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Settings::bound(int value, int min, int max) {
|
|
||||||
return (value <= min ? min : (value >= max ? max : value));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Settings::loadInteger(const char* key, int *value, int min, int max) {
|
bool Settings::loadInteger(const char* key, int *value, int min, int max) {
|
||||||
oldValue = *value;
|
oldValue = *value;
|
||||||
|
@ -101,7 +94,7 @@ void Settings::updateConfig(QString path) {
|
||||||
|
|
||||||
// Use the same file location as GUI for data exchange
|
// Use the same file location as GUI for data exchange
|
||||||
if(!mySettings) {
|
if(!mySettings) {
|
||||||
mySettings = new QSettings("harbour-batterybuddy", "harbour-batterybuddy");
|
mySettings = new QSettings(appName, appName, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Reading values...";
|
qDebug() << "Reading values...";
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
private:
|
private:
|
||||||
QSettings* mySettings = nullptr;
|
QSettings* mySettings = nullptr;
|
||||||
QFileSystemWatcher *watcher = nullptr;
|
QFileSystemWatcher *watcher = nullptr;
|
||||||
|
const char* appName = APP_NAME;
|
||||||
|
|
||||||
int oldValue;
|
int oldValue;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue