1 /***************************************************************************
2 * Copyright (C) 2009 by Lassi Väätämöinen *
3 * lassi.vaatamoinen@ixonos.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
23 #include "DownloadView.h"
26 DownloadView::DownloadView(QWidget* parent) :
30 setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
31 setHeaderItem(DownloadViewItem::getHeaderItem());
33 connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)),
34 this, SLOT(on_itemClicked(QTreeWidgetItem*, int)));
39 DownloadView::~DownloadView()
44 void DownloadView::newItem(QTorrentHandle handle)
46 qDebug() << "DownloadView::newItem() " << items_.count(handle);
48 DownloadViewItem *item = new DownloadViewItem(QStringList()
50 << QString::number(handle.getTotalSize())
51 << GetStatusString(handle.state())
52 << QString::number(handle.progress())
53 << QString::number(handle.downloadRate())
54 << QString::number(handle.uploadRate())
55 << QString::number(handle.numSeeds()) + "/"
56 + QString::number(handle.numLeeches())
57 << QString::number(handle.ratio())
60 QBrush brushTmp(GetStatusColor(handle.state()));
61 item->setForeground(2, brushTmp);
63 addTopLevelItem(item);
64 items_[handle] = item;
68 void DownloadView::updateItem(QTorrentHandle handle)
70 qDebug() << "DownloadView::updateItem() " << items_.count(handle);
72 if (items_.count(handle) > 0) {
73 DownloadViewItem *item = items_[handle];
74 item->setData(2, Qt::DisplayRole,
75 QVariant(GetStatusString(handle.state())));
76 item->setData(3, Qt::DisplayRole,
77 QVariant(QString::number(handle.progress())));
78 item->setData(4, Qt::DisplayRole,
79 QVariant(QString::number(handle.downloadRate())));
80 item->setData(5, Qt::DisplayRole,
81 QVariant(QString::number(handle.uploadRate())));
82 item->setData(6, Qt::DisplayRole,
83 QString::number(handle.numSeeds()) + "/"
84 + QString::number(handle.numLeeches()));
86 QBrush brushTmp(GetStatusColor(handle.state()));
87 item->setForeground(2, brushTmp);
93 QTorrentHandle DownloadView::removeSelected()
95 qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
97 DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
99 std::map<QTorrentHandle, DownloadViewItem*>::iterator listIter
101 std::map<QTorrentHandle, DownloadViewItem*>::iterator listEnd
104 while (listIter != listEnd) {
105 if (listIter->second == item) {
111 QTorrentHandle handle = listIter->first;
112 items_.erase(listIter);
115 int index = indexOfTopLevelItem(currentItem());
117 takeTopLevelItem(index);
120 qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
126 void DownloadView::removeItem(QTorrentHandle handle)
131 void DownloadView::on_itemClicked(QTreeWidgetItem * item, int column)
133 qDebug() << "DownloadView::on_itemClicked(()" << item << "," << column;
134 qDebug() << "current item" << currentItem();
136 if (item == currentItem() && item->isSelected()) {
137 item->setSelected(false);
143 QString DownloadView::GetStatusString(QTorrentHandle::State const& status) const
146 case QTorrentHandle::QUEUED_FOR_CHECKING :
148 case QTorrentHandle::CHECKING_FILES :
150 case QTorrentHandle::DOWNLOADING_METADATA :
152 case QTorrentHandle::DOWNLOADING :
153 return "Downloading";
154 case QTorrentHandle::FINISHED :
156 case QTorrentHandle::SEEDING :
158 case QTorrentHandle::ALLOCATING :
166 QColor DownloadView::GetStatusColor(QTorrentHandle::State const& status) const
168 QColor green(40,205,40);
169 QColor yellow(255,174,0);
172 case QTorrentHandle::QUEUED_FOR_CHECKING :
173 case QTorrentHandle::CHECKING_FILES :
174 case QTorrentHandle::DOWNLOADING_METADATA :
175 case QTorrentHandle::ALLOCATING :
177 case QTorrentHandle::DOWNLOADING :
178 case QTorrentHandle::FINISHED :
179 case QTorrentHandle::SEEDING :