diff --git a/src/GUI.cpp b/src/GUI.cpp index bef4e3b84..1689a0ca7 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -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); diff --git a/src/TransferListWidget.cpp b/src/TransferListWidget.cpp index 2555d197e..b13859b20 100644 --- a/src/TransferListWidget.cpp +++ b/src/TransferListWidget.cpp @@ -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: diff --git a/src/TransferListWidget.h b/src/TransferListWidget.h index 474f2bdc4..7e451af3a 100644 --- a/src/TransferListWidget.h +++ b/src/TransferListWidget.h @@ -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 diff --git a/src/propertiesWidget.ui b/src/propertiesWidget.ui index 759207441..ce34fe123 100644 --- a/src/propertiesWidget.ui +++ b/src/propertiesWidget.ui @@ -22,7 +22,7 @@ - + @@ -34,82 +34,146 @@ Torrent information - + - + - - - - 50 - false - - - - Save path: - - - - - - - - 50 - false - - - - Creator: - - - - - - - - 50 - false - - - - Torrent hash: - - - - - - - - 50 - false - - - - Comment: - - + + + + + + 16777215 + 22 + + + + + 50 + false + + + + Save path: + + + + + + + + 50 + false + + + + Creator: + + + + + + + + 50 + false + + + + Torrent hash: + + + + + + + + 50 + false + + + + Comment: + + + + - - - - - + - + + + + + + 16777215 + 22 + + + + + 50 + false + + + + + + + + + + + + 22 + 22 + + + + + 50 + false + + + + ... + + + + + + + + + + 50 + false + + - - - - 27 - 16777215 - + + + + 50 + false + + + + + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + 50 @@ -117,39 +181,12 @@ - ... + - - - - - - - - - - - - - - - - - - - 50 - false - - - - - - - @@ -159,7 +196,7 @@ - 185 + 190 20 @@ -303,6 +340,12 @@ + + + 50 + false + + @@ -310,6 +353,12 @@ + + + 50 + false + + @@ -317,6 +366,12 @@ + + + 50 + false + + @@ -324,6 +379,12 @@ + + + 50 + false + + diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index 4a1b573f3..1f4ac9619 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -28,12 +28,88 @@ * Contact : chris@qbittorrent.org */ +#include +#include #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) {} } diff --git a/src/propertieswidget.h b/src/propertieswidget.h index f439a93d2..38ed0b2e4 100644 --- a/src/propertieswidget.h +++ b/src/propertieswidget.h @@ -33,11 +33,31 @@ #include #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(); };