refactor: Remove country flag from server selector

This feature does not work anymore anyway with the AUTOMATIC VATSIM
server
This commit is contained in:
Lars Toenning
2024-10-17 08:43:31 +02:00
parent 4ea378f751
commit d810469504
3 changed files with 7 additions and 55 deletions

View File

@@ -106,7 +106,7 @@ namespace BlackGui::Components
if (vatsimFsdServers.isEmpty()) { return; }
vatsimFsdServers.sortBy(&CServer::getName);
const CServer currentServer = m_networkSetup.getLastVatsimServer();
ui->comp_VatsimServers->setServers(vatsimFsdServers, true);
ui->comp_VatsimServers->setServers(vatsimFsdServers);
ui->comp_VatsimServers->preSelect(currentServer.getName());
}
}

View File

@@ -27,10 +27,10 @@ namespace BlackGui::Components
connect(this, &QComboBox::currentTextChanged, this, &CServerListSelector::onServerTextChanged);
}
void CServerListSelector::setServers(const CServerList &servers, bool nameIsCountry)
void CServerListSelector::setServers(const CServerList &servers)
{
if (m_servers == servers) { return; }
this->setServerItems(servers, nameIsCountry);
this->setServerItems(servers);
if (!servers.isEmpty() && !m_pendingPreselect.isEmpty())
{
this->preSelect(m_pendingPreselect);
@@ -64,7 +64,7 @@ namespace BlackGui::Components
return false;
}
void CServerListSelector::setServerItems(const CServerList &servers, bool nameToCountry)
void CServerListSelector::setServerItems(const CServerList &servers)
{
QString currentlySelected(this->currentText());
int index = -1;
@@ -72,7 +72,6 @@ namespace BlackGui::Components
m_items.clear();
this->clear(); // ui
nameToCountry = nameToCountry && knowsAllCountries();
for (const CServer &server : servers)
{
const QString d(server.getName() + ": " + server.getDescription());
@@ -82,22 +81,7 @@ namespace BlackGui::Components
index = m_items.size() - 1;
}
if (nameToCountry)
{
const CCountry country(this->findCountry(server));
if (country.getName().isEmpty())
{
this->addItem(CIcons::empty16(), d);
}
else
{
this->addItem(CIcon(country.toIcon()).toPixmap(), d);
}
}
else
{
this->addItem(d);
}
this->addItem(d);
}
// reselect
@@ -118,29 +102,4 @@ namespace BlackGui::Components
emit this->serverChanged(this->currentServer());
}
bool CServerListSelector::knowsAllCountries()
{
return (sGui && sGui->getWebDataServices() && sGui->getWebDataServices()->getCountriesCount() > 0);
}
CCountry CServerListSelector::findCountry(const CServer &server)
{
if (!CServerListSelector::knowsAllCountries()) { return CCountry(); }
static const CCountryList countries(sGui->getWebDataServices()->getCountries());
const CCountry ctryByName = countries.findBestMatchByCountryName(server.getName());
if (ctryByName.isValid()) { return ctryByName; }
// own approach, see if description contains a valid countr name
for (const CCountry &testCtry : countries)
{
if (testCtry.getName().isEmpty()) { continue; }
if (server.getDescription().contains(testCtry.getName(), Qt::CaseInsensitive))
{
return testCtry;
}
}
const CCountry ctryByDescription = countries.findBestMatchByCountryName(server.getDescription());
return ctryByDescription;
}
} // ns

View File

@@ -9,7 +9,6 @@
#include "blackgui/blackguiexport.h"
#include "blackmisc/network/data/lastserver.h"
#include "blackmisc/network/serverlist.h"
#include "blackmisc/country.h"
#include "blackmisc/datacache.h"
#include <QComboBox>
@@ -28,7 +27,7 @@ namespace BlackGui::Components
explicit CServerListSelector(QWidget *parent = nullptr);
//! Set the servers
void setServers(const BlackMisc::Network::CServerList &servers, bool nameIsCountry = false);
void setServers(const BlackMisc::Network::CServerList &servers);
//! Get the current server
BlackMisc::Network::CServer currentServer() const;
@@ -42,17 +41,11 @@ namespace BlackGui::Components
private:
//! Build the item string descriptions
void setServerItems(const BlackMisc::Network::CServerList &servers, bool nameToCountry);
void setServerItems(const BlackMisc::Network::CServerList &servers);
//! Server index has been changed
void onServerTextChanged(const QString &text);
//! Do we know all countries?
static bool knowsAllCountries();
//! Turn server name into country (for VATSIM servers)
static BlackMisc::CCountry findCountry(const BlackMisc::Network::CServer &server);
BlackMisc::Network::CServerList m_servers; //!< corresponding servers
QStringList m_items; //!< items strings
QString m_pendingPreselect; //!< pending preselect value