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();
36 CUser::CUser(
const QString &
id,
const QString &realname,
const QString &email,
const QString &password,
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>");
74 QString s = m_realname;
75 if (this->
hasId()) { s += u
" (" % m_id % u
')'; }
80 void CUser::deriveHomeBaseFromCallsign()
82 if (m_callsign.
isEmpty()) {
return; }
112 thread_local QRegularExpression tsRegex(
"(-\\s*|\\s)([A-Z]{4})$");
113 const QRegularExpressionMatch match = tsRegex.match(rn);
114 if (match.hasMatch())
116 const int pos = match.capturedStart(0);
117 const QString icao = match.captured(0).trimmed().right(4);
118 rn = QStringView { rn }.left(pos).trimmed().toString();
150 if (m_id.length() > 6) {
return m_id; }
152 static const QString zeros(
"0000000");
153 return zeros.left(7 - m_id.length()) % m_id;
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;
195 QString newRealName(realName.simplified().trimmed());
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();
225 QString::Iterator i = newRealName.begin();
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;
243 if (index.
isMyself()) {
return QVariant::fromValue(*
this); }
247 case IndexEmail:
return QVariant(m_email);
248 case IndexId:
return QVariant(m_id);
249 case IndexId7Digit:
return QVariant(this->
get7DigitId());
250 case IndexIdInteger:
return QVariant::fromValue(this->
getIntegerId());
251 case IndexPassword:
return QVariant(m_password);
252 case IndexRealName:
return QVariant(m_realname);
263 (*this) = variant.value<
CUser>();
269 case IndexEmail: this->
setEmail(variant.value<QString>());
break;
271 case IndexId7Digit: this->
setId(variant.value<QString>());
break;
272 case IndexIdInteger: this->
setId(QString::number(variant.toInt()));
break;
273 case IndexPassword: this->
setPassword(variant.value<QString>());
break;
274 case IndexRealName: this->
setRealName(variant.value<QString>());
break;
287 case IndexEmail:
return m_email.compare(compareValue.
getEmail(), Qt::CaseInsensitive);
288 case IndexId:
return m_id.compare(compareValue.
getId(), Qt::CaseInsensitive);
291 case IndexRealName:
return m_realname.compare(compareValue.
getRealName(), Qt::CaseInsensitive);
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.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.