Use QString literals

This patch covers src/app and src/base folders.
Follow up of ab64ee872b.
This commit is contained in:
Chocobo1
2022-03-04 14:24:14 +08:00
parent ab64ee872b
commit f0dd7b7dae
38 changed files with 771 additions and 764 deletions

View File

@@ -32,6 +32,7 @@
#include <QRegularExpression>
#include <QUrlQuery>
#include "base/global.h"
#include "base/logger.h"
#include "base/net/downloadmanager.h"
#include "base/version.h"
@@ -76,7 +77,7 @@ void DNSUpdater::checkPublicIP()
Q_ASSERT(m_state == OK);
DownloadManager::instance()->download(
DownloadRequest("http://checkip.dyndns.org").userAgent("qBittorrent/" QBT_VERSION_2)
DownloadRequest(u"http://checkip.dyndns.org"_qs).userAgent(QStringLiteral("qBittorrent/" QBT_VERSION_2))
, this, &DNSUpdater::ipRequestFinished);
m_lastIPCheckTime = QDateTime::currentDateTime();
@@ -91,7 +92,7 @@ void DNSUpdater::ipRequestFinished(const DownloadResult &result)
}
// Parse response
const QRegularExpressionMatch ipRegexMatch = QRegularExpression("Current IP Address:\\s+([^<]+)</body>").match(result.data);
const QRegularExpressionMatch ipRegexMatch = QRegularExpression(u"Current IP Address:\\s+([^<]+)</body>"_qs).match(QString::fromUtf8(result.data));
if (ipRegexMatch.hasMatch())
{
QString ipStr = ipRegexMatch.captured(1);
@@ -124,7 +125,7 @@ void DNSUpdater::updateDNSService()
m_lastIPCheckTime = QDateTime::currentDateTime();
DownloadManager::instance()->download(
DownloadRequest(getUpdateUrl()).userAgent("qBittorrent/" QBT_VERSION_2)
DownloadRequest(getUpdateUrl()).userAgent(QStringLiteral("qBittorrent/" QBT_VERSION_2))
, this, &DNSUpdater::ipUpdateFinished);
}
@@ -132,9 +133,9 @@ QString DNSUpdater::getUpdateUrl() const
{
QUrl url;
#ifdef QT_NO_OPENSSL
url.setScheme("http");
url.setScheme(u"http"_qs);
#else
url.setScheme("https");
url.setScheme(u"https"_qs);
#endif
url.setUserName(m_username);
url.setPassword(m_password);
@@ -144,21 +145,21 @@ QString DNSUpdater::getUpdateUrl() const
switch (m_service)
{
case DNS::Service::DynDNS:
url.setHost("members.dyndns.org");
url.setHost(u"members.dyndns.org"_qs);
break;
case DNS::Service::NoIP:
url.setHost("dynupdate.no-ip.com");
url.setHost(u"dynupdate.no-ip.com"_qs);
break;
default:
qWarning() << "Unrecognized Dynamic DNS service!";
Q_ASSERT(false);
break;
}
url.setPath("/nic/update");
url.setPath(u"/nic/update"_qs);
QUrlQuery urlQuery(url);
urlQuery.addQueryItem("hostname", m_domain);
urlQuery.addQueryItem("myip", m_lastIP.toString());
urlQuery.addQueryItem(u"hostname"_qs, m_domain);
urlQuery.addQueryItem(u"myip"_qs, m_lastIP.toString());
url.setQuery(urlQuery);
Q_ASSERT(url.isValid());
@@ -169,7 +170,7 @@ QString DNSUpdater::getUpdateUrl() const
void DNSUpdater::ipUpdateFinished(const DownloadResult &result)
{
if (result.status == DownloadStatus::Success)
processIPUpdateReply(result.data);
processIPUpdateReply(QString::fromUtf8(result.data));
else
qWarning() << "IP update failed:" << result.errorString;
}
@@ -178,16 +179,16 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
{
Logger *const logger = Logger::instance();
qDebug() << Q_FUNC_INFO << reply;
const QString code = reply.split(' ').first();
const QString code = reply.split(u' ').first();
qDebug() << Q_FUNC_INFO << "Code:" << code;
if ((code == "good") || (code == "nochg"))
if ((code == u"good") || (code == u"nochg"))
{
logger->addMessage(tr("Your dynamic DNS was successfully updated."), Log::INFO);
return;
}
if ((code == "911") || (code == "dnserr"))
if ((code == u"911") || (code == u"dnserr"))
{
logger->addMessage(tr("Dynamic DNS error: The service is temporarily unavailable, it will be retried in 30 minutes."), Log::CRITICAL);
m_lastIP.clear();
@@ -198,21 +199,21 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
// Everything below is an error, stop updating until the user updates something
m_ipCheckTimer.stop();
m_lastIP.clear();
if (code == "nohost")
if (code == u"nohost")
{
logger->addMessage(tr("Dynamic DNS error: hostname supplied does not exist under specified account."), Log::CRITICAL);
m_state = INVALID_CREDS;
return;
}
if (code == "badauth")
if (code == u"badauth")
{
logger->addMessage(tr("Dynamic DNS error: Invalid username/password."), Log::CRITICAL);
m_state = INVALID_CREDS;
return;
}
if (code == "badagent")
if (code == u"badagent")
{
logger->addMessage(tr("Dynamic DNS error: qBittorrent was blacklisted by the service, please submit a bug report at http://bugs.qbittorrent.org."),
Log::CRITICAL);
@@ -220,15 +221,15 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
return;
}
if (code == "!donator")
if (code == u"!donator")
{
logger->addMessage(tr("Dynamic DNS error: %1 was returned by the service, please submit a bug report at http://bugs.qbittorrent.org.").arg("!donator"),
logger->addMessage(tr("Dynamic DNS error: %1 was returned by the service, please submit a bug report at http://bugs.qbittorrent.org.").arg(u"!donator"_qs),
Log::CRITICAL);
m_state = FATAL;
return;
}
if (code == "abuse")
if (code == u"abuse")
{
logger->addMessage(tr("Dynamic DNS error: Your username was blocked due to abuse."), Log::CRITICAL);
m_state = FATAL;
@@ -250,7 +251,7 @@ void DNSUpdater::updateCredentials()
if (m_domain != pref->getDynDomainName())
{
m_domain = pref->getDynDomainName();
const QRegularExpressionMatch domainRegexMatch = QRegularExpression("^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$").match(m_domain);
const QRegularExpressionMatch domainRegexMatch = QRegularExpression(u"^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$"_qs).match(m_domain);
if (!domainRegexMatch.hasMatch())
{
logger->addMessage(tr("Dynamic DNS error: supplied domain name is invalid."), Log::CRITICAL);
@@ -301,9 +302,9 @@ QUrl DNSUpdater::getRegistrationUrl(const DNS::Service service)
switch (service)
{
case DNS::Service::DynDNS:
return {"https://account.dyn.com/entrance/"};
return {u"https://account.dyn.com/entrance/"_qs};
case DNS::Service::NoIP:
return {"https://www.noip.com/remote-access"};
return {u"https://www.noip.com/remote-access"_qs};
default:
Q_ASSERT(false);
break;

View File

@@ -183,7 +183,7 @@ void DownloadHandlerImpl::handleRedirection(const QUrl &newUrl)
qDebug("Redirecting from %s to %s...", qUtf8Printable(m_reply->url().toString()), qUtf8Printable(newUrlString));
// Redirect to magnet workaround
if (newUrlString.startsWith("magnet:", Qt::CaseInsensitive))
if (newUrlString.startsWith(u"magnet:", Qt::CaseInsensitive))
{
qDebug("Magnet redirect detected.");
m_result.status = Net::DownloadStatus::RedirectedToMagnet;

View File

@@ -293,7 +293,7 @@ void Net::DownloadManager::ignoreSslErrors(QNetworkReply *reply, const QList<QSs
QStringList errorList;
for (const QSslError &error : errors)
errorList += error.errorString();
LogMsg(tr("Ignoring SSL error, URL: \"%1\", errors: \"%2\"").arg(reply->url().toString(), errorList.join(". ")), Log::WARNING);
LogMsg(tr("Ignoring SSL error, URL: \"%1\", errors: \"%2\"").arg(reply->url().toString(), errorList.join(u". ")), Log::WARNING);
// Ignore all SSL errors
reply->ignoreSslErrors();

View File

@@ -34,6 +34,7 @@
#include <QHostAddress>
#include <QVariant>
#include "base/global.h"
#include "base/path.h"
namespace
@@ -197,7 +198,7 @@ QString GeoIPDatabase::lookup(const QHostAddress &hostAddr) const
const QVariant val = readDataField(tmp);
if (val.userType() == QMetaType::QVariantHash)
{
country = val.toHash()["country"].toHash()["iso_code"].toString();
country = val.toHash()[u"country"_qs].toHash()[u"iso_code"_qs].toString();
m_countries[id] = country;
}
}
@@ -212,23 +213,23 @@ QString GeoIPDatabase::lookup(const QHostAddress &hostAddr) const
}
#define CHECK_METADATA_REQ(key, type) \
if (!metadata.contains(#key)) \
if (!metadata.contains(key)) \
{ \
error = errMsgNotFound.arg(#key); \
error = errMsgNotFound.arg(key); \
return false; \
} \
if (metadata.value(#key).userType() != QMetaType::type) \
if (metadata.value(key).userType() != QMetaType::type) \
{ \
error = errMsgInvalid.arg(#key); \
error = errMsgInvalid.arg(key); \
return false; \
}
#define CHECK_METADATA_OPT(key, type) \
if (metadata.contains(#key)) \
if (metadata.contains(key)) \
{ \
if (metadata.value(#key).userType() != QMetaType::type) \
if (metadata.value(key).userType() != QMetaType::type) \
{ \
error = errMsgInvalid.arg(#key); \
error = errMsgInvalid.arg(key); \
return false; \
} \
}
@@ -240,26 +241,26 @@ bool GeoIPDatabase::parseMetadata(const QVariantHash &metadata, QString &error)
qDebug() << "Parsing MaxMindDB metadata...";
CHECK_METADATA_REQ(binary_format_major_version, UShort);
CHECK_METADATA_REQ(binary_format_minor_version, UShort);
const uint versionMajor = metadata.value("binary_format_major_version").toUInt();
const uint versionMinor = metadata.value("binary_format_minor_version").toUInt();
CHECK_METADATA_REQ(u"binary_format_major_version"_qs, UShort);
CHECK_METADATA_REQ(u"binary_format_minor_version"_qs, UShort);
const uint versionMajor = metadata.value(u"binary_format_major_version"_qs).toUInt();
const uint versionMinor = metadata.value(u"binary_format_minor_version"_qs).toUInt();
if (versionMajor != 2)
{
error = tr("Unsupported database version: %1.%2").arg(versionMajor).arg(versionMinor);
return false;
}
CHECK_METADATA_REQ(ip_version, UShort);
m_ipVersion = metadata.value("ip_version").value<quint16>();
CHECK_METADATA_REQ(u"ip_version"_qs, UShort);
m_ipVersion = metadata.value(u"ip_version"_qs).value<quint16>();
if (m_ipVersion != 6)
{
error = tr("Unsupported IP version: %1").arg(m_ipVersion);
return false;
}
CHECK_METADATA_REQ(record_size, UShort);
m_recordSize = metadata.value("record_size").value<quint16>();
CHECK_METADATA_REQ(u"record_size"_qs, UShort);
m_recordSize = metadata.value(u"record_size"_qs).value<quint16>();
if (m_recordSize != 24)
{
error = tr("Unsupported record size: %1").arg(m_recordSize);
@@ -268,18 +269,18 @@ bool GeoIPDatabase::parseMetadata(const QVariantHash &metadata, QString &error)
m_nodeSize = m_recordSize / 4;
m_recordBytes = m_nodeSize / 2;
CHECK_METADATA_REQ(node_count, UInt);
m_nodeCount = metadata.value("node_count").value<quint32>();
CHECK_METADATA_REQ(u"node_count"_qs, UInt);
m_nodeCount = metadata.value(u"node_count"_qs).value<quint32>();
m_indexSize = m_nodeCount * m_nodeSize;
CHECK_METADATA_REQ(database_type, QString);
m_dbType = metadata.value("database_type").toString();
CHECK_METADATA_REQ(u"database_type"_qs, QString);
m_dbType = metadata.value(u"database_type"_qs).toString();
CHECK_METADATA_REQ(build_epoch, ULongLong);
m_buildEpoch = QDateTime::fromSecsSinceEpoch(metadata.value("build_epoch").toULongLong());
CHECK_METADATA_REQ(u"build_epoch"_qs, ULongLong);
m_buildEpoch = QDateTime::fromSecsSinceEpoch(metadata.value(u"build_epoch"_qs).toULongLong());
CHECK_METADATA_OPT(languages, QVariantList);
CHECK_METADATA_OPT(description, QVariantHash);
CHECK_METADATA_OPT(u"languages"_qs, QVariantList);
CHECK_METADATA_OPT(u"description"_qs, QVariantHash);
return true;
}

View File

@@ -130,7 +130,7 @@ void GeoIPManager::manageDatabaseUpdate()
void GeoIPManager::downloadDatabaseFile()
{
const QDateTime curDatetime = QDateTime::currentDateTimeUtc();
const QString curUrl = DATABASE_URL.arg(QLocale::c().toString(curDatetime, "yyyy-MM"));
const QString curUrl = DATABASE_URL.arg(QLocale::c().toString(curDatetime, u"yyyy-MM"));
DownloadManager::instance()->download({curUrl}, this, &GeoIPManager::downloadFinished);
}
@@ -150,255 +150,255 @@ QString GeoIPManager::CountryName(const QString &countryISOCode)
// http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_txt-temp.htm
// Officially assigned
{"AD", tr("Andorra")},
{"AE", tr("United Arab Emirates")},
{"AF", tr("Afghanistan")},
{"AG", tr("Antigua and Barbuda")},
{"AI", tr("Anguilla")},
{"AL", tr("Albania")},
{"AM", tr("Armenia")},
{"AO", tr("Angola")},
{"AQ", tr("Antarctica")},
{"AR", tr("Argentina")},
{"AS", tr("American Samoa")},
{"AT", tr("Austria")},
{"AU", tr("Australia")},
{"AW", tr("Aruba")},
{"AX", tr("Aland Islands")},
{"AZ", tr("Azerbaijan")},
{"BA", tr("Bosnia and Herzegovina")},
{"BB", tr("Barbados")},
{"BD", tr("Bangladesh")},
{"BE", tr("Belgium")},
{"BF", tr("Burkina Faso")},
{"BG", tr("Bulgaria")},
{"BH", tr("Bahrain")},
{"BI", tr("Burundi")},
{"BJ", tr("Benin")},
{"BL", tr("Saint Barthelemy")},
{"BM", tr("Bermuda")},
{"BN", tr("Brunei Darussalam")},
{"BO", tr("Bolivia, Plurinational State of")},
{"BQ", tr("Bonaire, Sint Eustatius and Saba")},
{"BR", tr("Brazil")},
{"BS", tr("Bahamas")},
{"BT", tr("Bhutan")},
{"BV", tr("Bouvet Island")},
{"BW", tr("Botswana")},
{"BY", tr("Belarus")},
{"BZ", tr("Belize")},
{"CA", tr("Canada")},
{"CC", tr("Cocos (Keeling) Islands")},
{"CD", tr("Congo, The Democratic Republic of the")},
{"CF", tr("Central African Republic")},
{"CG", tr("Congo")},
{"CH", tr("Switzerland")},
{"CI", tr("Cote d'Ivoire")},
{"CK", tr("Cook Islands")},
{"CL", tr("Chile")},
{"CM", tr("Cameroon")},
{"CN", tr("China")},
{"CO", tr("Colombia")},
{"CR", tr("Costa Rica")},
{"CU", tr("Cuba")},
{"CV", tr("Cape Verde")},
{"CW", tr("Curacao")},
{"CX", tr("Christmas Island")},
{"CY", tr("Cyprus")},
{"CZ", tr("Czech Republic")},
{"DE", tr("Germany")},
{"DJ", tr("Djibouti")},
{"DK", tr("Denmark")},
{"DM", tr("Dominica")},
{"DO", tr("Dominican Republic")},
{"DZ", tr("Algeria")},
{"EC", tr("Ecuador")},
{"EE", tr("Estonia")},
{"EG", tr("Egypt")},
{"EH", tr("Western Sahara")},
{"ER", tr("Eritrea")},
{"ES", tr("Spain")},
{"ET", tr("Ethiopia")},
{"FI", tr("Finland")},
{"FJ", tr("Fiji")},
{"FK", tr("Falkland Islands (Malvinas)")},
{"FM", tr("Micronesia, Federated States of")},
{"FO", tr("Faroe Islands")},
{"FR", tr("France")},
{"GA", tr("Gabon")},
{"GB", tr("United Kingdom")},
{"GD", tr("Grenada")},
{"GE", tr("Georgia")},
{"GF", tr("French Guiana")},
{"GG", tr("Guernsey")},
{"GH", tr("Ghana")},
{"GI", tr("Gibraltar")},
{"GL", tr("Greenland")},
{"GM", tr("Gambia")},
{"GN", tr("Guinea")},
{"GP", tr("Guadeloupe")},
{"GQ", tr("Equatorial Guinea")},
{"GR", tr("Greece")},
{"GS", tr("South Georgia and the South Sandwich Islands")},
{"GT", tr("Guatemala")},
{"GU", tr("Guam")},
{"GW", tr("Guinea-Bissau")},
{"GY", tr("Guyana")},
{"HK", tr("Hong Kong")},
{"HM", tr("Heard Island and McDonald Islands")},
{"HN", tr("Honduras")},
{"HR", tr("Croatia")},
{"HT", tr("Haiti")},
{"HU", tr("Hungary")},
{"ID", tr("Indonesia")},
{"IE", tr("Ireland")},
{"IL", tr("Israel")},
{"IM", tr("Isle of Man")},
{"IN", tr("India")},
{"IO", tr("British Indian Ocean Territory")},
{"IQ", tr("Iraq")},
{"IR", tr("Iran, Islamic Republic of")},
{"IS", tr("Iceland")},
{"IT", tr("Italy")},
{"JE", tr("Jersey")},
{"JM", tr("Jamaica")},
{"JO", tr("Jordan")},
{"JP", tr("Japan")},
{"KE", tr("Kenya")},
{"KG", tr("Kyrgyzstan")},
{"KH", tr("Cambodia")},
{"KI", tr("Kiribati")},
{"KM", tr("Comoros")},
{"KN", tr("Saint Kitts and Nevis")},
{"KP", tr("Korea, Democratic People's Republic of")},
{"KR", tr("Korea, Republic of")},
{"KW", tr("Kuwait")},
{"KY", tr("Cayman Islands")},
{"KZ", tr("Kazakhstan")},
{"LA", tr("Lao People's Democratic Republic")},
{"LB", tr("Lebanon")},
{"LC", tr("Saint Lucia")},
{"LI", tr("Liechtenstein")},
{"LK", tr("Sri Lanka")},
{"LR", tr("Liberia")},
{"LS", tr("Lesotho")},
{"LT", tr("Lithuania")},
{"LU", tr("Luxembourg")},
{"LV", tr("Latvia")},
{"LY", tr("Libya")},
{"MA", tr("Morocco")},
{"MC", tr("Monaco")},
{"MD", tr("Moldova, Republic of")},
{"ME", tr("Montenegro")},
{"MF", tr("Saint Martin (French part)")},
{"MG", tr("Madagascar")},
{"MH", tr("Marshall Islands")},
{"MK", tr("Macedonia, The Former Yugoslav Republic of")},
{"ML", tr("Mali")},
{"MM", tr("Myanmar")},
{"MN", tr("Mongolia")},
{"MO", tr("Macao")},
{"MP", tr("Northern Mariana Islands")},
{"MQ", tr("Martinique")},
{"MR", tr("Mauritania")},
{"MS", tr("Montserrat")},
{"MT", tr("Malta")},
{"MU", tr("Mauritius")},
{"MV", tr("Maldives")},
{"MW", tr("Malawi")},
{"MX", tr("Mexico")},
{"MY", tr("Malaysia")},
{"MZ", tr("Mozambique")},
{"NA", tr("Namibia")},
{"NC", tr("New Caledonia")},
{"NE", tr("Niger")},
{"NF", tr("Norfolk Island")},
{"NG", tr("Nigeria")},
{"NI", tr("Nicaragua")},
{"NL", tr("Netherlands")},
{"NO", tr("Norway")},
{"NP", tr("Nepal")},
{"NR", tr("Nauru")},
{"NU", tr("Niue")},
{"NZ", tr("New Zealand")},
{"OM", tr("Oman")},
{"PA", tr("Panama")},
{"PE", tr("Peru")},
{"PF", tr("French Polynesia")},
{"PG", tr("Papua New Guinea")},
{"PH", tr("Philippines")},
{"PK", tr("Pakistan")},
{"PL", tr("Poland")},
{"PM", tr("Saint Pierre and Miquelon")},
{"PN", tr("Pitcairn")},
{"PR", tr("Puerto Rico")},
{"PS", tr("Palestine, State of")},
{"PT", tr("Portugal")},
{"PW", tr("Palau")},
{"PY", tr("Paraguay")},
{"QA", tr("Qatar")},
{"RE", tr("Reunion")},
{"RO", tr("Romania")},
{"RS", tr("Serbia")},
{"RU", tr("Russian Federation")},
{"RW", tr("Rwanda")},
{"SA", tr("Saudi Arabia")},
{"SB", tr("Solomon Islands")},
{"SC", tr("Seychelles")},
{"SD", tr("Sudan")},
{"SE", tr("Sweden")},
{"SG", tr("Singapore")},
{"SH", tr("Saint Helena, Ascension and Tristan da Cunha")},
{"SI", tr("Slovenia")},
{"SJ", tr("Svalbard and Jan Mayen")},
{"SK", tr("Slovakia")},
{"SL", tr("Sierra Leone")},
{"SM", tr("San Marino")},
{"SN", tr("Senegal")},
{"SO", tr("Somalia")},
{"SR", tr("Suriname")},
{"SS", tr("South Sudan")},
{"ST", tr("Sao Tome and Principe")},
{"SV", tr("El Salvador")},
{"SX", tr("Sint Maarten (Dutch part)")},
{"SY", tr("Syrian Arab Republic")},
{"SZ", tr("Swaziland")},
{"TC", tr("Turks and Caicos Islands")},
{"TD", tr("Chad")},
{"TF", tr("French Southern Territories")},
{"TG", tr("Togo")},
{"TH", tr("Thailand")},
{"TJ", tr("Tajikistan")},
{"TK", tr("Tokelau")},
{"TL", tr("Timor-Leste")},
{"TM", tr("Turkmenistan")},
{"TN", tr("Tunisia")},
{"TO", tr("Tonga")},
{"TR", tr("Turkey")},
{"TT", tr("Trinidad and Tobago")},
{"TV", tr("Tuvalu")},
{"TW", tr("Taiwan")},
{"TZ", tr("Tanzania, United Republic of")},
{"UA", tr("Ukraine")},
{"UG", tr("Uganda")},
{"UM", tr("United States Minor Outlying Islands")},
{"US", tr("United States")},
{"UY", tr("Uruguay")},
{"UZ", tr("Uzbekistan")},
{"VA", tr("Holy See (Vatican City State)")},
{"VC", tr("Saint Vincent and the Grenadines")},
{"VE", tr("Venezuela, Bolivarian Republic of")},
{"VG", tr("Virgin Islands, British")},
{"VI", tr("Virgin Islands, U.S.")},
{"VN", tr("Vietnam")},
{"VU", tr("Vanuatu")},
{"WF", tr("Wallis and Futuna")},
{"WS", tr("Samoa")},
{"YE", tr("Yemen")},
{"YT", tr("Mayotte")},
{"ZA", tr("South Africa")},
{"ZM", tr("Zambia")},
{"ZW", tr("Zimbabwe")},
{u"AD"_qs, tr("Andorra")},
{u"AE"_qs, tr("United Arab Emirates")},
{u"AF"_qs, tr("Afghanistan")},
{u"AG"_qs, tr("Antigua and Barbuda")},
{u"AI"_qs, tr("Anguilla")},
{u"AL"_qs, tr("Albania")},
{u"AM"_qs, tr("Armenia")},
{u"AO"_qs, tr("Angola")},
{u"AQ"_qs, tr("Antarctica")},
{u"AR"_qs, tr("Argentina")},
{u"AS"_qs, tr("American Samoa")},
{u"AT"_qs, tr("Austria")},
{u"AU"_qs, tr("Australia")},
{u"AW"_qs, tr("Aruba")},
{u"AX"_qs, tr("Aland Islands")},
{u"AZ"_qs, tr("Azerbaijan")},
{u"BA"_qs, tr("Bosnia and Herzegovina")},
{u"BB"_qs, tr("Barbados")},
{u"BD"_qs, tr("Bangladesh")},
{u"BE"_qs, tr("Belgium")},
{u"BF"_qs, tr("Burkina Faso")},
{u"BG"_qs, tr("Bulgaria")},
{u"BH"_qs, tr("Bahrain")},
{u"BI"_qs, tr("Burundi")},
{u"BJ"_qs, tr("Benin")},
{u"BL"_qs, tr("Saint Barthelemy")},
{u"BM"_qs, tr("Bermuda")},
{u"BN"_qs, tr("Brunei Darussalam")},
{u"BO"_qs, tr("Bolivia, Plurinational State of")},
{u"BQ"_qs, tr("Bonaire, Sint Eustatius and Saba")},
{u"BR"_qs, tr("Brazil")},
{u"BS"_qs, tr("Bahamas")},
{u"BT"_qs, tr("Bhutan")},
{u"BV"_qs, tr("Bouvet Island")},
{u"BW"_qs, tr("Botswana")},
{u"BY"_qs, tr("Belarus")},
{u"BZ"_qs, tr("Belize")},
{u"CA"_qs, tr("Canada")},
{u"CC"_qs, tr("Cocos (Keeling) Islands")},
{u"CD"_qs, tr("Congo, The Democratic Republic of the")},
{u"CF"_qs, tr("Central African Republic")},
{u"CG"_qs, tr("Congo")},
{u"CH"_qs, tr("Switzerland")},
{u"CI"_qs, tr("Cote d'Ivoire")},
{u"CK"_qs, tr("Cook Islands")},
{u"CL"_qs, tr("Chile")},
{u"CM"_qs, tr("Cameroon")},
{u"CN"_qs, tr("China")},
{u"CO"_qs, tr("Colombia")},
{u"CR"_qs, tr("Costa Rica")},
{u"CU"_qs, tr("Cuba")},
{u"CV"_qs, tr("Cape Verde")},
{u"CW"_qs, tr("Curacao")},
{u"CX"_qs, tr("Christmas Island")},
{u"CY"_qs, tr("Cyprus")},
{u"CZ"_qs, tr("Czech Republic")},
{u"DE"_qs, tr("Germany")},
{u"DJ"_qs, tr("Djibouti")},
{u"DK"_qs, tr("Denmark")},
{u"DM"_qs, tr("Dominica")},
{u"DO"_qs, tr("Dominican Republic")},
{u"DZ"_qs, tr("Algeria")},
{u"EC"_qs, tr("Ecuador")},
{u"EE"_qs, tr("Estonia")},
{u"EG"_qs, tr("Egypt")},
{u"EH"_qs, tr("Western Sahara")},
{u"ER"_qs, tr("Eritrea")},
{u"ES"_qs, tr("Spain")},
{u"ET"_qs, tr("Ethiopia")},
{u"FI"_qs, tr("Finland")},
{u"FJ"_qs, tr("Fiji")},
{u"FK"_qs, tr("Falkland Islands (Malvinas)")},
{u"FM"_qs, tr("Micronesia, Federated States of")},
{u"FO"_qs, tr("Faroe Islands")},
{u"FR"_qs, tr("France")},
{u"GA"_qs, tr("Gabon")},
{u"GB"_qs, tr("United Kingdom")},
{u"GD"_qs, tr("Grenada")},
{u"GE"_qs, tr("Georgia")},
{u"GF"_qs, tr("French Guiana")},
{u"GG"_qs, tr("Guernsey")},
{u"GH"_qs, tr("Ghana")},
{u"GI"_qs, tr("Gibraltar")},
{u"GL"_qs, tr("Greenland")},
{u"GM"_qs, tr("Gambia")},
{u"GN"_qs, tr("Guinea")},
{u"GP"_qs, tr("Guadeloupe")},
{u"GQ"_qs, tr("Equatorial Guinea")},
{u"GR"_qs, tr("Greece")},
{u"GS"_qs, tr("South Georgia and the South Sandwich Islands")},
{u"GT"_qs, tr("Guatemala")},
{u"GU"_qs, tr("Guam")},
{u"GW"_qs, tr("Guinea-Bissau")},
{u"GY"_qs, tr("Guyana")},
{u"HK"_qs, tr("Hong Kong")},
{u"HM"_qs, tr("Heard Island and McDonald Islands")},
{u"HN"_qs, tr("Honduras")},
{u"HR"_qs, tr("Croatia")},
{u"HT"_qs, tr("Haiti")},
{u"HU"_qs, tr("Hungary")},
{u"ID"_qs, tr("Indonesia")},
{u"IE"_qs, tr("Ireland")},
{u"IL"_qs, tr("Israel")},
{u"IM"_qs, tr("Isle of Man")},
{u"IN"_qs, tr("India")},
{u"IO"_qs, tr("British Indian Ocean Territory")},
{u"IQ"_qs, tr("Iraq")},
{u"IR"_qs, tr("Iran, Islamic Republic of")},
{u"IS"_qs, tr("Iceland")},
{u"IT"_qs, tr("Italy")},
{u"JE"_qs, tr("Jersey")},
{u"JM"_qs, tr("Jamaica")},
{u"JO"_qs, tr("Jordan")},
{u"JP"_qs, tr("Japan")},
{u"KE"_qs, tr("Kenya")},
{u"KG"_qs, tr("Kyrgyzstan")},
{u"KH"_qs, tr("Cambodia")},
{u"KI"_qs, tr("Kiribati")},
{u"KM"_qs, tr("Comoros")},
{u"KN"_qs, tr("Saint Kitts and Nevis")},
{u"KP"_qs, tr("Korea, Democratic People's Republic of")},
{u"KR"_qs, tr("Korea, Republic of")},
{u"KW"_qs, tr("Kuwait")},
{u"KY"_qs, tr("Cayman Islands")},
{u"KZ"_qs, tr("Kazakhstan")},
{u"LA"_qs, tr("Lao People's Democratic Republic")},
{u"LB"_qs, tr("Lebanon")},
{u"LC"_qs, tr("Saint Lucia")},
{u"LI"_qs, tr("Liechtenstein")},
{u"LK"_qs, tr("Sri Lanka")},
{u"LR"_qs, tr("Liberia")},
{u"LS"_qs, tr("Lesotho")},
{u"LT"_qs, tr("Lithuania")},
{u"LU"_qs, tr("Luxembourg")},
{u"LV"_qs, tr("Latvia")},
{u"LY"_qs, tr("Libya")},
{u"MA"_qs, tr("Morocco")},
{u"MC"_qs, tr("Monaco")},
{u"MD"_qs, tr("Moldova, Republic of")},
{u"ME"_qs, tr("Montenegro")},
{u"MF"_qs, tr("Saint Martin (French part)")},
{u"MG"_qs, tr("Madagascar")},
{u"MH"_qs, tr("Marshall Islands")},
{u"MK"_qs, tr("Macedonia, The Former Yugoslav Republic of")},
{u"ML"_qs, tr("Mali")},
{u"MM"_qs, tr("Myanmar")},
{u"MN"_qs, tr("Mongolia")},
{u"MO"_qs, tr("Macao")},
{u"MP"_qs, tr("Northern Mariana Islands")},
{u"MQ"_qs, tr("Martinique")},
{u"MR"_qs, tr("Mauritania")},
{u"MS"_qs, tr("Montserrat")},
{u"MT"_qs, tr("Malta")},
{u"MU"_qs, tr("Mauritius")},
{u"MV"_qs, tr("Maldives")},
{u"MW"_qs, tr("Malawi")},
{u"MX"_qs, tr("Mexico")},
{u"MY"_qs, tr("Malaysia")},
{u"MZ"_qs, tr("Mozambique")},
{u"NA"_qs, tr("Namibia")},
{u"NC"_qs, tr("New Caledonia")},
{u"NE"_qs, tr("Niger")},
{u"NF"_qs, tr("Norfolk Island")},
{u"NG"_qs, tr("Nigeria")},
{u"NI"_qs, tr("Nicaragua")},
{u"NL"_qs, tr("Netherlands")},
{u"NO"_qs, tr("Norway")},
{u"NP"_qs, tr("Nepal")},
{u"NR"_qs, tr("Nauru")},
{u"NU"_qs, tr("Niue")},
{u"NZ"_qs, tr("New Zealand")},
{u"OM"_qs, tr("Oman")},
{u"PA"_qs, tr("Panama")},
{u"PE"_qs, tr("Peru")},
{u"PF"_qs, tr("French Polynesia")},
{u"PG"_qs, tr("Papua New Guinea")},
{u"PH"_qs, tr("Philippines")},
{u"PK"_qs, tr("Pakistan")},
{u"PL"_qs, tr("Poland")},
{u"PM"_qs, tr("Saint Pierre and Miquelon")},
{u"PN"_qs, tr("Pitcairn")},
{u"PR"_qs, tr("Puerto Rico")},
{u"PS"_qs, tr("Palestine, State of")},
{u"PT"_qs, tr("Portugal")},
{u"PW"_qs, tr("Palau")},
{u"PY"_qs, tr("Paraguay")},
{u"QA"_qs, tr("Qatar")},
{u"RE"_qs, tr("Reunion")},
{u"RO"_qs, tr("Romania")},
{u"RS"_qs, tr("Serbia")},
{u"RU"_qs, tr("Russian Federation")},
{u"RW"_qs, tr("Rwanda")},
{u"SA"_qs, tr("Saudi Arabia")},
{u"SB"_qs, tr("Solomon Islands")},
{u"SC"_qs, tr("Seychelles")},
{u"SD"_qs, tr("Sudan")},
{u"SE"_qs, tr("Sweden")},
{u"SG"_qs, tr("Singapore")},
{u"SH"_qs, tr("Saint Helena, Ascension and Tristan da Cunha")},
{u"SI"_qs, tr("Slovenia")},
{u"SJ"_qs, tr("Svalbard and Jan Mayen")},
{u"SK"_qs, tr("Slovakia")},
{u"SL"_qs, tr("Sierra Leone")},
{u"SM"_qs, tr("San Marino")},
{u"SN"_qs, tr("Senegal")},
{u"SO"_qs, tr("Somalia")},
{u"SR"_qs, tr("Suriname")},
{u"SS"_qs, tr("South Sudan")},
{u"ST"_qs, tr("Sao Tome and Principe")},
{u"SV"_qs, tr("El Salvador")},
{u"SX"_qs, tr("Sint Maarten (Dutch part)")},
{u"SY"_qs, tr("Syrian Arab Republic")},
{u"SZ"_qs, tr("Swaziland")},
{u"TC"_qs, tr("Turks and Caicos Islands")},
{u"TD"_qs, tr("Chad")},
{u"TF"_qs, tr("French Southern Territories")},
{u"TG"_qs, tr("Togo")},
{u"TH"_qs, tr("Thailand")},
{u"TJ"_qs, tr("Tajikistan")},
{u"TK"_qs, tr("Tokelau")},
{u"TL"_qs, tr("Timor-Leste")},
{u"TM"_qs, tr("Turkmenistan")},
{u"TN"_qs, tr("Tunisia")},
{u"TO"_qs, tr("Tonga")},
{u"TR"_qs, tr("Turkey")},
{u"TT"_qs, tr("Trinidad and Tobago")},
{u"TV"_qs, tr("Tuvalu")},
{u"TW"_qs, tr("Taiwan")},
{u"TZ"_qs, tr("Tanzania, United Republic of")},
{u"UA"_qs, tr("Ukraine")},
{u"UG"_qs, tr("Uganda")},
{u"UM"_qs, tr("United States Minor Outlying Islands")},
{u"US"_qs, tr("United States")},
{u"UY"_qs, tr("Uruguay")},
{u"UZ"_qs, tr("Uzbekistan")},
{u"VA"_qs, tr("Holy See (Vatican City State)")},
{u"VC"_qs, tr("Saint Vincent and the Grenadines")},
{u"VE"_qs, tr("Venezuela, Bolivarian Republic of")},
{u"VG"_qs, tr("Virgin Islands, British")},
{u"VI"_qs, tr("Virgin Islands, U.S.")},
{u"VN"_qs, tr("Vietnam")},
{u"VU"_qs, tr("Vanuatu")},
{u"WF"_qs, tr("Wallis and Futuna")},
{u"WS"_qs, tr("Samoa")},
{u"YE"_qs, tr("Yemen")},
{u"YT"_qs, tr("Mayotte")},
{u"ZA"_qs, tr("South Africa")},
{u"ZM"_qs, tr("Zambia")},
{u"ZW"_qs, tr("Zimbabwe")},
{{}, tr("N/A")}
};

View File

@@ -30,6 +30,7 @@
#include <QObject>
#include "base/global.h"
#include "base/settingvalue.h"
namespace Net
@@ -50,7 +51,7 @@ namespace Net
struct ProxyConfiguration
{
ProxyType type = ProxyType::None;
QString ip = "0.0.0.0";
QString ip = u"0.0.0.0"_qs;
ushort port = 8080;
QString username;
QString password;

View File

@@ -84,7 +84,7 @@ namespace
{
QString hostname = QHostInfo::localHostName();
if (hostname.isEmpty())
hostname = "localhost";
hostname = u"localhost"_qs;
return hostname.toLocal8Bit();
}
@@ -140,16 +140,16 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje
{
const Preferences *const pref = Preferences::instance();
m_message = "Date: " + getCurrentDateTime().toLatin1() + "\r\n"
+ encodeMimeHeader("From", from)
+ encodeMimeHeader("Subject", subject)
+ encodeMimeHeader("To", to)
+ encodeMimeHeader(u"From"_qs, from)
+ encodeMimeHeader(u"Subject"_qs, subject)
+ encodeMimeHeader(u"To"_qs, to)
+ "MIME-Version: 1.0\r\n"
+ "Content-Type: text/plain; charset=UTF-8\r\n"
+ "Content-Transfer-Encoding: base64\r\n"
+ "\r\n";
// Encode the body in base64
QString crlfBody = body;
const QByteArray b = crlfBody.replace("\n", "\r\n").toUtf8().toBase64();
const QByteArray b = crlfBody.replace(u"\n"_qs, u"\r\n"_qs).toUtf8().toBase64();
const int ct = b.length();
for (int i = 0; i < ct; i += 78)
m_message += b.mid(i, 78);
@@ -208,14 +208,14 @@ void Smtp::readyRead()
}
else
{
logError(QLatin1String("Connection failed, unrecognized reply: ") + line);
logError(tr("Connection failed, unrecognized reply: %1").arg(QString::fromUtf8(line)));
m_state = Close;
}
break;
case EhloSent:
case HeloSent:
case EhloGreetReceived:
parseEhloResponse(code, line[3] != ' ', line.mid(4));
parseEhloResponse(code, (line[3] != ' '), line.mid(4));
break;
#ifndef QT_NO_OPENSSL
case StartTLSSent:
@@ -248,7 +248,7 @@ void Smtp::readyRead()
else
{
// Authentication failed!
logError(QLatin1String("Authentication failed, msg: ") + line);
logError(tr("Authentication failed, msg: %1").arg(QString::fromUtf8(line)));
m_state = Close;
}
break;
@@ -261,7 +261,7 @@ void Smtp::readyRead()
}
else
{
logError(QLatin1String("<mail from> was rejected by server, msg: ") + line);
logError(tr("<mail from> was rejected by server, msg: %1").arg(QString::fromUtf8(line)));
m_state = Close;
}
break;
@@ -274,7 +274,7 @@ void Smtp::readyRead()
}
else
{
logError(QLatin1String("<Rcpt to> was rejected by server, msg: ") + line);
logError(tr("<Rcpt to> was rejected by server, msg: %1").arg(QString::fromUtf8(line)));
m_state = Close;
}
break;
@@ -287,7 +287,7 @@ void Smtp::readyRead()
}
else
{
logError(QLatin1String("<data> was rejected by server, msg: ") + line);
logError(tr("<data> was rejected by server, msg: %1").arg(QString::fromUtf8(line)));
m_state = Close;
}
break;
@@ -301,7 +301,7 @@ void Smtp::readyRead()
}
else
{
logError(QLatin1String("Message was rejected by the server, error: ") + line);
logError(tr("Message was rejected by the server, error: %1").arg(QString::fromUtf8(line)));
m_state = Close;
}
break;
@@ -318,7 +318,7 @@ QByteArray Smtp::encodeMimeHeader(const QString &key, const QString &value, cons
QByteArray rv = "";
QByteArray line = key.toLatin1() + ": ";
if (!prefix.isEmpty()) line += prefix;
if (!value.contains("=?") && canEncodeAsLatin1(value))
if (!value.contains(u"=?") && canEncodeAsLatin1(value))
{
bool firstWord = true;
for (const QByteArray &word : asConst(value.toLatin1().split(' ')))
@@ -389,7 +389,7 @@ void Smtp::parseEhloResponse(const QByteArray &code, const bool continued, const
{
// Both EHLO and HELO failed, chances are this is NOT
// a SMTP server
logError("Both EHLO and HELO failed, msg: " + line);
logError(tr("Both EHLO and HELO failed, msg: %1").arg(line));
m_state = Close;
}
return;
@@ -413,16 +413,16 @@ void Smtp::parseEhloResponse(const QByteArray &code, const bool continued, const
}
else
{
qDebug() << Q_FUNC_INFO << "Supported extension: " << line.section(' ', 0, 0).toUpper()
<< line.section(' ', 1);
m_extensions[line.section(' ', 0, 0).toUpper()] = line.section(' ', 1);
qDebug() << Q_FUNC_INFO << "Supported extension: " << line.section(u' ', 0, 0).toUpper()
<< line.section(u' ', 1);
m_extensions[line.section(u' ', 0, 0).toUpper()] = line.section(u' ', 1);
if (!continued)
m_state = EhloDone;
}
if (m_state != EhloDone) return;
if (m_extensions.contains("STARTTLS") && m_useSsl)
if (m_extensions.contains(u"STARTTLS"_qs) && m_useSsl)
{
qDebug() << "STARTTLS";
startTLS();
@@ -436,7 +436,7 @@ void Smtp::parseEhloResponse(const QByteArray &code, const bool continued, const
void Smtp::authenticate()
{
qDebug() << Q_FUNC_INFO;
if (!m_extensions.contains("AUTH") ||
if (!m_extensions.contains(u"AUTH"_qs) ||
m_username.isEmpty() || m_password.isEmpty())
{
// Skip authentication
@@ -451,18 +451,18 @@ void Smtp::authenticate()
// AUTH extension is supported, check which
// authentication modes are supported by
// the server
const QStringList auth = m_extensions["AUTH"].toUpper().split(' ', Qt::SkipEmptyParts);
if (auth.contains("CRAM-MD5"))
const QStringList auth = m_extensions[u"AUTH"_qs].toUpper().split(u' ', Qt::SkipEmptyParts);
if (auth.contains(u"CRAM-MD5"))
{
qDebug() << "Using CRAM-MD5 authentication...";
authCramMD5();
}
else if (auth.contains("PLAIN"))
else if (auth.contains(u"PLAIN"))
{
qDebug() << "Using PLAIN authentication...";
authPlain();
}
else if (auth.contains("LOGIN"))
else if (auth.contains(u"LOGIN"))
{
qDebug() << "Using LOGIN authentication...";
authLogin();
@@ -470,9 +470,9 @@ void Smtp::authenticate()
else
{
// Skip authentication
logError("The SMTP server does not seem to support any of the authentications modes "
"we support [CRAM-MD5|PLAIN|LOGIN], skipping authentication, "
"knowing it is likely to fail... Server Auth Modes: " + auth.join('|'));
logError(tr("The SMTP server does not seem to support any of the authentications modes "
"we support [CRAM-MD5|PLAIN|LOGIN], skipping authentication, "
"knowing it is likely to fail... Server Auth Modes: %1").arg(auth.join(u'|')));
m_state = Authenticated;
// At this point the server will not send any response
// So fill the buffer with a fake one to pass the tests
@@ -558,7 +558,7 @@ void Smtp::authLogin()
void Smtp::logError(const QString &msg)
{
qDebug() << "Email Notification Error:" << msg;
Logger::instance()->addMessage(tr("Email Notification Error:") + ' ' + msg, Log::CRITICAL);
Logger::instance()->addMessage(tr("Email Notification Error: %1").arg(msg), Log::WARNING);
}
QString Smtp::getCurrentDateTime() const
@@ -568,7 +568,7 @@ QString Smtp::getCurrentDateTime() const
const QDate nowDate = nowDateTime.date();
const QLocale eng(QLocale::English);
const QString timeStr = nowDateTime.time().toString("HH:mm:ss");
const QString timeStr = nowDateTime.time().toString(u"HH:mm:ss");
const QString weekDayStr = eng.dayName(nowDate.dayOfWeek(), QLocale::ShortFormat);
const QString dayStr = QString::number(nowDate.day());
const QString monthStr = eng.monthName(nowDate.month(), QLocale::ShortFormat);
@@ -582,9 +582,9 @@ QString Smtp::getCurrentDateTime() const
// buf size = 11 to avoid format truncation warnings from snprintf
char buf[11] = {0};
std::snprintf(buf, sizeof(buf), "%+05d", timeOffset);
const QString timeOffsetStr = buf;
const auto timeOffsetStr = QString::fromUtf8(buf);
const QString ret = weekDayStr + ", " + dayStr + ' ' + monthStr + ' ' + yearStr + ' ' + timeStr + ' ' + timeOffsetStr;
const QString ret = weekDayStr + u", " + dayStr + u' ' + monthStr + u' ' + yearStr + u' ' + timeStr + u' ' + timeOffsetStr;
return ret;
}