summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseniy-Movshev <dodoradio@outlook.com>2023-06-08 14:55:29 +0100
committerArseniy-Movshev <dodoradio@outlook.com>2023-06-20 00:05:28 +0100
commita816cfed03b7a02156377c29bd8a77b9c58333db (patch)
tree4b0d3db87240d94441c493de163a09eff743da2a
parent6087e0b0dd7a5246aca9024ef777b62080d35834 (diff)
Move fileNameForDate to a common header file
This function shows up in quite a few places so this seems justified. Other functions may get this treatment later
-rw-r--r--common.cpp18
-rw-r--r--common.h19
-rw-r--r--daemon/CMakeLists.txt2
-rw-r--r--daemon/logger.cpp6
-rw-r--r--daemon/logger.h1
-rw-r--r--qmlplugin/CMakeLists.txt2
-rw-r--r--qmlplugin/stepsDataLoader.cpp7
-rw-r--r--qmlplugin/stepsDataLoader.h1
8 files changed, 43 insertions, 13 deletions
diff --git a/common.cpp b/common.cpp
new file mode 100644
index 0000000..077bc4d
--- /dev/null
+++ b/common.cpp
@@ -0,0 +1,18 @@
+ /*
+ * Copyright (C) 2023 Arseniy Movshev <dodoradio@outlook.com>
+ * This file is part of sensorlogd, a sensor logger for the AsteroidOS smartwatch OS.
+ *
+ * sensorlogd is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * sensorlogd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <QSettings>
+#include <QStandardPaths>
+#include "common.h"
+
+QString fileNameForDate(QDate date, 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 + "/" + date.toString("yyyy-MM-dd.log");
+}
diff --git a/common.h b/common.h
new file mode 100644
index 0000000..573b006
--- /dev/null
+++ b/common.h
@@ -0,0 +1,19 @@
+ /*
+ * Copyright (C) 2023 Arseniy Movshev <dodoradio@outlook.com>
+ * This file is part of sensorlogd, a sensor logger for the AsteroidOS smartwatch OS.
+ *
+ * sensorlogd is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * sensorlogd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef SENSORLOGD_COMMON_H
+#define SENSORLOGD_COMMON_H
+
+#include <QDate>
+#include <QString>
+
+QString fileNameForDate(QDate date, QString prefix);
+
+#endif //SENSORLOGD_COMMON_H
diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt
index e38052b..b76527c 100644
--- a/daemon/CMakeLists.txt
+++ b/daemon/CMakeLists.txt
@@ -6,6 +6,8 @@ add_executable(sensorlogd
sensorPlugins/stepCounter.h
sensorPlugins/heartrateSensor.cpp
sensorPlugins/heartrateSensor.h
+ ../common.cpp
+ ../common.h
)
set_target_properties(sensorlogd PROPERTIES AUTOMOC ON)
#add_compile_definitions(Q_DECLARE_PRIVATE_SUPPORTS_UNIQUE_PTR=${Q_DECLARE_PRIVATE_SUPPORTS_UNIQUE_PTR})
diff --git a/daemon/logger.cpp b/daemon/logger.cpp
index 76f6e25..e8f75ba 100644
--- a/daemon/logger.cpp
+++ b/daemon/logger.cpp
@@ -21,6 +21,7 @@
#include <QStandardPaths>
#include "logger.h"
+#include "../common.h"
#include "sensorPlugins/stepCounter.h"
#include "sensorPlugins/heartrateSensor.h"
@@ -146,11 +147,6 @@ QStringList fileGetPrevRecord(QString sensorPrefix, QDateTime recordTime) {
return line.split(":");
}
-QString fileNameForDate(QDate date, 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 + "/" + date.toString("yyyy-MM-dd.log");
-}
-
void setupFilePath(QString sensorPrefix) {
QSettings settings("asteroid","sensorlogd"); //this should be moved out of here at some point TODO
QDir::root().mkpath(settings.value("loggerRootPath",QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + sensorPrefix);
diff --git a/daemon/logger.h b/daemon/logger.h
index 2eff33f..328c0d7 100644
--- a/daemon/logger.h
+++ b/daemon/logger.h
@@ -50,7 +50,6 @@ private:
void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime = QDateTime::currentDateTime()); //adds a record to today's log file for the given sensor
bool dayFileExists(QString sensorPrefix, QDateTime date = QDateTime::currentDateTime()); //check if today has a log file for the given sensor
QStringList fileGetPrevRecord(QString sensorPrefix, QDateTime recordTime = QDateTime::currentDateTime()); //works backwards to find the last record in today's file before the given time - returns nothing if no file is found.
- QString fileNameForDate(QDate date, QString prefix);
void setupFilePath(QString sensorPrefix); //sets up the paths for sensors to write into
#endif // LOGGER_H
diff --git a/qmlplugin/CMakeLists.txt b/qmlplugin/CMakeLists.txt
index 2b36163..3d24374 100644
--- a/qmlplugin/CMakeLists.txt
+++ b/qmlplugin/CMakeLists.txt
@@ -6,6 +6,8 @@ add_library(
stepsDataLoader.h
loggerSettings.cpp
loggerSettings.h
+ ../common.cpp
+ ../common.h
)
target_link_libraries(sensorlogdqmlplugin
diff --git a/qmlplugin/stepsDataLoader.cpp b/qmlplugin/stepsDataLoader.cpp
index 8a281a2..2fbd9f1 100644
--- a/qmlplugin/stepsDataLoader.cpp
+++ b/qmlplugin/stepsDataLoader.cpp
@@ -13,11 +13,11 @@
#include <QTextStream>
#include <QDate>
#include <QSettings>
-#include <QStandardPaths>
#include <QDBusInterface>
#include <QPointF>
#include "stepsDataLoader.h"
+#include "../common.h"
StepsDataLoader::StepsDataLoader() : QObject()
{
@@ -79,8 +79,3 @@ QList<QPointF> StepsDataLoader::getDataForDate(QDate date) {
void StepsDataLoader::triggerDaemonRecording() {
m_iface->call("triggerRecording");
}
-
-QString fileNameForDate(QDate date, 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 + "/" + date.toString("yyyy-MM-dd.log");
-}
diff --git a/qmlplugin/stepsDataLoader.h b/qmlplugin/stepsDataLoader.h
index fa551a3..a1bcb5d 100644
--- a/qmlplugin/stepsDataLoader.h
+++ b/qmlplugin/stepsDataLoader.h
@@ -29,6 +29,5 @@ public:
private:
QDBusInterface *m_iface;
};
-QString fileNameForDate(QDate date, QString prefix);
#endif // STEPSDATALOADER_H