Merge pull request #16585 from Chocobo1/qstring

Use QString literals
This commit is contained in:
Chocobo1
2022-03-12 12:49:08 +08:00
committed by GitHub
40 changed files with 775 additions and 768 deletions

View File

@@ -285,9 +285,9 @@ void BitTorrent::BencodeResumeDataStorage::loadQueue(const Path &queueFilename)
if (queueFile.open(QFile::ReadOnly))
{
const QRegularExpression hashPattern {QLatin1String("^([A-Fa-f0-9]{40})$")};
QByteArray line;
QString line;
int start = 0;
while (!(line = queueFile.readLine().trimmed()).isEmpty())
while (!(line = QString::fromLatin1(queueFile.readLine().trimmed())).isEmpty())
{
const QRegularExpressionMatch rxMatch = hashPattern.match(line);
if (rxMatch.hasMatch())

View File

@@ -58,14 +58,14 @@
namespace
{
const char DB_CONNECTION_NAME[] = "ResumeDataStorage";
const QString DB_CONNECTION_NAME = u"ResumeDataStorage"_qs;
const int DB_VERSION = 2;
const char DB_TABLE_META[] = "meta";
const char DB_TABLE_TORRENTS[] = "torrents";
const QString DB_TABLE_META = u"meta"_qs;
const QString DB_TABLE_TORRENTS = u"torrents"_qs;
const char META_VERSION[] = "version";
const QString META_VERSION = u"version"_qs;
struct Column
{
@@ -370,7 +370,7 @@ int BitTorrent::DBResumeDataStorage::currentDBVersion() const
if (!query.prepare(selectDBVersionStatement))
throw RuntimeError(query.lastError().text());
query.bindValue(DB_COLUMN_NAME.placeholder, QString::fromLatin1(META_VERSION));
query.bindValue(DB_COLUMN_NAME.placeholder, META_VERSION);
if (!query.exec())
throw RuntimeError(query.lastError().text());
@@ -410,7 +410,7 @@ void BitTorrent::DBResumeDataStorage::createDB() const
if (!query.prepare(insertMetaVersionQuery))
throw RuntimeError(query.lastError().text());
query.bindValue(DB_COLUMN_NAME.placeholder, QString::fromLatin1(META_VERSION));
query.bindValue(DB_COLUMN_NAME.placeholder, META_VERSION);
query.bindValue(DB_COLUMN_VALUE.placeholder, DB_VERSION);
if (!query.exec())
@@ -468,7 +468,7 @@ void BitTorrent::DBResumeDataStorage::updateDBFromVersion1() const
if (!query.prepare(updateMetaVersionQuery))
throw RuntimeError(query.lastError().text());
query.bindValue(DB_COLUMN_NAME.placeholder, QString::fromLatin1(META_VERSION));
query.bindValue(DB_COLUMN_NAME.placeholder, META_VERSION);
query.bindValue(DB_COLUMN_VALUE.placeholder, DB_VERSION);
if (!query.exec())

View File

@@ -113,7 +113,7 @@ const Path CATEGORIES_FILE_NAME {u"categories.json"_qs};
namespace
{
const char PEER_ID[] = "qB";
const char USER_AGENT[] = "qBittorrent/" QBT_VERSION_2;
const auto USER_AGENT = QStringLiteral("qBittorrent/" QBT_VERSION_2);
void torrentQueuePositionUp(const lt::torrent_handle &handle)
{
@@ -693,7 +693,7 @@ Path Session::downloadPath() const
bool Session::isValidCategoryName(const QString &name)
{
static const QRegularExpression re(R"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)");
static const QRegularExpression re(uR"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"_qs);
if (!name.isEmpty() && (name.indexOf(re) != 0))
{
qDebug() << "Incorrect category name:" << name;
@@ -710,7 +710,7 @@ QStringList Session::expandCategory(const QString &category)
return result;
int index = 0;
while ((index = category.indexOf('/', index)) >= 0)
while ((index = category.indexOf(u'/', index)) >= 0)
{
result << category.left(index);
++index;
@@ -826,7 +826,7 @@ bool Session::removeCategory(const QString &name)
for (TorrentImpl *const torrent : asConst(m_torrents))
{
if (torrent->belongsToCategory(name))
torrent->setCategory("");
torrent->setCategory(u""_qs);
}
// remove stored category and its subcategories if exist
@@ -834,7 +834,7 @@ bool Session::removeCategory(const QString &name)
if (isSubcategoriesEnabled())
{
// remove subcategories
const QString test = name + '/';
const QString test = name + u'/';
Algorithm::removeIf(m_categories, [this, &test, &result](const QString &category, const CategoryOptions &)
{
if (category.startsWith(test))
@@ -902,7 +902,7 @@ QSet<QString> Session::tags() const
bool Session::isValidTag(const QString &tag)
{
return (!tag.trimmed().isEmpty() && !tag.contains(','));
return (!tag.trimmed().isEmpty() && !tag.contains(u','));
}
bool Session::hasTag(const QString &tag) const
@@ -1130,7 +1130,7 @@ void Session::initializeNativeSession()
lt::settings_pack pack;
pack.set_str(lt::settings_pack::peer_fingerprint, peerId);
pack.set_bool(lt::settings_pack::listen_system_port_fallback, false);
pack.set_str(lt::settings_pack::user_agent, USER_AGENT);
pack.set_str(lt::settings_pack::user_agent, USER_AGENT.toStdString());
pack.set_bool(lt::settings_pack::use_dht_as_fallback, false);
// Speed up exit
pack.set_int(lt::settings_pack::auto_scrape_interval, 1200); // 20 minutes
@@ -1508,7 +1508,7 @@ void Session::configureNetworkInterfaces(lt::settings_pack &settingsPack)
QStringList endpoints;
QStringList outgoingInterfaces;
const QString portString = ':' + QString::number(port());
const QString portString = u':' + QString::number(port());
for (const QString &ip : asConst(getListeningIPs()))
{
@@ -1520,7 +1520,7 @@ void Session::configureNetworkInterfaces(lt::settings_pack &settingsPack)
? Utils::Net::canonicalIPv6Addr(addr).toString()
: addr.toString();
endpoints << ((isIPv6 ? ('[' + ip + ']') : ip) + portString);
endpoints << ((isIPv6 ? (u'[' + ip + u']') : ip) + portString);
if ((ip != QLatin1String("0.0.0.0")) && (ip != QLatin1String("::")))
outgoingInterfaces << ip;
@@ -1553,11 +1553,11 @@ void Session::configureNetworkInterfaces(lt::settings_pack &settingsPack)
}
}
const QString finalEndpoints = endpoints.join(',');
const QString finalEndpoints = endpoints.join(u',');
settingsPack.set_str(lt::settings_pack::listen_interfaces, finalEndpoints.toStdString());
LogMsg(tr("Trying to listen on the following list of IP addresses: \"%1\"").arg(finalEndpoints));
settingsPack.set_str(lt::settings_pack::outgoing_interfaces, outgoingInterfaces.join(',').toStdString());
settingsPack.set_str(lt::settings_pack::outgoing_interfaces, outgoingInterfaces.join(u',').toStdString());
m_listenInterfaceConfigured = true;
}
@@ -2154,7 +2154,7 @@ LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorr
const QString category = addTorrentParams.category;
if (!category.isEmpty() && !m_categories.contains(category) && !addCategory(category))
loadTorrentParams.category = "";
loadTorrentParams.category = u""_qs;
else
loadTorrentParams.category = category;
@@ -5048,7 +5048,7 @@ void Session::handleFileErrorAlert(const lt::file_error_alert *p)
const QString msg = QString::fromStdString(p->message());
LogMsg(tr("File error alert. Torrent: \"%1\". File: \"%2\". Reason: \"%3\"")
.arg(torrent->name(), p->filename(), msg)
.arg(torrent->name(), QString::fromLocal8Bit(p->filename()), msg)
, Log::WARNING);
emit fullDiskError(torrent, msg);
}
@@ -5079,7 +5079,7 @@ void Session::handlePeerBlockedAlert(const lt::peer_blocked_alert *p)
reason = tr("port filter", "this peer was blocked. Reason: port filter.");
break;
case lt::peer_blocked_alert::i2p_mixed:
reason = tr("%1 mixed mode restrictions", "this peer was blocked. Reason: I2P mixed mode restrictions.").arg("I2P"); // don't translate I2P
reason = tr("%1 mixed mode restrictions", "this peer was blocked. Reason: I2P mixed mode restrictions.").arg(u"I2P"_qs); // don't translate I2P
break;
case lt::peer_blocked_alert::privileged_ports:
reason = tr("use of privileged port", "this peer was blocked. Reason: use of privileged port.");
@@ -5088,7 +5088,7 @@ void Session::handlePeerBlockedAlert(const lt::peer_blocked_alert *p)
reason = tr("%1 is disabled", "this peer was blocked. Reason: uTP is disabled.").arg(QString::fromUtf8(C_UTP)); // don't translate μTP
break;
case lt::peer_blocked_alert::tcp_disabled:
reason = tr("%1 is disabled", "this peer was blocked. Reason: TCP is disabled.").arg("TCP"); // don't translate TCP
reason = tr("%1 is disabled", "this peer was blocked. Reason: TCP is disabled.").arg(u"TCP"_qs); // don't translate TCP
break;
}
@@ -5113,13 +5113,13 @@ void Session::handleUrlSeedAlert(const lt::url_seed_alert *p)
if (p->error)
{
LogMsg(tr("URL seed DNS lookup failed. Torrent: \"%1\". URL: \"%2\". Error: \"%3\"")
.arg(torrent->name(), p->server_url(), QString::fromStdString(p->message()))
.arg(torrent->name(), QString::fromUtf8(p->server_url()), QString::fromStdString(p->message()))
, Log::WARNING);
}
else
{
LogMsg(tr("Received error message from URL seed. Torrent: \"%1\". URL: \"%2\". Message: \"%3\"")
.arg(torrent->name(), p->server_url(), p->error_message())
.arg(torrent->name(), QString::fromUtf8(p->server_url()), QString::fromUtf8(p->error_message()))
, Log::WARNING);
}
}
@@ -5334,7 +5334,7 @@ void Session::handleTrackerAlert(const lt::tracker_alert *a)
if (a->type() == lt::tracker_reply_alert::alert_type)
{
const int numPeers = static_cast<const lt::tracker_reply_alert *>(a)->num_peers;
torrent->updatePeerCount(trackerURL, a->local_endpoint, numPeers);
torrent->updatePeerCount(QString::fromUtf8(trackerURL), a->local_endpoint, numPeers);
}
}

View File

@@ -30,6 +30,7 @@
#include <QDateTime>
#include "base/global.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h"
#include "base/profile.h"
@@ -94,9 +95,9 @@ void Statistics::save() const
SettingsPtr s = Profile::instance()->applicationSettings(QLatin1String("qBittorrent-data"));
QVariantHash v;
v.insert("AlltimeDL", m_alltimeDL + m_sessionDL);
v.insert("AlltimeUL", m_alltimeUL + m_sessionUL);
s->setValue("Stats/AllStats", v);
v.insert(u"AlltimeDL"_qs, m_alltimeDL + m_sessionDL);
v.insert(u"AlltimeUL"_qs, m_alltimeUL + m_sessionUL);
s->setValue(u"Stats/AllStats"_qs, v);
m_dirty = false;
m_lastWrite = now;
}
@@ -104,8 +105,8 @@ void Statistics::save() const
void Statistics::load()
{
const SettingsPtr s = Profile::instance()->applicationSettings(QLatin1String("qBittorrent-data"));
const QVariantHash v = s->value("Stats/AllStats").toHash();
const QVariantHash v = s->value(u"Stats/AllStats"_qs).toHash();
m_alltimeDL = v["AlltimeDL"].toULongLong();
m_alltimeUL = v["AlltimeUL"].toULongLong();
m_alltimeDL = v[u"AlltimeDL"_qs].toULongLong();
m_alltimeUL = v[u"AlltimeUL"_qs].toULongLong();
}

View File

@@ -52,7 +52,7 @@ namespace
// name starts with a .
bool fileFilter(const std::string &f)
{
return !Path(f).filename().startsWith('.');
return !Path(f).filename().startsWith(u'.');
}
#ifdef QBT_USES_LIBTORRENT2

View File

@@ -762,7 +762,7 @@ bool TorrentImpl::belongsToCategory(const QString &category) const
if (m_category == category) return true;
if (m_session->isSubcategoriesEnabled() && m_category.startsWith(category + '/'))
if (m_session->isSubcategoriesEnabled() && m_category.startsWith(category + u'/'))
return true;
return false;
@@ -1859,7 +1859,7 @@ void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p)
// For example renaming "a/b/c" to "d/b/c", then folders "a/b" and "a" will
// be removed if they are empty
const Path oldFilePath = m_filePaths.at(fileIndex);
const Path newFilePath {QString(p->new_name())};
const Path newFilePath {QString::fromUtf8(p->new_name())};
// Check if ".!qB" extension was just added or removed
// We should compare path in a case sensitive manner even on case insensitive

View File

@@ -122,7 +122,7 @@ nonstd::expected<TorrentInfo, QString> TorrentInfo::loadFromFile(const Path &pat
}
catch (const std::bad_alloc &e)
{
return nonstd::make_unexpected(tr("Torrent file read error: %1").arg(e.what()));
return nonstd::make_unexpected(tr("Torrent file read error: %1").arg(QString::fromLocal8Bit(e.what())));
}
if (data.size() != file.size())
@@ -294,7 +294,7 @@ QVector<QUrl> TorrentInfo::urlSeeds() const
for (const lt::web_seed_entry &webSeed : nativeWebSeeds)
{
if (webSeed.type == lt::web_seed_entry::url_seed)
urlSeeds.append(QUrl(webSeed.url.c_str()));
urlSeeds.append(QUrl(QString::fromStdString(webSeed.url)));
}
return urlSeeds;

View File

@@ -53,23 +53,23 @@ namespace
// constants
const int PEER_ID_SIZE = 20;
const char ANNOUNCE_REQUEST_PATH[] = "/announce";
const QString ANNOUNCE_REQUEST_PATH = u"/announce"_qs;
const char ANNOUNCE_REQUEST_COMPACT[] = "compact";
const char ANNOUNCE_REQUEST_INFO_HASH[] = "info_hash";
const char ANNOUNCE_REQUEST_IP[] = "ip";
const char ANNOUNCE_REQUEST_LEFT[] = "left";
const char ANNOUNCE_REQUEST_NO_PEER_ID[] = "no_peer_id";
const char ANNOUNCE_REQUEST_NUM_WANT[] = "numwant";
const char ANNOUNCE_REQUEST_PEER_ID[] = "peer_id";
const char ANNOUNCE_REQUEST_PORT[] = "port";
const QString ANNOUNCE_REQUEST_COMPACT = u"compact"_qs;
const QString ANNOUNCE_REQUEST_INFO_HASH = u"info_hash"_qs;
const QString ANNOUNCE_REQUEST_IP = u"ip"_qs;
const QString ANNOUNCE_REQUEST_LEFT = u"left"_qs;
const QString ANNOUNCE_REQUEST_NO_PEER_ID = u"no_peer_id"_qs;
const QString ANNOUNCE_REQUEST_NUM_WANT = u"numwant"_qs;
const QString ANNOUNCE_REQUEST_PEER_ID = u"peer_id"_qs;
const QString ANNOUNCE_REQUEST_PORT = u"port"_qs;
const char ANNOUNCE_REQUEST_EVENT[] = "event";
const char ANNOUNCE_REQUEST_EVENT_COMPLETED[] = "completed";
const char ANNOUNCE_REQUEST_EVENT_EMPTY[] = "empty";
const char ANNOUNCE_REQUEST_EVENT_STARTED[] = "started";
const char ANNOUNCE_REQUEST_EVENT_STOPPED[] = "stopped";
const char ANNOUNCE_REQUEST_EVENT_PAUSED[] = "paused";
const QString ANNOUNCE_REQUEST_EVENT = u"event"_qs;
const QString ANNOUNCE_REQUEST_EVENT_COMPLETED = u"completed"_qs;
const QString ANNOUNCE_REQUEST_EVENT_EMPTY = u"empty"_qs;
const QString ANNOUNCE_REQUEST_EVENT_STARTED = u"started"_qs;
const QString ANNOUNCE_REQUEST_EVENT_STOPPED = u"stopped"_qs;
const QString ANNOUNCE_REQUEST_EVENT_PAUSED = u"paused"_qs;
const char ANNOUNCE_RESPONSE_COMPLETE[] = "complete";
const char ANNOUNCE_RESPONSE_EXTERNAL_IP[] = "external ip";
@@ -293,32 +293,32 @@ void Tracker::processAnnounceRequest()
// 1. info_hash
const auto infoHashIter = queryParams.find(ANNOUNCE_REQUEST_INFO_HASH);
if (infoHashIter == queryParams.end())
throw TrackerError("Missing \"info_hash\" parameter");
throw TrackerError(u"Missing \"info_hash\" parameter"_qs);
const auto torrentID = TorrentID::fromString(infoHashIter->toHex());
const auto torrentID = TorrentID::fromString(QString::fromLatin1(infoHashIter->toHex()));
if (!torrentID.isValid())
throw TrackerError("Invalid \"info_hash\" parameter");
throw TrackerError(u"Invalid \"info_hash\" parameter"_qs);
announceReq.torrentID = torrentID;
// 2. peer_id
const auto peerIdIter = queryParams.find(ANNOUNCE_REQUEST_PEER_ID);
if (peerIdIter == queryParams.end())
throw TrackerError("Missing \"peer_id\" parameter");
throw TrackerError(u"Missing \"peer_id\" parameter"_qs);
if (peerIdIter->size() > PEER_ID_SIZE)
throw TrackerError("Invalid \"peer_id\" parameter");
throw TrackerError(u"Invalid \"peer_id\" parameter"_qs);
announceReq.peer.peerId = *peerIdIter;
// 3. port
const auto portIter = queryParams.find(ANNOUNCE_REQUEST_PORT);
if (portIter == queryParams.end())
throw TrackerError("Missing \"port\" parameter");
throw TrackerError(u"Missing \"port\" parameter"_qs);
const ushort portNum = portIter->toUShort();
if (portNum == 0)
throw TrackerError("Invalid \"port\" parameter");
throw TrackerError(u"Invalid \"port\" parameter"_qs);
announceReq.peer.port = portNum;
@@ -328,7 +328,7 @@ void Tracker::processAnnounceRequest()
{
const int num = numWantIter->toInt();
if (num < 0)
throw TrackerError("Invalid \"numwant\" parameter");
throw TrackerError(u"Invalid \"numwant\" parameter"_qs);
announceReq.numwant = num;
}
@@ -355,7 +355,7 @@ void Tracker::processAnnounceRequest()
: announceReq.socketAddress.toString().toLatin1().constData(),
// 10. event
announceReq.event = queryParams.value(ANNOUNCE_REQUEST_EVENT);
announceReq.event = QString::fromLatin1(queryParams.value(ANNOUNCE_REQUEST_EVENT));
if (announceReq.event.isEmpty()
|| (announceReq.event == ANNOUNCE_REQUEST_EVENT_EMPTY)
@@ -373,7 +373,7 @@ void Tracker::processAnnounceRequest()
}
else
{
throw TrackerError("Invalid \"event\" parameter");
throw TrackerError(u"Invalid \"event\" parameter"_qs);
}
prepareAnnounceResponse(announceReq);