From e01c00ded80bda86ddfc3604661720051d52df1e Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Mon, 6 Apr 2020 17:52:48 +0200 Subject: [PATCH] - cleanup - some changed to comply with new standards of shared libraries --- ScStwSrc/headers/climbingrace.h | 27 ++-- .../qml/ProfilesDialog/AddProfilePage.qml | 2 +- .../qml/ProfilesDialog/ProfileListPage.qml | 2 +- .../qml/ProfilesDialog/ProfilesDialog.qml | 2 +- .../qml/ProfilesDialog/ProfilesStack.qml | 2 +- .../qml/ProfilesDialog/ResultListPage.qml | 2 +- ScStwSrc/sources/climbingrace.cpp | 131 +++++++++--------- ScStwSrc/sources/main.cpp | 35 +---- shared-libraries | 2 +- 9 files changed, 84 insertions(+), 121 deletions(-) diff --git a/ScStwSrc/headers/climbingrace.h b/ScStwSrc/headers/climbingrace.h index cc0366a..d246d50 100644 --- a/ScStwSrc/headers/climbingrace.h +++ b/ScStwSrc/headers/climbingrace.h @@ -7,6 +7,7 @@ #include #include +#include #include "headers/appsettings.h" #include "headers/speedtimer.h" @@ -27,13 +28,8 @@ class ClimbingRace : public QObject public: explicit ClimbingRace(QObject *parent = nullptr); - enum raceState { IDLE, STARTING, WAITING, RUNNING, STOPPED }; - raceState state; - - enum raceMode { LOCAL, REMOTE }; - raceMode mode; - - enum NextStartAction { AtYourMarks, Ready, Start, None }; + enum RaceMode { LOCAL, REMOTE }; + RaceMode mode; private: AppSettings * appSettings; @@ -48,7 +44,8 @@ private: QList speedTimers; - NextStartAction nextStartAction; + ScStw::NextStartAction nextStartAction; + ScStw::RaceState state; double nextStartActionDelayProgress; // only used in remote mode: @@ -57,14 +54,20 @@ private: // helper vars QVariantList qmlTimers; - const QStringList remoteSettings = {"ready_en", "ready_delay", "at_marks_en", "at_marks_delay"}; - const QStringList remoteOnlySettings = {"soundVolume"}; + + const QMap remoteSettings = { + {"ready_en", ScStw::ReadySoundEnableSetting}, + {"ready_delay", ScStw::ReadySoundDelaySetting}, + {"at_marks_en", ScStw::AtYourMarksSoundEnableSetting}, + {"at_marks_delay", ScStw::AtYourMarksSoundDelaySetting}, + {"soundVolume", ScStw::SoundVolumeSetting} + }; private slots: // helper functions void playSoundsAndStartRace(); bool playSound(QString path); - void setState(raceState newState); + void setState(ScStw::RaceState newState); void refreshMode(); void refreshTimerText(); @@ -87,7 +90,7 @@ public slots: Q_INVOKABLE int resetRace(); // base station sync - void handleBaseStationUpdate(QVariant data); + void handleBaseStationSignal(ScStw::SignalKey key, QVariant data); Q_INVOKABLE bool pairConnectedUsbExtensions(); // functions for qml diff --git a/ScStwSrc/resources/qml/ProfilesDialog/AddProfilePage.qml b/ScStwSrc/resources/qml/ProfilesDialog/AddProfilePage.qml index 0617d96..583961c 100644 --- a/ScStwSrc/resources/qml/ProfilesDialog/AddProfilePage.qml +++ b/ScStwSrc/resources/qml/ProfilesDialog/AddProfilePage.qml @@ -21,7 +21,7 @@ import QtQuick.Window 2.2 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 -import com.itsblue.speedclimbingstopwatch 1.0 +import com.itsblue.speedclimbingstopwatch 2.0 import "../components" diff --git a/ScStwSrc/resources/qml/ProfilesDialog/ProfileListPage.qml b/ScStwSrc/resources/qml/ProfilesDialog/ProfileListPage.qml index 8dd109a..5290c0e 100644 --- a/ScStwSrc/resources/qml/ProfilesDialog/ProfileListPage.qml +++ b/ScStwSrc/resources/qml/ProfilesDialog/ProfileListPage.qml @@ -21,7 +21,7 @@ import QtQuick.Window 2.2 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 -import com.itsblue.speedclimbingstopwatch 1.0 +import com.itsblue.speedclimbingstopwatch 2.0 import "../components" diff --git a/ScStwSrc/resources/qml/ProfilesDialog/ProfilesDialog.qml b/ScStwSrc/resources/qml/ProfilesDialog/ProfilesDialog.qml index 3885185..ab2cb0d 100644 --- a/ScStwSrc/resources/qml/ProfilesDialog/ProfilesDialog.qml +++ b/ScStwSrc/resources/qml/ProfilesDialog/ProfilesDialog.qml @@ -21,7 +21,7 @@ import QtQuick.Window 2.2 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 -import com.itsblue.speedclimbingstopwatch 1.0 +import com.itsblue.speedclimbingstopwatch 2.0 import "../components" diff --git a/ScStwSrc/resources/qml/ProfilesDialog/ProfilesStack.qml b/ScStwSrc/resources/qml/ProfilesDialog/ProfilesStack.qml index 59fb0a4..012be83 100644 --- a/ScStwSrc/resources/qml/ProfilesDialog/ProfilesStack.qml +++ b/ScStwSrc/resources/qml/ProfilesDialog/ProfilesStack.qml @@ -21,7 +21,7 @@ import QtQuick.Window 2.2 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 -import com.itsblue.speedclimbingstopwatch 1.0 +import com.itsblue.speedclimbingstopwatch 2.0 import "../components" diff --git a/ScStwSrc/resources/qml/ProfilesDialog/ResultListPage.qml b/ScStwSrc/resources/qml/ProfilesDialog/ResultListPage.qml index 30f5fbd..32e2870 100644 --- a/ScStwSrc/resources/qml/ProfilesDialog/ResultListPage.qml +++ b/ScStwSrc/resources/qml/ProfilesDialog/ResultListPage.qml @@ -21,7 +21,7 @@ import QtQuick.Window 2.2 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 -import com.itsblue.speedclimbingstopwatch 1.0 +import com.itsblue.speedclimbingstopwatch 2.0 import "../components" RemoteDataListView { diff --git a/ScStwSrc/sources/climbingrace.cpp b/ScStwSrc/sources/climbingrace.cpp index 0b326f0..2604099 100644 --- a/ScStwSrc/sources/climbingrace.cpp +++ b/ScStwSrc/sources/climbingrace.cpp @@ -12,18 +12,17 @@ ClimbingRace::ClimbingRace(QObject *parent) : QObject(parent) { - this->state = IDLE; + this->state = ScStw::ScStw::IDLE; this->mode = LOCAL; this->appSettings = new AppSettings(this); - this->scStwClient = new ScStwClient(this); + this->scStwClient = new ScStwClient(); this->scStwClient->setIP(pGlobalAppSettings->loadSetting("baseStationIpAdress")); connect(this->scStwClient, &ScStwClient::stateChanged, this, &ClimbingRace::baseStationStateChanged); connect(this->scStwClient, &ScStwClient::stateChanged, this, &ClimbingRace::refreshMode); - connect(this->scStwClient, &ScStwClient::connectionsChanged, this, &ClimbingRace::baseStationConnectionsChanged); - connect(this->scStwClient, &ScStwClient::gotUpdate, this, &ClimbingRace::handleBaseStationUpdate); - connect(this->scStwClient, &ScStwClient::propertiesChanged, this, &ClimbingRace::baseStationPropertiesChanged); + connect(this->scStwClient, &ScStwClient::gotSignal, this, &ClimbingRace::handleBaseStationSignal); + connect(this, &ClimbingRace::baseStationStateChanged, this, &ClimbingRace::baseStationPropertiesChanged); this->speedTimers.append( new SpeedTimer(this) ); @@ -46,7 +45,7 @@ ClimbingRace::ClimbingRace(QObject *parent) : QObject(parent) int ClimbingRace::startRace() { - if(this->state != IDLE) { + if(this->state != ScStw::IDLE) { return 904; } @@ -58,9 +57,9 @@ int ClimbingRace::startRace() { case LOCAL: { - this->setState(STARTING); + this->setState(ScStw::STARTING); - this->nextStartAction = None; + this->nextStartAction = ScStw::None; this->playSoundsAndStartRace(); returnCode = 200; @@ -90,7 +89,7 @@ int ClimbingRace::startRace() { int ClimbingRace::stopRace(int type) { - if(this->state != RUNNING && this->state != STARTING) { + if(this->state != ScStw::RUNNING && this->state != ScStw::STARTING) { return 904; } @@ -110,13 +109,13 @@ int ClimbingRace::stopRace(int type) { if(type == 1){ this->nextStartActionTimer->stop(); this->player->stop(); - this->nextStartAction = None; + this->nextStartAction = ScStw::None; } returnCode = this->speedTimers[0]->stop(type) ? 200:904; if(returnCode == 200) { - this->setState(STOPPED); + this->setState(ScStw::STOPPED); } break; @@ -141,7 +140,7 @@ int ClimbingRace::stopRace(int type) { int ClimbingRace::resetRace() { - if(this->state != STOPPED) { + if(this->state != ScStw::STOPPED) { return 904; } @@ -156,7 +155,7 @@ int ClimbingRace::resetRace() { returnCode = this->speedTimers[0]->reset() ? 200:904; if(returnCode == 200){ - this->setState(IDLE); + this->setState(ScStw::IDLE); } break; @@ -193,36 +192,35 @@ int ClimbingRace::resetRace() { * * @param data */ -void ClimbingRace::handleBaseStationUpdate(QVariant data) { +void ClimbingRace::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) { //qDebug() << "got update: " << data; - int header = data.toMap()["header"].toInt(); - switch (header) { - case 9000: + switch (key) { + case ScStw::RaceStateChanged: { // the remote race state has changed - this->setState( raceState( data.toMap()["data"].toInt() ) ); + this->setState( ScStw::RaceState( data.toMap()["data"].toInt() ) ); break; } - case 9001: + case ScStw::TimersChanged: { // the remote timers have changed this->refreshRemoteTimers(data.toMap()["data"].toList()); break; } - case 9002: - { - // the extension connections have changed - this->scStwClient->setConnections(data.toMap()["data"].toList()); - break; - } - case 9003: + case ScStw::NextStartActionChanged: { // the next start action has changed this->nextStartActionTotalDelay = data.toMap()["data"].toMap()["nextActionDelay"].toDouble(); this->nextStartActionDelayStartedAt = this->date->currentMSecsSinceEpoch() - (this->nextStartActionTotalDelay * data.toMap()["data"].toMap()["nextActionDelayProg"].toDouble()); - this->nextStartAction = NextStartAction( data.toMap()["data"].toMap()["nextAction"].toInt() ); + this->nextStartAction = ScStw::NextStartAction( data.toMap()["data"].toMap()["nextAction"].toInt() ); emit this->nextStartActionChanged(); + break; + } + case ScStw::ExtensionsChanged: + { + emit this->baseStationConnectionsChanged(); + break; } } @@ -269,60 +267,60 @@ void ClimbingRace::playSoundsAndStartRace() { nextStartActionTimer->disconnect(nextStartActionTimer, SIGNAL(timeout()), this, SLOT(playSoundsAndStartRace())); switch (this->nextStartAction) { - case AtYourMarks: + case ScStw::AtYourMarks: { if(!playSound("qrc:/sounds/at_marks_1.wav")){ return; } if(appSettings->loadSetting("ready_en") == "true"){ - nextStartAction = Ready; + nextStartAction = ScStw::Ready; nextStartActionTimer->setInterval(appSettings->loadSetting("ready_delay").toInt() <= 0 ? 1:appSettings->loadSetting("ready_delay").toInt()); } else{ - nextStartAction = Start; + nextStartAction = ScStw::Start; nextStartActionTimer->setInterval(1); } break; } - case Ready: + case ScStw::Ready: { if(!playSound("qrc:/sounds/ready_1.wav")){ return; } - nextStartAction = Start; + nextStartAction = ScStw::Start; nextStartActionTimer->setInterval(1); break; } - case Start: + case ScStw::Start: { if(!playSound("qrc:/sounds/IFSC_STARTSIGNAL_SINE.wav")){ return; } - nextStartAction = None; + nextStartAction = ScStw::None; nextStartActionTimer->disconnect(nextStartActionTimer, SIGNAL(timeout()), this, SLOT(playSoundsAndStartRace())); - this->setState(RUNNING); + this->setState(ScStw::RUNNING); speedTimers[0]->start(); emit this->nextStartActionChanged(); return; } - case None: + case ScStw::None: { this->speedTimers[0]->setState(SpeedTimer::STARTING); if(appSettings->loadSetting("at_marks_en") == "true"){ - nextStartAction = AtYourMarks; + nextStartAction = ScStw::AtYourMarks; nextStartActionTimer->setInterval(appSettings->loadSetting("at_marks_delay").toInt() <= 0 ? 1:appSettings->loadSetting("at_marks_delay").toInt()); } else if(appSettings->loadSetting("ready_en") == "true"){ - nextStartAction = Ready; + nextStartAction = ScStw::Ready; nextStartActionTimer->setInterval(appSettings->loadSetting("ready_delay").toInt() <= 0 ? 1:appSettings->loadSetting("ready_delay").toInt()); } else{ - nextStartAction = Start; + nextStartAction = ScStw::Start; nextStartActionTimer->setInterval(1); } @@ -362,7 +360,7 @@ bool ClimbingRace::playSound(QString path) { } } -void ClimbingRace::setState(raceState newState) { +void ClimbingRace::setState(ScStw::RaceState newState) { if(newState != this->state) { this->state = newState; @@ -371,8 +369,8 @@ void ClimbingRace::setState(raceState newState) { } void ClimbingRace::refreshMode() { - raceMode newMode; - if(this->scStwClient->getState() == "connected"){ + RaceMode newMode; + if(this->scStwClient->getState() == ScStwClient::CONNECTED){ newMode = REMOTE; } else { @@ -386,7 +384,7 @@ void ClimbingRace::refreshMode() { // reset race // reset state - this->setState(IDLE); + this->setState(ScStw::IDLE); // reset timers // go back to one timer @@ -397,10 +395,6 @@ void ClimbingRace::refreshMode() { this->speedTimers.clear(); this->speedTimers.append(new SpeedTimer); - - // reset base conn - // clear extensions - this->scStwClient->connections.clear(); } this->mode = newMode; @@ -462,7 +456,7 @@ void ClimbingRace::refreshTimerText() { } - /*if (this->mode == REMOTE && this->state == IDLE) { + /*if (this->mode == REMOTE && this->state == ScStw::IDLE) { this->nextStartActionDelayProgress = 0; emit this->nextStartActionDelayProgressChanged(); }*/ @@ -582,31 +576,20 @@ int ClimbingRace::getNextStartAction() { } void ClimbingRace::writeSetting(QString key, QVariant value) { - this->refreshMode(); - - if(this->mode == REMOTE && ( this->remoteSettings.contains(key) || this->remoteOnlySettings.contains(key) ) ){ - this->scStwClient->writeRemoteSetting(key, value.toString()); + if(this->mode == REMOTE && this->remoteSettings.contains(key) ){ + this->scStwClient->writeRemoteSetting(remoteSettings[key], value.toString()); } - else if(!this->remoteOnlySettings.contains(key)){ + else { this->appSettings->writeSetting(key, value); } } QString ClimbingRace::readSetting(QString key) { - this->refreshMode(); - - if(this->mode == REMOTE && ( this->remoteSettings.contains(key) || this->remoteOnlySettings.contains(key) )){ - QVariantMap reply = this->scStwClient->sendCommand(3001, key); - if(reply["status"] != 200){ - return "false"; - } - return reply["data"].toString(); - } - else if(!this->remoteOnlySettings.contains(key)){ - return this->appSettings->loadSetting(key); + if(this->mode == REMOTE && this->remoteSettings.contains(key)){ + return this->scStwClient->readRemoteSetting(this->remoteSettings[key]); } else { - return "false"; + return this->appSettings->loadSetting(key); } } @@ -620,7 +603,17 @@ void ClimbingRace::disconnectBaseStation() { } QString ClimbingRace::getBaseStationState() { - return this->scStwClient->getState(); + switch (this->scStwClient->getState()) { + case ScStwClient::CONNECTED: + return "connected"; + case ScStwClient::CONNECTING: + return "connecting"; + case ScStwClient::DISCONNECTED: + return "disconnected"; + case ScStwClient::INITIALISING: + return "initialising"; + } + return ""; } QVariant ClimbingRace::getBaseStationConnections() { @@ -628,8 +621,8 @@ QVariant ClimbingRace::getBaseStationConnections() { } QVariantMap ClimbingRace::getBaseStationProperties() { - QVariantMap firmware = {{"version", this->scStwClient->firmwareVersion}, {"upToDate", this->scStwClient->firmwareUpToDate}}; - return {{"firmware", firmware}, {"timeOffset", this->scStwClient->timeOffset}}; + QVariantMap firmware = {{"version", this->scStwClient->getFirmwareVersion()}, {"upToDate", this->scStwClient->isFirmwareUpToDate()}}; + return {{"firmware", firmware}, {"timeOffset", this->scStwClient->getTimeOffset()}}; } bool ClimbingRace::updateBasestationFirmware() { @@ -641,7 +634,7 @@ bool ClimbingRace::updateBasestationTime() { } bool ClimbingRace::reloadBaseStationIpAdress() { - if(this->scStwClient->getState() == "disconnected"){ + if(this->scStwClient->getState() == ScStwClient::DISCONNECTED){ this->scStwClient->setIP(pGlobalAppSettings->loadSetting("baseStationIpAdress")); return true; } diff --git a/ScStwSrc/sources/main.cpp b/ScStwSrc/sources/main.cpp index 30d1f21..89170bc 100644 --- a/ScStwSrc/sources/main.cpp +++ b/ScStwSrc/sources/main.cpp @@ -48,40 +48,13 @@ #ifdef Q_OS_ANDROID #include #endif -#include "headers/sqlstoragemodel.h" -#include "headers/sqlprofilemodel.h" + #include "headers/appsettings.h" #include "headers/speedtimer.h" #include "headers/climbingrace.h" #include "headers/apptheme.h" #include -static void connectToDatabase() -{ - QSqlDatabase database = QSqlDatabase::database(); - if (!database.isValid()) { - database = QSqlDatabase::addDatabase("QSQLITE"); - if (!database.isValid()) - qFatal("Cannot add database: %s", qPrintable(database.lastError().text())); - } - - const QDir writeDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - - if (!writeDir.mkpath(".")) - qFatal("Failed to create writable directory at %s", qPrintable(writeDir.absolutePath())); - - // Ensure that we have a writable location on all devices. - const QString fileName = writeDir.absolutePath() + "/chat-database.sqlite3"; - //QFile::remove(fileName); - // When using the SQLite driver, open() will create the SQLite database if it doesn't exist. - database.setDatabaseName(fileName); - if (!database.open()) { - QFile::remove(fileName); - qFatal("Cannot open database: %s", qPrintable(database.lastError().text())); - - } -} - int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -106,14 +79,8 @@ int main(int argc, char *argv[]) }); #endif - connectToDatabase(); - AppSettings * pAppSettings = new AppSettings(); - //setup the sql storage model as a qml model - qmlRegisterType("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlProfileModel"); - qmlRegisterType("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlStorageModel"); - // setup speed backend and App themes qmlRegisterType("com.itsblue.speedclimbingstopwatch", 2, 0, "SpeedBackend"); qmlRegisterType("com.itsblue.speedclimbingstopwatch", 2, 0, "AppTheme"); diff --git a/shared-libraries b/shared-libraries index 5ea1744..b752bde 160000 --- a/shared-libraries +++ b/shared-libraries @@ -1 +1 @@ -Subproject commit 5ea17449e7cb9fceda20b9e78733512d5b2e1575 +Subproject commit b752bdeed25f17b4840b2b215e8695eca4bfa711