Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ QString UsageArguments ( char** argv )
" -L, --licence show an agreement window before users can connect\n"
" -m, --htmlstatus enable HTML status file, set file name\n"
" -o, --serverinfo registration info for this Server. Format:\n"
" [name];[city];[country as Qt5 QLocale ID]\n"
" [name];[city];[country as two-letter ISO country code or Qt5 QLocale ID]\n"
" --serverpublicip public IP address for this Server. Needed when\n"
" registering with a server list hosted\n"
" behind the same NAT\n"
Expand Down
36 changes: 28 additions & 8 deletions src/serverlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,36 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum,
// [this server country as QLocale ID]
bool ok;
const int iCountry = slServInfoSeparateParams[2].toInt ( &ok );
if ( ok && iCountry >= 0 && CLocale::IsCountryCodeSupported ( iCountry ) )
if ( ok )
{
// Convert from externally-supplied format ("wire format", Qt5 codes) to
// native format. On Qt5 builds, this is a noop, on Qt6 builds, a conversion
// takes place.
// We try to do such conversions at the outer-most interface which is capable of doing it.
// Although the value comes from src/main -> src/server, this very place is
// the first where we have access to the parsed country code:
ThisServerListEntry.eCountry = CLocale::WireFormatCountryCodeToQtCountry ( iCountry );
if ( iCountry >= 0 && CLocale::IsCountryCodeSupported ( iCountry ) )
{
// Convert from externally-supplied format ("wire format", Qt5 codes) to
// native format. On Qt5 builds, this is a noop, on Qt6 builds, a conversion
// takes place.
// We try to do such conversions at the outer-most interface which is capable of doing it.
// Although the value comes from src/main -> src/server, this very place is
// the first where we have access to the parsed country code:
ThisServerListEntry.eCountry = CLocale::WireFormatCountryCodeToQtCountry ( iCountry );
}
}
else
{
QLocale::Country qlCountry = CLocale::GetCountryCodeByTwoLetterCode ( slServInfoSeparateParams[2] );
if ( qlCountry != QLocale::AnyCountry )
{
ThisServerListEntry.eCountry = qlCountry;
}
}
qInfo() << qUtf8Printable ( QString ( "Using server info: name = \"%1\", city = \"%2\", country/region = \"%3\" (%4)" )
.arg ( ThisServerListEntry.strName )
.arg ( ThisServerListEntry.strCity )
.arg ( slServInfoSeparateParams[2] )
.arg ( QLocale::countryToString ( ThisServerListEntry.eCountry ) ) );
}
else
{
qWarning() << "Ignoring invalid serverinfo, please verify the parameter syntax.";
}

// per definition, the very first entry is this server and this entry will
Expand Down
25 changes: 25 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,31 @@ bool CLocale::IsCountryCodeSupported ( unsigned short iCountryCode )
#endif
}

QLocale::Country CLocale::GetCountryCodeByTwoLetterCode ( QString sTwoLetterCode )
{
#if QT_VERSION >= QT_VERSION_CHECK( 6, 2, 0 )
return QLocale::codeToTerritory ( sTwoLetterCode );
Comment thread
pljones marked this conversation as resolved.
#else
QList<QLocale> vLocaleList = QLocale::matchingLocales ( QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry );
QStringList vstrLocParts;

// Qt < 6.2 does not support lookups from two-letter iso codes to
Comment thread
pljones marked this conversation as resolved.
// QLocale::Country. Therefore, we have to loop over all supported
// locales and perform the matching ourselves.
// In the future, QLocale::codeToTerritory can be used.
foreach ( const QLocale qLocale, vLocaleList )
{
QStringList vstrLocParts = qLocale.name().split ( "_" );

if ( vstrLocParts.size() >= 2 && vstrLocParts.at ( 1 ).toLower() == sTwoLetterCode )
{
return qLocale.country();
}
}
return QLocale::AnyCountry;
#endif
}

QString CLocale::GetCountryFlagIconsResourceReference ( const QLocale::Country eCountry /* Qt-native value */ )
{
QString strReturn = "";
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ class CLocale
static QLocale::Country WireFormatCountryCodeToQtCountry ( unsigned short iCountryCode );
static unsigned short QtCountryToWireFormatCountryCode ( const QLocale::Country eCountry );
static bool IsCountryCodeSupported ( unsigned short iCountryCode );
static QLocale::Country GetCountryCodeByTwoLetterCode ( QString sTwoLetterCode );
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
// ./tools/qt5-to-qt6-country-code-table.py generates these lists:
constexpr int const static wireFormatToQt6Table[] = {
Expand Down