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 ***************************************************************************/
21 #include "DownloadView.h"
23 DownloadView::DownloadView(QWidget* parent) :
27 setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
28 setHeaderItem(DownloadViewItem::getHeaderItem());
30 connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)),
31 this, SLOT(on_itemClicked(QTreeWidgetItem*, int)));
36 DownloadView::~DownloadView()
41 void DownloadView::newItem(QTorrentHandle handle)
43 qDebug() << "DownloadView::newItem() " << items_.count(handle);
45 DownloadViewItem *item = new DownloadViewItem(QStringList()
47 << QString::number(handle.getTotalSize())
49 << QString::number(handle.progress())
50 << QString::number(handle.downloadRate())
51 << QString::number(handle.uploadRate())
52 << QString::number(handle.numSeeds()) + "/"
53 + QString::number(handle.numLeeches())
54 << QString::number(handle.ratio())
57 addTopLevelItem(item);
58 items_[handle] = item;
62 void DownloadView::updateItem(QTorrentHandle handle)
64 qDebug() << "DownloadView::updateItem() " << items_.count(handle);
66 if (items_.count(handle) > 0) {
67 DownloadViewItem *item = items_[handle];
68 item->setData(2, Qt::DisplayRole, QVariant(handle.state()));
69 item->setData(3, Qt::DisplayRole,
70 QVariant(QString::number(handle.progress())));
71 item->setData(4, Qt::DisplayRole,
72 QVariant(QString::number(handle.downloadRate())));
73 item->setData(5, Qt::DisplayRole,
74 QVariant(QString::number(handle.uploadRate())));
75 item->setData(6, Qt::DisplayRole,
76 QString::number(handle.numSeeds()) + "/"
77 + QString::number(handle.numLeeches()));
82 QTorrentHandle DownloadView::removeSelected()
84 qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
86 DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
88 std::map<QTorrentHandle, DownloadViewItem*>::iterator listIter
90 std::map<QTorrentHandle, DownloadViewItem*>::iterator listEnd
93 while (listIter != listEnd) {
94 if (listIter->second == item) {
100 QTorrentHandle handle = listIter->first;
101 items_.erase(listIter);
104 int index = indexOfTopLevelItem(currentItem());
106 takeTopLevelItem(index);
109 qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
115 void DownloadView::removeItem(QTorrentHandle handle)
120 void DownloadView::on_itemClicked(QTreeWidgetItem * item, int column)
122 qDebug() << "DownloadView::on_itemClicked(()" << item << "," << column;
123 qDebug() << "current item" << currentItem();
125 if (item == currentItem() && item->isSelected()) {
126 item->setSelected(false);