Merge pull request #17187 from Chocobo1/names

Fix wrong file names displayed in tooltip
This commit is contained in:
Chocobo1 2022-06-11 12:27:41 +08:00 committed by GitHub
commit 5b0cbf9eb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 19 deletions

View file

@ -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))
{

View file

@ -265,30 +265,25 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
{
const PieceIndexToImagePos transform {torrentInfo, m_image};
const int pieceIndex = transform.pieceIndex(imagePos);
const QVector<int> files {torrentInfo.fileIndicesForPiece(pieceIndex)};
const QVector<int> 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"<html><body>";
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"</body></html>";
}