mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-08 12:54:27 +00:00
- Rewrote the bar to display the downloaded piece as the one we had was overly complicated
This commit is contained in:
parent
ac021aaecb
commit
fb6b40ccd1
60
src/downloadedpiecesbar.h
Normal file
60
src/downloadedpiecesbar.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#ifndef DOWNLOADEDPIECESBAR_H
|
||||||
|
#define DOWNLOADEDPIECESBAR_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QList>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <libtorrent/bitfield.hpp>
|
||||||
|
|
||||||
|
using namespace libtorrent;
|
||||||
|
#define BAR_HEIGHT 18
|
||||||
|
|
||||||
|
class DownloadedPiecesBar: public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPixmap pixmap;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
DownloadedPiecesBar(QWidget *parent): QWidget(parent) {
|
||||||
|
setFixedHeight(BAR_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setProgress(bitfield pieces) {
|
||||||
|
if(pieces.empty()) {
|
||||||
|
// Empty bar
|
||||||
|
pixmap = QPixmap(1, 1);
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
painter.drawPoint(0,0);
|
||||||
|
} else {
|
||||||
|
pixmap = QPixmap(pieces.size(), 1);
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
for(uint i=0; i<pieces.size(); ++i) {
|
||||||
|
if(pieces[i])
|
||||||
|
painter.setPen(Qt::blue);
|
||||||
|
else
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
painter.drawPoint(i,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
pixmap = QPixmap();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *) {
|
||||||
|
if(pixmap.isNull()) return;
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.drawPixmap(rect(), pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DOWNLOADEDPIECESBAR_H
|
@ -41,14 +41,13 @@
|
|||||||
#include "propertieswidget.h"
|
#include "propertieswidget.h"
|
||||||
#include "transferlistwidget.h"
|
#include "transferlistwidget.h"
|
||||||
#include "torrentpersistentdata.h"
|
#include "torrentpersistentdata.h"
|
||||||
#include "realprogressbar.h"
|
|
||||||
#include "realprogressbarthread.h"
|
|
||||||
#include "bittorrent.h"
|
#include "bittorrent.h"
|
||||||
#include "proplistdelegate.h"
|
#include "proplistdelegate.h"
|
||||||
#include "torrentfilesmodel.h"
|
#include "torrentfilesmodel.h"
|
||||||
#include "peerlistwidget.h"
|
#include "peerlistwidget.h"
|
||||||
#include "trackerlist.h"
|
#include "trackerlist.h"
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
|
#include "downloadedpiecesbar.h"
|
||||||
|
|
||||||
#ifdef Q_WS_MAC
|
#ifdef Q_WS_MAC
|
||||||
#define DEFAULT_BUTTON_CSS ""
|
#define DEFAULT_BUTTON_CSS ""
|
||||||
@ -99,17 +98,16 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferLi
|
|||||||
connect(stackedProperties, SIGNAL(currentChanged(int)), this, SLOT(loadDynamicData()));
|
connect(stackedProperties, SIGNAL(currentChanged(int)), this, SLOT(loadDynamicData()));
|
||||||
|
|
||||||
// Downloaded pieces progress bar
|
// Downloaded pieces progress bar
|
||||||
progressBar = new RealProgressBar(this);
|
downloaded_pieces = new DownloadedPiecesBar(this);
|
||||||
progressBar->setForegroundColor(Qt::blue);
|
//progressBar = new RealProgressBar(this);
|
||||||
ProgressHLayout->insertWidget(1, progressBar);
|
//progressBar->setForegroundColor(Qt::blue);
|
||||||
|
ProgressHLayout->insertWidget(1, downloaded_pieces);
|
||||||
// Tracker list
|
// Tracker list
|
||||||
trackerList = new TrackerList(this);
|
trackerList = new TrackerList(this);
|
||||||
verticalLayout_trackers->addWidget(trackerList);
|
verticalLayout_trackers->addWidget(trackerList);
|
||||||
// Peers list
|
// Peers list
|
||||||
peersList = new PeerListWidget(this);
|
peersList = new PeerListWidget(this);
|
||||||
peerpage_layout->addWidget(peersList);
|
peerpage_layout->addWidget(peersList);
|
||||||
// Pointers init
|
|
||||||
progressBarUpdater = 0;
|
|
||||||
// Dynamic data refresher
|
// Dynamic data refresher
|
||||||
refreshTimer = new QTimer(this);
|
refreshTimer = new QTimer(this);
|
||||||
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData()));
|
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData()));
|
||||||
@ -119,11 +117,9 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferLi
|
|||||||
PropertiesWidget::~PropertiesWidget() {
|
PropertiesWidget::~PropertiesWidget() {
|
||||||
saveSettings();
|
saveSettings();
|
||||||
delete refreshTimer;
|
delete refreshTimer;
|
||||||
if(progressBarUpdater)
|
|
||||||
delete progressBarUpdater;
|
|
||||||
delete trackerList;
|
delete trackerList;
|
||||||
delete peersList;
|
delete peersList;
|
||||||
delete progressBar;
|
delete downloaded_pieces;
|
||||||
delete PropListModel;
|
delete PropListModel;
|
||||||
delete PropDelegate;
|
delete PropDelegate;
|
||||||
// Delete QActions
|
// Delete QActions
|
||||||
@ -166,8 +162,9 @@ void PropertiesWidget::clear() {
|
|||||||
lbl_creationDate->clear();
|
lbl_creationDate->clear();
|
||||||
hash_lbl->clear();
|
hash_lbl->clear();
|
||||||
comment_text->clear();
|
comment_text->clear();
|
||||||
|
progress_lbl->clear();
|
||||||
trackerList->clear();
|
trackerList->clear();
|
||||||
progressBar->setProgress(QRealArray());
|
downloaded_pieces->clear();
|
||||||
wasted->clear();
|
wasted->clear();
|
||||||
upTotal->clear();
|
upTotal->clear();
|
||||||
dlTotal->clear();
|
dlTotal->clear();
|
||||||
@ -197,10 +194,6 @@ void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
if(progressBarUpdater) {
|
|
||||||
delete progressBarUpdater;
|
|
||||||
progressBarUpdater = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Save path
|
// Save path
|
||||||
@ -213,9 +206,6 @@ void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) {
|
|||||||
comment_text->setHtml(h.comment());
|
comment_text->setHtml(h.comment());
|
||||||
// URL seeds
|
// URL seeds
|
||||||
loadUrlSeeds();
|
loadUrlSeeds();
|
||||||
// downloaded pieces updater
|
|
||||||
progressBarUpdater = new RealProgressBarThread(progressBar, h);
|
|
||||||
progressBarUpdater->start();
|
|
||||||
// List files in torrent
|
// List files in torrent
|
||||||
PropListModel->clear();
|
PropListModel->clear();
|
||||||
PropListModel->setupModelData(h.get_torrent_info());
|
PropListModel->setupModelData(h.get_torrent_info());
|
||||||
@ -316,8 +306,7 @@ void PropertiesWidget::loadDynamicData() {
|
|||||||
}
|
}
|
||||||
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
|
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
|
||||||
// Downloaded pieces
|
// Downloaded pieces
|
||||||
if(progressBarUpdater)
|
downloaded_pieces->setProgress(h.pieces());
|
||||||
progressBarUpdater->refresh();
|
|
||||||
// Progress
|
// Progress
|
||||||
progress_lbl->setText(QString::number(h.progress()*100., 'f', 1)+"%");
|
progress_lbl->setText(QString::number(h.progress()*100., 'f', 1)+"%");
|
||||||
return;
|
return;
|
||||||
|
@ -38,8 +38,6 @@
|
|||||||
|
|
||||||
class TransferListWidget;
|
class TransferListWidget;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class RealProgressBar;
|
|
||||||
class RealProgressBarThread;
|
|
||||||
class Bittorrent;
|
class Bittorrent;
|
||||||
class TorrentFilesModel;
|
class TorrentFilesModel;
|
||||||
class PropListDelegate;
|
class PropListDelegate;
|
||||||
@ -48,6 +46,7 @@ class torrent_file;
|
|||||||
class PeerListWidget;
|
class PeerListWidget;
|
||||||
class TrackerList;
|
class TrackerList;
|
||||||
class GUI;
|
class GUI;
|
||||||
|
class DownloadedPiecesBar;
|
||||||
|
|
||||||
enum Tab {MAIN_TAB, TRACKERS_TAB, PEERS_TAB, URLSEEDS_TAB, FILES_TAB};
|
enum Tab {MAIN_TAB, TRACKERS_TAB, PEERS_TAB, URLSEEDS_TAB, FILES_TAB};
|
||||||
enum SlideState {REDUCED, VISIBLE};
|
enum SlideState {REDUCED, VISIBLE};
|
||||||
@ -60,8 +59,6 @@ private:
|
|||||||
GUI *main_window;
|
GUI *main_window;
|
||||||
QTorrentHandle h;
|
QTorrentHandle h;
|
||||||
QTimer *refreshTimer;
|
QTimer *refreshTimer;
|
||||||
RealProgressBar *progressBar;
|
|
||||||
RealProgressBarThread *progressBarUpdater;
|
|
||||||
Bittorrent* BTSession;
|
Bittorrent* BTSession;
|
||||||
SlideState state;
|
SlideState state;
|
||||||
TorrentFilesModel *PropListModel;
|
TorrentFilesModel *PropListModel;
|
||||||
@ -73,6 +70,7 @@ private:
|
|||||||
QAction *actionMaximum;
|
QAction *actionMaximum;
|
||||||
QAction *actionHigh;
|
QAction *actionHigh;
|
||||||
QList<int> slideSizes;
|
QList<int> slideSizes;
|
||||||
|
DownloadedPiecesBar *downloaded_pieces;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QPushButton* getButtonFromIndex(int index);
|
QPushButton* getButtonFromIndex(int index);
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give permission to
|
|
||||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
||||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
||||||
* and distribute the linked executables. You must obey the GNU General Public
|
|
||||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
||||||
* modify file(s), you may extend this exception to your version of the file(s),
|
|
||||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
||||||
* exception statement from your version.
|
|
||||||
*
|
|
||||||
* Contact : chris@qbittorrent.org, arnaud@qbittorrent.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qrealarray.h"
|
|
||||||
|
|
||||||
int id = qRegisterMetaType<QRealArray>();
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give permission to
|
|
||||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
||||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
||||||
* and distribute the linked executables. You must obey the GNU General Public
|
|
||||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
||||||
* modify file(s), you may extend this exception to your version of the file(s),
|
|
||||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
||||||
* exception statement from your version.
|
|
||||||
*
|
|
||||||
* Contact : chris@qbittorrent.org, arnaud@qbittorrent.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef QREALARRAY_H
|
|
||||||
#define QREALARRAY_H
|
|
||||||
|
|
||||||
#include <QVarLengthArray>
|
|
||||||
#include <QMetaType>
|
|
||||||
|
|
||||||
typedef QVarLengthArray<qreal, 256> QRealArray;
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QRealArray)
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,115 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give permission to
|
|
||||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
||||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
||||||
* and distribute the linked executables. You must obey the GNU General Public
|
|
||||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
||||||
* modify file(s), you may extend this exception to your version of the file(s),
|
|
||||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
||||||
* exception statement from your version.
|
|
||||||
*
|
|
||||||
* 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;
|
|
||||||
setFixedHeight(18);
|
|
||||||
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 *)
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
if(x < 0.)
|
|
||||||
x = 0.;
|
|
||||||
else
|
|
||||||
if(x > 1.)
|
|
||||||
x = 1.;
|
|
||||||
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;
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give permission to
|
|
||||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
||||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
||||||
* and distribute the linked executables. You must obey the GNU General Public
|
|
||||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
||||||
* modify file(s), you may extend this exception to your version of the file(s),
|
|
||||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
||||||
* exception statement from your version.
|
|
||||||
*
|
|
||||||
* 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
|
|
@ -1,170 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give permission to
|
|
||||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
||||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
||||||
* and distribute the linked executables. You must obey the GNU General Public
|
|
||||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
||||||
* modify file(s), you may extend this exception to your version of the file(s),
|
|
||||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
||||||
* exception statement from your version.
|
|
||||||
*
|
|
||||||
* Contact : chris@qbittorrent.org, arnaud@qbittorrent.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "realprogressbarthread.h"
|
|
||||||
#include "realprogressbar.h"
|
|
||||||
#include <QtDebug>
|
|
||||||
#include <QMutexLocker>
|
|
||||||
|
|
||||||
RealProgressBarThread::RealProgressBarThread(RealProgressBar *pb, QTorrentHandle &handle) : QThread(pb), thandle(handle), array(pb->width()){
|
|
||||||
size = pb->width();
|
|
||||||
abort = false;
|
|
||||||
connect(pb, SIGNAL(widthChanged(int)), this, SLOT(resize(int)), Qt::DirectConnection);
|
|
||||||
connect(this, SIGNAL(refreshed(QRealArray)), pb, SLOT(setProgress(QRealArray)));
|
|
||||||
}
|
|
||||||
|
|
||||||
RealProgressBarThread::~RealProgressBarThread(){
|
|
||||||
qDebug("RealProgressBarThread destruction");
|
|
||||||
resize(-1);
|
|
||||||
qDebug("RealProgressBarThread waiting");
|
|
||||||
wait();
|
|
||||||
qDebug("RealProgressBarThread destroyed");
|
|
||||||
}
|
|
||||||
|
|
||||||
void RealProgressBarThread::resize(int width)
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&mutex);
|
|
||||||
size = width;
|
|
||||||
abort = true;
|
|
||||||
condition.wakeOne();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RealProgressBarThread::refresh()
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&mutex);
|
|
||||||
condition.wakeOne();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RealProgressBarThread::run(){
|
|
||||||
forever
|
|
||||||
{
|
|
||||||
//start checking the torrent information
|
|
||||||
if(ifInterrupted() == stop)
|
|
||||||
{
|
|
||||||
qDebug("RealProgressBarThread stop");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
size_type total_size = thandle.total_size();
|
|
||||||
size_type piece_length = thandle.piece_length();
|
|
||||||
int num_pieces = thandle.num_pieces();
|
|
||||||
bitfield pieces = thandle.pieces();
|
|
||||||
//pieces not returned
|
|
||||||
if (pieces.empty())
|
|
||||||
{
|
|
||||||
qDebug("pieces vector not returned");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//empty the array
|
|
||||||
mutex.lock();
|
|
||||||
for(int i=0; i<array.size(); i++)
|
|
||||||
array[i] = 0.;
|
|
||||||
mutex.unlock();
|
|
||||||
qreal subfraction = array.size() / (qreal) total_size;
|
|
||||||
qreal fraction = subfraction * piece_length;
|
|
||||||
bool success = true;
|
|
||||||
//fill the array with complete pieces
|
|
||||||
for(int i=0; i<num_pieces; i++)
|
|
||||||
{
|
|
||||||
Interrupt temp = ifInterrupted();
|
|
||||||
if (temp == stop)
|
|
||||||
{
|
|
||||||
qDebug("RealProgressBarThread stop");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (temp == restart)
|
|
||||||
{
|
|
||||||
qDebug("RealProgressBarThread restart");
|
|
||||||
success = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
qreal start = i * fraction;
|
|
||||||
qreal end = start + fraction;
|
|
||||||
if(pieces[i])
|
|
||||||
mark(start, end);
|
|
||||||
}
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
qreal sum = 0.;
|
|
||||||
mutex.lock();
|
|
||||||
for(int i=0; i<array.size(); i++)
|
|
||||||
sum += array[i];
|
|
||||||
qDebug()<<"progress:"<<sum*100./array.size();
|
|
||||||
mutex.unlock();*/
|
|
||||||
qDebug("refreshed emmitted");
|
|
||||||
emit refreshed(array);
|
|
||||||
//wait for refresh or rezise slot
|
|
||||||
mutex.lock();
|
|
||||||
condition.wait(&mutex);
|
|
||||||
mutex.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Interrupt RealProgressBarThread::ifInterrupted()
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&mutex);
|
|
||||||
if(abort)
|
|
||||||
{
|
|
||||||
abort = false;
|
|
||||||
if(size < 0)
|
|
||||||
return stop;
|
|
||||||
if(size != array.size())
|
|
||||||
{
|
|
||||||
array.resize(size);
|
|
||||||
return restart;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ignore;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RealProgressBarThread::mark(qreal start, qreal end, qreal progress){
|
|
||||||
QMutexLocker locker(&mutex);
|
|
||||||
if (end > array.size())
|
|
||||||
end = array.size();
|
|
||||||
int start_int, end_int;
|
|
||||||
qreal start_frac, end_frac;
|
|
||||||
double temp;
|
|
||||||
start_frac = modf(start, &temp);
|
|
||||||
start_int = (int) temp;
|
|
||||||
end_frac = modf(end, &temp);
|
|
||||||
end_int = (int) temp;
|
|
||||||
if(start_int == end_int)
|
|
||||||
{
|
|
||||||
array[start_int] += progress * (end - start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (start_frac > 0.)
|
|
||||||
array[start_int] += progress * (1 - start_frac);
|
|
||||||
if (end_frac > 0.)
|
|
||||||
array[end_int] += progress * end_frac;
|
|
||||||
for(int i=start_int+1; i<end_int; i++)
|
|
||||||
array[i] += progress;
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give permission to
|
|
||||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
||||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
||||||
* and distribute the linked executables. You must obey the GNU General Public
|
|
||||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
||||||
* modify file(s), you may extend this exception to your version of the file(s),
|
|
||||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
||||||
* exception statement from your version.
|
|
||||||
*
|
|
||||||
* Contact : chris@qbittorrent.org, arnaud@qbittorrent.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef REALPROGRESSBARTHREAD_H
|
|
||||||
#define REALPROGRESSBARTHREAD_H
|
|
||||||
|
|
||||||
#include "qtorrenthandle.h"
|
|
||||||
#include "qrealarray.h"
|
|
||||||
|
|
||||||
#include <QThread>
|
|
||||||
#include <QMutex>
|
|
||||||
#include <QWaitCondition>
|
|
||||||
|
|
||||||
class RealProgressBar;
|
|
||||||
|
|
||||||
enum Interrupt
|
|
||||||
{
|
|
||||||
ignore,
|
|
||||||
restart,
|
|
||||||
stop
|
|
||||||
};
|
|
||||||
|
|
||||||
class RealProgressBarThread : public QThread {
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
bool abort;
|
|
||||||
int size;
|
|
||||||
QTorrentHandle thandle;
|
|
||||||
QMutex mutex;
|
|
||||||
QWaitCondition condition;
|
|
||||||
QRealArray array;
|
|
||||||
|
|
||||||
public:
|
|
||||||
RealProgressBarThread(RealProgressBar *pb, QTorrentHandle &handle);
|
|
||||||
~RealProgressBarThread();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void resize(int width);
|
|
||||||
void refresh();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void refreshed(QRealArray progress);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void run();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Interrupt ifInterrupted();
|
|
||||||
void mark(qreal start, qreal end, qreal progress = 1.);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -163,9 +163,6 @@ HEADERS += GUI.h \
|
|||||||
engineselectdlg.h \
|
engineselectdlg.h \
|
||||||
pluginsource.h \
|
pluginsource.h \
|
||||||
qgnomelook.h \
|
qgnomelook.h \
|
||||||
realprogressbar.h \
|
|
||||||
realprogressbarthread.h \
|
|
||||||
qrealarray.h \
|
|
||||||
httpserver.h \
|
httpserver.h \
|
||||||
httpconnection.h \
|
httpconnection.h \
|
||||||
httprequestparser.h \
|
httprequestparser.h \
|
||||||
@ -196,7 +193,8 @@ HEADERS += GUI.h \
|
|||||||
peeraddition.h \
|
peeraddition.h \
|
||||||
deletionconfirmationdlg.h \
|
deletionconfirmationdlg.h \
|
||||||
statusbar.h \
|
statusbar.h \
|
||||||
trackerlist.h
|
trackerlist.h \
|
||||||
|
downloadedpiecesbar.h
|
||||||
FORMS += ui/mainwindow.ui \
|
FORMS += ui/mainwindow.ui \
|
||||||
ui/options.ui \
|
ui/options.ui \
|
||||||
ui/about.ui \
|
ui/about.ui \
|
||||||
@ -226,9 +224,6 @@ SOURCES += GUI.cpp \
|
|||||||
qtorrenthandle.cpp \
|
qtorrenthandle.cpp \
|
||||||
engineselectdlg.cpp \
|
engineselectdlg.cpp \
|
||||||
downloadthread.cpp \
|
downloadthread.cpp \
|
||||||
realprogressbar.cpp \
|
|
||||||
realprogressbarthread.cpp \
|
|
||||||
qrealarray.cpp \
|
|
||||||
httpserver.cpp \
|
httpserver.cpp \
|
||||||
httpconnection.cpp \
|
httpconnection.cpp \
|
||||||
httprequestparser.cpp \
|
httprequestparser.cpp \
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>-59</y>
|
<y>0</y>
|
||||||
<width>518</width>
|
<width>518</width>
|
||||||
<height>348</height>
|
<height>348</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -93,7 +93,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>44</width>
|
<width>50</width>
|
||||||
<height>16777215</height>
|
<height>16777215</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
@ -580,7 +580,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="icons.qrc">
|
<iconset>
|
||||||
<normaloff>:/Icons/oxygen/list-remove.png</normaloff>:/Icons/oxygen/list-remove.png</iconset>
|
<normaloff>:/Icons/oxygen/list-remove.png</normaloff>:/Icons/oxygen/list-remove.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -597,7 +597,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="icons.qrc">
|
<iconset>
|
||||||
<normaloff>:/Icons/oxygen/list-add.png</normaloff>:/Icons/oxygen/list-add.png</iconset>
|
<normaloff>:/Icons/oxygen/list-add.png</normaloff>:/Icons/oxygen/list-add.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -712,7 +712,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<string>General</string>
|
<string>General</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="icons.qrc">
|
<iconset>
|
||||||
<normaloff>:/Icons/oxygen/help-about.png</normaloff>:/Icons/oxygen/help-about.png</iconset>
|
<normaloff>:/Icons/oxygen/help-about.png</normaloff>:/Icons/oxygen/help-about.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@ -729,7 +729,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<string>Trackers</string>
|
<string>Trackers</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="icons.qrc">
|
<iconset>
|
||||||
<normaloff>:/Icons/oxygen/network-server.png</normaloff>:/Icons/oxygen/network-server.png</iconset>
|
<normaloff>:/Icons/oxygen/network-server.png</normaloff>:/Icons/oxygen/network-server.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@ -752,7 +752,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<string>Peers</string>
|
<string>Peers</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="icons.qrc">
|
<iconset>
|
||||||
<normaloff>:/Icons/oxygen/peer.png</normaloff>:/Icons/oxygen/peer.png</iconset>
|
<normaloff>:/Icons/oxygen/peer.png</normaloff>:/Icons/oxygen/peer.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@ -769,7 +769,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<string>URL seeds</string>
|
<string>URL seeds</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="icons.qrc">
|
<iconset>
|
||||||
<normaloff>:/Icons/oxygen/urlseed.png</normaloff>:/Icons/oxygen/urlseed.png</iconset>
|
<normaloff>:/Icons/oxygen/urlseed.png</normaloff>:/Icons/oxygen/urlseed.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@ -786,7 +786,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<string>Files</string>
|
<string>Files</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="icons.qrc">
|
<iconset>
|
||||||
<normaloff>:/Icons/oxygen/folder.png</normaloff>:/Icons/oxygen/folder.png</iconset>
|
<normaloff>:/Icons/oxygen/folder.png</normaloff>:/Icons/oxygen/folder.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user