From b24ef1ee15a2264644d3326a4517237fbe786c5f Mon Sep 17 00:00:00 2001 From: Luca Date: Mon, 21 Mar 2022 14:41:24 +0100 Subject: [PATCH] Move isValidID to Client --- src/Client.cpp | 4 ++++ src/Client.h | 5 +++++ src/ControllerDetails.cpp | 2 +- src/PilotDetails.cpp | 2 +- src/Settings.cpp | 6 +++--- src/helpers.h | 6 ------ 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Client.cpp b/src/Client.cpp index 4c3736de..97eafcc9 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -106,3 +106,7 @@ const QString Client::name() const { return m_name; } + +bool Client::hasValidID() const { + return Client::isValidID(userId); +} \ No newline at end of file diff --git a/src/Client.h b/src/Client.h index 68a405a5..dc843da1 100644 --- a/src/Client.h +++ b/src/Client.h @@ -37,6 +37,11 @@ class Client: public MapObject { int rating; + static bool isValidID(const QString id) { + return !id.isEmpty() && id.toInt() >= 800000; + }; + bool hasValidID() const; + protected: QString m_name; }; diff --git a/src/ControllerDetails.cpp b/src/ControllerDetails.cpp index 24dd48f5..0920ffa3 100644 --- a/src/ControllerDetails.cpp +++ b/src/ControllerDetails.cpp @@ -92,7 +92,7 @@ void ControllerDetails::refresh(Controller *newController) { buttonAddFriend->setText("add &friend"); // check if we know UserId - bool invalidID = !isValidID(_controller->userId); + bool invalidID = !(_controller->hasValidID()); buttonAddFriend->setDisabled(invalidID); pbAlias->setDisabled(invalidID); diff --git a/src/PilotDetails.cpp b/src/PilotDetails.cpp index cfe4a3e0..48c868cb 100644 --- a/src/PilotDetails.cpp +++ b/src/PilotDetails.cpp @@ -101,7 +101,7 @@ void PilotDetails::refresh(Pilot *pilot) { lblRemarks->setText(QString("%1").arg(_pilot->planRemarks)); // check if we know userId - bool invalidID = !isValidID(_pilot->userId); + bool invalidID = !(_pilot->hasValidID()); buttonAddFriend->setDisabled(invalidID); pbAlias->setDisabled(invalidID); buttonAddFriend->setText(_pilot->isFriend()? "remove &friend": "add &friend"); diff --git a/src/Settings.cpp b/src/Settings.cpp index a8c4ffcc..8c77bc37 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -10,7 +10,7 @@ #include "PilotDetails.h" #include "ControllerDetails.h" #include "AirportDetails.h" -#include "helpers.h" +#include "Client.h" QSettings *settingsInstance = 0; QSettings* Settings::instance() { @@ -37,7 +37,7 @@ QSettings* Settings::instance() { foreach(auto key, keys) { if(key.startsWith("alias_")) { QString id = key.mid(6); - if(!isValidID(id)) { + if(!Client::isValidID(id)) { settingsInstance->remove(key); qDebug() << "Found an alias for (invalid) client " << id << " and removed it. For more information see https://github.com/qutescoop/qutescoop/issues/130"; } @@ -46,7 +46,7 @@ QSettings* Settings::instance() { settingsInstance->endGroup(); QStringList friendList = settingsInstance->value("friends/friendList", QStringList()).toStringList(); foreach(auto friendID, friendList) { - if(!isValidID(friendID)) { + if(!Client::isValidID(friendID)) { friendList.removeAt(friendList.indexOf(friendID)); qDebug() << "Found a friend list entry for (invalid) client " << friendID << " and removed it. For more information see https://github.com/qutescoop/qutescoop/issues/130"; } diff --git a/src/helpers.h b/src/helpers.h index 7d82edcc..a1d20019 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -21,12 +21,6 @@ static float lerp(float v0, float v1, float t) { return v0 + t * (v1 - v0); } -static bool isValidID(QString id) { - if(id.isEmpty()) return false; - int iid = id.toInt(); - return iid >= 800000; -} - /* mathematical constants */ const double Pi180 = M_PI / 180.;