Merge pull request #4994 from evsh/availability-column

Add availability column to torrent contents
This commit is contained in:
Eugene Shalygin
2017-05-12 17:47:51 +02:00
committed by GitHub
15 changed files with 371 additions and 221 deletions

View File

@@ -1953,3 +1953,24 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)
updateStatus();
}
QVector<qreal> TorrentHandle::availableFileFractions() const
{
QVector<int> piecesAvailability = pieceAvailability();
const auto filesCount = this->filesCount();
// libtorrent returns empty array for seeding only torrents
if (piecesAvailability.empty()) return QVector<qreal>(filesCount, -1.);
QVector<qreal> res;
res.reserve(filesCount);
TorrentInfo info = this->info();
for (int file = 0; file < filesCount; ++file) {
TorrentInfo::PieceRange filePieces = info.filePieces(file);
int availablePieces = 0;
for (int piece = filePieces.first(); piece <= filePieces.last(); ++piece) {
availablePieces += piecesAvailability[piece] > 0 ? 1 : 0;
}
res.push_back(static_cast<qreal>(availablePieces) / filePieces.size());
}
return res;
}

View File

@@ -361,6 +361,14 @@ namespace BitTorrent
void handleAppendExtensionToggled();
void saveResumeData(bool updateStatus = false);
/**
* @brief fraction of file pieces that are available at least from one peer
*
* This is not the same as torrrent availability, it is just a fraction of pieces
* that can be downloaded right now. It varies between 0 to 1.
*/
QVector<qreal> availableFileFractions() const;
private:
typedef boost::function<void ()> EventTrigger;

View File

@@ -39,6 +39,7 @@ const char C_NON_BREAKING_SPACE[] = " ";
const char C_UP[] = "";
const char C_DOWN[] = "";
const char C_COPYRIGHT[] = "©";
const char C_THIN_SPACE[] = "";
const char C_UTP[] = "μTP";
const char C_LOCALE_ENGLISH[] = "English";
const char C_LOCALE_ENGLISH_AUSTRALIA[] = "English(Australia)";