From 58c78fa6f6a5da23ac8084bcaba5d1dff1906979 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 18 Nov 2007 18:06:44 +0000 Subject: [PATCH] - FEATURE: Real progress bar in torrent properties that displays downloaded pieces (contribution by Ishan Arora) --- AUTHORS | 1 + Changelog | 1 + src/properties.ui | 21 +++++++- src/properties_imp.cpp | 13 +++++ src/properties_imp.h | 4 ++ src/qtorrenthandle.cpp | 28 ++++++++-- src/qtorrenthandle.h | 6 ++- src/realprogressbar.cpp | 102 ++++++++++++++++++++++++++++++++++++ src/realprogressbar.h | 70 +++++++++++++++++++++++++ src/src.pro | 113 +++++++++++++++++++++------------------- 10 files changed, 300 insertions(+), 59 deletions(-) create mode 100644 src/realprogressbar.cpp create mode 100644 src/realprogressbar.h diff --git a/AUTHORS b/AUTHORS index 560821d74b82..1306f39d2641 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,3 +3,4 @@ Author: Contributors: * Arnaud Demaizière +* Ishan Arora diff --git a/Changelog b/Changelog index cd75fe904a42..d6bcb5b2e8d4 100644 --- a/Changelog +++ b/Changelog @@ -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 - v1.0.0 diff --git a/src/properties.ui b/src/properties.ui index 0abc015051a5..159d3e63b907 100644 --- a/src/properties.ui +++ b/src/properties.ui @@ -6,7 +6,7 @@ 0 0 594 - 567 + 621 @@ -312,6 +312,25 @@ + + + + + 0 + 50 + + + + + 75 + true + + + + Downloaded pieces + + + diff --git a/src/properties_imp.cpp b/src/properties_imp.cpp index 0e7d643a826f..1136a7eeff53 100644 --- a/src/properties_imp.cpp +++ b/src/properties_imp.cpp @@ -24,6 +24,8 @@ #include "PropListDelegate.h" #include "bittorrent.h" #include "arborescence.h" +#include "realprogressbar.h" +#include "realprogressbarthread.h" #include #include @@ -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(); } @@ -128,6 +139,8 @@ properties::~properties(){ delete updateInfosTimer; delete PropDelegate; delete PropListModel; + delete progressBarUpdater; + delete progressBar; } void properties::addFilesToTree(file *root, QStandardItem *parent) { diff --git a/src/properties_imp.h b/src/properties_imp.h index ec59479d36eb..4d7cd115cc0a 100644 --- a/src/properties_imp.h +++ b/src/properties_imp.h @@ -31,6 +31,8 @@ class bittorrent; class QStandardItemModel; class file; class QStandardItem; +class RealProgressBar; +class RealProgressBarThread; using namespace libtorrent; @@ -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(); diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index c6ed3f58dc95..18ad2b0610a2 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -60,6 +60,16 @@ float QTorrentHandle::progress() const { return progress; } +const std::vector* QTorrentHandle::pieces() const { + Q_ASSERT(h.is_valid()); + return h.status().pieces; +} + +void QTorrentHandle::get_download_queue(std::vector& 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); @@ -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()); diff --git a/src/qtorrenthandle.h b/src/qtorrenthandle.h index 6a644d39d7da..0565ae511255 100644 --- a/src/qtorrenthandle.h +++ b/src/qtorrenthandle.h @@ -54,11 +54,15 @@ class QTorrentHandle { QString hash() const; QString name() const; float progress() const; + const std::vector* pieces() const; + void get_download_queue(std::vector& 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; diff --git a/src/realprogressbar.cpp b/src/realprogressbar.cpp new file mode 100644 index 000000000000..f874a31a7d61 --- /dev/null +++ b/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 +#include +#include + +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= 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; +} diff --git a/src/realprogressbar.h b/src/realprogressbar.h new file mode 100644 index 000000000000..43472d96a4b5 --- /dev/null +++ b/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 +#include + +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 diff --git a/src/src.pro b/src/src.pro index 0699965767b0..df14d93474a9 100644 --- a/src/src.pro +++ b/src/src.pro @@ -17,15 +17,15 @@ DEFINES += VERSION_MINOR=0 DEFINES += VERSION_BUGFIX=0 contains(DEBUG_MODE, 1){ - CONFIG += debug - CONFIG -= release - message(Debug build!) + CONFIG += debug + CONFIG -= release + message(Debug build!) } contains(DEBUG_MODE, 0){ - CONFIG -= debug - CONFIG += release - DEFINES += QT_NO_DEBUG_OUTPUT - message(Release build!) + CONFIG -= debug + CONFIG += release + DEFINES += QT_NO_DEBUG_OUTPUT + message(Release build!) } # For libtorrent stuff @@ -35,56 +35,56 @@ contains(DEBUG_MODE, 0){ # Install !win32 { - # Binary - exists(../conf.pri) { - include(../conf.pri) - # Target - target.path = $$BINDIR - INSTALLS += target - } - - # Man page - man.files = ../doc/qbittorrent.1.gz - man.path = $$PREFIX/share/man/man1/ - INSTALLS += man - - # Menu Icon - menuicon.files = Icons/qBittorrent.desktop - menuicon.path = $$PREFIX/share/applications/ - INSTALLS += menuicon - icon16.files = menuicons/16x16/apps/qbittorrent.png - icon16.path = $$PREFIX/share/icons/hicolor/16x16/apps/ - icon22.files = menuicons/22x22/apps/qbittorrent.png - icon22.path = $$PREFIX/share/icons/hicolor/22x22/apps/ - icon24.files = menuicons/24x24/apps/qbittorrent.png - icon24.path = $$PREFIX/share/icons/hicolor/24x24/apps/ - icon32.files = menuicons/32x32/apps/qbittorrent.png - icon32.path = $$PREFIX/share/icons/hicolor/32x32/apps/ - icon36.files = menuicons/36x36/apps/qbittorrent.png - icon36.path = $$PREFIX/share/icons/hicolor/36x36/apps/ - icon48.files = menuicons/48x48/apps/qbittorrent.png - icon48.path = $$PREFIX/share/icons/hicolor/48x48/apps/ - icon64.files = menuicons/64x64/apps/qbittorrent.png - icon64.path = $$PREFIX/share/icons/hicolor/64x64/apps/ - icon72.files = menuicons/72x72/apps/qbittorrent.png - icon72.path = $$PREFIX/share/icons/hicolor/72x72/apps/ - icon96.files = menuicons/96x96/apps/qbittorrent.png - icon96.path = $$PREFIX/share/icons/hicolor/96x96/apps/ - icon128.files = menuicons/128x128/apps/qbittorrent.png - icon128.path = $$PREFIX/share/icons/hicolor/128x128/apps/ - icon192.files = menuicons/192x192/apps/qbittorrent.png - icon192.path = $$PREFIX/share/icons/hicolor/192x192/apps/ - INSTALLS += icon16 icon22 icon24 icon32 icon36 icon48 icon64 icon72 icon96 icon128 icon192 + # Binary + exists(../conf.pri){ + include(../conf.pri) + # Target + target.path = $$BINDIR + INSTALLS += target + } + + # Man page + man.files = ../doc/qbittorrent.1.gz + man.path = $$PREFIX/share/man/man1/ + INSTALLS += man + + # Menu Icon + menuicon.files = Icons/qBittorrent.desktop + menuicon.path = $$PREFIX/share/applications/ + INSTALLS += menuicon + icon16.files = menuicons/16x16/apps/qbittorrent.png + icon16.path = $$PREFIX/share/icons/hicolor/16x16/apps/ + icon22.files = menuicons/22x22/apps/qbittorrent.png + icon22.path = $$PREFIX/share/icons/hicolor/22x22/apps/ + icon24.files = menuicons/24x24/apps/qbittorrent.png + icon24.path = $$PREFIX/share/icons/hicolor/24x24/apps/ + icon32.files = menuicons/32x32/apps/qbittorrent.png + icon32.path = $$PREFIX/share/icons/hicolor/32x32/apps/ + icon36.files = menuicons/36x36/apps/qbittorrent.png + icon36.path = $$PREFIX/share/icons/hicolor/36x36/apps/ + icon48.files = menuicons/48x48/apps/qbittorrent.png + icon48.path = $$PREFIX/share/icons/hicolor/48x48/apps/ + icon64.files = menuicons/64x64/apps/qbittorrent.png + icon64.path = $$PREFIX/share/icons/hicolor/64x64/apps/ + icon72.files = menuicons/72x72/apps/qbittorrent.png + icon72.path = $$PREFIX/share/icons/hicolor/72x72/apps/ + icon96.files = menuicons/96x96/apps/qbittorrent.png + icon96.path = $$PREFIX/share/icons/hicolor/96x96/apps/ + icon128.files = menuicons/128x128/apps/qbittorrent.png + icon128.path = $$PREFIX/share/icons/hicolor/128x128/apps/ + icon192.files = menuicons/192x192/apps/qbittorrent.png + icon192.path = $$PREFIX/share/icons/hicolor/192x192/apps/ + INSTALLS += icon16 icon22 icon24 icon32 icon36 icon48 icon64 icon72 icon96 icon128 icon192 } QMAKE_CXXFLAGS_RELEASE += -fwrapv -O2 QMAKE_CXXFLAGS_DEBUG += -fwrapv -O1 CONFIG += link_pkgconfig -PKGCONFIG += libtorrent libccext2 libccgnu2 +PKGCONFIG += "libtorrent libccext2 libccgnu2" !contains(DEFINES, HAVE_MAGICK){ - message(ImageMagick disabled) + message(ImageMagick disabled) } QT += network xml @@ -94,8 +94,8 @@ DEFINES += QT_NO_CAST_TO_ASCII # Windows win32 { - LIBS += -ltorrent -lccext2 -lccgnu2 - #-lMagick++ -lWand -lMagick + LIBS += -ltorrent -lccext2 -lccgnu2 + #-lMagick++ -lWand -lMagick } RESOURCES = icons.qrc \ @@ -142,7 +142,9 @@ HEADERS += GUI.h misc.h options_imp.h about_imp.h \ allocationDlg.h FinishedListDelegate.h \ qtorrenthandle.h downloadingTorrents.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 \ properties.ui createtorrent.ui preview.ui \ login.ui downloadFromURL.ui addTorrentDialog.ui \ @@ -160,5 +162,10 @@ SOURCES += GUI.cpp \ qtorrenthandle.cpp \ downloadingTorrents.cpp \ engineSelectDlg.cpp \ - downloadThread.cpp + downloadThread.cpp \ + realprogressbar.cpp \ + realprogressbarthread.cpp \ + qrealarray.cpp + +DESTDIR = .