- Moved status string mapping to view from QTorrentHandle
[qtrapids] / src / gui / DownloadView.cpp
index 2f91ff4..d7424b0 100644 (file)
  *   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)));
 
 }
 
@@ -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