7#include <QRegularExpression>
8#include <QRegularExpressionMatch>
9#include <QStringBuilder>
21using namespace swift::misc::aviation;
25namespace swift::misc::network
32 this->deriveHomeBaseFromCallsign();
41 this->deriveHomeBaseFromCallsign();
73 if (m_callsign == callsign)
77 m_callsign = callsign;
78 this->deriveHomeBaseFromCallsign();
85 if (m_realname.isEmpty())
return QStringLiteral(
"<no realname>");
89 s += u
" (" % m_id % u
')';
98 void CUser::deriveHomeBaseFromCallsign()
180 if (m_id.length() > 6)
185 static const QString zeros(
"0000000");
186 return zeros.
left(7 - m_id.length()) % m_id;
213 if (
this == &otherUser)
237 if (
this == &otherUser)
255 const int i =
id.toInt();
256 return i >= 100000 && i <= 9999999;
274 for (
const QChar &ch : realName)
279 if (uc > 1 && lc > 2 && lc > uc)
296 newRealName = newRealName.
toLower();
298 bool upperNextChar =
true;
299 while (i != newRealName.
end())
301 if (i->isSpace() || *i ==
'-')
303 upperNextChar =
true;
305 else if (upperNextChar)
307 const QChar u(i->toUpper());
309 upperNextChar =
false;
325 case IndexEmail:
return { m_email };
326 case IndexId:
return { m_id };
327 case IndexId7Digit:
return { this->
get7DigitId() };
329 case IndexPassword:
return { m_password };
330 case IndexRealName:
return { m_realname };
331 case IndexHomebase:
return m_homebase.propertyByIndex(index.
copyFrontRemoved());
332 case IndexCallsign:
return m_callsign.propertyByIndex(index.
copyFrontRemoved());
353 case IndexHomebase: m_homebase.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
354 case IndexCallsign: m_callsign.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
377 case IndexPassword:
break;
380 Q_ASSERT_X(
false, Q_FUNC_INFO,
"compare failed");
Utility class to obfuscate strings in the source code to make them unreadable.
static QString decode(const QString &inString, bool trimmed=true)
Decode string if it has the prefix, otherwise do nothing with it.
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
void push_back(const T &value)
Appends an element at the end of the sequence.
Streamable status message, e.g.
static constexpr auto SeverityWarning
Status severities.
Status messages, e.g. from Core -> GUI.
Value object encapsulating information of airport ICAO data.
bool isEmpty() const
Is empty?
const QString & asString() const
Get code.
Value object encapsulating information of a callsign.
bool isObserverCallsign() const
Observer callsign?
const QString & getStringAsSet() const
Get callsign.
bool isEmpty() const
Is empty?
QString getIcaoCode() const
Get ICAO code, if this makes sense (EDDF_TWR -> EDDF).
bool isAtcCallsign() const
ATC callsign.
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
bool hasValidOrEmptyHomeBase() const
Has valid or empty home base?
bool hasRealName() const
Valid real name?
bool hasNumericId() const
Has a numeric id?
bool hasValidHomeBase() const
Has valid home base?
int getIntegerId() const
Id as integer if possible, otherwise -1.
static QString beautifyRealName(const QString &realName)
Beautify real name, e.g. "JOE DoE" -> "Joe Doe";.
void setRealName(const QString &realname)
Set real name.
QString getRealNameAndId() const
Real name and id.
ColumnIndex
Properties by index.
bool hasValidEmail() const
Valid email?
int comparePropertyByIndex(CPropertyIndexRef index, const CUser &compareValue) const
Compare for index.
QString get7DigitId() const
Numeric ids get a leading zeros if required.
const QString & getId() const
Get id.
void setId(const QString &id)
Set id.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setHomeBase(const aviation::CAirportIcaoCode &homebase)
Set homebase.
CUser()=default
Default constructor.
const QString & getEmail() const
Get email.
void setEmail(const QString &email)
Set email.
bool hasId() const
Valid id?
bool hasHomeBase() const
Has home base?
bool setCallsign(const aviation::CCallsign &callsign)
Set associated callsign.
void setPassword(const QString &pw)
Set password.
const QString & getRealName() const
Get full name.
const aviation::CCallsign & getCallsign() const
Get associated callsign.
CStatusMessageList validate() const
Validate, provide details about issues.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QString convertToQString(bool i18n=false) const
Cast as QString.
bool hasCredentials() const
Valid credentials?
static bool isValidVatsimId(const QString &id)
Valid VATSIM id.
QString getRealNameAndHomeBase(const QString &separator=QString(" ")) const
Real name + homebase.
const aviation::CAirportIcaoCode & getHomeBase() const
Homebase.
void synchronizeData(CUser &otherUser)
This and another user exchange missing data, This user has priority and overrides first.
bool hasCallsign() const
Has associated callsign?
void updateMissingParts(const CUser &otherUser)
Update missing parts in this object.
int compare(T a, T b)
Compare arithmetic values.
bool is09OnlyString(const QString &testString)
String with 0-9 only.
SWIFT_MISC_EXPORT QString simplifyAccents(const QString &candidate)
Remove accents / diacritic marks from a string.
QRegularExpressionMatch match(QStringView subjectView, qsizetype offset, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions) const const
QString captured(QAnyStringView name) const const
qsizetype capturedStart(QAnyStringView name) const const
bool hasMatch() const const
QString::iterator begin()
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool isEmpty() const const
QString left(qsizetype n) &&
QString number(double n, char format, int precision)
QString right(qsizetype n) &&
QString simplified() const const
QString toLower() const const
QString trimmed() const const
QStringView left(qsizetype length) const const
QString toString() const const
QStringView trimmed() const const
QVariant fromValue(T &&value)
int toInt(bool *ok) const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.