From: lvaatamoinen Date: Mon, 2 Nov 2009 12:22:11 +0000 (+0000) Subject: - Moved status string mapping to view from QTorrentHandle X-Git-Url: http://git.maemo.org/git/?p=qtrapids;a=commitdiff_plain;h=3b087a27d415059adf505d398ffe0b9fbd5ed0ba - Moved status string mapping to view from QTorrentHandle - Added enum mapping to Qtorrenhandle - DownloadView now has colorful state message git-svn-id: file:///svnroot/qtrapids/trunk@16 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda --- diff --git a/src/engine/QTorrentHandle.cpp b/src/engine/QTorrentHandle.cpp index 3fb6ec0..d2470c7 100644 --- a/src/engine/QTorrentHandle.cpp +++ b/src/engine/QTorrentHandle.cpp @@ -61,11 +61,33 @@ size_t QTorrentHandle::getTotalSize() const return static_cast (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(); @@ -133,27 +155,7 @@ bool QTorrentHandle::operator<(QTorrentHandle const& h) const -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 diff --git a/src/engine/QTorrentHandle.h b/src/engine/QTorrentHandle.h index f03194d..0d8d4a5 100644 --- a/src/engine/QTorrentHandle.h +++ b/src/engine/QTorrentHandle.h @@ -29,18 +29,29 @@ typedef libtorrent::torrent_status TorrentStatus; typedef libtorrent::torrent_info TorrentInfo; typedef libtorrent::torrent_handle TorrentHandle; + /** @author Lassi Väätämöinen */ 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; @@ -48,7 +59,7 @@ class QTorrentHandle QString name() const; size_t getTotalSize() const; - QString state() const; + QTorrentHandle::State state() const; float progress() const; float uploadRate() const; float downloadRate() const; @@ -64,9 +75,9 @@ class QTorrentHandle private: QTorrentHandle(); // Prevent default construct. TorrentHandle torrentHandle_; - - // Private functions. - QString GetStatusString(TorrentStatus const& status) const; + + TorrentStatus status() const; + }; #endif 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 diff --git a/src/gui/DownloadView.h b/src/gui/DownloadView.h index 408a232..5ab1442 100644 --- a/src/gui/DownloadView.h +++ b/src/gui/DownloadView.h @@ -54,6 +54,9 @@ Q_OBJECT // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent. std::map items_; + // Private functions. + QString GetStatusString(QTorrentHandle::State const& status) const; + QColor GetStatusColor(QTorrentHandle::State const& status) const; };