Library migration #36

Merged
dorian merged 62 commits from library_migration into master 2024-10-17 17:52:36 +02:00
9 changed files with 151 additions and 151 deletions
Showing only changes of commit 1a2fbcc170 - Show all commits

View file

@ -27,11 +27,11 @@ include($$PWD/shared-libraries/ScStwLibraries/ScStwLibraries.pri)
SOURCES += \ SOURCES += \
sources/scstwappbackend.cpp \ sources/scstwappbackend.cpp \
sources/main.cpp \ sources/main.cpp \
sources/appsettings.cpp sources/scstwappsettings.cpp
HEADERS += \ HEADERS += \
headers/appsettings.h \ headers/scstwappbackend.h \
headers/scstwappbackend.h headers/scstwappsettings.h
RESOURCES += \ RESOURCES += \
resources/shared/shared.qrc \ resources/shared/shared.qrc \

View file

@ -1,28 +0,0 @@
#ifndef APPSETTINGS_H
#define APPSETTINGS_H
#include <QObject>
#include <QSettings>
#include <QStandardPaths>
class AppSettings : public QObject
{
Q_OBJECT
public:
explicit AppSettings(QObject *parent = nullptr);
~AppSettings();
Q_INVOKABLE QString loadSetting(QString key);
Q_INVOKABLE void writeSetting(QString key, QVariant variant);
Q_INVOKABLE void setDefaultSetting(QString key, QVariant defaultVariant);
QSettings *settingsManager;
signals:
public slots:
};
extern AppSettings * pGlobalAppSettings;
#endif // APPSETTINGS_H

View file

@ -8,7 +8,7 @@
#include <ScStw.hpp> #include <ScStw.hpp>
#include <scstwremotemonitorrace.h> #include <scstwremotemonitorrace.h>
#include "headers/appsettings.h" #include "headers/scstwappsettings.h"
class ScStwAppBackend : public QObject class ScStwAppBackend : public QObject
@ -18,6 +18,7 @@ class ScStwAppBackend : public QObject
Q_PROPERTY(int mode READ getMode NOTIFY modeChanged) Q_PROPERTY(int mode READ getMode NOTIFY modeChanged)
Q_PROPERTY(ScStwRace* race READ getRace NOTIFY raceChanged) Q_PROPERTY(ScStwRace* race READ getRace NOTIFY raceChanged)
Q_PROPERTY(ScStwClient *scStwClient READ getScStwClient NOTIFY scStwClientChanged) Q_PROPERTY(ScStwClient *scStwClient READ getScStwClient NOTIFY scStwClientChanged)
Q_PROPERTY(ScStwAppSettings *settings READ getSettings NOTIFY settingsChanged)
public: public:
explicit ScStwAppBackend(QObject *parent = nullptr); explicit ScStwAppBackend(QObject *parent = nullptr);
@ -27,7 +28,7 @@ public:
private: private:
RaceMode mode; RaceMode mode;
AppSettings * appSettings; ScStwAppSettings * appSettings;
ScStwClient * scStwClient; ScStwClient * scStwClient;
QTimer * timerTextRefreshTimer; QTimer * timerTextRefreshTimer;
@ -39,13 +40,9 @@ public slots:
// functions for qml // functions for qml
Q_INVOKABLE ScStwRace *getRace(); Q_INVOKABLE ScStwRace *getRace();
Q_INVOKABLE ScStwClient *getScStwClient(); Q_INVOKABLE ScStwClient *getScStwClient();
Q_INVOKABLE ScStwAppSettings *getSettings();
Q_INVOKABLE int getMode(); Q_INVOKABLE int getMode();
Q_INVOKABLE void writeSetting(QString key, QVariant value);
Q_INVOKABLE void writeSetting(ScStw::BaseStationSetting key, QVariant value);
Q_INVOKABLE QString readSetting(QString key);
Q_INVOKABLE QString readSetting(ScStw::BaseStationSetting key);
// athlete management // athlete management
Q_INVOKABLE QVariant getAthletes(); Q_INVOKABLE QVariant getAthletes();
Q_INVOKABLE bool createAthlete( QString userName, QString fullName ); Q_INVOKABLE bool createAthlete( QString userName, QString fullName );
@ -58,11 +55,13 @@ private slots:
void refreshMode(); void refreshMode();
void reloadRaceSettings(); void reloadRaceSettings();
void reloadBaseStationIpAdress(); void reloadBaseStationIpAdress();
void handleSettingChange(int keyInt, int keyLevel);
signals: signals:
void modeChanged(); void modeChanged();
void raceChanged(); void raceChanged();
void scStwClientChanged(); void scStwClientChanged();
void settingsChanged();
void baseStationStateChanged(); void baseStationStateChanged();
void baseStationConnectionsChanged(); void baseStationConnectionsChanged();

View file

@ -0,0 +1,39 @@
#ifndef APPSETTINGS_H
#define APPSETTINGS_H
#include <QObject>
#include <QSettings>
#include <QStandardPaths>
#include "scstwsettings.h"
class ScStwAppSettings : public ScStwSettings
{
Q_OBJECT
public:
explicit ScStwAppSettings(QObject *parent = nullptr);
~ScStwAppSettings();
enum AppInternalSetting {
InvalidSetting = -1,
AppThemeSetting,
BaseStationIpSetting
};
Q_ENUM(AppInternalSetting)
using ScStwSettings::readSetting;
QVariant readSetting(AppInternalSetting key);
using ScStwSettings::writeSetting;
bool writeSetting(AppInternalSetting key, QVariant value);
using ScStwSettings::setDefaultSetting;
void setDefaultSetting(AppInternalSetting key, QVariant defaultVariant);
QSettings *settingsManager;
signals:
public slots:
};
extern ScStwAppSettings * pGlobalAppSettings;
#endif // APPSETTINGS_H

@ -1 +1 @@
Subproject commit ae9e6398ac233217ac89ef009fd84d8ce19f4159 Subproject commit 3d18b72eaf7fc8993ff60f1e087fa0c30516f4b5

View file

@ -1,69 +0,0 @@
/*
Speed Climbing Stopwatch - Simple Stopwatch for Climbers
Copyright (C) 2018 Itsblue Development - Dorian Zeder
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "headers/appsettings.h"
AppSettings * pGlobalAppSettings = nullptr;
AppSettings::AppSettings(QObject* parent)
:QObject(parent)
{
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
this->settingsManager = new QSettings(path+"/settings.ini", QSettings::IniFormat, this);
this->setDefaultSetting("ready_en", "false");
this->setDefaultSetting("ready_delay", 0);
this->setDefaultSetting("at_marks_en", "false");
this->setDefaultSetting("at_marks_delay", 0);
this->setDefaultSetting("theme", "Light");
this->setDefaultSetting("baseStationIpAdress", "192.168.4.1");
pGlobalAppSettings = this;
}
QString AppSettings::loadSetting(QString key)
{
this->settingsManager->beginGroup("AppSettings");
QString value = this->settingsManager->value(key , false).toString();
this->settingsManager->endGroup();
return(value);
}
void AppSettings::writeSetting(QString key, QVariant variant)
{
this->settingsManager->beginGroup("AppSettings");
this->settingsManager->setValue(key , variant);
this->settingsManager->endGroup();
}
void AppSettings::setDefaultSetting(QString key, QVariant defaultVariant)
{
QString value = this->loadSetting(key);
if(value == "false"){
this->writeSetting(key, defaultVariant);
}
}
AppSettings::~AppSettings()
{
delete settingsManager;
}

View file

@ -50,7 +50,7 @@
#include <QtAndroidExtras> #include <QtAndroidExtras>
#endif #endif
#include "headers/appsettings.h" #include "headers/scstwappsettings.h"
//#include "headers/speedtimer.h" //#include "headers/speedtimer.h"
//#include "headers/climbingrace.h" //#include "headers/climbingrace.h"
#include "headers/scstwappbackend.h" #include "headers/scstwappbackend.h"
@ -81,7 +81,7 @@ int main(int argc, char *argv[])
}); });
#endif #endif
AppSettings * pAppSettings = new AppSettings(); ScStwAppSettings * pAppSettings = new ScStwAppSettings();
// setup speed backend // setup speed backend
qmlRegisterType<ScStwAppBackend>("de.itsblue.ScStwApp", 2, 0, "SpeedBackend"); qmlRegisterType<ScStwAppBackend>("de.itsblue.ScStwApp", 2, 0, "SpeedBackend");

View file

@ -2,13 +2,23 @@
ScStwAppBackend::ScStwAppBackend(QObject *parent) : QObject(parent) ScStwAppBackend::ScStwAppBackend(QObject *parent) : QObject(parent)
{ {
this->appSettings = new AppSettings(this); this->appSettings = new ScStwAppSettings(this);
this->appSettings->setDefaultSetting(ScStwSettings::ReadySoundEnableSetting, false);
this->appSettings->setDefaultSetting(ScStwSettings::ReadySoundDelaySetting, 0);
this->appSettings->setDefaultSetting(ScStwSettings::AtYourMarksSoundEnableSetting, false);
this->appSettings->setDefaultSetting(ScStwSettings::AtYourMarksSoundDelaySetting, 0);
this->appSettings->setDefaultSetting(ScStwAppSettings::AppThemeSetting, "Light");
this->appSettings->setDefaultSetting(ScStwAppSettings::BaseStationIpSetting, "192.168.4.1");
this->scStwClient = new ScStwClient(); this->scStwClient = new ScStwClient();
this->localRace = new ScStwRace(this); this->localRace = new ScStwRace(this);
this->remoteRace = new ScStwRemoteMonitorRace(this->scStwClient, this); this->remoteRace = new ScStwRemoteMonitorRace(this->scStwClient, this);
this->mode = LOCAL; this->mode = LOCAL;
this->scStwClient->setIP(pGlobalAppSettings->loadSetting("baseStationIpAdress")); this->scStwClient->setIP(this->appSettings->readSetting(ScStwAppSettings::BaseStationIpSetting).toString());
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwAppBackend::baseStationStateChanged); connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwAppBackend::baseStationStateChanged);
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwAppBackend::refreshMode); connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwAppBackend::refreshMode);
connect(this, &ScStwAppBackend::baseStationStateChanged, this, &ScStwAppBackend::baseStationPropertiesChanged); connect(this, &ScStwAppBackend::baseStationStateChanged, this, &ScStwAppBackend::baseStationPropertiesChanged);
@ -164,6 +174,10 @@ ScStwRace* ScStwAppBackend::getRace() {
return nullptr; return nullptr;
} }
ScStwAppSettings * ScStwAppBackend::getSettings() {
return this->appSettings;
}
ScStwClient* ScStwAppBackend::getScStwClient() { ScStwClient* ScStwAppBackend::getScStwClient() {
return this->scStwClient; return this->scStwClient;
} }
@ -172,51 +186,17 @@ int ScStwAppBackend::getMode() {
return this->mode; return this->mode;
} }
void ScStwAppBackend::writeSetting(QString key, QVariant value) {
if(this->mode == REMOTE && ScStw::baseStationSettingFromString(key) != ScStw::InvalidSetting ){
this->scStwClient->writeRemoteSetting(ScStw::baseStationSettingFromString(key), value.toString());
}
else {
this->appSettings->writeSetting(key, value);
}
this->reloadRaceSettings();
this->reloadBaseStationIpAdress();
}
void ScStwAppBackend::writeSetting(ScStw::BaseStationSetting key, QVariant value) {
if(ScStw::baseStationSettingToString(key) != "Invalid" ){
this->writeSetting(ScStw::baseStationSettingToString(key), value);
}
}
QString ScStwAppBackend::readSetting(QString key) {
if(this->mode == REMOTE && ScStw::baseStationSettingFromString(key) != ScStw::InvalidSetting){
return this->scStwClient->readRemoteSetting(ScStw::baseStationSettingFromString(key));
}
else {
return this->appSettings->loadSetting(key);
}
}
QString ScStwAppBackend::readSetting(ScStw::BaseStationSetting key) {
if(ScStw::baseStationSettingToString(key) != "Invalid") {
return this->readSetting(ScStw::baseStationSettingToString(key));
}
return "false";
}
void ScStwAppBackend::reloadRaceSettings() { void ScStwAppBackend::reloadRaceSettings() {
this->getRace()->writeStartActionSetting( this->getRace()->writeStartActionSetting(
ScStwRace::AtYourMarks, ScStwRace::AtYourMarks,
this->appSettings->loadSetting(ScStw::baseStationSettingToString(ScStw::AtYourMarksSoundEnableSetting)) == "true", this->appSettings->readSetting(ScStwSettings::AtYourMarksSoundEnableSetting).toBool(),
this->appSettings->loadSetting(ScStw::baseStationSettingToString(ScStw::AtYourMarksSoundDelaySetting)).toDouble() this->appSettings->readSetting(ScStwSettings::AtYourMarksSoundDelaySetting).toDouble()
); );
this->getRace()->writeStartActionSetting( this->getRace()->writeStartActionSetting(
ScStwRace::Ready, ScStwRace::Ready,
this->appSettings->loadSetting(ScStw::baseStationSettingToString(ScStw::ReadySoundEnableSetting)) == "true", this->appSettings->readSetting(ScStwSettings::ReadySoundEnableSetting).toBool(),
this->appSettings->loadSetting(ScStw::baseStationSettingToString(ScStw::ReadySoundDelaySetting)).toDouble() this->appSettings->readSetting(ScStwSettings::ReadySoundDelaySetting).toDouble()
); );
this->getRace()->setSoundVolume(1); this->getRace()->setSoundVolume(1);
@ -224,5 +204,36 @@ void ScStwAppBackend::reloadRaceSettings() {
} }
void ScStwAppBackend::reloadBaseStationIpAdress() { void ScStwAppBackend::reloadBaseStationIpAdress() {
this->scStwClient->setIP(pGlobalAppSettings->loadSetting("baseStationIpAdress")); this->scStwClient->setIP(this->appSettings->readSetting(ScStwAppSettings::BaseStationIpSetting).toString());
}
void ScStwAppBackend::handleSettingChange(int keyInt, int keyLevel) {
switch (keyLevel) {
case 0: {
// BaseStationSetting!!
ScStwSettings::BaseStationSetting key = static_cast<ScStwSettings::BaseStationSetting>(keyInt);
switch (key) {
case ScStwSettings::InvalidSetting:
return;
default:
this->reloadRaceSettings();
return;
}
break;
}
case 1: {
// BaseStationInternalSetting!!
ScStwAppSettings::AppInternalSetting key = static_cast<ScStwAppSettings::AppInternalSetting>(keyInt);
switch (key) {
case ScStwAppSettings::InvalidSetting:
return;
case ScStwAppSettings::BaseStationIpSetting:
this->reloadBaseStationIpAdress();
break;
default:
break;
}
break;
}
}
} }

View file

@ -0,0 +1,48 @@
/*
Speed Climbing Stopwatch - Simple Stopwatch for Climbers
Copyright (C) 2018 Itsblue Development - Dorian Zeder
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "headers/scstwappsettings.h"
ScStwAppSettings * pGlobalAppSettings = nullptr;
ScStwAppSettings::ScStwAppSettings(QObject* parent)
:ScStwSettings(parent)
{
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
this->settingsManager = new QSettings(path+"/settings.ini", QSettings::IniFormat, this);
pGlobalAppSettings = this;
}
QVariant ScStwAppSettings::readSetting(AppInternalSetting key) {
return ScStwSettings::readSetting(QMetaEnum::fromType<AppInternalSetting>().valueToKey(int(key)));
}
bool ScStwAppSettings::writeSetting(AppInternalSetting key, QVariant value) {
return ScStwSettings::writeSetting(QMetaEnum::fromType<AppInternalSetting>().valueToKey(int(key)), value, int(key), 1);
}
void ScStwAppSettings::setDefaultSetting(AppInternalSetting key, QVariant defaultVariant) {
ScStwSettings::setDefaultSetting(QMetaEnum::fromType<AppInternalSetting>().valueToKey(int(key)), defaultVariant, int(key), 1);
}
ScStwAppSettings::~ScStwAppSettings()
{
delete settingsManager;
}