swift
user.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_NETWORK_USER_H
7 #define SWIFT_MISC_NETWORK_USER_H
8 
9 #include <QMetaType>
10 #include <QString>
11 
13 #include "misc/aviation/callsign.h"
14 #include "misc/metaclass.h"
15 #include "misc/propertyindexref.h"
16 #include "misc/statusmessagelist.h"
17 #include "misc/swiftmiscexport.h"
18 #include "misc/valueobject.h"
19 
20 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::network, CUser)
21 
22 namespace swift::misc::network
23 {
27  class SWIFT_MISC_EXPORT CUser : public CValueObject<CUser>
28  {
29  public:
34  {
35  IndexEmail = CPropertyIndexRef::GlobalIndexCUser,
36  IndexId,
37  IndexIdInteger,
38  IndexId7Digit,
39  IndexPassword,
40  IndexRealName,
41  IndexCallsign,
42  IndexHomebase
43  };
44 
46  CUser() = default;
47 
49  CUser(const aviation::CCallsign &callsign);
50 
52  CUser(const QString &id, const QString &realname, const aviation::CCallsign &callsign);
53 
55  CUser(const QString &id, const QString &realname, const QString &email = "", const QString &password = "",
56  const aviation::CCallsign &callsign = {});
57 
59  const QString &getRealName() const { return m_realname; }
60 
62  void setRealName(const QString &realname);
63 
65  const QString &getPassword() const { return m_password; }
66 
68  void setPassword(const QString &pw);
69 
71  bool isValid() const { return !isNull(); }
72 
74  bool isNull() const { return m_realname.isEmpty() && m_id.isEmpty(); }
75 
77  bool hasCredentials() const { return this->isValid() && !m_password.isEmpty(); }
78 
80  bool hasRealName() const { return !m_realname.isEmpty(); }
81 
83  bool hasId() const { return !m_id.isEmpty(); }
84 
86  bool hasValidVatsimId() const { return CUser::isValidVatsimId(this->getId()); }
87 
89  bool hasCallsign() const { return !m_callsign.isEmpty(); }
90 
92  bool hasHomeBase() const { return !m_homebase.isEmpty(); }
93 
95  bool hasValidHomeBase() const;
96 
98  bool hasValidOrEmptyHomeBase() const;
99 
101  QString getRealNameAndHomeBase(const QString &separator = QString(" ")) const;
102 
104  QString getRealNameAndId() const;
105 
107  CStatusMessageList validate() const;
108 
110  const QString &getEmail() const { return m_email; }
111 
113  void setEmail(const QString &email);
114 
116  bool hasValidEmail() const { return !m_email.isEmpty(); }
117 
119  const QString &getId() const { return m_id; }
120 
122  QString get7DigitId() const;
123 
125  int getIntegerId() const;
126 
128  bool hasNumericId() const;
129 
131  void setId(const QString &id);
132 
134  const aviation::CAirportIcaoCode &getHomeBase() const { return m_homebase; }
135 
137  void setHomeBase(const aviation::CAirportIcaoCode &homebase) { m_homebase = homebase; }
138 
140  const aviation::CCallsign &getCallsign() const { return m_callsign; }
141 
143  bool setCallsign(const aviation::CCallsign &callsign);
144 
146  CIcons::IconIndex toIcon() const { return this->getCallsign().toIcon(); }
147 
149  QVariant propertyByIndex(CPropertyIndexRef index) const;
150 
152  void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant);
153 
155  int comparePropertyByIndex(CPropertyIndexRef index, const CUser &compareValue) const;
156 
158  void synchronizeData(CUser &otherUser);
159 
161  void updateMissingParts(const CUser &otherUser);
162 
164  static bool isValidVatsimId(const QString &id);
165 
167  static QString beautifyRealName(const QString &realName);
168 
170  QString convertToQString(bool i18n = false) const;
171 
172  private:
174  void deriveHomeBaseFromCallsign();
175 
176  QString m_id;
177  QString m_realname;
178  QString m_email;
179  QString m_password;
180  aviation::CCallsign m_callsign;
181  aviation::CAirportIcaoCode m_homebase;
182 
184  CUser,
185  SWIFT_METAMEMBER(id),
186  SWIFT_METAMEMBER(realname),
187  SWIFT_METAMEMBER(email),
188  SWIFT_METAMEMBER(password),
189  SWIFT_METAMEMBER(callsign),
190  SWIFT_METAMEMBER(homebase));
191  };
192 } // namespace swift::misc::network
193 
194 Q_DECLARE_METATYPE(swift::misc::network::CUser)
195 
196 #endif // SWIFT_MISC_NETWORK_USER_H
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition: icons.h:32
Non-owning reference to a CPropertyIndex with a subset of its features.
Status messages, e.g. from Core -> GUI.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Value object encapsulating information of airport ICAO data.
Value object encapsulating information of a callsign.
Definition: callsign.h:30
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
Value object encapsulating information of a user.
Definition: user.h:28
const aviation::CAirportIcaoCode & getHomeBase() const
Homebase.
Definition: user.h:134
const QString & getPassword() const
Get password.
Definition: user.h:65
bool hasRealName() const
Valid real name?
Definition: user.h:80
const QString & getRealName() const
Get full name.
Definition: user.h:59
bool isValid() const
Valid user object?
Definition: user.h:71
bool hasValidEmail() const
Valid email?
Definition: user.h:116
bool isNull() const
Null?
Definition: user.h:74
const QString & getId() const
Get id.
Definition: user.h:119
const aviation::CCallsign & getCallsign() const
Get associated callsign.
Definition: user.h:140
void setHomeBase(const aviation::CAirportIcaoCode &homebase)
Set homebase.
Definition: user.h:137
CUser()=default
Default constructor.
bool hasId() const
Valid id?
Definition: user.h:83
bool hasHomeBase() const
Has home base?
Definition: user.h:92
CIcons::IconIndex toIcon() const
As icon, not implemented by all classes.
Definition: user.h:146
bool hasValidVatsimId() const
Has a valid VATSIM id?
Definition: user.h:86
const QString & getEmail() const
Get email.
Definition: user.h:110
bool hasCredentials() const
Valid credentials?
Definition: user.h:77
static bool isValidVatsimId(const QString &id)
Valid VATSIM id.
Definition: user.cpp:185
bool hasCallsign() const
Has associated callsign?
Definition: user.h:89
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65