mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T215, some adjustments of user object
* remove "valid" from some functions, because no validity is checked * homebase + real name string
This commit is contained in:
@@ -35,7 +35,7 @@ namespace BlackMisc
|
||||
|
||||
bool CClient::isValid() const
|
||||
{
|
||||
return m_user.hasValidCallsign();
|
||||
return m_user.hasCallsign();
|
||||
}
|
||||
|
||||
void CClient::setCapability(bool hasCapability, CClient::Capabilities capability)
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <QThreadStorage>
|
||||
#include <Qt>
|
||||
#include <QtGlobal>
|
||||
#include <QStringBuilder>
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
@@ -47,6 +48,13 @@ namespace BlackMisc
|
||||
this->setRealName(realname); // extracts homebase
|
||||
}
|
||||
|
||||
QString CUser::getRealNameAndHomeBase(const QString &separator) const
|
||||
{
|
||||
if (!this->hasHomeBase()) { return this->getRealName(); }
|
||||
if (!this->hasRealName()) { return this->getHomeBase().asString(); }
|
||||
return this->getRealName() % separator % this->getHomeBase().asString();
|
||||
}
|
||||
|
||||
void CUser::setCallsign(const CCallsign &callsign)
|
||||
{
|
||||
m_callsign = callsign;
|
||||
@@ -58,13 +66,13 @@ namespace BlackMisc
|
||||
Q_UNUSED(i18n);
|
||||
if (m_realname.isEmpty()) return "<no realname>";
|
||||
QString s = m_realname;
|
||||
if (this->hasValidId())
|
||||
if (this->hasId())
|
||||
{
|
||||
s.append(" (").append(m_id).append(')');
|
||||
s += QStringLiteral(" (") % m_id % QStringLiteral(")");
|
||||
}
|
||||
if (this->hasValidCallsign())
|
||||
if (this->hasCallsign())
|
||||
{
|
||||
s.append(' ').append(this->getCallsign().getStringAsSet());
|
||||
s += QStringLiteral(" ") % this->getCallsign().getStringAsSet();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -86,11 +94,11 @@ namespace BlackMisc
|
||||
QString rn(removeAccents(realname.trimmed().simplified()));
|
||||
if (rn.isEmpty())
|
||||
{
|
||||
m_realname = "";
|
||||
m_realname.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->hasValidHomebase())
|
||||
if (!this->hasHomeBase())
|
||||
{
|
||||
// only apply stripping if home base is not explicitly given
|
||||
// try to strip homebase: I understand the limitations, but we will have more correct hits as failures I assume
|
||||
@@ -115,8 +123,8 @@ namespace BlackMisc
|
||||
{
|
||||
CStatusMessageList msgs;
|
||||
// callsign optional
|
||||
if (!this->hasValidId()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid id"));}
|
||||
if (!this->hasValidRealName()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid real name"));}
|
||||
if (!this->hasId()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid id"));}
|
||||
if (!this->hasRealName()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid real name"));}
|
||||
if (!this->hasValidCredentials()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid credentials"));}
|
||||
return msgs;
|
||||
}
|
||||
@@ -124,10 +132,10 @@ namespace BlackMisc
|
||||
void CUser::updateMissingParts(const CUser &otherUser)
|
||||
{
|
||||
if (this == &otherUser) { return; }
|
||||
if (!this->hasValidRealName()) { this->setRealName(otherUser.getRealName()); }
|
||||
if (!this->hasValidId()) { this->setId(otherUser.getId()); }
|
||||
if (!this->hasRealName()) { this->setRealName(otherUser.getRealName()); }
|
||||
if (!this->hasId()) { this->setId(otherUser.getId()); }
|
||||
if (!this->hasValidEmail()) { this->setEmail(otherUser.getEmail()); }
|
||||
if (!this->hasValidCallsign()) { this->setCallsign(otherUser.getCallsign()); }
|
||||
if (!this->hasCallsign()) { this->setCallsign(otherUser.getCallsign()); }
|
||||
}
|
||||
|
||||
void CUser::synchronizeData(CUser &otherUser)
|
||||
@@ -141,7 +149,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (id.isEmpty()) { return false; }
|
||||
bool ok;
|
||||
int i = id.toInt(&ok);
|
||||
const int i = id.toInt(&ok);
|
||||
if (!ok) { return false; }
|
||||
return i >= 100000 && i <= 9999999;
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ namespace BlackMisc
|
||||
CUser(const QString &id, const QString &realname, const QString &email = "", const QString &password = "", const Aviation::CCallsign &callsign = {});
|
||||
|
||||
//! Get full name.
|
||||
QString getRealName() const { return m_realname; }
|
||||
const QString &getRealName() const { return m_realname; }
|
||||
|
||||
//! setRealName
|
||||
//! Set real name
|
||||
void setRealName(const QString &realname);
|
||||
|
||||
//! Get password
|
||||
QString getPassword() const { return m_password; }
|
||||
const QString &getPassword() const { return m_password; }
|
||||
|
||||
//! Set password
|
||||
void setPassword(const QString &pw) { m_password = pw.trimmed(); }
|
||||
@@ -79,22 +79,25 @@ namespace BlackMisc
|
||||
bool hasValidCredentials() const { return this->isValid() && !m_password.isEmpty(); }
|
||||
|
||||
//! Valid real name?
|
||||
bool hasValidRealName() const { return !m_realname.isEmpty(); }
|
||||
bool hasRealName() const { return !m_realname.isEmpty(); }
|
||||
|
||||
//! Valid id?
|
||||
bool hasValidId() const { return !m_id.isEmpty(); }
|
||||
bool hasId() const { return !m_id.isEmpty(); }
|
||||
|
||||
//! Has associated callsign?
|
||||
bool hasValidCallsign() const { return !m_callsign.isEmpty(); }
|
||||
bool hasCallsign() const { return !m_callsign.isEmpty(); }
|
||||
|
||||
//! Valid homebase
|
||||
bool hasValidHomebase() const { return !m_homebase.isEmpty(); }
|
||||
//! Has home base?
|
||||
bool hasHomeBase() const { return !m_homebase.isEmpty(); }
|
||||
|
||||
//! Real name + homebase
|
||||
QString getRealNameAndHomeBase(const QString &separator = QString(" ")) const;
|
||||
|
||||
//! Validate, provide details about issues
|
||||
CStatusMessageList validate() const;
|
||||
|
||||
//! Get email.
|
||||
QString getEmail() const { return m_email; }
|
||||
const QString &getEmail() const { return m_email; }
|
||||
|
||||
//! Set email.
|
||||
void setEmail(const QString &email) { m_email = email.trimmed(); }
|
||||
@@ -103,7 +106,7 @@ namespace BlackMisc
|
||||
bool hasValidEmail() const { return !m_email.isEmpty(); }
|
||||
|
||||
//! Get id.
|
||||
QString getId() const { return m_id; }
|
||||
const QString &getId() const { return m_id; }
|
||||
|
||||
//! Set id
|
||||
void setId(const QString &id) { m_id = id.trimmed(); }
|
||||
@@ -114,9 +117,6 @@ namespace BlackMisc
|
||||
//! Set homebase
|
||||
void setHomeBase(const Aviation::CAirportIcaoCode &homebase) { m_homebase = homebase; }
|
||||
|
||||
//! Has home base?
|
||||
bool hasHomeBase() const { return !m_homebase.isEmpty(); }
|
||||
|
||||
//! Get associated callsign.
|
||||
const Aviation::CCallsign &getCallsign() const { return m_callsign; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user