Use qUtf8Printable() for logging strings

qDebug(), qInfo(), qWarning(), qCritical(), qFatal() expect %s arguments
to be UTF-8 encoded, while qPrintable() converts to local 8-bit encoding.
Therefore qUtf8Printable() should be used for logging strings instead of
qPrintable().
This commit is contained in:
Vladimir Golovnev (qlassez)
2017-08-13 13:56:03 +03:00
committed by sledgehammer999
parent 0b6cf54508
commit 8fc931a61b
28 changed files with 100 additions and 99 deletions

View File

@@ -476,7 +476,7 @@ void AddNewTorrentDialog::renameSelectedFile()
const QString newFilePath = oldFilePath.leftRef(oldFilePath.size() - oldFileName.size()) + newName;
if (oldFileName == newName) {
qDebug("Name did not change: %s", qPrintable(oldFileName));
qDebug("Name did not change: %s", qUtf8Printable(oldFileName));
return;
}
@@ -491,7 +491,7 @@ void AddNewTorrentDialog::renameSelectedFile()
}
}
qDebug("Renaming %s to %s", qPrintable(oldFilePath), qPrintable(newFilePath));
qDebug("Renaming %s to %s", qUtf8Printable(oldFilePath), qUtf8Printable(newFilePath));
m_torrentInfo.renameFile(fileIndex, newFilePath);
m_contentModel->setData(modelIndex, newName);
@@ -535,7 +535,7 @@ void AddNewTorrentDialog::renameSelectedFile()
QString newName = currentName;
newName.replace(0, oldPath.length(), newPath);
newName = Utils::Fs::expandPath(newName);
qDebug("Rename %s to %s", qPrintable(currentName), qPrintable(newName));
qDebug("Rename %s to %s", qUtf8Printable(currentName), qUtf8Printable(newName));
m_torrentInfo.renameFile(i, newName);
}
}

View File

@@ -1247,7 +1247,7 @@ void MainWindow::dropEvent(QDropEvent *event)
// Download torrents
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
foreach (const QString &file, torrentFiles) {
qDebug("Dropped file %s on download list", qPrintable(file));
qDebug("Dropped file %s on download list", qUtf8Printable(file));
if (useTorrentAdditionDialog)
AddNewTorrentDialog::show(file, this);
else
@@ -1341,7 +1341,7 @@ void MainWindow::on_actionOpen_triggered()
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
if (!pathsList.isEmpty()) {
foreach (QString file, pathsList) {
qDebug("Dropped file %s on download list", qPrintable(file));
qDebug("Dropped file %s on download list", qUtf8Printable(file));
if (useTorrentAdditionDialog)
AddNewTorrentDialog::show(file, this);
else
@@ -2027,7 +2027,7 @@ bool MainWindow::addPythonPathToEnv()
if (pathEnvar.isNull())
pathEnvar = "";
pathEnvar = pythonPath + ";" + pathEnvar;
qDebug("New PATH envvar is: %s", qPrintable(pathEnvar));
qDebug("New PATH envvar is: %s", qUtf8Printable(pathEnvar));
qputenv("PATH", Utils::Fs::toNativePath(pathEnvar).toLocal8Bit());
return true;
}

View File

@@ -476,9 +476,9 @@ void OptionsDialog::saveOptions()
if (pref->getLocale() != locale) {
QTranslator *translator = new QTranslator;
if (translator->load(QString::fromUtf8(":/lang/qbittorrent_") + locale))
qDebug("%s locale recognized, using translation.", qPrintable(locale));
qDebug("%s locale recognized, using translation.", qUtf8Printable(locale));
else
qDebug("%s locale unrecognized, using default (en).", qPrintable(locale));
qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale));
qApp->installTranslator(translator);
}

View File

@@ -136,7 +136,7 @@ void PowerManagementInhibitor::OnAsyncReply(QDBusPendingCallWatcher *call)
if (reply.isError())
{
qDebug("D-Bus: Reply: Error: %s", qPrintable(reply.error().message()));
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message()));
m_state = error;
}
else
@@ -152,7 +152,7 @@ void PowerManagementInhibitor::OnAsyncReply(QDBusPendingCallWatcher *call)
if (reply.isError())
{
qDebug("D-Bus: Reply: Error: %s", qPrintable(reply.error().message()));
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message()));
if (!m_use_gsm)
{

View File

@@ -99,9 +99,9 @@ void ProgramUpdater::rssDownloadFinished(const QString &url, const QByteArray &d
else if (xml.isEndElement()) {
if (inItem && xml.name() == "item") {
if (type.compare(OS_TYPE, Qt::CaseInsensitive) == 0) {
qDebug("The last update available is %s", qPrintable(version));
qDebug("The last update available is %s", qUtf8Printable(version));
if (!version.isEmpty()) {
qDebug("Detected version is %s", qPrintable(version));
qDebug("Detected version is %s", qUtf8Printable(version));
if (isVersionMoreRecent(version))
m_updateUrl = updateLink;
}

View File

@@ -249,7 +249,7 @@ void PeerListWidget::showPeerListMenu(const QPoint &)
int peerCount = 0;
foreach (const BitTorrent::PeerAddress &addr, peersList) {
if (torrent->connectPeer(addr)) {
qDebug("Adding peer %s...", qPrintable(addr.ip.toString()));
qDebug("Adding peer %s...", qUtf8Printable(addr.ip.toString()));
Logger::instance()->addMessage(tr("Manually adding peer '%1'...").arg(addr.ip.toString()));
peerCount++;
}
@@ -442,7 +442,7 @@ void PeerListWidget::handleResolved(const QString &ip, const QString &hostname)
{
QStandardItem *item = m_peerItems.value(ip, 0);
if (item) {
qDebug("Resolved %s -> %s", qPrintable(ip), qPrintable(hostname));
qDebug("Resolved %s -> %s", qUtf8Printable(ip), qUtf8Printable(hostname));
item->setData(hostname, Qt::DisplayRole);
}
}

View File

@@ -514,7 +514,7 @@ void PropertiesWidget::loadUrlSeeds()
const QList<QUrl> hc_seeds = m_torrent->urlSeeds();
// Add url seeds
foreach (const QUrl &hc_seed, hc_seeds) {
qDebug("Loading URL seed: %s", qPrintable(hc_seed.toString()));
qDebug("Loading URL seed: %s", qUtf8Printable(hc_seed.toString()));
new QListWidgetItem(hc_seed.toString(), m_ui->listWebSeeds);
}
}
@@ -535,7 +535,7 @@ void PropertiesWidget::openFile(const QModelIndex &index)
const QDir saveDir(m_torrent->savePath(true));
const QString filename = m_torrent->filePath(i);
const QString file_path = Utils::Fs::expandPath(saveDir.absoluteFilePath(filename));
qDebug("Trying to open file at %s", qPrintable(file_path));
qDebug("Trying to open file at %s", qUtf8Printable(file_path));
// Flush data
m_torrent->flushCache();
Utils::Misc::openPath(file_path);
@@ -704,7 +704,7 @@ void PropertiesWidget::renameSelectedFile()
const QString newFilePath = oldFilePath.leftRef(oldFilePath.size() - oldFileName.size()) + newFileName;
if (oldFileName == newFileName) {
qDebug("Name did not change: %s", qPrintable(oldFileName));
qDebug("Name did not change: %s", qUtf8Printable(oldFileName));
return;
}
@@ -719,7 +719,7 @@ void PropertiesWidget::renameSelectedFile()
}
}
qDebug("Renaming %s to %s", qPrintable(oldFilePath), qPrintable(newFilePath));
qDebug("Renaming %s to %s", qUtf8Printable(oldFilePath), qUtf8Printable(newFilePath));
m_torrent->renameFile(fileIndex, newFilePath);
PropListModel->setData(modelIndex, newName);
@@ -766,7 +766,7 @@ void PropertiesWidget::renameSelectedFile()
if (!forceRecheck && QDir(m_torrent->savePath(true)).exists(newName))
forceRecheck = true;
newName = Utils::Fs::expandPath(newName);
qDebug("Rename %s to %s", qPrintable(currentName), qPrintable(newName));
qDebug("Rename %s to %s", qUtf8Printable(currentName), qUtf8Printable(newName));
m_torrent->renameFile(i, newName);
}
}
@@ -801,7 +801,7 @@ void PropertiesWidget::askWebSeed()
tr("New URL seed:"), QLineEdit::Normal,
QString::fromUtf8("http://www."), &ok);
if (!ok) return;
qDebug("Adding %s web seed", qPrintable(url_seed));
qDebug("Adding %s web seed", qUtf8Printable(url_seed));
if (!m_ui->listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) {
QMessageBox::warning(this, "qBittorrent",
tr("This URL seed is already in the list."),

View File

@@ -128,7 +128,7 @@ void PluginSelectDlg::dropEvent(QDropEvent *event)
if (files.isEmpty()) return;
foreach (QString file, files) {
qDebug("dropped %s", qPrintable(file));
qDebug("dropped %s", qUtf8Printable(file));
startAsyncOp();
m_pluginManager->installPlugin(file);
}
@@ -139,7 +139,7 @@ void PluginSelectDlg::dragEnterEvent(QDragEnterEvent *event)
{
QString mime;
foreach (mime, event->mimeData()->formats()) {
qDebug("mimeData: %s", qPrintable(mime));
qDebug("mimeData: %s", qUtf8Printable(mime));
}
if (event->mimeData()->hasFormat(QLatin1String("text/plain")) || event->mimeData()->hasFormat(QLatin1String("text/uri-list"))) {
@@ -413,7 +413,7 @@ void PluginSelectDlg::iconDownloaded(const QString &url, QString filePath)
void PluginSelectDlg::iconDownloadFailed(const QString &url, const QString &reason)
{
qDebug("Could not download favicon: %s, reason: %s", qPrintable(url), qPrintable(reason));
qDebug("Could not download favicon: %s, reason: %s", qUtf8Printable(url), qUtf8Printable(reason));
}
void PluginSelectDlg::checkForUpdatesFinished(const QHash<QString, PluginVersion> &updateInfo)

View File

@@ -153,7 +153,7 @@ void SearchWidget::fillCatCombobox()
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); });
foreach (const QStrPair &p, tmpList) {
qDebug("Supported category: %s", qPrintable(p.second));
qDebug("Supported category: %s", qUtf8Printable(p.second));
m_ui->comboCategory->addItem(p.first, QVariant(p.second));
}
}
@@ -318,7 +318,7 @@ void SearchWidget::on_searchButton_clicked()
else if (selectedPlugin() == "multi") plugins = m_searchEngine->enabledPlugins();
else plugins << selectedPlugin();
qDebug("Search with category: %s", qPrintable(selectedCategory()));
qDebug("Search with category: %s", qUtf8Printable(selectedCategory()));
// Update SearchEngine widgets
m_noSearchResults = true;

View File

@@ -280,7 +280,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::CheckStateRole)) {
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
qDebug("setData(%s, %d", qPrintable(item->name()), value.toInt());
qDebug("setData(%s, %d", qUtf8Printable(item->name()), value.toInt());
if (item->priority() != value.toInt()) {
if (value.toInt() == Qt::PartiallyChecked)
item->setPriority(prio::MIXED);

View File

@@ -380,12 +380,12 @@ void TransferListWidget::setSelectedTorrentsLocation()
if (torrents.isEmpty()) return;
const QString oldLocation = torrents[0]->savePath();
qDebug("Old location is %s", qPrintable(oldLocation));
qDebug("Old location is %s", qUtf8Printable(oldLocation));
const QString newLocation = QFileDialog::getExistingDirectory(this, tr("Choose save path"), oldLocation,
QFileDialog::DontConfirmOverwrite | QFileDialog::ShowDirsOnly | QFileDialog::HideNameFilterDetails);
if (newLocation.isEmpty() || !QDir(newLocation).exists()) return;
qDebug("New location is %s", qPrintable(newLocation));
qDebug("New location is %s", qUtf8Printable(newLocation));
// Actually move storage
foreach (BitTorrent::TorrentHandle *const torrent, torrents) {
@@ -592,7 +592,7 @@ void TransferListWidget::setDlLimitSelectedTorrents()
if (!ok) return;
foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) {
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qPrintable(torrent->hash()));
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qUtf8Printable(torrent->hash()));
torrent->setDownloadLimit(newLimit);
}
}
@@ -617,7 +617,7 @@ void TransferListWidget::setUpLimitSelectedTorrents()
if (!ok) return;
foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) {
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qPrintable(torrent->hash()));
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qUtf8Printable(torrent->hash()));
torrent->setUploadLimit(newLimit);
}
}
@@ -1174,7 +1174,7 @@ void TransferListWidget::applyStatusFilter(int f)
nameFilterModel->setStatusFilter(static_cast<TorrentFilter::Type>(f));
// Select first item if nothing is selected
if (selectionModel()->selectedRows(0).empty() && nameFilterModel->rowCount() > 0) {
qDebug("Nothing is selected, selecting first row: %s", qPrintable(nameFilterModel->index(0, TorrentModel::TR_NAME).data().toString()));
qDebug("Nothing is selected, selecting first row: %s", qUtf8Printable(nameFilterModel->index(0, TorrentModel::TR_NAME).data().toString()));
selectionModel()->setCurrentIndex(nameFilterModel->index(0, TorrentModel::TR_NAME), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
}
}