mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-14 00:37:58 +00:00
"Downloaded pieces" bar now displays in yellow the pieces being downloaded
This commit is contained in:
parent
419d719ab8
commit
af3755bf91
@ -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<bool> scaled_pieces;
|
||||
std::vector<bool> scaled_pieces;
|
||||
std::vector<bool> scaled_downloading;
|
||||
for(int i=0; i<nb_pieces; i+= ratio) {
|
||||
bool have = true;
|
||||
for(int j=i; j<qMin(i+ratio, nb_pieces); ++j) {
|
||||
if(!pieces[i]) { have = false; break; }
|
||||
}
|
||||
scaled_pieces << have;
|
||||
scaled_pieces.push_back(have);
|
||||
if(have) {
|
||||
scaled_downloading.push_back(false);
|
||||
} else {
|
||||
bool downloading = false;
|
||||
for(int j=i; j<qMin(i+ratio, nb_pieces); ++j) {
|
||||
if(downloading_pieces[i]) { downloading = true; break; }
|
||||
}
|
||||
scaled_downloading.push_back(downloading);
|
||||
}
|
||||
}
|
||||
QPixmap pix = QPixmap(scaled_pieces.size(), 1);
|
||||
pix.fill();
|
||||
QPainter painter(&pix);
|
||||
for(int i=0; i<scaled_pieces.size(); ++i) {
|
||||
if(scaled_pieces[i])
|
||||
for(uint i=0; i<scaled_pieces.size(); ++i) {
|
||||
if(scaled_pieces[i]) {
|
||||
painter.setPen(Qt::blue);
|
||||
else
|
||||
painter.setPen(Qt::white);
|
||||
} else {
|
||||
if(scaled_downloading[i]) {
|
||||
painter.setPen(Qt::yellow);
|
||||
} else {
|
||||
painter.setPen(Qt::white);
|
||||
}
|
||||
}
|
||||
painter.drawPoint(i,0);
|
||||
}
|
||||
pixmap = pix;
|
||||
@ -89,10 +104,15 @@ public:
|
||||
pix.fill();
|
||||
QPainter painter(&pix);
|
||||
for(uint i=0; i<pieces.size(); ++i) {
|
||||
if(pieces[i])
|
||||
if(pieces[i]) {
|
||||
painter.setPen(Qt::blue);
|
||||
else
|
||||
painter.setPen(Qt::white);
|
||||
} else {
|
||||
if(downloading_pieces[i]) {
|
||||
painter.setPen(Qt::yellow);
|
||||
} else {
|
||||
painter.setPen(Qt::white);
|
||||
}
|
||||
}
|
||||
painter.drawPoint(i,0);
|
||||
}
|
||||
pixmap = pix;
|
||||
|
@ -338,7 +338,9 @@ void PropertiesWidget::loadDynamicData() {
|
||||
if(!h.is_seed()) {
|
||||
showPiecesDownloaded(true);
|
||||
// Downloaded pieces
|
||||
downloaded_pieces->setProgress(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);
|
||||
|
@ -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<partial_piece_info> queue;
|
||||
h.get_download_queue(queue);
|
||||
for(std::vector<partial_piece_info>::iterator it=queue.begin(); it!= queue.end(); it++) {
|
||||
bf.set_bit(it->piece_index);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Setters
|
||||
//
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user