Skip to content
Snippets Groups Projects
Commit 37d20f9a authored by Jaron Emmenegger's avatar Jaron Emmenegger
Browse files

Added configfile watch timer for automatic updates

parent da653b28
No related branches found
No related tags found
No related merge requests found
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
#include "configstorage.h" #include "configstorage.h"
#define CHECK_INTERVAL 300
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
ConfigStorage::ConfigStorage() ConfigStorage::ConfigStorage()
: mConfigFile(nullptr) : mConfigFile(nullptr)
{ {
connect(&mWatchTimer, &QTimer::timeout, this, &ConfigStorage::checkConfigUpdate);
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
...@@ -37,9 +39,30 @@ bool ConfigStorage::init() ...@@ -37,9 +39,30 @@ bool ConfigStorage::init()
if (useDefaults) if (useDefaults)
revertToDefaults(); revertToDefaults();
updateConfig();
mWatchTimer.start(CHECK_INTERVAL);
return true; return true;
} }
//-------------------------------------------------------------------------------------------------
void ConfigStorage::checkConfigUpdate()
{
Q_ASSERT(mConfigFile);
if (QFileInfo(*mConfigFile).lastModified() > mLastUpdate)
updateConfig();
}
//-------------------------------------------------------------------------------------------------
void ConfigStorage::updateConfig()
{
Q_ASSERT(mConfigFile->isOpen());
mLastUpdate = QDateTime::currentDateTime();
qDebug() << "update config";
}
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
void ConfigStorage::revertToDefaults() void ConfigStorage::revertToDefaults()
{ {
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
#define CONFIGSTORAGE_H #define CONFIGSTORAGE_H
#include <QObject> #include <QObject>
#include <QFile> #include <QTimer>
#include <QDateTime>
class QFile;
class ConfigStorage : public QObject class ConfigStorage : public QObject
{ {
...@@ -12,10 +15,16 @@ public: ...@@ -12,10 +15,16 @@ public:
bool init(); bool init();
private slots:
void checkConfigUpdate();
private: private:
void revertToDefaults(); void revertToDefaults();
void updateConfig();
QFile *mConfigFile; QFile *mConfigFile;
QTimer mWatchTimer;
QDateTime mLastUpdate;
}; };
#endif // CONFIGSTORAGE_H #endif // CONFIGSTORAGE_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment