Avoid temporary QString allocations

This fixes clazy warning: Use multi-arg instead [-Wclazy-qstring-arg]
This commit is contained in:
Chocobo1
2018-03-06 23:49:12 +08:00
parent c60b7b213e
commit 0457fd260e
29 changed files with 137 additions and 123 deletions

View File

@@ -68,11 +68,11 @@ public:
"<tr><td>%5</td><td><a href=\"http://bugs.qbittorrent.org\">http://bugs.qbittorrent.org</a></td></tr>"
"</table>"
"</p>")
.arg(tr("An advanced BitTorrent client programmed in C++, based on Qt toolkit and libtorrent-rasterbar."))
.arg(tr("Copyright %1 2006-2018 The qBittorrent project").arg(QString::fromUtf8(C_COPYRIGHT)))
.arg(tr("Home Page:"))
.arg(tr("Forum:"))
.arg(tr("Bug Tracker:"));
.arg(tr("An advanced BitTorrent client programmed in C++, based on Qt toolkit and libtorrent-rasterbar.")
, tr("Copyright %1 2006-2018 The qBittorrent project").arg(QString::fromUtf8(C_COPYRIGHT))
, tr("Home Page:")
, tr("Forum:")
, tr("Bug Tracker:"));
lb_about->setText(aboutText);
labelMascot->setPixmap(Utils::Gui::scaledPixmap(":/icons/skin/mascot.png", this));

View File

@@ -288,7 +288,8 @@ bool AddNewTorrentDialog::loadTorrent(const QString &torrentPath)
QString error;
m_torrentInfo = BitTorrent::TorrentInfo::loadFromFile(m_filePath, &error);
if (!m_torrentInfo.isValid()) {
MessageBoxRaised::critical(this, tr("Invalid torrent"), tr("Failed to load the torrent: %1.\nError: %2", "Don't remove the '\n' characters. They insert a newline.").arg(Utils::Fs::toNativePath(m_filePath)).arg(error));
MessageBoxRaised::critical(this, tr("Invalid torrent"), tr("Failed to load the torrent: %1.\nError: %2", "Don't remove the '\n' characters. They insert a newline.")
.arg(Utils::Fs::toNativePath(m_filePath), error));
return false;
}
@@ -768,7 +769,8 @@ void AddNewTorrentDialog::setupTreeview()
void AddNewTorrentDialog::handleDownloadFailed(const QString &url, const QString &reason)
{
MessageBoxRaised::critical(this, tr("Download Error"), QString("Cannot download '%1': %2").arg(url).arg(reason));
MessageBoxRaised::critical(this, tr("Download Error"),
QString("Cannot download '%1': %2").arg(url, reason));
this->deleteLater();
}

View File

@@ -284,12 +284,13 @@ void AdvancedSettings::loadAdvancedSettings()
boldFont.setBold(true);
addRow(QBITTORRENT_HEADER, tr("qBittorrent Section"), &labelQbtLink);
item(QBITTORRENT_HEADER, PROPERTY)->setFont(boldFont);
labelQbtLink.setText(QString("<a href=\"%1\">%2</a>").arg("https://github.com/qbittorrent/qBittorrent/wiki/Explanation-of-Options-in-qBittorrent#Advanced").arg(tr("Open documentation")));
labelQbtLink.setText(QString("<a href=\"%1\">%2</a>")
.arg("https://github.com/qbittorrent/qBittorrent/wiki/Explanation-of-Options-in-qBittorrent#Advanced", tr("Open documentation")));
labelQbtLink.setOpenExternalLinks(true);
addRow(LIBTORRENT_HEADER, tr("libtorrent Section"), &labelLibtorrentLink);
item(LIBTORRENT_HEADER, PROPERTY)->setFont(boldFont);
labelLibtorrentLink.setText(QString("<a href=\"%1\">%2</a>").arg("https://www.libtorrent.org/reference.html").arg(tr("Open documentation")));
labelLibtorrentLink.setText(QString("<a href=\"%1\">%2</a>").arg("https://www.libtorrent.org/reference.html", tr("Open documentation")));
labelLibtorrentLink.setOpenExternalLinks(true);
// Disk write cache
spin_cache.setMinimum(-1);

View File

@@ -74,7 +74,7 @@ public:
if (!m_parent || m_parent->name().isEmpty())
return m_name;
return QString("%1/%2").arg(m_parent->fullName()).arg(m_name);
return QString("%1/%2").arg(m_parent->fullName(), m_name);
}
CategoryModelItem *parent() const

View File

@@ -105,7 +105,8 @@ void ExecutionLog::addPeerMessage(const Log::Peer& peer)
QDateTime time = QDateTime::fromMSecsSinceEpoch(peer.timestamp);
if (peer.blocked)
text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - " + tr("<font color='red'>%1</font> was blocked %2", "x.y.z.w was blocked").arg(peer.ip).arg(peer.reason);
text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - "
+ tr("<font color='red'>%1</font> was blocked %2", "x.y.z.w was blocked").arg(peer.ip, peer.reason);
else
text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - " + tr("<font color='red'>%1</font> was banned", "x.y.z.w was banned").arg(peer.ip);

View File

@@ -832,7 +832,9 @@ void MainWindow::finishedTorrent(BitTorrent::TorrentHandle *const torrent) const
// Notification when disk is full
void MainWindow::fullDiskError(BitTorrent::TorrentHandle *const torrent, QString msg) const
{
showNotificationBaloon(tr("I/O Error", "i.e: Input/Output Error"), tr("An I/O error occurred for torrent '%1'.\n Reason: %2", "e.g: An error occurred for torrent 'xxx.avi'.\n Reason: disk is full.").arg(torrent->name()).arg(msg));
showNotificationBaloon(tr("I/O Error", "i.e: Input/Output Error")
, tr("An I/O error occurred for torrent '%1'.\n Reason: %2"
, "e.g: An error occurred for torrent 'xxx.avi'.\n Reason: disk is full.").arg(torrent->name(), msg));
}
void MainWindow::createKeyboardShortcuts()
@@ -937,7 +939,8 @@ void MainWindow::askRecursiveTorrentDownloadConfirmation(BitTorrent::TorrentHand
void MainWindow::handleDownloadFromUrlFailure(QString url, QString reason) const
{
// Display a message box
showNotificationBaloon(tr("URL download error"), tr("Couldn't download file at URL '%1', reason: %2.").arg(url).arg(reason));
showNotificationBaloon(tr("URL download error")
, tr("Couldn't download file at URL '%1', reason: %2.").arg(url, reason));
}
void MainWindow::on_actionSetGlobalUploadLimit_triggered()
@@ -1542,9 +1545,9 @@ void MainWindow::updateGUI()
if (m_displaySpeedInTitle) {
setWindowTitle(tr("[D: %1, U: %2] qBittorrent %3", "D = Download; U = Upload; %3 is qBittorrent version")
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
.arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true))
.arg(QBT_VERSION));
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)
, Utils::Misc::friendlyUnit(status.payloadUploadRate, true)
, QBT_VERSION));
}
}
@@ -1740,7 +1743,8 @@ void MainWindow::on_actionSearchWidget_triggered()
// Check if python is already in PATH
if (pythonVersion > 0)
// Prevent translators from messing with PATH
Logger::instance()->addMessage(tr("Python found in %1: %2", "Python found in PATH: /usr/local/bin:/usr/bin:/etc/bin").arg("PATH").arg(qgetenv("PATH").constData()), Log::INFO);
Logger::instance()->addMessage(tr("Python found in %1: %2", "Python found in PATH: /usr/local/bin:/usr/bin:/etc/bin")
.arg("PATH", qgetenv("PATH").constData()), Log::INFO);
#ifdef Q_OS_WIN
else if (addPythonPathToEnv())
pythonVersion = Utils::Misc::pythonVersion();

View File

@@ -273,17 +273,17 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(m_ui->autoRun_txt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
const QString autoRunStr = QString("%1\n %2\n %3\n %4\n %5\n %6\n %7\n %8\n %9\n %10\n%11")
.arg(tr("Supported parameters (case sensitive):"))
.arg(tr("%N: Torrent name"))
.arg(tr("%L: Category"))
.arg(tr("%F: Content path (same as root path for multifile torrent)"))
.arg(tr("%R: Root path (first torrent subdirectory path)"))
.arg(tr("%D: Save path"))
.arg(tr("%C: Number of files"))
.arg(tr("%Z: Torrent size (bytes)"))
.arg(tr("%T: Current tracker"))
.arg(tr("%I: Info hash"))
.arg(tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")"));
.arg(tr("Supported parameters (case sensitive):")
, tr("%N: Torrent name")
, tr("%L: Category")
, tr("%F: Content path (same as root path for multifile torrent)")
, tr("%R: Root path (first torrent subdirectory path)")
, tr("%D: Save path")
, tr("%C: Number of files")
, tr("%Z: Torrent size (bytes)")
, tr("%T: Current tracker"))
.arg(tr("%I: Info hash")
, tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")"));
m_ui->autoRun_param->setText(autoRunStr);
// Connection tab
@@ -1518,7 +1518,7 @@ void OptionsDialog::on_addScanFolderButton_clicked()
}
if (!error.isEmpty())
QMessageBox::critical(this, tr("Adding entry failed"), QString("%1\n%2").arg(error).arg(dir));
QMessageBox::critical(this, tr("Adding entry failed"), QString("%1\n%2").arg(error, dir));
}
}

View File

@@ -413,11 +413,11 @@ void PropertiesWidget::loadDynamicData()
case PropTabBar::MainTab: {
m_ui->labelWastedVal->setText(Utils::Misc::friendlyUnit(m_torrent->wastedSize()));
m_ui->labelUpTotalVal->setText(tr("%1 (%2 this session)").arg(Utils::Misc::friendlyUnit(m_torrent->totalUpload()))
.arg(Utils::Misc::friendlyUnit(m_torrent->totalPayloadUpload())));
m_ui->labelUpTotalVal->setText(tr("%1 (%2 this session)").arg(Utils::Misc::friendlyUnit(m_torrent->totalUpload())
, Utils::Misc::friendlyUnit(m_torrent->totalPayloadUpload())));
m_ui->labelDlTotalVal->setText(tr("%1 (%2 this session)").arg(Utils::Misc::friendlyUnit(m_torrent->totalDownload()))
.arg(Utils::Misc::friendlyUnit(m_torrent->totalPayloadDownload())));
m_ui->labelDlTotalVal->setText(tr("%1 (%2 this session)").arg(Utils::Misc::friendlyUnit(m_torrent->totalDownload())
, Utils::Misc::friendlyUnit(m_torrent->totalPayloadDownload())));
m_ui->labelUpLimitVal->setText(m_torrent->uploadLimit() <= 0 ? QString::fromUtf8(C_INFINITY) : Utils::Misc::friendlyUnit(m_torrent->uploadLimit(), true));
@@ -426,8 +426,8 @@ void PropertiesWidget::loadDynamicData()
QString elapsedString;
if (m_torrent->isSeed())
elapsedString = tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)")
.arg(Utils::Misc::userFriendlyDuration(m_torrent->activeTime()))
.arg(Utils::Misc::userFriendlyDuration(m_torrent->seedingTime()));
.arg(Utils::Misc::userFriendlyDuration(m_torrent->activeTime())
, Utils::Misc::userFriendlyDuration(m_torrent->seedingTime()));
else
elapsedString = Utils::Misc::userFriendlyDuration(m_torrent->activeTime());
m_ui->labelElapsedVal->setText(elapsedString);
@@ -446,20 +446,20 @@ void PropertiesWidget::loadDynamicData()
m_ui->labelShareRatioVal->setText(ratio > BitTorrent::TorrentHandle::MAX_RATIO ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2));
m_ui->labelSeedsVal->setText(tr("%1 (%2 total)", "%1 and %2 are numbers, e.g. 3 (10 total)")
.arg(QString::number(m_torrent->seedsCount()))
.arg(QString::number(m_torrent->totalSeedsCount())));
.arg(QString::number(m_torrent->seedsCount())
, QString::number(m_torrent->totalSeedsCount())));
m_ui->labelPeersVal->setText(tr("%1 (%2 total)", "%1 and %2 are numbers, e.g. 3 (10 total)")
.arg(QString::number(m_torrent->leechsCount()))
.arg(QString::number(m_torrent->totalLeechersCount())));
.arg(QString::number(m_torrent->leechsCount())
, QString::number(m_torrent->totalLeechersCount())));
m_ui->labelDlSpeedVal->setText(tr("%1 (%2 avg.)", "%1 and %2 are speed rates, e.g. 200KiB/s (100KiB/s avg.)")
.arg(Utils::Misc::friendlyUnit(m_torrent->downloadPayloadRate(), true))
.arg(Utils::Misc::friendlyUnit(m_torrent->totalDownload() / (1 + m_torrent->activeTime() - m_torrent->finishedTime()), true)));
.arg(Utils::Misc::friendlyUnit(m_torrent->downloadPayloadRate(), true)
, Utils::Misc::friendlyUnit(m_torrent->totalDownload() / (1 + m_torrent->activeTime() - m_torrent->finishedTime()), true)));
m_ui->labelUpSpeedVal->setText(tr("%1 (%2 avg.)", "%1 and %2 are speed rates, e.g. 200KiB/s (100KiB/s avg.)")
.arg(Utils::Misc::friendlyUnit(m_torrent->uploadPayloadRate(), true))
.arg(Utils::Misc::friendlyUnit(m_torrent->totalUpload() / (1 + m_torrent->activeTime()), true)));
.arg(Utils::Misc::friendlyUnit(m_torrent->uploadPayloadRate(), true)
, Utils::Misc::friendlyUnit(m_torrent->totalUpload() / (1 + m_torrent->activeTime()), true)));
m_ui->labelLastSeenCompleteVal->setText(m_torrent->lastSeenComplete().isValid() ? m_torrent->lastSeenComplete().toString(Qt::DefaultLocaleShortDate) : tr("Never"));

View File

@@ -60,8 +60,8 @@ const QString EXT_LEGACY {QStringLiteral(".rssrules")};
AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent)
: QDialog(parent)
, m_formatFilterJSON(QString("%1 (*%2)").arg(tr("Rules")).arg(EXT_JSON))
, m_formatFilterLegacy(QString("%1 (*%2)").arg(tr("Rules (legacy)")).arg(EXT_LEGACY))
, m_formatFilterJSON(QString("%1 (*%2)").arg(tr("Rules"), EXT_JSON))
, m_formatFilterLegacy(QString("%1 (*%2)").arg(tr("Rules (legacy)"), EXT_LEGACY))
, m_ui(new Ui::AutomatedRssDownloader)
, m_currentRuleItem(nullptr)
{
@@ -405,7 +405,7 @@ void AutomatedRssDownloader::on_exportBtn_clicked()
QString selectedFilter {m_formatFilterJSON};
QString path = QFileDialog::getSaveFileName(
this, tr("Export RSS rules"), QDir::homePath()
, QString("%1;;%2").arg(m_formatFilterJSON).arg(m_formatFilterLegacy), &selectedFilter);
, QString("%1;;%2").arg(m_formatFilterJSON, m_formatFilterLegacy), &selectedFilter);
if (path.isEmpty()) return;
const RSS::AutoDownloader::RulesFileFormat format {
@@ -437,7 +437,7 @@ void AutomatedRssDownloader::on_importBtn_clicked()
QString selectedFilter {m_formatFilterJSON};
QString path = QFileDialog::getOpenFileName(
this, tr("Import RSS rules"), QDir::homePath()
, QString("%1;;%2").arg(m_formatFilterJSON).arg(m_formatFilterLegacy), &selectedFilter);
, QString("%1;;%2").arg(m_formatFilterJSON, m_formatFilterLegacy), &selectedFilter);
if (path.isEmpty() || !QFile::exists(path))
return;
@@ -657,7 +657,7 @@ void AutomatedRssDownloader::updateFieldsToolTips(bool regex)
tip += tr("An expression with an empty %1 clause (e.g. %2)",
"We talk about regex/wildcards in the RSS filters section here."
" So a valid sentence would be: An expression with an empty | clause (e.g. expr|)"
).arg("<tt>|</tt>").arg("<tt>expr|</tt>");
).arg("<tt>|</tt>", "<tt>expr|</tt>");
m_ui->lineContains->setToolTip(tip + tr(" will match all articles.") + "</p>");
m_ui->lineNotContains->setToolTip(tip + tr(" will exclude all articles.") + "</p>");
}

View File

@@ -387,9 +387,9 @@ void PluginSelectDlg::iconDownloaded(const QString &url, QString filePath)
if (!plugin) continue;
QString iconPath = QString("%1/%2.%3")
.arg(SearchPluginManager::pluginsLocation())
.arg(id)
.arg(url.endsWith(".ico", Qt::CaseInsensitive) ? "ico" : "png");
.arg(SearchPluginManager::pluginsLocation()
, id
, url.endsWith(".ico", Qt::CaseInsensitive) ? "ico" : "png");
if (QFile::copy(filePath, iconPath)) {
// This 2nd check is necessary. Some favicons (eg from piratebay)
// decode fine without an ext, but fail to do so when appending the ext
@@ -448,7 +448,8 @@ void PluginSelectDlg::pluginInstalled(const QString &name)
void PluginSelectDlg::pluginInstallationFailed(const QString &name, const QString &reason)
{
finishAsyncOp();
QMessageBox::information(this, tr("Search plugin install"), tr("Couldn't install \"%1\" search engine plugin. %2").arg(name).arg(reason));
QMessageBox::information(this, tr("Search plugin install")
, tr("Couldn't install \"%1\" search engine plugin. %2").arg(name, reason));
finishPluginUpdate();
}
@@ -465,6 +466,7 @@ void PluginSelectDlg::pluginUpdated(const QString &name)
void PluginSelectDlg::pluginUpdateFailed(const QString &name, const QString &reason)
{
finishAsyncOp();
QMessageBox::information(this, tr("Search plugin update"), tr("Couldn't update \"%1\" search engine plugin. %2").arg(name).arg(reason));
QMessageBox::information(this, tr("Search plugin update")
, tr("Couldn't update \"%1\" search engine plugin. %2").arg(name, reason));
finishPluginUpdate();
}

View File

@@ -65,9 +65,8 @@ StatusBar::StatusBar(QWidget *parent)
m_connecStatusLblIcon->setCursor(Qt::PointingHandCursor);
m_connecStatusLblIcon->setIcon(QIcon(":/icons/skin/firewalled.png"));
m_connecStatusLblIcon->setToolTip(
QString(QLatin1String("<b>%1</b><br><i>%2</i>"))
.arg(tr("Connection status:"))
.arg(tr("No direct connections. This may indicate network configuration problems.")));
QString(QLatin1String("<b>%1</b><br><i>%2</i>")).arg(tr("Connection status:")
, tr("No direct connections. This may indicate network configuration problems.")));
connect(m_connecStatusLblIcon, &QAbstractButton::clicked, this, &StatusBar::connectionButtonClicked);
m_dlSpeedLbl = new QPushButton(this);

View File

@@ -200,7 +200,8 @@ void TorrentCreatorDlg::handleCreationSuccess(const QString &path, const QString
BitTorrent::Session::instance()->addTorrent(t, params);
}
QMessageBox::information(this, tr("Torrent creator"), QString("%1\n%2").arg(tr("Torrent created:")).arg(Utils::Fs::toNativePath(path)));
QMessageBox::information(this, tr("Torrent creator")
, QString("%1\n%2").arg(tr("Torrent created:"), Utils::Fs::toNativePath(path)));
setInteractionEnabled(true);
}

View File

@@ -126,8 +126,8 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
const int seedingTime = index.data(Qt::UserRole).toInt();
const QString txt = (seedingTime > 0)
? tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)")
.arg(Utils::Misc::userFriendlyDuration(elapsedTime))
.arg(Utils::Misc::userFriendlyDuration(seedingTime))
.arg(Utils::Misc::userFriendlyDuration(elapsedTime)
, Utils::Misc::userFriendlyDuration(seedingTime))
: Utils::Misc::userFriendlyDuration(elapsedTime);
QItemDelegate::drawDisplay(painter, opt, opt.rect, txt);
break;

View File

@@ -398,7 +398,9 @@ void TransferListWidget::setSelectedTorrentsLocation()
// Actually move storage
foreach (BitTorrent::TorrentHandle *const torrent, torrents) {
Logger::instance()->addMessage(tr("Set location: moving \"%1\", from \"%2\" to \"%3\"", "Set location: moving \"ubuntu_16_04.iso\", from \"/home/dir1\" to \"/home/dir2\"").arg(torrent->name()).arg(torrent->savePath()).arg(newLocation));
Logger::instance()->addMessage(tr("Set location: moving \"%1\", from \"%2\" to \"%3\""
, "Set location: moving \"ubuntu_16_04.iso\", from \"/home/dir1\" to \"/home/dir2\"")
.arg(torrent->name(), torrent->savePath(), newLocation));
torrent->move(Utils::Fs::expandPathAbs(newLocation));
}
}