mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-28 20:25:34 +08:00
Ref T219, added some utility functions in value classes
This commit is contained in:
@@ -21,6 +21,11 @@ namespace BlackMisc
|
|||||||
return this->m_icaoCode.compare(compareValue.getIcaoCode(), Qt::CaseInsensitive);
|
return this->m_icaoCode.compare(compareValue.getIcaoCode(), Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CAirportIcaoCode::hasValidIcaoCode() const
|
||||||
|
{
|
||||||
|
return CAirportIcaoCode::isValidIcaoDesignator(this->getIcaoCode());
|
||||||
|
}
|
||||||
|
|
||||||
bool CAirportIcaoCode::equalsString(const QString &icaoCode) const
|
bool CAirportIcaoCode::equalsString(const QString &icaoCode) const
|
||||||
{
|
{
|
||||||
CAirportIcaoCode other(icaoCode);
|
CAirportIcaoCode other(icaoCode);
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ namespace BlackMisc
|
|||||||
//! Is empty?
|
//! Is empty?
|
||||||
bool isEmpty() const { return this->m_icaoCode.isEmpty(); }
|
bool isEmpty() const { return this->m_icaoCode.isEmpty(); }
|
||||||
|
|
||||||
|
//! Has valid code?
|
||||||
|
bool hasValidIcaoCode() const;
|
||||||
|
|
||||||
//! Get code.
|
//! Get code.
|
||||||
const QString &asString() const { return this->m_icaoCode; }
|
const QString &asString() const { return this->m_icaoCode; }
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ namespace BlackMisc
|
|||||||
QLatin1String(" online: ") % boolToYesNo(m_isOnline) %
|
QLatin1String(" online: ") % boolToYesNo(m_isOnline) %
|
||||||
|
|
||||||
// controller
|
// controller
|
||||||
(!m_controller.isValid() ? QStringLiteral("") :
|
(m_controller.isNull() ? QStringLiteral("") :
|
||||||
QStringLiteral(" ") % m_controller.toQString(i18n)) %
|
QStringLiteral(" ") % m_controller.toQString(i18n)) %
|
||||||
|
|
||||||
// frequency
|
// frequency
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CServer::isValidForLogin() const
|
bool CServer::isValidForLogin() const
|
||||||
{
|
{
|
||||||
return m_user.hasValidCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections();
|
return m_user.hasCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServer::hasAddressAndPort() const
|
bool CServer::hasAddressAndPort() const
|
||||||
|
|||||||
@@ -119,13 +119,18 @@ namespace BlackMisc
|
|||||||
m_realname = beautifyRealName(rn);
|
m_realname = beautifyRealName(rn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CUser::hasValidHomeBase() const
|
||||||
|
{
|
||||||
|
return m_homebase.hasValidIcaoCode();
|
||||||
|
}
|
||||||
|
|
||||||
CStatusMessageList CUser::validate() const
|
CStatusMessageList CUser::validate() const
|
||||||
{
|
{
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
// callsign optional
|
// callsign optional
|
||||||
if (!this->hasId()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid id"));}
|
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->hasRealName()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid real name"));}
|
||||||
if (!this->hasValidCredentials()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid credentials"));}
|
if (!this->hasCredentials()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid credentials"));}
|
||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,10 +73,13 @@ namespace BlackMisc
|
|||||||
void setPassword(const QString &pw) { m_password = pw.trimmed(); }
|
void setPassword(const QString &pw) { m_password = pw.trimmed(); }
|
||||||
|
|
||||||
//! Valid user object?
|
//! Valid user object?
|
||||||
bool isValid() const { return !m_realname.isEmpty() && !m_id.isEmpty(); }
|
bool isValid() const { return !isNull(); }
|
||||||
|
|
||||||
|
//! Null?
|
||||||
|
bool isNull() const { return m_realname.isEmpty() && m_id.isEmpty(); }
|
||||||
|
|
||||||
//! Valid credentials?
|
//! Valid credentials?
|
||||||
bool hasValidCredentials() const { return this->isValid() && !m_password.isEmpty(); }
|
bool hasCredentials() const { return this->isValid() && !m_password.isEmpty(); }
|
||||||
|
|
||||||
//! Valid real name?
|
//! Valid real name?
|
||||||
bool hasRealName() const { return !m_realname.isEmpty(); }
|
bool hasRealName() const { return !m_realname.isEmpty(); }
|
||||||
@@ -84,12 +87,18 @@ namespace BlackMisc
|
|||||||
//! Valid id?
|
//! Valid id?
|
||||||
bool hasId() const { return !m_id.isEmpty(); }
|
bool hasId() const { return !m_id.isEmpty(); }
|
||||||
|
|
||||||
|
//! Has a valid VATSIM id?
|
||||||
|
bool hasValidVatsimId() const { return CUser::isValidVatsimId(this->getId()); }
|
||||||
|
|
||||||
//! Has associated callsign?
|
//! Has associated callsign?
|
||||||
bool hasCallsign() const { return !m_callsign.isEmpty(); }
|
bool hasCallsign() const { return !m_callsign.isEmpty(); }
|
||||||
|
|
||||||
//! Has home base?
|
//! Has home base?
|
||||||
bool hasHomeBase() const { return !m_homebase.isEmpty(); }
|
bool hasHomeBase() const { return !m_homebase.isEmpty(); }
|
||||||
|
|
||||||
|
//! Has valid home base?
|
||||||
|
bool hasValidHomeBase() const;
|
||||||
|
|
||||||
//! Real name + homebase
|
//! Real name + homebase
|
||||||
QString getRealNameAndHomeBase(const QString &separator = QString(" ")) const;
|
QString getRealNameAndHomeBase(const QString &separator = QString(" ")) const;
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CSimulatedAircraft::isValidForLogin() const
|
bool CSimulatedAircraft::isValidForLogin() const
|
||||||
{
|
{
|
||||||
if (m_callsign.asString().isEmpty()) { return false; }
|
if (m_callsign.isEmpty()) { return false; }
|
||||||
if (!m_pilot.isValid()) { return false; }
|
if (m_pilot.isNull()) { return false; }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user