* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QDebug>
+#include <QVariant>
+#include <QColor>
#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)));
}
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())
<< QString::number(handle.ratio())
<< "ETA" );
+ QBrush brushTmp(GetStatusColor(handle.state()));
+ item->setForeground(2, brushTmp);
+
addTopLevelItem(item);
items_[handle] = item;
}
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,
item->setData(6, Qt::DisplayRole,
QString::number(handle.numSeeds()) + "/"
+ QString::number(handle.numLeeches()));
+
+ QBrush brushTmp(GetStatusColor(handle.state()));
+ item->setForeground(2, brushTmp);
}
+
}
*/
}
+
+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