summaryrefslogtreecommitdiff
path: root/qmlplugin
diff options
context:
space:
mode:
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