summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseniy-Movshev <dodoradio@outlook.com>2023-06-11 00:17:54 +0100
committerArseniy-Movshev <dodoradio@outlook.com>2023-06-20 00:05:28 +0100
commitf6c090502058c63f7a51b7ba97672022657119d8 (patch)
tree4481872fa3d05e2d767f1533a2ee1eba43cfb7ac
parent451388685a13669561b778e5719379db39164d47 (diff)
StepsDataLoader: add a property that updates today's live step count
this also changes the behaviour of getTodayTotal()
-rw-r--r--qmlplugin/CMakeLists.txt2
-rw-r--r--qmlplugin/stepsDataLoader.cpp8
-rw-r--r--qmlplugin/stepsDataLoader.h7
3 files changed, 15 insertions, 2 deletions
diff --git a/qmlplugin/CMakeLists.txt b/qmlplugin/CMakeLists.txt
index 741f360..8149e49 100644
--- a/qmlplugin/CMakeLists.txt
+++ b/qmlplugin/CMakeLists.txt
@@ -13,7 +13,7 @@ add_library(
)
target_link_libraries(sensorlogdqmlplugin
- Qt5::Qml Qt5::Quick Qt5::DBus
+ Qt5::Qml Qt5::Quick Qt5::DBus Qt5::Sensors
)
install(TARGETS sensorlogdqmlplugin
diff --git a/qmlplugin/stepsDataLoader.cpp b/qmlplugin/stepsDataLoader.cpp
index 2fbd9f1..53bdc5e 100644
--- a/qmlplugin/stepsDataLoader.cpp
+++ b/qmlplugin/stepsDataLoader.cpp
@@ -16,11 +16,16 @@
#include <QDBusInterface>
#include <QPointF>
+#include <QtSensors/QStepCounterSensor>
+
#include "stepsDataLoader.h"
#include "../common.h"
StepsDataLoader::StepsDataLoader() : QObject()
{
+ m_stepcounterSensor = new QStepCounterSensor(this);
+ m_stepcounterSensor->start();
+ connect(m_stepcounterSensor,SIGNAL(readingChanged()),this,SIGNAL(todayTotalChanged()));
m_iface = new QDBusInterface("org.asteroid.sensorlogd.logger","/org/asteroid/sensorlogd/logger","", QDBusConnection::sessionBus(), this);
if (!m_iface->isValid()) {
qDebug()<<"interface is not valid";
@@ -30,7 +35,8 @@ StepsDataLoader::StepsDataLoader() : QObject()
}
int StepsDataLoader::getTodayTotal() {
- return getTotalForDate(QDate::currentDate());
+ QSettings settings("asteroid", "sensorlogd");
+ return m_stepcounterSensor->reading()->steps() - settings.value("StepCounterPrivate/stepsOffset", 0).toInt();
}
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.
diff --git a/qmlplugin/stepsDataLoader.h b/qmlplugin/stepsDataLoader.h
index a1bcb5d..f29dcb2 100644
--- a/qmlplugin/stepsDataLoader.h
+++ b/qmlplugin/stepsDataLoader.h
@@ -15,9 +15,12 @@
#include <QDBusInterface>
#include <QPointF>
+#include <QtSensors/QStepCounterSensor>
+
class StepsDataLoader : public QObject
{
Q_OBJECT
+ Q_PROPERTY(int todayTotal READ getTodayTotal() NOTIFY todayTotalChanged())
public:
explicit StepsDataLoader();
@@ -26,8 +29,12 @@ public:
Q_INVOKABLE QList<QPointF> getDataForDate(QDate date);
Q_INVOKABLE QList<QPointF> getTodayData();
Q_INVOKABLE void triggerDaemonRecording();
+
+signals:
+ void todayTotalChanged();
private:
QDBusInterface *m_iface;
+ QStepCounterSensor *m_stepcounterSensor;
};
#endif // STEPSDATALOADER_H