summaryrefslogtreecommitdiff
path: root/qmlplugin
diff options
context:
space:
mode:
authorArseniy-Movshev <dodoradio@outlook.com>2023-07-21 13:56:28 +0100
committerArseniy-Movshev <dodoradio@outlook.com>2023-07-21 14:07:59 +0100
commit0b0610efc2b93fa44915b9bf5ad1fb1c313bda15 (patch)
treee698834842aad2a222e8bdc93ecf96f353e02476 /qmlplugin
parentd69ab590c71fabc0135b2b07a8859a80e556cdf5 (diff)
Add file watcher to stepsDataLoader
this is essentially a copy of the previous commit applied to hrDataLoader
Diffstat (limited to 'qmlplugin')
-rw-r--r--qmlplugin/stepsDataLoader.cpp18
-rw-r--r--qmlplugin/stepsDataLoader.h3
2 files changed, 19 insertions, 2 deletions
diff --git a/qmlplugin/stepsDataLoader.cpp b/qmlplugin/stepsDataLoader.cpp
index d78ab94..8983d80 100644
--- a/qmlplugin/stepsDataLoader.cpp
+++ b/qmlplugin/stepsDataLoader.cpp
@@ -15,6 +15,7 @@
#include <QSettings>
#include <QDBusInterface>
#include <QPointF>
+#include <QFileSystemWatcher>
#include <QtSensors/QStepCounterSensor>
@@ -32,6 +33,10 @@ StepsDataLoader::StepsDataLoader() : QObject()
} else {
qDebug()<<"interface is valid";
}
+ m_fileWatcher = new QFileSystemWatcher();
+ m_fileWatcher->addPath(sensorDirPath("stepCounter"));
+ QObject::connect(m_fileWatcher,SIGNAL(directoryChanged(const QString)),this,SIGNAL(dataChanged()));
+ QObject::connect(m_fileWatcher,SIGNAL(fileChanged(const QString)),this,SIGNAL(dataChanged()));
}
int StepsDataLoader::getTodayTotal() {
@@ -45,11 +50,16 @@ int StepsDataLoader::getTodayTotal() {
int StepsDataLoader::getTotalForDate(QDate date) { // This is obvious garbage. This should really be abstracted and cached, so that every page doesn't have to reload the file from scratch.
// The intention is to also add graph functionality at some point. The graph will be simplifying the data before loading it in - it would be worth caching the simplified data when it comes to that as well.
- QFile file(fileNameForDate(date, "stepCounter"));
+
+ QString path = fileNameForDate(date, "stepCounter");
+ QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "failed to open file";
return 0;
}
+ if (!m_fileWatcher->files().contains(path)) {
+ m_fileWatcher->addPath(path);
+ }
QTextStream inStream(&file);
QString line = "0";
int i;
@@ -71,11 +81,15 @@ QVariant StepsDataLoader::getDataForDate(QDate date) {
QList<QPointF> StepsDataLoader::getRawDataForDate(QDate date) {
QList<QPointF> m_filedata;
- QFile file(fileNameForDate(date, "stepCounter"));
+ QString path = fileNameForDate(date, "stepCounter");
+ 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/stepsDataLoader.h b/qmlplugin/stepsDataLoader.h
index 312a9f5..a248f32 100644
--- a/qmlplugin/stepsDataLoader.h
+++ b/qmlplugin/stepsDataLoader.h
@@ -14,6 +14,7 @@
#include <QObject>
#include <QDBusInterface>
#include <QPointF>
+#include <QFileSystemWatcher>
#include <QtSensors/QStepCounterSensor>
@@ -33,8 +34,10 @@ public:
QList<QPointF> getRawDataForDate(QDate date);
signals:
void todayTotalChanged();
+ void dataChanged();
private:
QDBusInterface *m_iface;
+ QFileSystemWatcher *m_fileWatcher;
QStepCounterSensor *m_stepcounterSensor;
};