mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 17:55:45 +08:00
Gimmick and formatting
* flags for VATSIM servers * improved country resolution
This commit is contained in:
@@ -321,10 +321,11 @@ namespace BlackGui
|
|||||||
|
|
||||||
if (entity == CEntityFlags::VatsimDataFile)
|
if (entity == CEntityFlags::VatsimDataFile)
|
||||||
{
|
{
|
||||||
const CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers();
|
CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers();
|
||||||
if (vatsimFsdServers.isEmpty()) { return; }
|
if (vatsimFsdServers.isEmpty()) { return; }
|
||||||
|
vatsimFsdServers.sortBy(&CServer::getName);
|
||||||
const CServer currentServer = this->m_currentVatsimServer.get();
|
const CServer currentServer = this->m_currentVatsimServer.get();
|
||||||
this->ui->comp_VatsimServer->setServers(vatsimFsdServers);
|
this->ui->comp_VatsimServer->setServers(vatsimFsdServers, true);
|
||||||
this->ui->comp_VatsimServer->preSelect(currentServer.getName());
|
this->ui->comp_VatsimServer->preSelect(currentServer.getName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
// forward declaration to break compile dependency from all components
|
||||||
class CAircraftComponent;
|
class CAircraftComponent;
|
||||||
class CAtcStationComponent;
|
class CAtcStationComponent;
|
||||||
// forward declaration to break compile dependency from all components
|
|
||||||
class CCockpitComponent;
|
class CCockpitComponent;
|
||||||
class CFlightPlanComponent;
|
class CFlightPlanComponent;
|
||||||
class CLogComponent;
|
class CLogComponent;
|
||||||
@@ -122,10 +122,8 @@ namespace BlackGui
|
|||||||
void selectSettingsTab(int index);
|
void selectSettingsTab(int index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \copydoc CInfoArea::getPreferredSizeWhenFloating
|
// CInfoArea overrides
|
||||||
virtual QSize getPreferredSizeWhenFloating(int areaIndex) const override;
|
virtual QSize getPreferredSizeWhenFloating(int areaIndex) const override;
|
||||||
|
|
||||||
//! \copydoc CInfoArea::indexToPixmap
|
|
||||||
virtual const QPixmap &indexToPixmap(int areaIndex) const override;
|
virtual const QPixmap &indexToPixmap(int areaIndex) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -8,11 +8,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "blackgui/components/serverlistselector.h"
|
#include "blackgui/components/serverlistselector.h"
|
||||||
|
#include "blackgui/guiapplication.h"
|
||||||
#include "blackmisc/sequence.h"
|
#include "blackmisc/sequence.h"
|
||||||
|
#include "blackcore/webdataservices.h"
|
||||||
|
#include "blackcore/db/icaodatareader.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
|
using namespace BlackGui;
|
||||||
|
using namespace BlackCore;
|
||||||
|
using namespace BlackCore::Db;
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -20,13 +27,12 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CServerListSelector::CServerListSelector(QWidget *parent) :
|
CServerListSelector::CServerListSelector(QWidget *parent) :
|
||||||
QComboBox(parent)
|
QComboBox(parent)
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
void CServerListSelector::setServers(const BlackMisc::Network::CServerList &servers)
|
void CServerListSelector::setServers(const BlackMisc::Network::CServerList &servers, bool nameIsCountry)
|
||||||
{
|
{
|
||||||
if (this->m_servers == servers) { return; }
|
if (this->m_servers == servers) { return; }
|
||||||
this->setItemStrings(servers);
|
this->setServerItems(servers, nameIsCountry);
|
||||||
if (!servers.isEmpty() && !m_pendingPreselect.isEmpty())
|
if (!servers.isEmpty() && !m_pendingPreselect.isEmpty())
|
||||||
{
|
{
|
||||||
this->preSelect(m_pendingPreselect);
|
this->preSelect(m_pendingPreselect);
|
||||||
@@ -60,23 +66,41 @@ namespace BlackGui
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerListSelector::setItemStrings(const CServerList &servers)
|
void CServerListSelector::setServerItems(const CServerList &servers, bool nameToCountry)
|
||||||
{
|
{
|
||||||
QString currentlySelected(this->currentText());
|
QString currentlySelected(this->currentText());
|
||||||
int index = -1;
|
int index = -1;
|
||||||
this->m_servers = servers;
|
this->m_servers = servers;
|
||||||
this->m_items.clear();
|
this->m_items.clear();
|
||||||
|
this->clear(); // ui
|
||||||
|
|
||||||
|
nameToCountry = nameToCountry && knowsAllCountries();
|
||||||
for (const CServer &server : servers)
|
for (const CServer &server : servers)
|
||||||
{
|
{
|
||||||
QString d(server.getName() + ": " + server.getDescription());
|
const QString d(server.getName() + ": " + server.getDescription());
|
||||||
m_items.append(d);
|
m_items.append(d);
|
||||||
if (!currentlySelected.isEmpty() && index < 0 && d == currentlySelected)
|
if (!currentlySelected.isEmpty() && index < 0 && d == currentlySelected)
|
||||||
{
|
{
|
||||||
index = m_items.size() - 1;
|
index = m_items.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nameToCountry)
|
||||||
|
{
|
||||||
|
const CCountry country(findCountry(server));
|
||||||
|
if (country.getName().isEmpty())
|
||||||
|
{
|
||||||
|
this->addItem(d);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->addItem(country.toPixmap(), d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->addItem(d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this->clear(); // ui
|
|
||||||
this->addItems(m_items);
|
|
||||||
|
|
||||||
// reselect
|
// reselect
|
||||||
if (this->m_items.isEmpty()) { return; }
|
if (this->m_items.isEmpty()) { return; }
|
||||||
@@ -89,5 +113,17 @@ namespace BlackGui
|
|||||||
this->setCurrentIndex(index);
|
this->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CServerListSelector::knowsAllCountries()
|
||||||
|
{
|
||||||
|
return (sGui && sGui->getWebDataServices() && sGui->getWebDataServices()->getCountriesCount() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
CCountry CServerListSelector::findCountry(const CServer &server)
|
||||||
|
{
|
||||||
|
if (!knowsAllCountries()) { return CCountry(); }
|
||||||
|
static const CCountryList countries(sGui->getWebDataServices()->getCountries());
|
||||||
|
return countries.findBestMatchByCountryName(server.getName());
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include "blackmisc/network/server.h"
|
#include "blackmisc/network/server.h"
|
||||||
#include "blackmisc/network/serverlist.h"
|
#include "blackmisc/network/serverlist.h"
|
||||||
|
#include "blackmisc/country.h"
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@@ -36,7 +37,7 @@ namespace BlackGui
|
|||||||
explicit CServerListSelector(QWidget *parent = nullptr);
|
explicit CServerListSelector(QWidget *parent = nullptr);
|
||||||
|
|
||||||
//! Set the servers
|
//! Set the servers
|
||||||
void setServers(const BlackMisc::Network::CServerList &servers);
|
void setServers(const BlackMisc::Network::CServerList &servers, bool nameIsCountry = false);
|
||||||
|
|
||||||
//! Get the current server
|
//! Get the current server
|
||||||
BlackMisc::Network::CServer currentServer() const;
|
BlackMisc::Network::CServer currentServer() const;
|
||||||
@@ -46,7 +47,13 @@ namespace BlackGui
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//! Build the item string descriptions
|
//! Build the item string descriptions
|
||||||
void setItemStrings(const BlackMisc::Network::CServerList &servers);
|
void setServerItems(const BlackMisc::Network::CServerList &servers, bool nameToCountry);
|
||||||
|
|
||||||
|
//! 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
|
||||||
|
|||||||
@@ -119,8 +119,7 @@ namespace BlackMisc
|
|||||||
if (this->m_designator.length() > 2)
|
if (this->m_designator.length() > 2)
|
||||||
{
|
{
|
||||||
// relative to images
|
// relative to images
|
||||||
return CIcon("airlines/" + m_designator.toLower() + ".png",
|
return CIcon("airlines/" + m_designator.toLower() + ".png", this->convertToQString());
|
||||||
this->convertToQString());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ namespace BlackMisc
|
|||||||
if (this->m_dbKey.length() == 2)
|
if (this->m_dbKey.length() == 2)
|
||||||
{
|
{
|
||||||
// relative to images
|
// relative to images
|
||||||
return CIcon("flags/" + m_dbKey.toLower() + ".png",
|
return CIcon("flags/" + m_dbKey.toLower() + ".png", this->convertToQString());
|
||||||
this->convertToQString());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -73,7 +72,7 @@ namespace BlackMisc
|
|||||||
if (name.isEmpty() || m_name.isEmpty()) { return false; }
|
if (name.isEmpty() || m_name.isEmpty()) { return false; }
|
||||||
if (name.length() < 5)
|
if (name.length() < 5)
|
||||||
{
|
{
|
||||||
return m_name.length() == name.length() && m_name.startsWith(name, Qt::CaseInsensitive);
|
return m_name.length() == name.length() && (m_name.startsWith(name, Qt::CaseInsensitive) || name.startsWith(m_name, Qt::CaseInsensitive));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,17 +32,22 @@ namespace BlackMisc
|
|||||||
CCountry CCountryList::findBestMatchByCountryName(const QString &countryName) const
|
CCountry CCountryList::findBestMatchByCountryName(const QString &countryName) const
|
||||||
{
|
{
|
||||||
if (countryName.isEmpty()) { return CCountry(); }
|
if (countryName.isEmpty()) { return CCountry(); }
|
||||||
|
|
||||||
|
static const QRegExp reg("[^a-z]", Qt::CaseInsensitive);
|
||||||
|
QString cn(countryName);
|
||||||
|
cn.remove(reg);
|
||||||
CCountryList countries = this->findBy([&](const CCountry & country)
|
CCountryList countries = this->findBy([&](const CCountry & country)
|
||||||
{
|
{
|
||||||
return country.matchesCountryName(countryName);
|
return country.matchesCountryName(cn);
|
||||||
});
|
});
|
||||||
if (countries.size() < 2) { return countries.frontOrDefault(); }
|
if (countries.size() < 2) { return countries.frontOrDefault(); }
|
||||||
|
|
||||||
// find best match
|
// find best match by further reducing
|
||||||
for (const CCountry &c : countries)
|
for (const CCountry &c : countries)
|
||||||
{
|
{
|
||||||
if (c.getName() == countryName) { return c; }
|
if (c.getName() == cn) { return c; }
|
||||||
if (c.getName().startsWith(countryName, Qt::CaseInsensitive)) { return c; }
|
if (c.getName().startsWith(cn, Qt::CaseInsensitive)) { return c; }
|
||||||
|
if (cn.startsWith(c.getName(), Qt::CaseInsensitive)) { return c; }
|
||||||
}
|
}
|
||||||
return countries.front();
|
return countries.front();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user