7 #include <QRegularExpression>
8 #include <QRegularExpressionMatch>
9 #include <QStringBuilder>
21 using namespace swift::misc::aviation;
25 namespace swift::misc::network
27 CUser::CUser(
const CCallsign &callsign) : m_callsign(callsign) { this->deriveHomeBaseFromCallsign(); }
32 this->deriveHomeBaseFromCallsign();
41 this->deriveHomeBaseFromCallsign();
64 if (m_callsign == callsign) {
return false; }
65 m_callsign = callsign;
66 this->deriveHomeBaseFromCallsign();
73 if (m_realname.
isEmpty())
return QStringLiteral(
"<no realname>");
75 if (this->
hasId()) { s += u
" (" % m_id % u
')'; }
80 void CUser::deriveHomeBaseFromCallsign()
82 if (m_callsign.
isEmpty()) {
return; }
150 if (m_id.
length() > 6) {
return m_id; }
152 static const QString zeros(
"0000000");
158 if (m_id.
isEmpty()) {
return -1; }
165 if (m_id.
isEmpty()) {
return false; }
171 if (
this == &otherUser) {
return; }
180 if (
this == &otherUser) {
return; }
187 if (
id.isEmpty()) {
return false; }
189 const int i =
id.toInt();
190 return i >= 100000 && i <= 9999999;
196 if (newRealName.
isEmpty()) {
return newRealName; }
205 for (
const QChar &ch : realName)
210 if (uc > 1 && lc > 2 && lc > uc) {
return newRealName; }
224 newRealName = newRealName.
toLower();
226 bool upperNextChar =
true;
227 while (i != newRealName.
end())
229 if (i->isSpace() || *i ==
'-') { upperNextChar =
true; }
230 else if (upperNextChar)
232 const QChar u(i->toUpper());
234 upperNextChar =
false;
247 case IndexEmail:
return QVariant(m_email);
248 case IndexId:
return QVariant(m_id);
251 case IndexPassword:
return QVariant(m_password);
252 case IndexRealName:
return QVariant(m_realname);
296 case IndexPassword:
break;
299 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.
constexpr static auto SeverityWarning
Status severities.
Status messages, e.g. from Core -> GUI.
Value object encapsulating information of airport ICAO data.
int comparePropertyByIndex(CPropertyIndexRef index, const CAirportIcaoCode &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 isEmpty() const
Is empty?
bool hasValidIcaoCode(bool strict) const
Has valid code?
const QString & asString() const
Get code.
Value object encapsulating information of a callsign.
int comparePropertyByIndex(CPropertyIndexRef index, const CCallsign &compareValue) const
Compare for index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool isObserverCallsign() const
Observer callsign?
bool isEmpty() const
Is empty?
QString getIcaoCode() const
Get ICAO code, if this makes sense (EDDF_TWR -> EDDF)
bool isAtcCallsign() const
ATC callsign.
const QString & getStringAsSet() const
Get callsign.
ColumnIndex
Base class enums.
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.
Value object encapsulating information of a user.
const aviation::CAirportIcaoCode & getHomeBase() const
Homebase.
bool hasValidOrEmptyHomeBase() const
Has valid or empty home base?
bool hasRealName() const
Valid real name?
const QString & getRealName() const
Get full 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.
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.
void setId(const QString &id)
Set id.
const QString & getId() const
Get id.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
const aviation::CCallsign & getCallsign() const
Get associated callsign.
void setHomeBase(const aviation::CAirportIcaoCode &homebase)
Set homebase.
CUser()=default
Default constructor.
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.
CStatusMessageList validate() const
Validate, provide details about issues.
const QString & getEmail() const
Get email.
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.
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.
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.
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) &&
qsizetype length() const const
QString number(double n, char format, int precision)
QString right(qsizetype n) &&
QString simplified() const const
int toInt(bool *ok, int base) const const
QString toLower() const const
QString 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.