return static_cast<size_t> (info.total_size());
}
-QString QTorrentHandle::state() const
+
+QTorrentHandle::State QTorrentHandle::state() const
{
- return GetStatusString(status());
+ TorrentStatus statusTmp = status();
+
+ switch (statusTmp.state) {
+ case TorrentStatus::queued_for_checking :
+ return QTorrentHandle::QUEUED_FOR_CHECKING;
+ case TorrentStatus::checking_files :
+ return QTorrentHandle::CHECKING_FILES;
+ case TorrentStatus::downloading_metadata :
+ return QTorrentHandle::DOWNLOADING_METADATA;
+ case TorrentStatus::downloading :
+ return QTorrentHandle::DOWNLOADING;
+ case TorrentStatus::finished :
+ return QTorrentHandle::FINISHED;
+ case TorrentStatus::seeding :
+ return QTorrentHandle::SEEDING;
+ case TorrentStatus::allocating :
+ return QTorrentHandle::ALLOCATING;
+ default:
+ return QTorrentHandle::UNSPECIFIED;
+ }
+
}
+
float QTorrentHandle::progress() const
{
TorrentStatus statusTmp = status();
-QString QTorrentHandle::GetStatusString(TorrentStatus const& status) const
-{
- switch (status.state) {
- case TorrentStatus::queued_for_checking :
- return "Queued";
- case TorrentStatus::checking_files :
- return "Checking";
- case TorrentStatus::downloading_metadata :
- return "DL meta";
- case TorrentStatus::downloading :
- return "DL";
- case TorrentStatus::finished :
- return "Finished";
- case TorrentStatus::seeding :
- return "Seeding";
- case TorrentStatus::allocating :
- return "Allocating";
- default:
- return "N/A";
- }
-}
+
\ No newline at end of file
typedef libtorrent::torrent_info TorrentInfo;
typedef libtorrent::torrent_handle TorrentHandle;
+
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
*/
class QTorrentHandle
{
-
public:
+
+ enum State {
+ QUEUED_FOR_CHECKING = TorrentStatus::queued_for_checking,
+ CHECKING_FILES,
+ DOWNLOADING_METADATA,
+ DOWNLOADING,
+ FINISHED,
+ SEEDING,
+ ALLOCATING,
+ UNSPECIFIED
+ };
+
QTorrentHandle(libtorrent::torrent_handle handle);
~QTorrentHandle();
- TorrentStatus status() const;
TorrentInfo const& getTorrentInfo() const;
QString name() const;
size_t getTotalSize() const;
- QString state() const;
+ QTorrentHandle::State state() const;
float progress() const;
float uploadRate() const;
float downloadRate() const;
private:
QTorrentHandle(); // Prevent default construct.
TorrentHandle torrentHandle_;
-
- // Private functions.
- QString GetStatusString(TorrentStatus const& status) const;
+
+ TorrentStatus status() const;
+
};
#endif
* 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