Skip to content
Permalink
Browse files

Construct QString more efficiently

  • Loading branch information
Chocobo1 committed Mar 22, 2020
1 parent 2c23840 commit 7de8a4d6e0c33a8455262cc1f07632bb5cb4e0a1
@@ -587,7 +587,7 @@ int Application::exec(const QStringList &params)
#ifndef DISABLE_WEBUI
Preferences *const pref = Preferences::instance();
// Display some information to the user
const QString mesg = QString("\n******** %1 ********\n").arg(tr("Information"))
const QString mesg = QString::fromLatin1("\n******** %1 ********\n").arg(tr("Information"))
+ tr("To control qBittorrent, access the Web UI at %1")
.arg(QString("http://localhost:") + QString::number(pref->getWebUiPort())) + '\n';
printf("%s", qUtf8Printable(mesg));
@@ -364,7 +364,7 @@ QStringList QBtCommandLineParameters::paramList() const
// torrent paths or URLs.

if (!savePath.isEmpty())
result.append(QString("@savePath=%1").arg(savePath));
result.append(QLatin1String("@savePath=") + savePath);

if (addPaused == TriStateBool::True) {
result.append(QLatin1String("@addPaused=1"));
@@ -377,7 +377,7 @@ QStringList QBtCommandLineParameters::paramList() const
result.append(QLatin1String("@skipChecking"));

if (!category.isEmpty())
result.append(QString("@category=%1").arg(category));
result.append(QLatin1String("@category=") + category);

if (sequential)
result.append(QLatin1String("@sequential"));
@@ -395,7 +395,7 @@ bool userAgreesWithLegalNotice()
Q_ASSERT(!pref->getAcceptedLegal());

#ifdef DISABLE_GUI
const QString eula = QString("\n*** %1 ***\n").arg(QObject::tr("Legal Notice"))
const QString eula = QString::fromLatin1("\n*** %1 ***\n").arg(QObject::tr("Legal Notice"))
+ QObject::tr("qBittorrent is a file sharing program. When you run a torrent, its data will be made available to others by means of upload. Any content you share is your sole responsibility.") + "\n\n"
+ QObject::tr("No further notices will be issued.") + "\n\n"
+ QObject::tr("Press %1 key to accept and continue...").arg("'y'") + '\n';
@@ -93,16 +93,16 @@ BOOL CALLBACK straceWin::EnumModulesCB(LPCSTR ModuleName, DWORD64 BaseOfDll, PVO
EnumModulesContext* context = (EnumModulesContext*)UserContext;
mod.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
if(SymGetModuleInfo64(context->hProcess, BaseOfDll, &mod)) {
QString moduleBase = QString("0x%1").arg(BaseOfDll, 16, 16, QLatin1Char('0'));
QString line = QString("%1 %2 Image: %3")
QString moduleBase = QString::fromLatin1("0x%1").arg(BaseOfDll, 16, 16, QLatin1Char('0'));
QString line = QString::fromLatin1("%1 %2 Image: %3")
.arg(mod.ModuleName, -25)
.arg(moduleBase, -13)
.arg(mod.LoadedImageName);
context->stream << line << '\n';

QString pdbName(mod.LoadedPdbName);
if(!pdbName.isEmpty()) {
QString line2 = QString("%1 %2")
QString line2 = QString::fromLatin1("%1 %2")
.arg("", 35)
.arg(pdbName);
context->stream << line2 << '\n';
@@ -165,7 +165,7 @@ QString straceWin::getSourcePathAndLineNumber(HANDLE hProcess, DWORD64 addr)
}
#endif
#endif
return QString("%1 : %2").arg(path).arg(line.LineNumber);
return QString::fromLatin1("%1 : %2").arg(path).arg(line.LineNumber);
}

return QString();
@@ -296,15 +296,15 @@ const QString straceWin::getBacktrace()
sourceFile = getSourcePathAndLineNumber(hProcess, ihsf.InstructionOffset - 1);
}
else {
funcName = QString("0x%1").arg(ihsf.InstructionOffset, 8, 16, QLatin1Char('0'));
funcName = QString::fromLatin1("0x%1").arg(ihsf.InstructionOffset, 8, 16, QLatin1Char('0'));
}
SymSetContext(hProcess, &ihsf, NULL);
#ifndef __MINGW32__
QStringList params;
SymEnumSymbols(hProcess, 0, NULL, EnumSymbolsCB, (PVOID)&params);
#endif

QString insOffset = QString("0x%1").arg(ihsf.InstructionOffset, 16, 16, QLatin1Char('0'));
QString insOffset = QString::fromLatin1("0x%1").arg(ihsf.InstructionOffset, 16, 16, QLatin1Char('0'));
QString formatLine = "#%1 %2 %3 %4";
#ifndef __MINGW32__
formatLine += "(%5)";
@@ -318,7 +318,7 @@ const QString straceWin::getBacktrace()
.arg(params.join(", "));

if (!sourceFile.isEmpty())
debugLine += QString("[ %1 ]").arg(sourceFile);
debugLine += QString::fromLatin1("[ %1 ]").arg(sourceFile);
#else
;
#endif
@@ -1810,7 +1810,7 @@ bool Session::deleteTorrent(const InfoHash &hash, const DeleteOption deleteOptio
// Remove it from torrent resume directory
const QDir resumeDataDir(m_resumeFolderPath);
QStringList filters;
filters << QString("%1.*").arg(torrent->hash());
filters << QString::fromLatin1("%1.*").arg(torrent->hash());
const QStringList files = resumeDataDir.entryList(filters, QDir::Files, QDir::Unsorted);
for (const QString &file : files)
Utils::Fs::forceRemove(resumeDataDir.absoluteFilePath(file));
@@ -2457,16 +2457,16 @@ void Session::exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolde
((folder == TorrentExportFolder::Finished) && !finishedTorrentExportDirectory().isEmpty()));

const QString validName = Utils::Fs::toValidFileSystemName(torrent->name());
const QString torrentFilename = QString("%1.torrent").arg(torrent->hash());
QString torrentExportFilename = QString("%1.torrent").arg(validName);
const QString torrentFilename = QString::fromLatin1("%1.torrent").arg(torrent->hash());
QString torrentExportFilename = QString::fromLatin1("%1.torrent").arg(validName);
const QString torrentPath = QDir(m_resumeFolderPath).absoluteFilePath(torrentFilename);
const QDir exportPath(folder == TorrentExportFolder::Regular ? torrentExportDirectory() : finishedTorrentExportDirectory());
if (exportPath.exists() || exportPath.mkpath(exportPath.absolutePath())) {
QString newTorrentPath = exportPath.absoluteFilePath(torrentExportFilename);
int counter = 0;
while (QFile::exists(newTorrentPath) && !Utils::Fs::sameFiles(torrentPath, newTorrentPath)) {
// Append number to torrent name to make it unique
torrentExportFilename = QString("%1 %2.torrent").arg(validName).arg(++counter);
torrentExportFilename = QString::fromLatin1("%1 %2.torrent").arg(validName).arg(++counter);
newTorrentPath = exportPath.absoluteFilePath(torrentExportFilename);
}

@@ -3923,7 +3923,7 @@ void Session::handleTorrentResumeDataReady(TorrentHandle *const torrent, const l
out.reserve(1024 * 1024); // most fastresume file sizes are under 1 MB
lt::bencode(std::back_inserter(out), data);

const QString filename = QString("%1.fastresume").arg(torrent->hash());
const QString filename = QString::fromLatin1("%1.fastresume").arg(torrent->hash());
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
QMetaObject::invokeMethod(m_resumeDataSavingManager
, [this, filename, out]() { m_resumeDataSavingManager->save(filename, out); });
@@ -4160,7 +4160,7 @@ void Session::startUpTorrents()
int resumedTorrentsCount = 0;
const auto startupTorrent = [this, &resumeDataDir, &resumedTorrentsCount](const TorrentResumeData &params)
{
const QString filePath = resumeDataDir.filePath(QString("%1.torrent").arg(params.hash));
const QString filePath = resumeDataDir.filePath(QString::fromLatin1("%1.torrent").arg(params.hash));
qDebug() << "Starting up torrent" << params.hash << "...";
if (!addTorrent_impl(params.addTorrentData, params.magnetUri, TorrentInfo::loadFromFile(filePath), params.data))
LogMsg(tr("Unable to resume torrent '%1'.", "e.g: Unable to resume torrent 'hash'.")
@@ -54,7 +54,7 @@ QByteArray Http::toByteArray(Response response)

// Header Fields
for (auto i = response.headers.constBegin(); i != response.headers.constEnd(); ++i)
buf += QString("%1: %2").arg(i.key(), i.value()).toLatin1().append(CRLF);
buf += QString::fromLatin1("%1: %2").arg(i.key(), i.value()).toLatin1().append(CRLF);

// the first empty line
buf += CRLF;
@@ -88,7 +88,7 @@ void GeoIPManager::loadDatabase()
m_geoIPDatabase = nullptr;

const QString filepath = Utils::Fs::expandPathAbs(
QString("%1%2/%3").arg(specialFolderLocation(SpecialFolder::Data), GEODB_FOLDER, GEODB_FILENAME));
QString::fromLatin1("%1%2/%3").arg(specialFolderLocation(SpecialFolder::Data), GEODB_FOLDER, GEODB_FILENAME));

QString error;
m_geoIPDatabase = GeoIPDatabase::load(filepath, error);
@@ -442,7 +442,7 @@ void GeoIPManager::downloadFinished(const DownloadResult &result)
specialFolderLocation(SpecialFolder::Data) + GEODB_FOLDER);
if (!QDir(targetPath).exists())
QDir().mkpath(targetPath);
QFile targetFile(QString("%1/%2").arg(targetPath, GEODB_FILENAME));
QFile targetFile(QString::fromLatin1("%1/%2").arg(targetPath, GEODB_FILENAME));
if (!targetFile.open(QFile::WriteOnly) || (targetFile.write(data) == -1))
LogMsg(tr("Couldn't save downloaded IP geolocation database file."), Log::WARNING);
else
@@ -139,17 +139,17 @@ void ProxyConfigurationManager::configureProxy()
if (!m_isProxyOnlyForTorrents) {
switch (m_config.type) {
case ProxyType::HTTP_PW:
proxyStrHTTP = QString("http://%1:%2@%3:%4").arg(m_config.username
proxyStrHTTP = QString::fromLatin1("http://%1:%2@%3:%4").arg(m_config.username
, m_config.password, m_config.ip, QString::number(m_config.port));
break;
case ProxyType::HTTP:
proxyStrHTTP = QString("http://%1:%2").arg(m_config.ip, QString::number(m_config.port));
proxyStrHTTP = QString::fromLatin1("http://%1:%2").arg(m_config.ip, QString::number(m_config.port));
break;
case ProxyType::SOCKS5:
proxyStrSOCK = QString("%1:%2").arg(m_config.ip, QString::number(m_config.port));
proxyStrSOCK = QString::fromLatin1("%1:%2").arg(m_config.ip, QString::number(m_config.port));
break;
case ProxyType::SOCKS5_PW:
proxyStrSOCK = QString("%1:%2@%3:%4").arg(m_config.username
proxyStrSOCK = QString::fromLatin1("%1:%2@%3:%4").arg(m_config.username
, m_config.password, m_config.ip, QString::number(m_config.port));
break;
default:
@@ -100,7 +100,7 @@ QPointer<AutoDownloader> AutoDownloader::m_instance = nullptr;

QString computeSmartFilterRegex(const QStringList &filters)
{
return QString("(?:_|\\b)(?:%1)(?:_|\\b)").arg(filters.join(QString(")|(?:")));
return QString::fromLatin1("(?:_|\\b)(?:%1)(?:_|\\b)").arg(filters.join(QString(")|(?:")));
}

AutoDownloader::AutoDownloader()
@@ -323,7 +323,7 @@ bool AutoDownloadRule::matchesEpisodeFilterExpression(const QString &articleTitl
}
}
else { // Single number
const QString expStr {QString("\\b(?:s0?%1[ -_\\.]?e0?%2|%1x0?%2)(?:\\D|\\b)").arg(season, episode)};
const QString expStr {QString::fromLatin1("\\b(?:s0?%1[ -_\\.]?e0?%2|%1x0?%2)(?:\\D|\\b)").arg(season, episode)};
if (cachedRegex(expStr).match(articleTitle).hasMatch())
return true;
}
@@ -354,7 +354,7 @@ bool AutoDownloadRule::matchesSmartEpisodeFilter(const QString &articleTitle) co
if (!isRepack && !isProper)
return false;

const QString fullEpisodeStr = QString("%1%2%3").arg(episodeStr,
const QString fullEpisodeStr = QString::fromLatin1("%1%2%3").arg(episodeStr,
isRepack ? "-REPACK" : "",
isProper ? "-PROPER" : "");
const bool previouslyMatchedFull = m_dataPtr->previouslyMatchedEpisodes.contains(fullEpisodeStr);
@@ -366,8 +366,8 @@ bool AutoDownloadRule::matchesSmartEpisodeFilter(const QString &articleTitle) co
// If this is a REPACK and PROPER download, add the individual entries to the list
// so we don't download those
if (isRepack && isProper) {
m_dataPtr->lastComputedEpisodes.append(QString("%1-REPACK").arg(episodeStr));
m_dataPtr->lastComputedEpisodes.append(QString("%1-PROPER").arg(episodeStr));
m_dataPtr->lastComputedEpisodes.append(episodeStr + QLatin1String("-REPACK"));
m_dataPtr->lastComputedEpisodes.append(episodeStr + QLatin1String("-PROPER"));
}
}

@@ -400,7 +400,7 @@ void Feed::downloadIcon()
// Download the RSS Feed icon
// XXX: This works for most sites but it is not perfect
const QUrl url(m_url);
const auto iconUrl = QString("%1://%2/favicon.ico").arg(url.scheme(), url.host());
const auto iconUrl = QString::fromLatin1("%1://%2/favicon.ico").arg(url.scheme(), url.host());
Net::DownloadManager::instance()->download(
Net::DownloadRequest(iconUrl).saveToFile(true)
, this, &Feed::handleIconDownloadFinished);
@@ -330,7 +330,7 @@ void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder)
}
else {
LogMsg(tr("Couldn't load RSS Item '%1'. Invalid data format.")
.arg(QString("%1\\%2").arg(folder->path(), key)), Log::WARNING);
.arg(QString::fromLatin1("%1\\%2").arg(folder->path(), key)), Log::WARNING);
}
}

@@ -185,7 +185,7 @@ void SearchPluginManager::enablePlugin(const QString &name, const bool enabled)
// Updates shipped plugin
void SearchPluginManager::updatePlugin(const QString &name)
{
installPlugin(QString("%1%2.py").arg(m_updateUrl, name));
installPlugin(QString::fromLatin1("%1%2.py").arg(m_updateUrl, name));
}

// Install or update plugin from file or url
@@ -283,12 +283,12 @@ bool SearchPluginManager::uninstallPlugin(const QString &name)
void SearchPluginManager::updateIconPath(PluginInfo *const plugin)
{
if (!plugin) return;
QString iconPath = QString("%1/%2.png").arg(pluginsLocation(), plugin->name);
QString iconPath = QString::fromLatin1("%1/%2.png").arg(pluginsLocation(), plugin->name);
if (QFile::exists(iconPath)) {
plugin->iconPath = iconPath;
}
else {
iconPath = QString("%1/%2.ico").arg(pluginsLocation(), plugin->name);
iconPath = QString::fromLatin1("%1/%2.ico").arg(pluginsLocation(), plugin->name);
if (QFile::exists(iconPath))
plugin->iconPath = iconPath;
}
@@ -338,7 +338,7 @@ QString SearchPluginManager::pluginFullName(const QString &pluginName)

QString SearchPluginManager::pluginsLocation()
{
return QString("%1/engines").arg(engineLocation());
return QString::fromLatin1("%1/engines").arg(engineLocation());
}

QString SearchPluginManager::engineLocation()
@@ -526,7 +526,7 @@ bool SearchPluginManager::isUpdateNeeded(const QString &pluginName, const Plugin

QString SearchPluginManager::pluginPath(const QString &name)
{
return QString("%1/%2.py").arg(pluginsLocation(), name);
return QString::fromLatin1("%1/%2.py").arg(pluginsLocation(), name);
}

PluginVersion SearchPluginManager::getPluginVersion(const QString &filePath)
@@ -43,7 +43,7 @@ AboutDialog::AboutDialog(QWidget *parent)
setAttribute(Qt::WA_DeleteOnClose);

// Title
m_ui->labelName->setText(QString("<b><h2>qBittorrent " QBT_VERSION " (%1-bit)</h2></b>").arg(QT_POINTER_SIZE * 8));
m_ui->labelName->setText(QString::fromLatin1("<b><h2>qBittorrent " QBT_VERSION " (%1-bit)</h2></b>").arg(QT_POINTER_SIZE * 8));

m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/skin/qbittorrent-tray.svg", this, 32));

@@ -333,15 +333,15 @@ void AdvancedSettings::loadAdvancedSettings()
, tr("Open documentation"))
, this);
labelQbtLink->setOpenExternalLinks(true);
addRow(QBITTORRENT_HEADER, QString("<b>%1</b>").arg(tr("qBittorrent Section")), labelQbtLink);
addRow(QBITTORRENT_HEADER, QString::fromLatin1("<b>%1</b>").arg(tr("qBittorrent Section")), labelQbtLink);
static_cast<QLabel *>(cellWidget(QBITTORRENT_HEADER, PROPERTY))->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);

auto *labelLibtorrentLink = new QLabel(
makeLink(QLatin1String("https://www.libtorrent.org/reference.html")
, tr("Open documentation"))
, this);
labelLibtorrentLink->setOpenExternalLinks(true);
addRow(LIBTORRENT_HEADER, QString("<b>%1</b>").arg(tr("libtorrent Section")), labelLibtorrentLink);
addRow(LIBTORRENT_HEADER, QString::fromLatin1("<b>%1</b>").arg(tr("libtorrent Section")), labelLibtorrentLink);
static_cast<QLabel *>(cellWidget(LIBTORRENT_HEADER, PROPERTY))->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);

#if defined(Q_OS_WIN)
@@ -75,7 +75,7 @@ class CategoryModelItem
if (!m_parent || m_parent->name().isEmpty())
return m_name;

return QString("%1/%2").arg(m_parent->fullName(), m_name);
return QString::fromLatin1("%1/%2").arg(m_parent->fullName(), m_name);
}

CategoryModelItem *parent() const
@@ -27,7 +27,7 @@ LineEdit::LineEdit(QWidget *parent)
m_searchButton->setStyleSheet("QToolButton {border: none; padding: 2px;}");

// padding between text and widget borders
setStyleSheet(QString("QLineEdit {padding-left: %1px;}").arg(m_searchButton->sizeHint().width()));
setStyleSheet(QString::fromLatin1("QLineEdit {padding-left: %1px;}").arg(m_searchButton->sizeHint().width()));

setClearButtonEnabled(true);

@@ -1539,7 +1539,7 @@ void MainWindow::reloadSessionStats()
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)));
#else
// OSes such as Windows do not support html here
const QString toolTip = QString("%1\n%2").arg(
const QString toolTip = QString::fromLatin1("%1\n%2").arg(
tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)));
#endif // Q_OS_UNIX
@@ -1818,7 +1818,7 @@ void MainWindow::handleUpdateCheckFinished(bool updateAvailable, QString newVers
answer = QMessageBox::question(this, tr("qBittorrent Update Available")
, tr("A new version is available.") + "<br/>"
+ tr("Do you want to download %1?").arg(newVersion) + "<br/><br/>"
+ QString("<a href=\"https://www.qbittorrent.org/news.php\">%1</a>").arg(tr("Open changelog..."))
+ QString::fromLatin1("<a href=\"https://www.qbittorrent.org/news.php\">%1</a>").arg(tr("Open changelog..."))
, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (answer == QMessageBox::Yes) {
// The user want to update, let's download the update
@@ -1559,7 +1559,7 @@ void OptionsDialog::on_addScanFolderButton_clicked()
}

if (!error.isEmpty())
QMessageBox::critical(this, tr("Adding entry failed"), QString("%1\n%2").arg(error, dir));
QMessageBox::critical(this, tr("Adding entry failed"), QString::fromLatin1("%1\n%2").arg(error, dir));
}
}

0 comments on commit 7de8a4d

Please sign in to comment.
You can’t perform that action at this time.