From af3755bf919ffacba430c2fe86ad00ead1b61f88 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 18 Mar 2010 22:58:32 +0000 Subject: [PATCH] "Downloaded pieces" bar now displays in yellow the pieces being downloaded --- src/downloadedpiecesbar.h | 42 +++++++++++++++++++++++++++++---------- src/propertieswidget.cpp | 4 +++- src/qtorrenthandle.cpp | 10 ++++++++++ src/qtorrenthandle.h | 1 + 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/downloadedpiecesbar.h b/src/downloadedpiecesbar.h index 9dba245c6..8a5ee9d38 100644 --- a/src/downloadedpiecesbar.h +++ b/src/downloadedpiecesbar.h @@ -53,34 +53,49 @@ public: setFixedHeight(BAR_HEIGHT); } - void setProgress(bitfield pieces) { + void setProgress(const bitfield &pieces, const bitfield &downloading_pieces) { if(pieces.empty()) { // Empty bar QPixmap pix = QPixmap(1, 1); pix.fill(); pixmap = pix; } else { - int nb_pieces = pieces.size(); + const int nb_pieces = pieces.size(); // Reduce the number of pieces before creating the pixmap // otherwise it can crash when there are too many pieces if(nb_pieces > width()) { int ratio = floor(nb_pieces/(double)width()); - QVector scaled_pieces; + std::vector scaled_pieces; + std::vector scaled_downloading; for(int i=0; isetProgress(h.pieces()); + bitfield bf(h.get_torrent_info().num_pieces(), 0); + h.downloading_pieces(bf); + downloaded_pieces->setProgress(h.pieces(), bf); // Pieces availability if(h.has_metadata() && !h.is_paused() && !h.is_queued() && !h.is_checking()) { showPiecesAvailability(true); diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index 3509333a7..4d16ed451 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -451,6 +451,16 @@ bool QTorrentHandle::has_error() const { return h.status().error.empty(); } +void QTorrentHandle::downloading_pieces(bitfield &bf) const { + Q_ASSERT(h.is_valid()); + std::vector queue; + h.get_download_queue(queue); + for(std::vector::iterator it=queue.begin(); it!= queue.end(); it++) { + bf.set_bit(it->piece_index); + } + return; +} + // // Setters // diff --git a/src/qtorrenthandle.h b/src/qtorrenthandle.h index 86c9e7922..64ce17d5f 100644 --- a/src/qtorrenthandle.h +++ b/src/qtorrenthandle.h @@ -129,6 +129,7 @@ class QTorrentHandle { bool first_last_piece_first() const; QString root_path() const; bool has_error() const; + void downloading_pieces(bitfield &bf) const; // // Setters