Fixed adding the hardcoded test servers in a dev. environment

(issue found during debugging of #533)
Added some functions to find similar servers by address/port
This commit is contained in:
Klaus Basan
2015-12-06 05:40:50 +01:00
parent f4eec653c1
commit 22ca6ae922
7 changed files with 80 additions and 10 deletions

View File

@@ -144,8 +144,8 @@ namespace BlackGui
// add a testserver when no servers can be loaded // add a testserver when no servers can be loaded
if (otherServers.isEmpty() && CProject::isRunningInBetaOrDeveloperEnvironment()) if (otherServers.isEmpty() && CProject::isRunningInBetaOrDeveloperEnvironment())
{ {
otherServers.push_back(m_setup.get().fsdTestServers()); otherServers.push_back(m_setup.get().fsdTestServersPlusHardcodedServers());
CLogMessage(this).info("Added servers (other) for testing"); CLogMessage(this).info("Added servers for testing");
} }
this->ui->cbp_OtherServers->setServers(otherServers); this->ui->cbp_OtherServers->setServers(otherServers);
} }

View File

@@ -38,6 +38,8 @@ namespace BlackGui
this->connect(this->ui->pb_SettingsTnServersRemoveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer); this->connect(this->ui->pb_SettingsTnServersRemoveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer);
this->connect(this->ui->pb_SettingsTnServersSaveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer); this->connect(this->ui->pb_SettingsTnServersSaveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer);
this->connect(this->ui->tvp_SettingsTnServers, &QTableView::clicked, this, &CSettingsNetworkServersComponent::ps_networkServerSelected); this->connect(this->ui->tvp_SettingsTnServers, &QTableView::clicked, this, &CSettingsNetworkServersComponent::ps_networkServerSelected);
this->ps_reloadSettings();
} }
CSettingsNetworkServersComponent::~CSettingsNetworkServersComponent() CSettingsNetworkServersComponent::~CSettingsNetworkServersComponent()
@@ -47,11 +49,11 @@ namespace BlackGui
{ {
CServerList serverList(m_trafficNetworkServers.get()); CServerList serverList(m_trafficNetworkServers.get());
// add swift test server in case we have no servers: // add swift test servers in case we have no servers:
// this is debug/bootstrap feature we can continue to test when something goes wrong // this is debug/bootstrap feature we can continue to test when something goes wrong
if (serverList.isEmpty() && CProject::isRunningInBetaOrDeveloperEnvironment()) if (serverList.isEmpty() && CProject::isRunningInBetaOrDeveloperEnvironment())
{ {
serverList.push_back(m_setup.get().fsdTestServers()); serverList.push_back(m_setup.get().fsdTestServersPlusHardcodedServers());
} }
this->ui->tvp_SettingsTnServers->updateContainer(serverList); this->ui->tvp_SettingsTnServers->updateContainer(serverList);
} }
@@ -69,7 +71,6 @@ namespace BlackGui
if (!msgs.isEmpty()) if (!msgs.isEmpty())
{ {
msgs.addCategories(this); msgs.addCategories(this);
msgs.addCategory(CLogCategory::validation());
CLogMessage::preformatted(msgs); CLogMessage::preformatted(msgs);
return; return;
} }
@@ -84,7 +85,13 @@ namespace BlackGui
{ {
serverList.replaceOrAdd(&CServer::getName, server.getName(), server); serverList.replaceOrAdd(&CServer::getName, server.getName(), server);
} }
m_trafficNetworkServers.set(serverList);
CStatusMessage msg = m_trafficNetworkServers.set(serverList);
if (msg.isWarningOrAbove())
{
msg.addCategories(this);
CLogMessage::preformatted(msg);
}
} }
} // namespace } // namespace

View File

@@ -35,19 +35,38 @@ namespace BlackMisc
m_name.startsWith(name, Qt::CaseInsensitive); m_name.startsWith(name, Qt::CaseInsensitive);
} }
bool CServer::matchesAddressPort(const CServer &server) const
{
return server.getPort() == this->getPort() &&
server.matchesAddress(this->getAddress());
}
bool CServer::matchesAddress(const QString &address) const
{
return m_address.length() == address.length() &&
m_address.startsWith(address, Qt::CaseInsensitive);
}
bool CServer::isValidForLogin() const bool CServer::isValidForLogin() const
{ {
return this->m_user.hasValidCredentials() && this->m_port > 0 && !this->m_address.isEmpty() && this->isAcceptingConnections(); return this->m_user.hasValidCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections();
}
bool CServer::hasAddressAndPort() const
{
return m_port > 0 && !m_address.isEmpty();
} }
CStatusMessageList CServer::validate() const CStatusMessageList CServer::validate() const
{ {
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
CStatusMessageList msgs; CStatusMessageList msgs;
if (this->getName().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing name")); } if (this->getName().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing name")); }
if (this->getAddress().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing address")); } if (this->getAddress().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing address")); }
if (this->getDescription().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing description")); } if (this->getDescription().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing description")); }
if (this->getPort() < 1 || this->getPort() > 65535) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Wrong port")); } if (this->getPort() < 1 || this->getPort() > 65535) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Wrong port")); }
msgs.push_back(this->getUser().validate()); msgs.push_back(this->getUser().validate());
msgs.addCategories(cats);
return msgs; return msgs;
} }

View File

@@ -64,6 +64,12 @@ namespace BlackMisc
//! Matches server name? //! Matches server name?
bool matchesName(const QString &name) const; bool matchesName(const QString &name) const;
//! Same address and port?
bool matchesAddressPort(const CServer &server) const;
//! Same address?
bool matchesAddress(const QString &address) const;
//! Get description //! Get description
const QString &getDescription() const { return m_description; } const QString &getDescription() const { return m_description; }
@@ -85,6 +91,9 @@ namespace BlackMisc
//! Is valid for login? //! Is valid for login?
bool isValidForLogin() const; bool isValidForLogin() const;
//! Address and port?
bool hasAddressAndPort() const;
//! Validate, provide details about issues //! Validate, provide details about issues
BlackMisc::CStatusMessageList validate() const; BlackMisc::CStatusMessageList validate() const;

View File

@@ -13,7 +13,6 @@ namespace BlackMisc
{ {
namespace Network namespace Network
{ {
CServerList::CServerList() { } CServerList::CServerList() { }
CServerList::CServerList(const CSequence<CServer> &other) : CServerList::CServerList(const CSequence<CServer> &other) :
@@ -29,5 +28,30 @@ namespace BlackMisc
return false; return false;
} }
bool CServerList::containsAddressPort(const CServer &server)
{
for (const CServer &s : *this)
{
if (s.matchesAddressPort(server)) { return true; }
}
return false;
}
void CServerList::addIfAddressNotExists(const CServer &server)
{
if (!server.hasAddressAndPort() || server.getName().isEmpty()) { return; }
if (!this->containsAddressPort(server))
{
this->push_back(server);
}
}
void CServerList::addIfAddressNotExists(const CServerList &servers)
{
for (const CServer &s : servers)
{
this->addIfAddressNotExists(s);
}
}
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -37,8 +37,16 @@ namespace BlackMisc
//! Contains name //! Contains name
bool containsName(const QString &name) const; bool containsName(const QString &name) const;
};
//! Contains server with same address/port
bool containsAddressPort(const CServer &server);
//! Add if address not already exists
void addIfAddressNotExists(const CServer &server);
//! Add if address not already exists
void addIfAddressNotExists(const CServerList &servers);
};
} //namespace } //namespace
} // namespace } // namespace

View File

@@ -139,9 +139,12 @@ namespace BlackMisc
//! Valid designators? //! Valid designators?
bool hasAircraftAndAirlineDesignator() const; bool hasAircraftAndAirlineDesignator() const;
//! Valid callsign //! Valid callsign?
bool hasValidCallsign() const { return BlackMisc::Aviation::CCallsign::isValidCallsign(this->getCallsign().asString()); } bool hasValidCallsign() const { return BlackMisc::Aviation::CCallsign::isValidCallsign(this->getCallsign().asString()); }
//! Callsign not empty, no further checks
bool hasCallsign() const { return !getCallsign().isEmpty(); }
//! Get position //! Get position
BlackMisc::Geo::CCoordinateGeodetic getPosition() const { return this->m_situation.getPosition(); } BlackMisc::Geo::CCoordinateGeodetic getPosition() const { return this->m_situation.getPosition(); }