diff --git a/src/blackgui/components/flightplancomponent.cpp b/src/blackgui/components/flightplancomponent.cpp index bf8d74760..c4772c267 100644 --- a/src/blackgui/components/flightplancomponent.cpp +++ b/src/blackgui/components/flightplancomponent.cpp @@ -193,7 +193,7 @@ namespace BlackGui if (m_flightPlan.wasSentOrLoaded()) { return; } // only override with valid values - if (user.hasValidRealName()) + if (user.hasRealName()) { ui->le_PilotsName->setText(user.getRealName()); } @@ -201,7 +201,7 @@ namespace BlackGui { ui->le_PilotsHomeBase->setText(user.getHomeBase().getIcaoCode()); } - if (user.hasValidCallsign()) + if (user.hasCallsign()) { ui->le_Callsign->setText(user.getCallsign().asString()); } diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 11a76f1ca..bb38fc441 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -351,7 +351,7 @@ namespace BlackGui { const CServer lastServer = m_lastVatsimServer.get(); const CUser lastUser = lastServer.getUser(); - if (lastUser.hasValidCallsign()) + if (lastUser.hasCallsign()) { ui->le_Callsign->setText(lastUser.getCallsign().asString()); ui->le_VatsimId->setText(lastUser.getId()); diff --git a/src/blackgui/components/remoteaircraftselector.cpp b/src/blackgui/components/remoteaircraftselector.cpp index 8cc72467f..813eda5d6 100644 --- a/src/blackgui/components/remoteaircraftselector.cpp +++ b/src/blackgui/components/remoteaircraftselector.cpp @@ -110,7 +110,7 @@ namespace BlackGui aircraft.getAircraftIcaoCode().toQString(false) % QLatin1String(")"); } - if (aircraft.hasValidRealName()) + if (aircraft.hasRealName()) { i += QLatin1String(" - ") % aircraft.getPilotRealName(); } diff --git a/src/blackmisc/aviation/atcstation.cpp b/src/blackmisc/aviation/atcstation.cpp index 8b59cb648..1e31c3e7e 100644 --- a/src/blackmisc/aviation/atcstation.cpp +++ b/src/blackmisc/aviation/atcstation.cpp @@ -49,7 +49,7 @@ namespace BlackMisc { // sync callsigns m_callsign.setTypeHint(CCallsign::Atc); - if (!m_controller.hasValidCallsign() && !callsign.isEmpty()) + if (!m_controller.hasCallsign() && !callsign.isEmpty()) { m_controller.setCallsign(m_callsign); } diff --git a/src/blackmisc/aviation/atcstation.h b/src/blackmisc/aviation/atcstation.h index 06d9125f6..40b1d5697 100644 --- a/src/blackmisc/aviation/atcstation.h +++ b/src/blackmisc/aviation/atcstation.h @@ -117,13 +117,13 @@ namespace BlackMisc void setControllerId(const QString &controllerId) { m_controller.setId(controllerId); } //! Has valid realname? - bool hasValidRealName() const { return m_controller.hasValidRealName(); } + bool hasRealName() const { return m_controller.hasRealName(); } //! Has valid id? - bool hasValidId() const { return m_controller.hasValidId(); } + bool hasId() const { return m_controller.hasId(); } //! Valid COM frequency - bool hasValidFrequency() const { return BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->getFrequency()); } + bool hasValidFrequency() const { return CComSystem::isValidCivilAviationFrequency(this->getFrequency()); } //! Get frequency. const PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; } diff --git a/src/blackmisc/network/client.cpp b/src/blackmisc/network/client.cpp index 8d19e1853..934d8c697 100644 --- a/src/blackmisc/network/client.cpp +++ b/src/blackmisc/network/client.cpp @@ -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) diff --git a/src/blackmisc/network/user.cpp b/src/blackmisc/network/user.cpp index 450fec508..1d1cd7d22 100644 --- a/src/blackmisc/network/user.cpp +++ b/src/blackmisc/network/user.cpp @@ -20,6 +20,7 @@ #include #include #include +#include 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 ""; 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; } diff --git a/src/blackmisc/network/user.h b/src/blackmisc/network/user.h index d85fc16f2..dbe7ddb94 100644 --- a/src/blackmisc/network/user.h +++ b/src/blackmisc/network/user.h @@ -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; } diff --git a/src/blackmisc/simulation/simulatedaircraft.h b/src/blackmisc/simulation/simulatedaircraft.h index e7d2a6711..1454b0dbd 100644 --- a/src/blackmisc/simulation/simulatedaircraft.h +++ b/src/blackmisc/simulation/simulatedaircraft.h @@ -153,10 +153,10 @@ namespace BlackMisc void setAircraftIcaoDesignator(const QString &designator); //! Has valid realname? - bool hasValidRealName() const { return m_pilot.hasValidRealName(); } + bool hasRealName() const { return m_pilot.hasRealName(); } //! Has valid id? - bool hasValidId() const { return m_pilot.hasValidId(); } + bool hasId() const { return m_pilot.hasId(); } //! Valid designator? bool hasAircraftDesignator() const; diff --git a/src/blackmisc/simulation/simulatedaircraftlist.cpp b/src/blackmisc/simulation/simulatedaircraftlist.cpp index 9779b0186..b8815e267 100644 --- a/src/blackmisc/simulation/simulatedaircraftlist.cpp +++ b/src/blackmisc/simulation/simulatedaircraftlist.cpp @@ -69,7 +69,7 @@ namespace BlackMisc bool CSimulatedAircraftList::updateWithVatsimDataFileData(CSimulatedAircraft &aircraftToBeUpdated) const { 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()); if (currentDataFileAircraft.getCallsign().isEmpty()) return false;