Signal timer reset when necessary
This commit is contained in:
parent
5235b5b0a0
commit
16f8d1b30a
4 changed files with 15 additions and 9 deletions
|
@ -84,7 +84,7 @@ Battery::Battery(QObject *parent) : QObject(parent)
|
|||
}
|
||||
|
||||
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateData()));
|
||||
connect(settings, SIGNAL(configChanged()), this, SLOT(updateConfig()));
|
||||
connect(settings, SIGNAL(resetTimers()), this, SLOT(resetTimers()));
|
||||
connect(highNotifyTimer, SIGNAL(timeout()), this, SLOT(showHighNotification()));
|
||||
connect(lowNotifyTimer, SIGNAL(timeout()), this, SLOT(showLowNotification()));
|
||||
|
||||
|
@ -123,7 +123,7 @@ void Battery::updateData()
|
|||
// Hide/show notification right away
|
||||
updateNotification();
|
||||
// Reset the timer, too
|
||||
updateConfig();
|
||||
resetTimers();
|
||||
}
|
||||
stateFile->close();
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ void Battery::updateData()
|
|||
}
|
||||
}
|
||||
|
||||
void Battery::updateConfig() {
|
||||
void Battery::resetTimers() {
|
||||
highNotifyTimer->stop();
|
||||
lowNotifyTimer->stop();
|
||||
highNotifyTimer->setInterval(settings->getHighNotificationsInterval() * 1000);
|
||||
|
|
|
@ -84,7 +84,7 @@ signals:
|
|||
void chargerConnectedChanged(bool);
|
||||
|
||||
public slots:
|
||||
void updateConfig();
|
||||
void resetTimers();
|
||||
void showHighNotification();
|
||||
void showLowNotification();
|
||||
void updateNotification();
|
||||
|
|
|
@ -92,13 +92,15 @@ void Settings::updateConfig(QString path) {
|
|||
|
||||
qDebug() << "Reading values...";
|
||||
// Read in the values
|
||||
bool restartTimers = false;
|
||||
|
||||
loadInteger(sLowAlert, &lowAlert, 10, 99);
|
||||
loadInteger(sHighAlert, &highAlert, 11, 100);
|
||||
loadInteger(sHighNotificationsInterval, &highNotificationsInterval, 60, 600);
|
||||
loadInteger(sLowNotificationsInterval, &lowNotificationsInterval, 60, 600);
|
||||
restartTimers |= loadInteger(sHighNotificationsInterval, &highNotificationsInterval, 60, 600);
|
||||
restartTimers |= loadInteger(sLowNotificationsInterval, &lowNotificationsInterval, 60, 600);
|
||||
loadInteger(sLimitEnabled, &limitEnabled, 0, 1);
|
||||
loadInteger(sHighNotificationsEnabled, &highNotificationsEnabled, 0, 1);
|
||||
loadInteger(sLowNotificationsEnabled, &lowNotificationsEnabled, 0, 1);
|
||||
restartTimers |= loadInteger(sHighNotificationsEnabled, &highNotificationsEnabled, 0, 1);
|
||||
restartTimers |= loadInteger(sLowNotificationsEnabled, &lowNotificationsEnabled, 0, 1);
|
||||
loadInteger(sLowLimit, &lowLimit, 20, 94);
|
||||
loadInteger(sHighLimit, &highLimit, 21, 95);
|
||||
|
||||
|
@ -123,6 +125,10 @@ void Settings::updateConfig(QString path) {
|
|||
qDebug() << "File replaced, re-adding.";
|
||||
watcher->addPath(path);
|
||||
}
|
||||
|
||||
if(restartTimers) {
|
||||
emit resetTimers();
|
||||
}
|
||||
}
|
||||
|
||||
// Getters condensed
|
||||
|
|
|
@ -96,7 +96,7 @@ private slots:
|
|||
void updateConfig(QString path);
|
||||
|
||||
signals:
|
||||
void configChanged();
|
||||
void resetTimers();
|
||||
};
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
|
Loading…
Reference in a new issue