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:
Klaus Basan
2018-01-03 20:13:47 +01:00
parent b2c0d726bc
commit 2fb7bde447
10 changed files with 45 additions and 37 deletions

View File

@@ -193,7 +193,7 @@ namespace BlackGui
if (m_flightPlan.wasSentOrLoaded()) { return; } if (m_flightPlan.wasSentOrLoaded()) { return; }
// only override with valid values // only override with valid values
if (user.hasValidRealName()) if (user.hasRealName())
{ {
ui->le_PilotsName->setText(user.getRealName()); ui->le_PilotsName->setText(user.getRealName());
} }
@@ -201,7 +201,7 @@ namespace BlackGui
{ {
ui->le_PilotsHomeBase->setText(user.getHomeBase().getIcaoCode()); ui->le_PilotsHomeBase->setText(user.getHomeBase().getIcaoCode());
} }
if (user.hasValidCallsign()) if (user.hasCallsign())
{ {
ui->le_Callsign->setText(user.getCallsign().asString()); ui->le_Callsign->setText(user.getCallsign().asString());
} }

View File

@@ -351,7 +351,7 @@ namespace BlackGui
{ {
const CServer lastServer = m_lastVatsimServer.get(); const CServer lastServer = m_lastVatsimServer.get();
const CUser lastUser = lastServer.getUser(); const CUser lastUser = lastServer.getUser();
if (lastUser.hasValidCallsign()) if (lastUser.hasCallsign())
{ {
ui->le_Callsign->setText(lastUser.getCallsign().asString()); ui->le_Callsign->setText(lastUser.getCallsign().asString());
ui->le_VatsimId->setText(lastUser.getId()); ui->le_VatsimId->setText(lastUser.getId());

View File

@@ -110,7 +110,7 @@ namespace BlackGui
aircraft.getAircraftIcaoCode().toQString(false) % aircraft.getAircraftIcaoCode().toQString(false) %
QLatin1String(")"); QLatin1String(")");
} }
if (aircraft.hasValidRealName()) if (aircraft.hasRealName())
{ {
i += QLatin1String(" - ") % aircraft.getPilotRealName(); i += QLatin1String(" - ") % aircraft.getPilotRealName();
} }

View File

@@ -49,7 +49,7 @@ namespace BlackMisc
{ {
// sync callsigns // sync callsigns
m_callsign.setTypeHint(CCallsign::Atc); m_callsign.setTypeHint(CCallsign::Atc);
if (!m_controller.hasValidCallsign() && !callsign.isEmpty()) if (!m_controller.hasCallsign() && !callsign.isEmpty())
{ {
m_controller.setCallsign(m_callsign); m_controller.setCallsign(m_callsign);
} }

View File

@@ -117,13 +117,13 @@ namespace BlackMisc
void setControllerId(const QString &controllerId) { m_controller.setId(controllerId); } void setControllerId(const QString &controllerId) { m_controller.setId(controllerId); }
//! Has valid realname? //! Has valid realname?
bool hasValidRealName() const { return m_controller.hasValidRealName(); } bool hasRealName() const { return m_controller.hasRealName(); }
//! Has valid id? //! Has valid id?
bool hasValidId() const { return m_controller.hasValidId(); } bool hasId() const { return m_controller.hasId(); }
//! Valid COM frequency //! Valid COM frequency
bool hasValidFrequency() const { return BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->getFrequency()); } bool hasValidFrequency() const { return CComSystem::isValidCivilAviationFrequency(this->getFrequency()); }
//! Get frequency. //! Get frequency.
const PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; } const PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; }

View File

@@ -35,7 +35,7 @@ namespace BlackMisc
bool CClient::isValid() const bool CClient::isValid() const
{ {
return m_user.hasValidCallsign(); return m_user.hasCallsign();
} }
void CClient::setCapability(bool hasCapability, CClient::Capabilities capability) void CClient::setCapability(bool hasCapability, CClient::Capabilities capability)

View File

@@ -20,6 +20,7 @@
#include <QThreadStorage> #include <QThreadStorage>
#include <Qt> #include <Qt>
#include <QtGlobal> #include <QtGlobal>
#include <QStringBuilder>
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
@@ -47,6 +48,13 @@ namespace BlackMisc
this->setRealName(realname); // extracts homebase 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) void CUser::setCallsign(const CCallsign &callsign)
{ {
m_callsign = callsign; m_callsign = callsign;
@@ -58,13 +66,13 @@ namespace BlackMisc
Q_UNUSED(i18n); Q_UNUSED(i18n);
if (m_realname.isEmpty()) return "<no realname>"; if (m_realname.isEmpty()) return "<no realname>";
QString s = m_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; return s;
} }
@@ -86,11 +94,11 @@ namespace BlackMisc
QString rn(removeAccents(realname.trimmed().simplified())); QString rn(removeAccents(realname.trimmed().simplified()));
if (rn.isEmpty()) if (rn.isEmpty())
{ {
m_realname = ""; m_realname.clear();
return; return;
} }
if (!this->hasValidHomebase()) if (!this->hasHomeBase())
{ {
// only apply stripping if home base is not explicitly given // 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 // 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; CStatusMessageList msgs;
// callsign optional // callsign optional
if (!this->hasValidId()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid id"));} if (!this->hasId()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid id"));}
if (!this->hasValidRealName()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid real name"));} if (!this->hasRealName()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid real name"));}
if (!this->hasValidCredentials()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid credentials"));} if (!this->hasValidCredentials()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid credentials"));}
return msgs; return msgs;
} }
@@ -124,10 +132,10 @@ namespace BlackMisc
void CUser::updateMissingParts(const CUser &otherUser) void CUser::updateMissingParts(const CUser &otherUser)
{ {
if (this == &otherUser) { return; } if (this == &otherUser) { return; }
if (!this->hasValidRealName()) { this->setRealName(otherUser.getRealName()); } if (!this->hasRealName()) { this->setRealName(otherUser.getRealName()); }
if (!this->hasValidId()) { this->setId(otherUser.getId()); } if (!this->hasId()) { this->setId(otherUser.getId()); }
if (!this->hasValidEmail()) { this->setEmail(otherUser.getEmail()); } 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) void CUser::synchronizeData(CUser &otherUser)
@@ -141,7 +149,7 @@ namespace BlackMisc
{ {
if (id.isEmpty()) { return false; } if (id.isEmpty()) { return false; }
bool ok; bool ok;
int i = id.toInt(&ok); const int i = id.toInt(&ok);
if (!ok) { return false; } if (!ok) { return false; }
return i >= 100000 && i <= 9999999; return i >= 100000 && i <= 9999999;
} }

View File

@@ -61,13 +61,13 @@ namespace BlackMisc
CUser(const QString &id, const QString &realname, const QString &email = "", const QString &password = "", const Aviation::CCallsign &callsign = {}); CUser(const QString &id, const QString &realname, const QString &email = "", const QString &password = "", const Aviation::CCallsign &callsign = {});
//! Get full name. //! 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); void setRealName(const QString &realname);
//! Get password //! Get password
QString getPassword() const { return m_password; } const QString &getPassword() const { return m_password; }
//! Set password //! Set password
void setPassword(const QString &pw) { m_password = pw.trimmed(); } void setPassword(const QString &pw) { m_password = pw.trimmed(); }
@@ -79,22 +79,25 @@ namespace BlackMisc
bool hasValidCredentials() const { return this->isValid() && !m_password.isEmpty(); } bool hasValidCredentials() const { return this->isValid() && !m_password.isEmpty(); }
//! Valid real name? //! Valid real name?
bool hasValidRealName() const { return !m_realname.isEmpty(); } bool hasRealName() const { return !m_realname.isEmpty(); }
//! Valid id? //! Valid id?
bool hasValidId() const { return !m_id.isEmpty(); } bool hasId() const { return !m_id.isEmpty(); }
//! Has associated callsign? //! Has associated callsign?
bool hasValidCallsign() const { return !m_callsign.isEmpty(); } bool hasCallsign() const { return !m_callsign.isEmpty(); }
//! Valid homebase //! Has home base?
bool hasValidHomebase() const { return !m_homebase.isEmpty(); } bool hasHomeBase() const { return !m_homebase.isEmpty(); }
//! Real name + homebase
QString getRealNameAndHomeBase(const QString &separator = QString(" ")) const;
//! Validate, provide details about issues //! Validate, provide details about issues
CStatusMessageList validate() const; CStatusMessageList validate() const;
//! Get email. //! Get email.
QString getEmail() const { return m_email; } const QString &getEmail() const { return m_email; }
//! Set email. //! Set email.
void setEmail(const QString &email) { m_email = email.trimmed(); } void setEmail(const QString &email) { m_email = email.trimmed(); }
@@ -103,7 +106,7 @@ namespace BlackMisc
bool hasValidEmail() const { return !m_email.isEmpty(); } bool hasValidEmail() const { return !m_email.isEmpty(); }
//! Get id. //! Get id.
QString getId() const { return m_id; } const QString &getId() const { return m_id; }
//! Set id //! Set id
void setId(const QString &id) { m_id = id.trimmed(); } void setId(const QString &id) { m_id = id.trimmed(); }
@@ -114,9 +117,6 @@ namespace BlackMisc
//! Set homebase //! Set homebase
void setHomeBase(const Aviation::CAirportIcaoCode &homebase) { m_homebase = homebase; } void setHomeBase(const Aviation::CAirportIcaoCode &homebase) { m_homebase = homebase; }
//! Has home base?
bool hasHomeBase() const { return !m_homebase.isEmpty(); }
//! Get associated callsign. //! Get associated callsign.
const Aviation::CCallsign &getCallsign() const { return m_callsign; } const Aviation::CCallsign &getCallsign() const { return m_callsign; }

View File

@@ -153,10 +153,10 @@ namespace BlackMisc
void setAircraftIcaoDesignator(const QString &designator); void setAircraftIcaoDesignator(const QString &designator);
//! Has valid realname? //! Has valid realname?
bool hasValidRealName() const { return m_pilot.hasValidRealName(); } bool hasRealName() const { return m_pilot.hasRealName(); }
//! Has valid id? //! Has valid id?
bool hasValidId() const { return m_pilot.hasValidId(); } bool hasId() const { return m_pilot.hasId(); }
//! Valid designator? //! Valid designator?
bool hasAircraftDesignator() const; bool hasAircraftDesignator() const;

View File

@@ -69,7 +69,7 @@ namespace BlackMisc
bool CSimulatedAircraftList::updateWithVatsimDataFileData(CSimulatedAircraft &aircraftToBeUpdated) const bool CSimulatedAircraftList::updateWithVatsimDataFileData(CSimulatedAircraft &aircraftToBeUpdated) const
{ {
if (this->isEmpty()) return false; if (this->isEmpty()) return false;
if (aircraftToBeUpdated.hasValidRealName() && aircraftToBeUpdated.hasValidId() && aircraftToBeUpdated.hasAircraftAndAirlineDesignator()) { return false; } if (aircraftToBeUpdated.hasRealName() && aircraftToBeUpdated.hasId() && aircraftToBeUpdated.hasAircraftAndAirlineDesignator()) { return false; }
CSimulatedAircraft currentDataFileAircraft = this->findFirstByCallsign(aircraftToBeUpdated.getCallsign()); CSimulatedAircraft currentDataFileAircraft = this->findFirstByCallsign(aircraftToBeUpdated.getCallsign());
if (currentDataFileAircraft.getCallsign().isEmpty()) return false; if (currentDataFileAircraft.getCallsign().isEmpty()) return false;