Skip to content

Commit

Permalink
- FEATURE: Real progress bar in torrent properties that displays down…
Browse files Browse the repository at this point in the history
…loaded pieces (contribution by

Ishan Arora)
  • Loading branch information
Christophe Dumez committed Nov 18, 2007
1 parent 5484ec9 commit 58c78fa
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 59 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -3,3 +3,4 @@ Author:

Contributors:
* Arnaud Demaizière <arnaud@qbittorrent.org>
* Ishan Arora <ishanarora@gmail.com>
1 change: 1 addition & 0 deletions Changelog
Expand Up @@ -2,6 +2,7 @@
- FEATURE: Option to start qBittorrent minimized in systray
- FEATURE: Allow to define double-click actions in torrents lists
- FEATURE: Allow to open torrent destination folder
- FEATURE: Real progress bar in torrent properties that displays downloaded pieces
- BUGFIX: Do not display seeds number in seeding list (always 0)

* Unknown - Christophe Dumez <chris@qbittorrent.org> - v1.0.0
Expand Down
21 changes: 20 additions & 1 deletion src/properties.ui
Expand Up @@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>594</width>
<height>567</height>
<height>621</height>
</rect>
</property>
<property name="windowTitle" >
Expand Down Expand Up @@ -312,6 +312,25 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="RealProgressBox" >
<property name="minimumSize" >
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="font" >
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title" >
<string>Downloaded pieces</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="sizePolicy" >
Expand Down
13 changes: 13 additions & 0 deletions src/properties_imp.cpp
Expand Up @@ -24,6 +24,8 @@
#include "PropListDelegate.h"
#include "bittorrent.h"
#include "arborescence.h"
#include "realprogressbar.h"
#include "realprogressbarthread.h"

#include <QInputDialog>
#include <QMessageBox>
Expand Down Expand Up @@ -120,6 +122,15 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h
updateInfosTimer = new QTimer(this);
connect(updateInfosTimer, SIGNAL(timeout()), this, SLOT(updateInfos()));
updateInfosTimer->start(3000);
progressBar = new RealProgressBar(this);
progressBar->setForegroundColor(Qt::blue);
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->addWidget(progressBar);
RealProgressBox->setLayout(vbox);
progressBarUpdater = new RealProgressBarThread(progressBar, h);
progressBarUpdater->start();
// progressBarUpdater->refresh();
connect(updateInfosTimer, SIGNAL(timeout()), progressBarUpdater, SLOT(refresh()));
loadSettings();
}

Expand All @@ -128,6 +139,8 @@ properties::~properties(){
delete updateInfosTimer;
delete PropDelegate;
delete PropListModel;
delete progressBarUpdater;
delete progressBar;
}

void properties::addFilesToTree(file *root, QStandardItem *parent) {
Expand Down
4 changes: 4 additions & 0 deletions src/properties_imp.h
Expand Up @@ -31,6 +31,8 @@ class bittorrent;
class QStandardItemModel;
class file;
class QStandardItem;
class RealProgressBar;
class RealProgressBarThread;

using namespace libtorrent;

Expand All @@ -46,6 +48,8 @@ class properties : public QDialog, private Ui::properties{
QTimer *updateInfosTimer;
bool has_filtered_files;
QStringList urlSeeds;
RealProgressBar *progressBar;
RealProgressBarThread *progressBarUpdater;

protected slots:
void on_okButton_clicked();
Expand Down
28 changes: 24 additions & 4 deletions src/qtorrenthandle.cpp
Expand Up @@ -60,6 +60,16 @@ float QTorrentHandle::progress() const {
return progress;
}

const std::vector<bool>* QTorrentHandle::pieces() const {
Q_ASSERT(h.is_valid());
return h.status().pieces;
}

void QTorrentHandle::get_download_queue(std::vector<partial_piece_info>& queue) const {
Q_ASSERT(h.is_valid());
h.get_download_queue(queue);
}

QString QTorrentHandle::current_tracker() const {
Q_ASSERT(h.is_valid());
return misc::toQString(h.status().current_tracker);
Expand All @@ -74,10 +84,20 @@ bool QTorrentHandle::is_paused() const {
return h.is_paused();
}

// size_type QTorrentHandle::total_size() const {
// Q_ASSERT(h.is_valid());
// return h.get_torrent_info().total_size();
// }
size_type QTorrentHandle::total_size() const {
Q_ASSERT(h.is_valid());
return h.get_torrent_info().total_size();
}

size_type QTorrentHandle::piece_length() const {
Q_ASSERT(h.is_valid());
return h.get_torrent_info().piece_length();
}

int QTorrentHandle::num_pieces() const {
Q_ASSERT(h.is_valid());
return h.get_torrent_info().num_pieces();
}

size_type QTorrentHandle::total_wanted_done() const {
Q_ASSERT(h.is_valid());
Expand Down
6 changes: 5 additions & 1 deletion src/qtorrenthandle.h
Expand Up @@ -54,11 +54,15 @@ class QTorrentHandle {
QString hash() const;
QString name() const;
float progress() const;
const std::vector<bool>* pieces() const;
void get_download_queue(std::vector<partial_piece_info>& queue) const;
QString current_tracker() const;
bool is_valid() const;
bool is_paused() const;
bool has_filtered_pieces() const;
// size_type total_size() const;
size_type total_size() const;
size_type piece_length() const;
int num_pieces() const;
size_type total_wanted_done() const;
float download_payload_rate() const;
float upload_payload_rate() const;
Expand Down
102 changes: 102 additions & 0 deletions src/realprogressbar.cpp
@@ -0,0 +1,102 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez, Arnaud Demaiziere
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contact : chris@qbittorrent.org, arnaud@qbittorrent.org
*/

#include "realprogressbar.h"
#include <QPainter>
#include <QtDebug>
#include <QResizeEvent>

RealProgressBar::RealProgressBar(QWidget *parent)
: QWidget(parent), array(1)
{
background = Qt::white;
foreground = Qt::black;
active = false;
array[0] = 0.;
drawPixmap();
}

RealProgressBar::~RealProgressBar()
{
qDebug("RealProgressBar destruction");
}

void RealProgressBar::setBackgroundColor(const QColor &newColor)
{
background = newColor;
drawPixmap();
}

void RealProgressBar::setForegroundColor(const QColor &newColor)
{
foreground = newColor;
drawPixmap();
}
/*
void RealProgressBar::setThread(const RealProgressBarThread *newThread)
{
thread = newThread;
}
*/
void RealProgressBar::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.drawPixmap(rect(), pixmap);
}

void RealProgressBar::resizeEvent(QResizeEvent *event)
{
if(width() != event->oldSize().width())
emit widthChanged(width());
}

void RealProgressBar::setProgress(QRealArray progress)
{
qDebug("setProgress called");
array = progress;
drawPixmap();
}

void RealProgressBar::drawPixmap()
{
if(pixmap.width() != array.size())
pixmap = QPixmap(array.size(), 1);
QPainter painter(&pixmap);
for(int i=0; i<array.size(); i++)
{
painter.setPen(penColor(array[i]));
painter.drawPoint(i,0);
}
update();
}

QColor RealProgressBar::penColor(qreal x)
{
qreal y = 1 - x;
Q_ASSERT(x >= 0.);
Q_ASSERT(y >= 0.);
qreal r1, g1, b1, a1, r2, g2, b2, a2;
foreground.getRgbF(&r1, &g1, &b1, &a1);
background.getRgbF(&r2, &g2, &b2, &a2);
QColor color;
color.setRgbF(x*r1+y*r2, x*g1+y*g2, x*b1+y*b2, x*a1+y*a2);
return color;
}
70 changes: 70 additions & 0 deletions src/realprogressbar.h
@@ -0,0 +1,70 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez, Arnaud Demaiziere
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contact : chris@qbittorrent.org, arnaud@qbittorrent.org
*/

#ifndef REALPROGRESSBAR_H
#define REALPROGRESSBAR_H

#include "qrealarray.h"
#include <QWidget>
#include <QPixmap>

class RealProgressBar : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor)

private:
QColor foreground;
QColor background;
bool active;
QPixmap pixmap;
// RealProgressBarThread *thread;
QRealArray array;

public:
RealProgressBar(QWidget *parent = 0);
~RealProgressBar();

void setBackgroundColor(const QColor &newColor);
QColor backgroundColor() const {return background;}
void setForegroundColor(const QColor &newColor);
QColor foregroundColor() const {return foreground;}
// void setThread(const RealProgressBarThread *newThread);
// RealProgressBarThread *thread() const {return thread;}

public slots:
void setProgress(QRealArray progress);

signals:
void widthChanged(int width);

protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);

private:
void drawPixmap();
QColor penColor(qreal f);

};

#endif

0 comments on commit 58c78fa

Please sign in to comment.