From 9cb686a6b7c77fc9e460255624627c93529675d0 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 8 Jun 2022 18:50:12 +0800 Subject: [PATCH 1/2] Fix wrong file names displayed in tooltip Also rename variable. Closes #17179. --- src/gui/properties/piecesbar.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/gui/properties/piecesbar.cpp b/src/gui/properties/piecesbar.cpp index cf6d0c09a..eccbe6814 100644 --- a/src/gui/properties/piecesbar.cpp +++ b/src/gui/properties/piecesbar.cpp @@ -265,30 +265,25 @@ void PiecesBar::showToolTip(const QHelpEvent *e) { const PieceIndexToImagePos transform {torrentInfo, m_image}; const int pieceIndex = transform.pieceIndex(imagePos); - const QVector files {torrentInfo.fileIndicesForPiece(pieceIndex)}; + const QVector fileIndexes = torrentInfo.fileIndicesForPiece(pieceIndex); QString tooltipTitle; - if (files.count() > 1) - { + if (fileIndexes.count() > 1) tooltipTitle = tr("Files in this piece:"); - } + else if (torrentInfo.fileSize(fileIndexes.front()) == torrentInfo.pieceLength(pieceIndex)) + tooltipTitle = tr("File in this piece:"); else - { - if (torrentInfo.fileSize(files.front()) == torrentInfo.pieceLength(pieceIndex)) - tooltipTitle = tr("File in this piece"); - else - tooltipTitle = tr("File in these pieces"); - } + tooltipTitle = tr("File in these pieces:"); - toolTipText.reserve(files.size() * 128); + toolTipText.reserve(fileIndexes.size() * 128); toolTipText += u""; DetailedTooltipRenderer renderer {toolTipText, tooltipTitle}; - for (const int f : files) + for (const int index : fileIndexes) { - const Path filePath = torrentInfo.filePath(f); - renderer(Utils::Misc::friendlyUnit(torrentInfo.fileSize(f)), filePath); + const Path filePath = m_torrent->filePath(index); + renderer(Utils::Misc::friendlyUnit(torrentInfo.fileSize(index)), filePath); } toolTipText += u""; } From fed969ed64f7812a5e0cc65e554c974e914b9074 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 9 Jun 2022 10:44:33 +0800 Subject: [PATCH 2/2] Avoid string encoding conversion Use UTF-16 string literals to match QTextStream internal buffer encoding. --- src/app/filelogger.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/filelogger.cpp b/src/app/filelogger.cpp index 3d2b002a3..3cd5e6ac1 100644 --- a/src/app/filelogger.cpp +++ b/src/app/filelogger.cpp @@ -134,19 +134,19 @@ void FileLogger::addLogMessage(const Log::Msg &msg) switch (msg.type) { case Log::INFO: - stream << "(I) "; + stream << u"(I) "; break; case Log::WARNING: - stream << "(W) "; + stream << u"(W) "; break; case Log::CRITICAL: - stream << "(C) "; + stream << u"(C) "; break; default: - stream << "(N) "; + stream << u"(N) "; } - stream << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << " - " << msg.message << '\n'; + stream << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << u" - " << msg.message << u'\n'; if (m_backup && (m_logFile.size() >= m_maxSize)) {