From 6b6411d06b09b63b8f3e8be1e900e46e367a21a4 Mon Sep 17 00:00:00 2001 From: ngosang Date: Fri, 18 Sep 2015 04:58:16 +0200 Subject: [PATCH] Download more pieces in "Download first and last pieces first" feature --- src/base/bittorrent/torrenthandle.cpp | 14 ++++++++++++-- src/gui/transferlistwidget.cpp | 2 +- src/webui/www/private/index.html | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 057f83a27..708ac482e 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1143,6 +1143,8 @@ void TorrentHandle::setFirstLastPiecePriority(bool b) std::vector fp; SAFE_GET(fp, file_priorities); + std::vector pp; + SAFE_GET(pp, piece_priorities); // Download first and last pieces first for all media files in the torrent int nbfiles = static_cast(fp.size()); @@ -1151,14 +1153,22 @@ void TorrentHandle::setFirstLastPiecePriority(bool b) const QString ext = Utils::Fs::fileExtension(path); if (Utils::Misc::isPreviewable(ext) && (fp[index] > 0)) { qDebug() << "File" << path << "is previewable, toggle downloading of first/last pieces first"; + // Determine the priority to set int prio = b ? 7 : fp[index]; QPair extremities = fileExtremityPieces(index); - SAFE_CALL(piece_priority, extremities.first, prio); - SAFE_CALL(piece_priority, extremities.second, prio); + + // worst case: AVI index = 1% of total file size (at the end of the file) + int nNumPieces = ceil(fileSize(index) * 0.01 / pieceLength()); + for (int i = 0; i < nNumPieces; ++i) { + pp[extremities.first + i] = prio; + pp[extremities.second - i] = prio; + } } } + + SAFE_CALL(prioritize_pieces, pp); } void TorrentHandle::toggleFirstLastPiecePriority() diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 2e4cb03b2..5344b78bb 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -668,7 +668,7 @@ void TransferListWidget::displayListMenu(const QPoint&) QAction actionSequential_download(tr("Download in sequential order"), 0); actionSequential_download.setCheckable(true); connect(&actionSequential_download, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSequentialDownload())); - QAction actionFirstLastPiece_prio(tr("Download first and last piece first"), 0); + QAction actionFirstLastPiece_prio(tr("Download first and last pieces first"), 0); actionFirstLastPiece_prio.setCheckable(true); connect(&actionFirstLastPiece_prio, SIGNAL(triggered()), this, SLOT(toggleSelectedFirstLastPiecePrio())); // End of actions diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 8b7fac970..37794c4e7 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -122,7 +122,7 @@
  • QBT_TR(Limit upload rate...)QBT_TR QBT_TR(Limit upload rate...)QBT_TR
  • QBT_TR(Super seeding mode)QBT_TR QBT_TR(Super seeding mode)QBT_TR
  • QBT_TR(Download in sequential order)QBT_TR QBT_TR(Download in sequential order)QBT_TR
  • -
  • QBT_TR(Download first and last piece first)QBT_TR QBT_TR(Download first and last piece first)QBT_TR
  • +
  • QBT_TR(Download first and last pieces first)QBT_TR QBT_TR(Download first and last pieces first)QBT_TR
  • QBT_TR(Force recheck)QBT_TR QBT_TR(Force recheck)QBT_TR