Rename literal operator

Qt 6.4 introduced `QString operator""_s()` and the previous `""_qs` is
deprecated since Qt 6.8.
This commit is contained in:
Chocobo1 2023-06-18 02:02:02 +08:00
parent f6b58f36e2
commit e6d85a468b
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
141 changed files with 3610 additions and 3604 deletions

View file

@ -62,11 +62,11 @@
#include "api/transfercontroller.h"
const int MAX_ALLOWED_FILESIZE = 10 * 1024 * 1024;
const QString DEFAULT_SESSION_COOKIE_NAME = u"SID"_qs;
const QString DEFAULT_SESSION_COOKIE_NAME = u"SID"_s;
const QString WWW_FOLDER = u":/www"_qs;
const QString PUBLIC_FOLDER = u"/public"_qs;
const QString PRIVATE_FOLDER = u"/private"_qs;
const QString WWW_FOLDER = u":/www"_s;
const QString PUBLIC_FOLDER = u"/public"_s;
const QString PRIVATE_FOLDER = u"/private"_s;
namespace
{
@ -92,7 +92,7 @@ namespace
QUrl urlFromHostHeader(const QString &hostHeader)
{
if (!hostHeader.contains(u"://"))
return {u"http://"_qs + hostHeader};
return {u"http://"_s + hostHeader};
return hostHeader;
}
@ -101,28 +101,28 @@ namespace
contentType = contentType.toLower();
if (contentType.startsWith(u"image/"))
return u"private, max-age=604800"_qs; // 1 week
return u"private, max-age=604800"_s; // 1 week
if ((contentType == Http::CONTENT_TYPE_CSS)
|| (contentType == Http::CONTENT_TYPE_JS))
{
// short interval in case of program update
return u"private, max-age=43200"_qs; // 12 hrs
return u"private, max-age=43200"_s; // 12 hrs
}
return u"no-store"_qs;
return u"no-store"_s;
}
QString createLanguagesOptionsHtml()
{
// List language files
const QDir langDir {u":/www/translations"_qs};
const QStringList langFiles = langDir.entryList(QStringList(u"webui_*.qm"_qs), QDir::Files);
const QDir langDir {u":/www/translations"_s};
const QStringList langFiles = langDir.entryList(QStringList(u"webui_*.qm"_s), QDir::Files);
QStringList languages;
for (const QString &langFile : langFiles)
{
const QString localeStr = langFile.section(u"_"_qs, 1, -1).section(u"."_qs, 0, 0); // remove "webui_" and ".qm"
languages << u"<option value=\"%1\">%2</option>"_qs.arg(localeStr, Utils::Misc::languageToLocalizedString(localeStr));
const QString localeStr = langFile.section(u"_"_s, 1, -1).section(u"."_s, 0, 0); // remove "webui_" and ".qm"
languages << u"<option value=\"%1\">%2</option>"_s.arg(localeStr, Utils::Misc::languageToLocalizedString(localeStr));
qDebug() << "Supported locale:" << localeStr;
}
@ -134,7 +134,7 @@ namespace
if (cookieName.isEmpty() || (cookieName.size() > 128))
return false;
const QRegularExpression invalidNameRegex {u"[^a-zA-Z0-9_\\-]"_qs};
const QRegularExpression invalidNameRegex {u"[^a-zA-Z0-9_\\-]"_s};
if (invalidNameRegex.match(cookieName).hasMatch())
return false;
@ -148,7 +148,7 @@ WebApplication::WebApplication(IApplication *app, QObject *parent)
, m_cacheID {QString::number(Utils::Random::rand(), 36)}
, m_authController {new AuthController(this, app, this)}
{
declarePublicAPI(u"auth/login"_qs);
declarePublicAPI(u"auth/login"_s);
configure();
connect(Preferences::instance(), &Preferences::changed, this, &WebApplication::configure);
@ -184,7 +184,7 @@ void WebApplication::sendWebUIFile()
const QString path = (request().path != u"/")
? request().path
: u"/index.html"_qs;
: u"/index.html"_s;
Path localPath = m_rootFolder
/ Path(session() ? PRIVATE_FOLDER : PUBLIC_FOLDER)
@ -217,7 +217,7 @@ void WebApplication::sendWebUIFile()
void WebApplication::translateDocument(QString &data) const
{
const QRegularExpression regex(u"QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\]"_qs);
const QRegularExpression regex(u"QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\]"_s);
int i = 0;
bool found = true;
@ -238,8 +238,8 @@ void WebApplication::translateDocument(QString &data) const
QString translation = loadedText.isEmpty() ? sourceText : loadedText;
// Use HTML code for quotes to prevent issues with JS
translation.replace(u'\'', u"&#39;"_qs);
translation.replace(u'\"', u"&#34;"_qs);
translation.replace(u'\'', u"&#39;"_s);
translation.replace(u'\"', u"&#34;"_s);
data.replace(i, regexMatch.capturedLength(), translation);
i += translation.length();
@ -249,8 +249,8 @@ void WebApplication::translateDocument(QString &data) const
found = false; // no more translatable strings
}
data.replace(u"${LANG}"_qs, m_currentLocale.left(2));
data.replace(u"${CACHEID}"_qs, m_cacheID);
data.replace(u"${LANG}"_s, m_currentLocale.left(2));
data.replace(u"${CACHEID}"_s, m_cacheID);
}
}
@ -278,8 +278,8 @@ void WebApplication::doProcessRequest()
return;
}
const QString action = match.captured(u"action"_qs);
const QString scope = match.captured(u"scope"_qs);
const QString action = match.captured(u"action"_s);
const QString scope = match.captured(u"scope"_s);
// Check public/private scope
if (!session() && !isPublicAPI(scope, action))
@ -376,7 +376,7 @@ void WebApplication::configure()
m_currentLocale = newLocale;
m_translatedFiles.clear();
m_translationFileLoaded = m_translator.load((m_rootFolder / Path(u"translations/webui_"_qs) + newLocale).data());
m_translationFileLoaded = m_translator.load((m_rootFolder / Path(u"translations/webui_"_s) + newLocale).data());
if (m_translationFileLoaded)
{
LogMsg(tr("Web UI translation for selected locale (%1) has been successfully loaded.")
@ -402,25 +402,25 @@ void WebApplication::configure()
m_isHttpsEnabled = pref->isWebUiHttpsEnabled();
m_prebuiltHeaders.clear();
m_prebuiltHeaders.push_back({Http::HEADER_X_XSS_PROTECTION, u"1; mode=block"_qs});
m_prebuiltHeaders.push_back({Http::HEADER_X_CONTENT_TYPE_OPTIONS, u"nosniff"_qs});
m_prebuiltHeaders.push_back({Http::HEADER_X_XSS_PROTECTION, u"1; mode=block"_s});
m_prebuiltHeaders.push_back({Http::HEADER_X_CONTENT_TYPE_OPTIONS, u"nosniff"_s});
if (!m_isAltUIUsed)
{
m_prebuiltHeaders.push_back({Http::HEADER_CROSS_ORIGIN_OPENER_POLICY, u"same-origin"_qs});
m_prebuiltHeaders.push_back({Http::HEADER_REFERRER_POLICY, u"same-origin"_qs});
m_prebuiltHeaders.push_back({Http::HEADER_CROSS_ORIGIN_OPENER_POLICY, u"same-origin"_s});
m_prebuiltHeaders.push_back({Http::HEADER_REFERRER_POLICY, u"same-origin"_s});
}
const bool isClickjackingProtectionEnabled = pref->isWebUiClickjackingProtectionEnabled();
if (isClickjackingProtectionEnabled)
m_prebuiltHeaders.push_back({Http::HEADER_X_FRAME_OPTIONS, u"SAMEORIGIN"_qs});
m_prebuiltHeaders.push_back({Http::HEADER_X_FRAME_OPTIONS, u"SAMEORIGIN"_s});
const QString contentSecurityPolicy =
(m_isAltUIUsed
? QString()
: u"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; script-src 'self' 'unsafe-inline'; object-src 'none'; form-action 'self';"_qs)
+ (isClickjackingProtectionEnabled ? u" frame-ancestors 'self';"_qs : QString())
+ (m_isHttpsEnabled ? u" upgrade-insecure-requests;"_qs : QString());
: u"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; script-src 'self' 'unsafe-inline'; object-src 'none'; form-action 'self';"_s)
+ (isClickjackingProtectionEnabled ? u" frame-ancestors 'self';"_s : QString())
+ (m_isHttpsEnabled ? u" upgrade-insecure-requests;"_s : QString());
if (!contentSecurityPolicy.isEmpty())
m_prebuiltHeaders.push_back({Http::HEADER_CONTENT_SECURITY_POLICY, contentSecurityPolicy});
@ -526,7 +526,7 @@ void WebApplication::sendFile(const Path &path)
QByteArray data = readResult.value();
const QMimeType mimeType = QMimeDatabase().mimeTypeForFileNameAndData(path.data(), data);
const bool isTranslatable = !m_isAltUIUsed && mimeType.inherits(u"text/plain"_qs);
const bool isTranslatable = !m_isAltUIUsed && mimeType.inherits(u"text/plain"_s);
if (isTranslatable)
{
@ -535,8 +535,8 @@ void WebApplication::sendFile(const Path &path)
translateDocument(dataStr);
// Add the language options
if (path == (m_rootFolder / Path(PRIVATE_FOLDER) / Path(u"views/preferences.html"_qs)))
dataStr.replace(u"${LANGUAGE_OPTIONS}"_qs, createLanguagesOptionsHtml());
if (path == (m_rootFolder / Path(PRIVATE_FOLDER) / Path(u"views/preferences.html"_s)))
dataStr.replace(u"${LANGUAGE_OPTIONS}"_s, createLanguagesOptionsHtml());
data = dataStr.toUtf8();
m_translatedFiles[path] = {data, mimeType.name(), lastModified}; // caching translated file
@ -602,7 +602,7 @@ void WebApplication::sessionInitialize()
{
Q_ASSERT(!m_currentSession);
const QString sessionId {parseCookie(m_request.headers.value(u"cookie"_qs)).value(m_sessionCookieName)};
const QString sessionId {parseCookie(m_request.headers.value(u"cookie"_s)).value(m_sessionCookieName)};
// TODO: Additional session check
@ -659,7 +659,7 @@ bool WebApplication::isAuthNeeded()
bool WebApplication::isPublicAPI(const QString &scope, const QString &action) const
{
return m_publicAPIs.contains(u"%1/%2"_qs.arg(scope, action));
return m_publicAPIs.contains(u"%1/%2"_s.arg(scope, action));
}
void WebApplication::sessionStart()
@ -679,19 +679,19 @@ void WebApplication::sessionStart()
});
m_currentSession = new WebSession(generateSid(), app());
m_currentSession->registerAPIController<AppController>(u"app"_qs);
m_currentSession->registerAPIController<LogController>(u"log"_qs);
m_currentSession->registerAPIController<RSSController>(u"rss"_qs);
m_currentSession->registerAPIController<SearchController>(u"search"_qs);
m_currentSession->registerAPIController<SyncController>(u"sync"_qs);
m_currentSession->registerAPIController<TorrentsController>(u"torrents"_qs);
m_currentSession->registerAPIController<TransferController>(u"transfer"_qs);
m_currentSession->registerAPIController<AppController>(u"app"_s);
m_currentSession->registerAPIController<LogController>(u"log"_s);
m_currentSession->registerAPIController<RSSController>(u"rss"_s);
m_currentSession->registerAPIController<SearchController>(u"search"_s);
m_currentSession->registerAPIController<SyncController>(u"sync"_s);
m_currentSession->registerAPIController<TorrentsController>(u"torrents"_s);
m_currentSession->registerAPIController<TransferController>(u"transfer"_s);
m_sessions[m_currentSession->id()] = m_currentSession;
QNetworkCookie cookie {m_sessionCookieName.toLatin1(), m_currentSession->id().toUtf8()};
cookie.setHttpOnly(true);
cookie.setSecure(m_isSecureCookieEnabled && m_isHttpsEnabled);
cookie.setPath(u"/"_qs);
cookie.setPath(u"/"_s);
QByteArray cookieRawForm = cookie.toRawForm();
if (m_isCSRFProtectionEnabled)
cookieRawForm.append("; SameSite=Strict");
@ -705,7 +705,7 @@ void WebApplication::sessionEnd()
Q_ASSERT(m_currentSession);
QNetworkCookie cookie {m_sessionCookieName.toLatin1()};
cookie.setPath(u"/"_qs);
cookie.setPath(u"/"_s);
cookie.setExpirationDate(QDateTime::currentDateTime().addDays(-1));
delete m_sessions.take(m_currentSession->id());