Browse Source

- FEATURE: Real progress bar in torrent properties that displays downloaded pieces (contribution by

Ishan Arora)
adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
58c78fa6f6
  1. 1
      AUTHORS
  2. 1
      Changelog
  3. 21
      src/properties.ui
  4. 13
      src/properties_imp.cpp
  5. 4
      src/properties_imp.h
  6. 28
      src/qtorrenthandle.cpp
  7. 6
      src/qtorrenthandle.h
  8. 102
      src/realprogressbar.cpp
  9. 70
      src/realprogressbar.h
  10. 13
      src/src.pro

1
AUTHORS

@ -3,3 +3,4 @@ Author:
Contributors: Contributors:
* Arnaud Demaizière <arnaud@qbittorrent.org> * Arnaud Demaizière <arnaud@qbittorrent.org>
* Ishan Arora <ishanarora@gmail.com>

1
Changelog

@ -2,6 +2,7 @@
- FEATURE: Option to start qBittorrent minimized in systray - FEATURE: Option to start qBittorrent minimized in systray
- FEATURE: Allow to define double-click actions in torrents lists - FEATURE: Allow to define double-click actions in torrents lists
- FEATURE: Allow to open torrent destination folder - 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) - BUGFIX: Do not display seeds number in seeding list (always 0)
* Unknown - Christophe Dumez <chris@qbittorrent.org> - v1.0.0 * Unknown - Christophe Dumez <chris@qbittorrent.org> - v1.0.0

21
src/properties.ui

@ -6,7 +6,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>594</width> <width>594</width>
<height>567</height> <height>621</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
@ -312,6 +312,25 @@
</layout> </layout>
</widget> </widget>
</item> </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> <item>
<widget class="QGroupBox" name="groupBox" > <widget class="QGroupBox" name="groupBox" >
<property name="sizePolicy" > <property name="sizePolicy" >

13
src/properties_imp.cpp

@ -24,6 +24,8 @@
#include "PropListDelegate.h" #include "PropListDelegate.h"
#include "bittorrent.h" #include "bittorrent.h"
#include "arborescence.h" #include "arborescence.h"
#include "realprogressbar.h"
#include "realprogressbarthread.h"
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
@ -120,6 +122,15 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h
updateInfosTimer = new QTimer(this); updateInfosTimer = new QTimer(this);
connect(updateInfosTimer, SIGNAL(timeout()), this, SLOT(updateInfos())); connect(updateInfosTimer, SIGNAL(timeout()), this, SLOT(updateInfos()));
updateInfosTimer->start(3000); 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(); loadSettings();
} }
@ -128,6 +139,8 @@ properties::~properties(){
delete updateInfosTimer; delete updateInfosTimer;
delete PropDelegate; delete PropDelegate;
delete PropListModel; delete PropListModel;
delete progressBarUpdater;
delete progressBar;
} }
void properties::addFilesToTree(file *root, QStandardItem *parent) { void properties::addFilesToTree(file *root, QStandardItem *parent) {

4
src/properties_imp.h

@ -31,6 +31,8 @@ class bittorrent;
class QStandardItemModel; class QStandardItemModel;
class file; class file;
class QStandardItem; class QStandardItem;
class RealProgressBar;
class RealProgressBarThread;
using namespace libtorrent; using namespace libtorrent;
@ -46,6 +48,8 @@ class properties : public QDialog, private Ui::properties{
QTimer *updateInfosTimer; QTimer *updateInfosTimer;
bool has_filtered_files; bool has_filtered_files;
QStringList urlSeeds; QStringList urlSeeds;
RealProgressBar *progressBar;
RealProgressBarThread *progressBarUpdater;
protected slots: protected slots:
void on_okButton_clicked(); void on_okButton_clicked();

28
src/qtorrenthandle.cpp

@ -60,6 +60,16 @@ float QTorrentHandle::progress() const {
return progress; 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 { QString QTorrentHandle::current_tracker() const {
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
return misc::toQString(h.status().current_tracker); return misc::toQString(h.status().current_tracker);
@ -74,10 +84,20 @@ bool QTorrentHandle::is_paused() const {
return h.is_paused(); return h.is_paused();
} }
// size_type QTorrentHandle::total_size() const { size_type QTorrentHandle::total_size() const {
// Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
// return h.get_torrent_info().total_size(); 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 { size_type QTorrentHandle::total_wanted_done() const {
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());

6
src/qtorrenthandle.h

@ -54,11 +54,15 @@ class QTorrentHandle {
QString hash() const; QString hash() const;
QString name() const; QString name() const;
float progress() 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; QString current_tracker() const;
bool is_valid() const; bool is_valid() const;
bool is_paused() const; bool is_paused() const;
bool has_filtered_pieces() 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; size_type total_wanted_done() const;
float download_payload_rate() const; float download_payload_rate() const;
float upload_payload_rate() const; float upload_payload_rate() const;

102
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
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

13
src/src.pro

@ -81,7 +81,7 @@ QMAKE_CXXFLAGS_RELEASE += -fwrapv -O2
QMAKE_CXXFLAGS_DEBUG += -fwrapv -O1 QMAKE_CXXFLAGS_DEBUG += -fwrapv -O1
CONFIG += link_pkgconfig CONFIG += link_pkgconfig
PKGCONFIG += libtorrent libccext2 libccgnu2 PKGCONFIG += "libtorrent libccext2 libccgnu2"
!contains(DEFINES, HAVE_MAGICK){ !contains(DEFINES, HAVE_MAGICK){
message(ImageMagick disabled) message(ImageMagick disabled)
@ -142,7 +142,9 @@ HEADERS += GUI.h misc.h options_imp.h about_imp.h \
allocationDlg.h FinishedListDelegate.h \ allocationDlg.h FinishedListDelegate.h \
qtorrenthandle.h downloadingTorrents.h \ qtorrenthandle.h downloadingTorrents.h \
engineSelectDlg.h pluginSource.h \ engineSelectDlg.h pluginSource.h \
arborescence.h qgnomelook.h arborescence.h qgnomelook.h realprogressbar.h \
realprogressbarthread.h \
qrealarray.h
FORMS += MainWindow.ui options.ui about.ui \ FORMS += MainWindow.ui options.ui about.ui \
properties.ui createtorrent.ui preview.ui \ properties.ui createtorrent.ui preview.ui \
login.ui downloadFromURL.ui addTorrentDialog.ui \ login.ui downloadFromURL.ui addTorrentDialog.ui \
@ -160,5 +162,10 @@ SOURCES += GUI.cpp \
qtorrenthandle.cpp \ qtorrenthandle.cpp \
downloadingTorrents.cpp \ downloadingTorrents.cpp \
engineSelectDlg.cpp \ engineSelectDlg.cpp \
downloadThread.cpp downloadThread.cpp \
realprogressbar.cpp \
realprogressbarthread.cpp \
qrealarray.cpp
DESTDIR = .

Loading…
Cancel
Save