- Made progress on torrent properties (main tab)

This commit is contained in:
Christophe Dumez 2009-11-08 15:41:32 +00:00
parent 707e87f5b8
commit 75e5a7e3d4
6 changed files with 269 additions and 102 deletions

View file

@ -141,8 +141,8 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis
hSplitter = new QSplitter(Qt::Vertical, vSplitter);
// Transfer List tab
properties = new PropertiesWidget(hSplitter);
transferList = new TransferListWidget(vSplitter, BTSession);
transferList = new TransferListWidget(hSplitter, BTSession);
properties = new PropertiesWidget(hSplitter, transferList);
transferListFilters = new TransferListFiltersWidget(vSplitter, transferList);
hSplitter->addWidget(transferList);
hSplitter->addWidget(properties);

View file

@ -789,6 +789,12 @@ void TransferListWidget::loadLastSortedColumn() {
}
}
void TransferListWidget::currentChanged(const QModelIndex& current, const QModelIndex&) {
int row = proxyModel->mapToSource(current).row();
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row));
emit currentTorrentChanged(h);
}
void TransferListWidget::applyFilter(int f) {
switch(f) {
case DOWNLOADING:

View file

@ -74,6 +74,7 @@ protected slots:
void saveHiddenColumns();
void displayListMenu(const QPoint&);
void updateMetadata(QTorrentHandle &h);
void currentChanged(const QModelIndex& current, const QModelIndex&);
//void setRowColor(int row, QColor color);
public slots:
@ -101,6 +102,9 @@ public slots:
void displayDLHoSMenu(const QPoint&);
void applyFilter(int f);
signals:
void currentTorrentChanged(QTorrentHandle &h);
};
#endif // TRANSFERLISTWIDGET_H

View file

@ -22,7 +22,7 @@
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QGroupBox" name="groupTorrentInfos">
<property name="font">
@ -34,11 +34,19 @@
<property name="title">
<string>Torrent information</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="savePath_lbl">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>22</height>
</size>
</property>
<property name="font">
<font>
<weight>50</weight>
@ -97,17 +105,10 @@
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="save_path">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="changeSavePathButton">
<property name="maximumSize">
<size>
<width>27</width>
<height>16777215</height>
<width>16777215</width>
<height>22</height>
</size>
</property>
<property name="font">
@ -117,7 +118,26 @@
</font>
</property>
<property name="text">
<string>...</string>
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="changeSavePathButton">
<property name="maximumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string notr="true">...</string>
</property>
</widget>
</item>
@ -125,6 +145,12 @@
</item>
<item>
<widget class="QLabel" name="creator">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
@ -132,9 +158,18 @@
</item>
<item>
<widget class="QLabel" name="hash_lbl">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
@ -152,6 +187,8 @@
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer>
<property name="orientation">
@ -159,7 +196,7 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>185</width>
<width>190</width>
<height>20</height>
</size>
</property>
@ -303,6 +340,12 @@
</property>
<item>
<widget class="QLabel" name="upTotal">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
@ -310,6 +353,12 @@
</item>
<item>
<widget class="QLabel" name="dlTotal">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
@ -317,6 +366,12 @@
</item>
<item>
<widget class="QLabel" name="shareRatio">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
@ -324,6 +379,12 @@
</item>
<item>
<widget class="QLabel" name="failed">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>

View file

@ -28,12 +28,88 @@
* Contact : chris@qbittorrent.org
*/
#include <QTimer>
#include <QVBoxLayout>
#include "propertieswidget.h"
#include "TransferListWidget.h"
#include "torrentPersistentData.h"
#include "realprogressbar.h"
#include "realprogressbarthread.h"
PropertiesWidget::PropertiesWidget(QWidget *parent): QWidget(parent) {
PropertiesWidget::PropertiesWidget(QWidget *parent, TransferListWidget *transferList): QWidget(parent), transferList(transferList) {
setupUi(this);
connect(transferList, SIGNAL(currentTorrentChanged(QTorrentHandle&)), this, SLOT(loadTorrentInfos(QTorrentHandle &)));
// Downloaded pieces progress bar
progressBar = new RealProgressBar(this);
progressBar->setForegroundColor(Qt::blue);
progressBarVbox = new QVBoxLayout(RealProgressBox);
progressBarVbox->addWidget(progressBar);
progressBarUpdater = 0;
// Dynamic data refresher
refreshTimer = new QTimer(this);
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData()));
refreshTimer->start(10000); // 10sec
}
PropertiesWidget::~PropertiesWidget() {
delete refreshTimer;
if(progressBarUpdater)
delete progressBarUpdater;
delete progressBar;
delete progressBarVbox;
}
void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) {
h = _h;
if(!h.is_valid()) return;
if(progressBarUpdater)
delete progressBarUpdater;
progressBarUpdater = 0;
try {
// Save path
save_path->setText(TorrentPersistentData::getSavePath(h.hash()));
// Author
QString author = h.creator().trimmed();
if(author.isEmpty())
author = tr("Unknown");
creator->setText(author);
// Hash
hash_lbl->setText(h.hash());
// Comment
comment_lbl->setText(h.comment());
// downloaded pieces updater
progressBarUpdater = new RealProgressBarThread(progressBar, h);
progressBarUpdater->start();
} catch(invalid_handle e) {
}
// Load dynamic data
loadDynamicData();
}
void PropertiesWidget::loadDynamicData() {
if(!h.is_valid()) return;
try {
// Session infos
failed->setText(misc::friendlyUnit(h.total_failed_bytes()));
upTotal->setText(misc::friendlyUnit(h.total_payload_upload()));
dlTotal->setText(misc::friendlyUnit(h.total_payload_download()));
// Update ratio info
float ratio;
if(h.total_payload_download() == 0){
if(h.total_payload_upload() == 0)
ratio = 1.;
else
ratio = 10.; // Max ratio
}else{
ratio = (double)h.total_payload_upload()/(double)h.total_payload_download();
if(ratio > 10.){
ratio = 10.;
}
}
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
// Downloaded pieces
if(progressBarUpdater)
progressBarUpdater->refresh();
} catch(invalid_handle e) {}
}

View file

@ -33,11 +33,31 @@
#include <QWidget>
#include "ui_propertiesWidget.h"
#include "qtorrenthandle.h"
class TransferListWidget;
class QTimer;
class RealProgressBar;
class QVBoxLayout;
class RealProgressBarThread;
class PropertiesWidget : public QWidget, private Ui::PropertiesWidget {
Q_OBJECT
private:
TransferListWidget *transferList;
QTorrentHandle h;
QTimer *refreshTimer;
RealProgressBar *progressBar;
RealProgressBarThread *progressBarUpdater;
QVBoxLayout *progressBarVbox;
protected slots:
void loadTorrentInfos(QTorrentHandle &h);
void loadDynamicData();
public:
PropertiesWidget(QWidget *parent);
PropertiesWidget(QWidget *parent, TransferListWidget *transferList);
~PropertiesWidget();
};