X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fgui%2FDownloadView.cpp;h=d7424b01d5c2613015494970a8afeae0d3fdb775;hb=3b087a27d415059adf505d398ffe0b9fbd5ed0ba;hp=2f91ff4f5dd11ab34a6e01ad21110818d614c0fb;hpb=521566ad342423822a7e0353c2cc6ec639a10c63;p=qtrapids diff --git a/src/gui/DownloadView.cpp b/src/gui/DownloadView.cpp index 2f91ff4..d7424b0 100644 --- a/src/gui/DownloadView.cpp +++ b/src/gui/DownloadView.cpp @@ -18,17 +18,20 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include +#include +#include #include "DownloadView.h" -DownloadView::DownloadView(QWidget* parent) : - QTreeWidget(parent), - items_() + +DownloadView::DownloadView(QWidget* parent) : + QTreeWidget(parent), + items_() { - setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list) - setHeaderItem(DownloadViewItem::getHeaderItem()); - - connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)), - this, SLOT(on_itemClicked(QTreeWidgetItem*, int))); + setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list) + setHeaderItem(DownloadViewItem::getHeaderItem()); + + connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)), + this, SLOT(on_itemClicked(QTreeWidgetItem*, int))); } @@ -45,7 +48,7 @@ void DownloadView::newItem(QTorrentHandle handle) DownloadViewItem *item = new DownloadViewItem(QStringList() << handle.name() << QString::number(handle.getTotalSize()) - << handle.state() + << GetStatusString(handle.state()) << QString::number(handle.progress()) << QString::number(handle.downloadRate()) << QString::number(handle.uploadRate()) @@ -54,6 +57,9 @@ void DownloadView::newItem(QTorrentHandle handle) << QString::number(handle.ratio()) << "ETA" ); + QBrush brushTmp(GetStatusColor(handle.state())); + item->setForeground(2, brushTmp); + addTopLevelItem(item); items_[handle] = item; } @@ -65,7 +71,8 @@ void DownloadView::updateItem(QTorrentHandle handle) if (items_.count(handle) > 0) { DownloadViewItem *item = items_[handle]; - item->setData(2, Qt::DisplayRole, QVariant(handle.state())); + item->setData(2, Qt::DisplayRole, + QVariant(GetStatusString(handle.state()))); item->setData(3, Qt::DisplayRole, QVariant(QString::number(handle.progress()))); item->setData(4, Qt::DisplayRole, @@ -75,7 +82,11 @@ void DownloadView::updateItem(QTorrentHandle handle) item->setData(6, Qt::DisplayRole, QString::number(handle.numSeeds()) + "/" + QString::number(handle.numLeeches())); + + QBrush brushTmp(GetStatusColor(handle.state())); + item->setForeground(2, brushTmp); } + } @@ -128,3 +139,47 @@ void DownloadView::on_itemClicked(QTreeWidgetItem * item, int column) */ } + +QString DownloadView::GetStatusString(QTorrentHandle::State const& status) const +{ + switch (status) { + case QTorrentHandle::QUEUED_FOR_CHECKING : + return "Queued"; + case QTorrentHandle::CHECKING_FILES : + return "Checking"; + case QTorrentHandle::DOWNLOADING_METADATA : + return "DL meta"; + case QTorrentHandle::DOWNLOADING : + return "Downloading"; + case QTorrentHandle::FINISHED : + return "Finished"; + case QTorrentHandle::SEEDING : + return "Seeding"; + case QTorrentHandle::ALLOCATING : + return "Allocating"; + default: + return "N/A"; + } +} + + +QColor DownloadView::GetStatusColor(QTorrentHandle::State const& status) const +{ + QColor green(40,205,40); + QColor yellow(255,174,0); + + switch (status) { + case QTorrentHandle::QUEUED_FOR_CHECKING : + case QTorrentHandle::CHECKING_FILES : + case QTorrentHandle::DOWNLOADING_METADATA : + case QTorrentHandle::ALLOCATING : + return yellow; + case QTorrentHandle::DOWNLOADING : + case QTorrentHandle::FINISHED : + case QTorrentHandle::SEEDING : + return green; + default: + return QColor(); + } + +} \ No newline at end of file