Use QString literals

The plan is to define `QT_NO_CAST_FROM_ASCII` eventually.
PR #16561.
This commit is contained in:
Chocobo1
2022-03-04 13:25:22 +08:00
committed by GitHub
parent 2c8447853b
commit ab64ee872b
23 changed files with 104 additions and 108 deletions

View File

@@ -114,7 +114,7 @@ BitTorrent::BencodeResumeDataStorage::BencodeResumeDataStorage(const Path &path,
m_registeredTorrents.append(TorrentID::fromString(rxMatch.captured(1)));
}
loadQueue(m_resumeDataPath / Path("queue"));
loadQueue(m_resumeDataPath / Path(u"queue"_qs));
qDebug() << "Registered torrents count: " << m_registeredTorrents.size();
@@ -403,7 +403,7 @@ void BitTorrent::BencodeResumeDataStorage::Worker::storeQueue(const QVector<Torr
for (const BitTorrent::TorrentID &torrentID : queue)
data += (torrentID.toString().toLatin1() + '\n');
const Path filepath = m_resumeDataDir / Path("queue");
const Path filepath = m_resumeDataDir / Path(u"queue"_qs);
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(filepath, data);
if (!result)
{

View File

@@ -108,7 +108,7 @@
using namespace BitTorrent;
const Path CATEGORIES_FILE_NAME {"categories.json"};
const Path CATEGORIES_FILE_NAME {u"categories.json"_qs};
namespace
{
@@ -457,7 +457,7 @@ Session::Session(QObject *parent)
, m_storedTags(BITTORRENT_SESSION_KEY("Tags"))
, m_maxRatioAction(BITTORRENT_SESSION_KEY("MaxRatioAction"), Pause)
, m_savePath(BITTORRENT_SESSION_KEY("DefaultSavePath"), specialFolderLocation(SpecialFolder::Downloads))
, m_downloadPath(BITTORRENT_SESSION_KEY("TempPath"), (savePath() / Path("temp")))
, m_downloadPath(BITTORRENT_SESSION_KEY("TempPath"), (savePath() / Path(u"temp"_qs)))
, m_isDownloadPathEnabled(BITTORRENT_SESSION_KEY("TempPathEnabled"), false)
, m_isSubcategoriesEnabled(BITTORRENT_SESSION_KEY("SubcategoriesEnabled"), false)
, m_useCategoryPathsInManualMode(BITTORRENT_SESSION_KEY("UseCategoryPathsInManualMode"), false)
@@ -2556,7 +2556,7 @@ void Session::setSavePath(const Path &path)
void Session::setDownloadPath(const Path &path)
{
const Path newPath = (path.isAbsolute() ? path : (savePath() / Path("temp") / path));
const Path newPath = (path.isAbsolute() ? path : (savePath() / Path(u"temp"_qs) / path));
if (newPath == m_downloadPath)
return;
@@ -4451,7 +4451,7 @@ void Session::startUpTorrents()
{
qDebug("Initializing torrents resume data storage...");
const Path dbPath = specialFolderLocation(SpecialFolder::Data) / Path("torrents.db");
const Path dbPath = specialFolderLocation(SpecialFolder::Data) / Path(u"torrents.db"_qs);
const bool dbStorageExists = dbPath.exists();
ResumeDataStorage *startupStorage = nullptr;
@@ -4461,13 +4461,13 @@ void Session::startUpTorrents()
if (!dbStorageExists)
{
const Path dataPath = specialFolderLocation(SpecialFolder::Data) / Path("BT_backup");
const Path dataPath = specialFolderLocation(SpecialFolder::Data) / Path(u"BT_backup"_qs);
startupStorage = new BencodeResumeDataStorage(dataPath, this);
}
}
else
{
const Path dataPath = specialFolderLocation(SpecialFolder::Data) / Path("BT_backup");
const Path dataPath = specialFolderLocation(SpecialFolder::Data) / Path(u"BT_backup"_qs);
m_resumeDataStorage = new BencodeResumeDataStorage(dataPath, this);
if (dbStorageExists)

View File

@@ -324,8 +324,8 @@ TorrentImpl::TorrentImpl(Session *session, lt::session *nativeSession
// Remove .unwanted directory if empty
const Path newPath = spath / newRelPath;
qDebug() << "Attempting to remove \".unwanted\" folder at " << (newPath / Path(".unwanted")).toString();
Utils::Fs::rmdir(newPath / Path(".unwanted"));
qDebug() << "Attempting to remove \".unwanted\" folder at " << (newPath / Path(u".unwanted"_qs)).toString();
Utils::Fs::rmdir(newPath / Path(u".unwanted"_qs));
}
}
// == END UPGRADE CODE ==

View File

@@ -35,7 +35,6 @@
#define QBT_APP_64BIT
#endif
inline const char C_TORRENT_FILE_EXTENSION[] = ".torrent";
inline const int MAX_TORRENT_SIZE = 100 * 1024 * 1024; // 100 MiB
template <typename T>
@@ -56,3 +55,5 @@ inline QString operator"" _qs(const char16_t *str, const std::size_t size)
return QString::fromRawData(reinterpret_cast<const QChar *>(str), static_cast<int>(size));
}
#endif
inline const QString TORRENT_FILE_EXTENSION = u".torrent"_qs;

View File

@@ -323,7 +323,7 @@ bool RequestParser::parseFormData(const QByteArray &data)
const QList<QStringView> headerLines = QStringView(headers).split(QString::fromLatin1(CRLF), Qt::SkipEmptyParts);
for (const auto &line : headerLines)
{
if (line.trimmed().startsWith(QString::fromLatin1(HEADER_CONTENT_DISPOSITION), Qt::CaseInsensitive))
if (line.trimmed().startsWith(HEADER_CONTENT_DISPOSITION, Qt::CaseInsensitive))
{
// extract out filename & name
const QList<QStringView> directives = line.split(u';', Qt::SkipEmptyParts);

View File

@@ -33,43 +33,45 @@
#include <QString>
#include <QVector>
#include "base/global.h"
namespace Http
{
inline const char METHOD_GET[] = "GET";
inline const char METHOD_POST[] = "POST";
inline const QString METHOD_GET = u"GET"_qs;
inline const QString METHOD_POST = u"POST"_qs;
inline const char HEADER_CACHE_CONTROL[] = "cache-control";
inline const char HEADER_CONNECTION[] = "connection";
inline const char HEADER_CONTENT_DISPOSITION[] = "content-disposition";
inline const char HEADER_CONTENT_ENCODING[] = "content-encoding";
inline const char HEADER_CONTENT_LENGTH[] = "content-length";
inline const char HEADER_CONTENT_SECURITY_POLICY[] = "content-security-policy";
inline const char HEADER_CONTENT_TYPE[] = "content-type";
inline const char HEADER_DATE[] = "date";
inline const char HEADER_HOST[] = "host";
inline const char HEADER_ORIGIN[] = "origin";
inline const char HEADER_REFERER[] = "referer";
inline const char HEADER_REFERRER_POLICY[] = "referrer-policy";
inline const char HEADER_SET_COOKIE[] = "set-cookie";
inline const char HEADER_X_CONTENT_TYPE_OPTIONS[] = "x-content-type-options";
inline const char HEADER_X_FORWARDED_FOR[] = "x-forwarded-for";
inline const char HEADER_X_FORWARDED_HOST[] = "x-forwarded-host";
inline const char HEADER_X_FRAME_OPTIONS[] = "x-frame-options";
inline const char HEADER_X_XSS_PROTECTION[] = "x-xss-protection";
inline const QString HEADER_CACHE_CONTROL = u"cache-control"_qs;
inline const QString HEADER_CONNECTION = u"connection"_qs;
inline const QString HEADER_CONTENT_DISPOSITION = u"content-disposition"_qs;
inline const QString HEADER_CONTENT_ENCODING = u"content-encoding"_qs;
inline const QString HEADER_CONTENT_LENGTH = u"content-length"_qs;
inline const QString HEADER_CONTENT_SECURITY_POLICY = u"content-security-policy"_qs;
inline const QString HEADER_CONTENT_TYPE = u"content-type"_qs;
inline const QString HEADER_DATE = u"date"_qs;
inline const QString HEADER_HOST = u"host"_qs;
inline const QString HEADER_ORIGIN = u"origin"_qs;
inline const QString HEADER_REFERER = u"referer"_qs;
inline const QString HEADER_REFERRER_POLICY = u"referrer-policy"_qs;
inline const QString HEADER_SET_COOKIE = u"set-cookie"_qs;
inline const QString HEADER_X_CONTENT_TYPE_OPTIONS = u"x-content-type-options"_qs;
inline const QString HEADER_X_FORWARDED_FOR = u"x-forwarded-for"_qs;
inline const QString HEADER_X_FORWARDED_HOST = u"x-forwarded-host"_qs;
inline const QString HEADER_X_FRAME_OPTIONS = u"x-frame-options"_qs;
inline const QString HEADER_X_XSS_PROTECTION = u"x-xss-protection"_qs;
inline const char HEADER_REQUEST_METHOD_GET[] = "GET";
inline const char HEADER_REQUEST_METHOD_HEAD[] = "HEAD";
inline const char HEADER_REQUEST_METHOD_POST[] = "POST";
inline const QString HEADER_REQUEST_METHOD_GET = u"GET"_qs;
inline const QString HEADER_REQUEST_METHOD_HEAD = u"HEAD"_qs;
inline const QString HEADER_REQUEST_METHOD_POST = u"POST"_qs;
inline const char CONTENT_TYPE_HTML[] = "text/html";
inline const char CONTENT_TYPE_CSS[] = "text/css";
inline const char CONTENT_TYPE_TXT[] = "text/plain; charset=UTF-8";
inline const char CONTENT_TYPE_JS[] = "application/javascript";
inline const char CONTENT_TYPE_JSON[] = "application/json";
inline const char CONTENT_TYPE_GIF[] = "image/gif";
inline const char CONTENT_TYPE_PNG[] = "image/png";
inline const char CONTENT_TYPE_FORM_ENCODED[] = "application/x-www-form-urlencoded";
inline const char CONTENT_TYPE_FORM_DATA[] = "multipart/form-data";
inline const QString CONTENT_TYPE_HTML = u"text/html"_qs;
inline const QString CONTENT_TYPE_CSS = u"text/css"_qs;
inline const QString CONTENT_TYPE_TXT = u"text/plain; charset=UTF-8"_qs;
inline const QString CONTENT_TYPE_JS = u"application/javascript"_qs;
inline const QString CONTENT_TYPE_JSON = u"application/json"_qs;
inline const QString CONTENT_TYPE_GIF = u"image/gif"_qs;
inline const QString CONTENT_TYPE_PNG = u"image/png"_qs;
inline const QString CONTENT_TYPE_FORM_ENCODED = u"application/x-www-form-urlencoded"_qs;
inline const QString CONTENT_TYPE_FORM_DATA = u"multipart/form-data"_qs;
// portability: "\r\n" doesn't guarantee mapping to the correct symbol
inline const char CRLF[] = {0x0D, 0x0A, '\0'};

View File

@@ -33,6 +33,7 @@
#include <QHostAddress>
#include <QLocale>
#include "base/global.h"
#include "base/logger.h"
#include "base/preferences.h"
#include "base/profile.h"
@@ -43,8 +44,8 @@
#include "geoipdatabase.h"
const QString DATABASE_URL = QStringLiteral("https://download.db-ip.com/free/dbip-country-lite-%1.mmdb.gz");
const char GEODB_FOLDER[] = "GeoDB";
const char GEODB_FILENAME[] = "dbip-country-lite.mmdb";
const QString GEODB_FOLDER = u"GeoDB"_qs;
const QString GEODB_FILENAME = u"dbip-country-lite.mmdb"_qs;
using namespace Net;

View File

@@ -68,11 +68,6 @@ Path::Path(const std::string &pathStr)
{
}
Path::Path(const char pathStr[])
: Path(QString::fromLatin1(pathStr))
{
}
bool Path::isValid() const
{
if (isEmpty())
@@ -211,11 +206,6 @@ Path &Path::operator+=(const QString &str)
return *this;
}
Path &Path::operator+=(const char str[])
{
return (*this += QString::fromLatin1(str));
}
Path &Path::operator+=(const std::string &str)
{
return (*this += QString::fromStdString(str));

View File

@@ -40,7 +40,6 @@ public:
Path() = default;
explicit Path(const QString &pathStr);
explicit Path(const char pathStr[]);
explicit Path(const std::string &pathStr);
bool isValid() const;
@@ -68,7 +67,6 @@ public:
Path &operator/=(const Path &other);
Path &operator+=(const QString &str);
Path &operator+=(const char str[]);
Path &operator+=(const std::string &str);
static Path commonPath(const Path &left, const Path &right);

View File

@@ -31,6 +31,7 @@
#include <QCoreApplication>
#include "base/global.h"
#include "base/utils/fs.h"
Private::Profile::Profile(const QString &configurationName)
@@ -91,7 +92,7 @@ Path Private::DefaultProfile::dataLocation() const
// On Linux keep using the legacy directory ~/.local/share/data/ if it exists
const Path genericDataPath {QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)};
const Path profilePath {profileName()};
const Path legacyDir = genericDataPath / Path("data") / profilePath;
const Path legacyDir = genericDataPath / Path(u"data"_qs) / profilePath;
const Path dataDir = genericDataPath / profilePath;
@@ -130,10 +131,10 @@ Private::CustomProfile::CustomProfile(const Path &rootPath, const QString &confi
: Profile {configurationName}
, m_rootPath {rootPath}
, m_basePath {m_rootPath / Path(profileName())}
, m_cacheLocation {m_basePath / Path("cache")}
, m_configLocation {m_basePath / Path("config")}
, m_dataLocation {m_basePath / Path("data")}
, m_downloadLocation {m_basePath / Path("downloads")}
, m_cacheLocation {m_basePath / Path(u"cache"_qs)}
, m_configLocation {m_basePath / Path(u"config"_qs)}
, m_dataLocation {m_basePath / Path(u"data"_qs)}
, m_downloadLocation {m_basePath / Path(u"downloads"_qs)}
{
}

View File

@@ -30,6 +30,7 @@
#include <QProcess>
#include "base/global.h"
#include "base/path.h"
#include "base/utils/foreignapps.h"
#include "base/utils/fs.h"
@@ -45,7 +46,7 @@ SearchDownloadHandler::SearchDownloadHandler(const QString &siteUrl, const QStri
, this, &SearchDownloadHandler::downloadProcessFinished);
const QStringList params
{
(m_manager->engineLocation() / Path("nova2dl.py")).toString(),
(m_manager->engineLocation() / Path(u"nova2dl.py"_qs)).toString(),
siteUrl,
url
};

View File

@@ -68,7 +68,7 @@ SearchHandler::SearchHandler(const QString &pattern, const QString &category, co
const QStringList params
{
(m_manager->engineLocation() / Path("nova2.py")).toString(),
(m_manager->engineLocation() / Path(u"nova2.py"_qs)).toString(),
m_usedPlugins.join(','),
m_category
};

View File

@@ -363,7 +363,7 @@ QString SearchPluginManager::pluginFullName(const QString &pluginName)
Path SearchPluginManager::pluginsLocation()
{
return (engineLocation() / Path("engines"));
return (engineLocation() / Path(u"engines"_qs));
}
Path SearchPluginManager::engineLocation()
@@ -371,7 +371,7 @@ Path SearchPluginManager::engineLocation()
static Path location;
if (location.isEmpty())
{
location = specialFolderLocation(SpecialFolder::Data) / Path("nova3");
location = specialFolderLocation(SpecialFolder::Data) / Path(u"nova3"_qs);
Utils::Fs::mkpath(location);
}
@@ -416,20 +416,20 @@ void SearchPluginManager::updateNova()
// create nova directory if necessary
const Path enginePath = engineLocation();
QFile packageFile {(enginePath / Path("__init__.py")).data()};
QFile packageFile {(enginePath / Path(u"__init__.py"_qs)).data()};
packageFile.open(QIODevice::WriteOnly);
packageFile.close();
Utils::Fs::mkdir(enginePath / Path("engines"));
Utils::Fs::mkdir(enginePath / Path(u"engines"_qs));
QFile packageFile2 {(enginePath / Path("engines/__init__.py")).data()};
QFile packageFile2 {(enginePath / Path(u"engines/__init__.py"_qs)).data()};
packageFile2.open(QIODevice::WriteOnly);
packageFile2.close();
// Copy search plugin files (if necessary)
const auto updateFile = [&enginePath](const Path &filename, const bool compareVersion)
{
const Path filePathBundled = Path(":/searchengine/nova3") / filename;
const Path filePathBundled = Path(u":/searchengine/nova3"_qs) / filename;
const Path filePathDisk = enginePath / filename;
if (compareVersion && (getPluginVersion(filePathBundled) <= getPluginVersion(filePathDisk)))
@@ -439,12 +439,12 @@ void SearchPluginManager::updateNova()
Utils::Fs::copyFile(filePathBundled, filePathDisk);
};
updateFile(Path("helpers.py"), true);
updateFile(Path("nova2.py"), true);
updateFile(Path("nova2dl.py"), true);
updateFile(Path("novaprinter.py"), true);
updateFile(Path("sgmllib3.py"), false);
updateFile(Path("socks.py"), false);
updateFile(Path(u"helpers.py"_qs), true);
updateFile(Path(u"nova2.py"_qs), true);
updateFile(Path(u"nova2dl.py"_qs), true);
updateFile(Path(u"novaprinter.py"_qs), true);
updateFile(Path(u"sgmllib3.py"_qs), false);
updateFile(Path(u"socks.py"_qs), false);
}
void SearchPluginManager::update()
@@ -452,7 +452,7 @@ void SearchPluginManager::update()
QProcess nova;
nova.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
const QStringList params {(engineLocation() / Path("/nova2.py")).toString(), QLatin1String("--capabilities")};
const QStringList params {(engineLocation() / Path(u"/nova2.py"_qs)).toString(), QLatin1String("--capabilities")};
nova.start(Utils::ForeignApps::pythonInfo().executableName, params, QIODevice::ReadOnly);
nova.waitForFinished();

View File

@@ -207,7 +207,7 @@ qint64 Utils::Fs::freeDiskSpaceOnPath(const Path &path)
Path Utils::Fs::tempPath()
{
static const Path path = Path(QDir::tempPath()) / Path(".qBittorrent");
static const Path path = Path(QDir::tempPath()) / Path(u".qBittorrent"_qs);
mkdir(path);
return path;
}