summaryrefslogtreecommitdiff
path: root/qmlplugin
diff options
context:
space:
mode:
authorArseniy-Movshev <dodoradio@outlook.com>2023-07-21 11:51:27 +0100
committerArseniy-Movshev <dodoradio@outlook.com>2023-07-21 13:44:08 +0100
commitd69ab590c71fabc0135b2b07a8859a80e556cdf5 (patch)
treee1e7d9dd5a7f869628cad5d17576c13fb3ce2037 /qmlplugin
parent439c082257448309073c312f008888568628323b (diff)
Add filesystem watchers to hrdataloader to update when new data comes in
When data for a specific file is requested, that file is added to the watch list. Currently these files aren't ever removed from the watch list, hopefully we won't be loading enough files to cause problems, at least for now
Diffstat (limited to 'qmlplugin')
-rw-r--r--qmlplugin/hrDataLoader.cpp11
-rw-r--r--qmlplugin/hrDataLoader.h4
2 files changed, 14 insertions, 1 deletions
diff --git a/qmlplugin/hrDataLoader.cpp b/qmlplugin/hrDataLoader.cpp
index 23f2ef0..16845ad 100644
--- a/qmlplugin/hrDataLoader.cpp
+++ b/qmlplugin/hrDataLoader.cpp
@@ -15,6 +15,7 @@
#include <QSettings>
#include <QDBusInterface>
#include <QPointF>
+#include <QFileSystemWatcher>
#include "hrDataLoader.h"
#include "../common.h"
@@ -27,6 +28,10 @@ HrDataLoader::HrDataLoader() : QObject()
} else {
qDebug()<<"interface is valid";
}
+ m_fileWatcher = new QFileSystemWatcher();
+ m_fileWatcher->addPath(sensorDirPath("heartrateMonitor"));
+ QObject::connect(m_fileWatcher,SIGNAL(directoryChanged(const QString)),this,SIGNAL(dataChanged()));
+ QObject::connect(m_fileWatcher,SIGNAL(fileChanged(const QString)),this,SIGNAL(dataChanged()));
}
QVariant HrDataLoader::getTodayData() {
@@ -39,11 +44,15 @@ QVariant HrDataLoader::getDataForDate(QDate date) {
QList<QPointF> HrDataLoader::getRawDataForDate(QDate date) {
QList<QPointF> m_filedata;
- QFile file(fileNameForDate(date, "heartrateMonitor"));
+ QString path = fileNameForDate(date, "heartrateMonitor");
+ QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "failed to open file";
return m_filedata;
}
+ if (!m_fileWatcher->files().contains(path)) {
+ m_fileWatcher->addPath(path);
+ }
QTextStream inStream(&file);
QString line;
while (!inStream.atEnd()) {
diff --git a/qmlplugin/hrDataLoader.h b/qmlplugin/hrDataLoader.h
index 78ac571..f14eacf 100644
--- a/qmlplugin/hrDataLoader.h
+++ b/qmlplugin/hrDataLoader.h
@@ -15,6 +15,7 @@
#include <QDBusInterface>
#include <QPointF>
#include <QDate>
+#include <QFileSystemWatcher>
class HrDataLoader : public QObject
{
@@ -27,8 +28,11 @@ public:
Q_INVOKABLE void triggerDaemonRecording();
Q_INVOKABLE QVariant getDataFromTo(QDate date1, QDate date2);
QList<QPointF> getRawDataForDate(QDate date);
+signals:
+ void dataChanged();
private:
QDBusInterface *m_iface;
+ QFileSystemWatcher *m_fileWatcher;
};
#endif // HRDATALOADER_H