Skip to content

Commit

Permalink
Move isValidID to Client
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca0208 committed Mar 21, 2022
1 parent 420ecda commit b24ef1e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ const QString Client::name() const
{
return m_name;
}

bool Client::hasValidID() const {
return Client::isValidID(userId);
}
5 changes: 5 additions & 0 deletions src/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/ControllerDetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/PilotDetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void PilotDetails::refresh(Pilot *pilot) {
lblRemarks->setText(QString("<code>%1</code>").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");
Expand Down
6 changes: 3 additions & 3 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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";
}
Expand All @@ -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";
}
Expand Down
6 changes: 0 additions & 6 deletions src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.;

Expand Down

0 comments on commit b24ef1e

Please sign in to comment.