summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.cpp5
-rw-r--r--common.h1
-rw-r--r--qmlplugin/hrDataLoader.cpp11
-rw-r--r--qmlplugin/hrDataLoader.h4
4 files changed, 20 insertions, 1 deletions
diff --git a/common.cpp b/common.cpp
index 4c0f252..10c18d4 100644
--- a/common.cpp
+++ b/common.cpp
@@ -19,6 +19,11 @@ QString fileNameForDate(QDate date, QString prefix) {
return settings.value("loggerRootPath", QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + prefix + "/" + date.toString("yyyy-MM-dd.log");
}
+QString sensorDirPath(QString prefix) {
+ QSettings settings("asteroid", "sensorlogd"); // this should be moved out of here at some point TODO
+ return settings.value("loggerRootPath", QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + prefix + "/";
+}
+
void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime) { //adds a record to today's log file for the given sensor
qDebug() << fileNameForDate(recordTime.date(), sensorPrefix);
QFile file(fileNameForDate(recordTime.date(), sensorPrefix));
diff --git a/common.h b/common.h
index a6b3197..8240d06 100644
--- a/common.h
+++ b/common.h
@@ -15,6 +15,7 @@
#include <QString>
QString fileNameForDate(QDate date, QString prefix);
+QString sensorDirPath(QString prefix);
void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime = QDateTime::currentDateTime()); //adds a record to today's log file for the given sensor
#endif //SENSORLOGD_COMMON_H
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