mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 19:35:33 +08:00
refs #494 Use QFileSystemWatcher to watch for remote changes to the data store.
This commit is contained in:
@@ -27,9 +27,10 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
connect(this, &CValueCache::valuesChangedByLocal, this, &CDataCache::saveToStore);
|
connect(this, &CValueCache::valuesChangedByLocal, this, &CDataCache::saveToStore);
|
||||||
|
connect(&m_watcher, &QFileSystemWatcher::fileChanged, this, [this] { loadFromStore(); });
|
||||||
|
|
||||||
connect(&m_reloadTimer, &QTimer::timeout, this, [this]() { loadFromStore(); });
|
if (! QFile::exists(m_revisionFileName)) { QFile(m_revisionFileName).open(QFile::WriteOnly); }
|
||||||
m_reloadTimer.start(1000);
|
m_watcher.addPath(m_revisionFileName);
|
||||||
loadFromStore();
|
loadFromStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#include "blackcore/blackcoreexport.h"
|
#include "blackcore/blackcoreexport.h"
|
||||||
#include "blackmisc/valuecache.h"
|
#include "blackmisc/valuecache.h"
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QTimer>
|
#include <QFileSystemWatcher>
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
@@ -46,7 +46,7 @@ namespace BlackCore
|
|||||||
//! \param defer Whether to defer applying the changes. Used when called by saveToStore.
|
//! \param defer Whether to defer applying the changes. Used when called by saveToStore.
|
||||||
void loadFromStore(bool lock = true, bool defer = false);
|
void loadFromStore(bool lock = true, bool defer = false);
|
||||||
|
|
||||||
QTimer m_reloadTimer;
|
QFileSystemWatcher m_watcher;
|
||||||
QUuid m_revision;
|
QUuid m_revision;
|
||||||
const QString m_revisionFileName { persistentStore() + "/.rev" };
|
const QString m_revisionFileName { persistentStore() + "/.rev" };
|
||||||
BlackMisc::CVariantMap m_deferredChanges;
|
BlackMisc::CVariantMap m_deferredChanges;
|
||||||
|
|||||||
Reference in New Issue
Block a user