mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 12:55:31 +08:00
refactor: Remove country flag from server selector
This feature does not work anymore anyway with the AUTOMATIC VATSIM server
This commit is contained in:
@@ -106,7 +106,7 @@ namespace BlackGui::Components
|
|||||||
if (vatsimFsdServers.isEmpty()) { return; }
|
if (vatsimFsdServers.isEmpty()) { return; }
|
||||||
vatsimFsdServers.sortBy(&CServer::getName);
|
vatsimFsdServers.sortBy(&CServer::getName);
|
||||||
const CServer currentServer = m_networkSetup.getLastVatsimServer();
|
const CServer currentServer = m_networkSetup.getLastVatsimServer();
|
||||||
ui->comp_VatsimServers->setServers(vatsimFsdServers, true);
|
ui->comp_VatsimServers->setServers(vatsimFsdServers);
|
||||||
ui->comp_VatsimServers->preSelect(currentServer.getName());
|
ui->comp_VatsimServers->preSelect(currentServer.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ namespace BlackGui::Components
|
|||||||
connect(this, &QComboBox::currentTextChanged, this, &CServerListSelector::onServerTextChanged);
|
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; }
|
if (m_servers == servers) { return; }
|
||||||
this->setServerItems(servers, nameIsCountry);
|
this->setServerItems(servers);
|
||||||
if (!servers.isEmpty() && !m_pendingPreselect.isEmpty())
|
if (!servers.isEmpty() && !m_pendingPreselect.isEmpty())
|
||||||
{
|
{
|
||||||
this->preSelect(m_pendingPreselect);
|
this->preSelect(m_pendingPreselect);
|
||||||
@@ -64,7 +64,7 @@ namespace BlackGui::Components
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerListSelector::setServerItems(const CServerList &servers, bool nameToCountry)
|
void CServerListSelector::setServerItems(const CServerList &servers)
|
||||||
{
|
{
|
||||||
QString currentlySelected(this->currentText());
|
QString currentlySelected(this->currentText());
|
||||||
int index = -1;
|
int index = -1;
|
||||||
@@ -72,7 +72,6 @@ namespace BlackGui::Components
|
|||||||
m_items.clear();
|
m_items.clear();
|
||||||
this->clear(); // ui
|
this->clear(); // ui
|
||||||
|
|
||||||
nameToCountry = nameToCountry && knowsAllCountries();
|
|
||||||
for (const CServer &server : servers)
|
for (const CServer &server : servers)
|
||||||
{
|
{
|
||||||
const QString d(server.getName() + ": " + server.getDescription());
|
const QString d(server.getName() + ": " + server.getDescription());
|
||||||
@@ -82,22 +81,7 @@ namespace BlackGui::Components
|
|||||||
index = m_items.size() - 1;
|
index = m_items.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nameToCountry)
|
this->addItem(d);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reselect
|
// reselect
|
||||||
@@ -118,29 +102,4 @@ namespace BlackGui::Components
|
|||||||
emit this->serverChanged(this->currentServer());
|
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
|
} // ns
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include "blackmisc/network/data/lastserver.h"
|
#include "blackmisc/network/data/lastserver.h"
|
||||||
#include "blackmisc/network/serverlist.h"
|
#include "blackmisc/network/serverlist.h"
|
||||||
#include "blackmisc/country.h"
|
|
||||||
#include "blackmisc/datacache.h"
|
#include "blackmisc/datacache.h"
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
@@ -28,7 +27,7 @@ namespace BlackGui::Components
|
|||||||
explicit CServerListSelector(QWidget *parent = nullptr);
|
explicit CServerListSelector(QWidget *parent = nullptr);
|
||||||
|
|
||||||
//! Set the servers
|
//! Set the servers
|
||||||
void setServers(const BlackMisc::Network::CServerList &servers, bool nameIsCountry = false);
|
void setServers(const BlackMisc::Network::CServerList &servers);
|
||||||
|
|
||||||
//! Get the current server
|
//! Get the current server
|
||||||
BlackMisc::Network::CServer currentServer() const;
|
BlackMisc::Network::CServer currentServer() const;
|
||||||
@@ -42,17 +41,11 @@ namespace BlackGui::Components
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//! Build the item string descriptions
|
//! 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
|
//! Server index has been changed
|
||||||
void onServerTextChanged(const QString &text);
|
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
|
BlackMisc::Network::CServerList m_servers; //!< corresponding servers
|
||||||
QStringList m_items; //!< items strings
|
QStringList m_items; //!< items strings
|
||||||
QString m_pendingPreselect; //!< pending preselect value
|
QString m_pendingPreselect; //!< pending preselect value
|
||||||
|
|||||||
Reference in New Issue
Block a user