- Moved status string mapping to view from QTorrentHandle
[qtrapids] / src / gui / DownloadView.h
index 07ec860..5ab1442 100644 (file)
 #ifndef DOWNLOADVIEW_H
 #define DOWNLOADVIEW_H
 
+#include <map>
+
 #include <QTreeWidget>
 
+#include "QBittorrentSession.h"
+
+class DownloadViewItem;
+
 /**
+       @class DownloadView
+       @brief A view showing all downloaded torrents
        @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
 */
 class DownloadView : public QTreeWidget
@@ -34,8 +42,21 @@ Q_OBJECT
 
     ~DownloadView();
 
+               void newItem(QTorrentHandle handle);
+               void updateItem(QTorrentHandle handle);
+               QTorrentHandle removeSelected();
+               void removeItem(QTorrentHandle handle);
+               
+       private slots:
+               void on_itemClicked(QTreeWidgetItem * item, int column);
        private:
-
+               // Maps torrent to downloadview item.
+               // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
+               std::map<QTorrentHandle, DownloadViewItem*> items_;
+               
+               // Private functions.
+               QString GetStatusString(QTorrentHandle::State const& status) const;
+               QColor GetStatusColor(QTorrentHandle::State const& status) const;
 };
 
 
@@ -45,18 +66,13 @@ Q_OBJECT
 */
 class DownloadViewItem : public QTreeWidgetItem {
        
-       public:
-               
+       public: 
                DownloadViewItem(QTreeWidget* parent, int type) : 
-                               QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType)
-               {
-               };
+                       QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {};
                
                DownloadViewItem(const QStringList& strings, 
-                                                                               int type = QTreeWidgetItem::UserType ) : 
-                       QTreeWidgetItem (strings, type = Type)
-               {
-               };
+                                                                               int type = QTreeWidgetItem::UserType) : 
+                       QTreeWidgetItem (strings, type = Type) {};
                
                
                /// @return An item comprising of string list, suitable for QTableView
@@ -64,11 +80,12 @@ class DownloadViewItem : public QTreeWidgetItem {
                static DownloadViewItem *getHeaderItem()
                {
                        DownloadViewItem *item  
-                               = new DownloadViewItem(QStringList() << "Name" 
+                               = new DownloadViewItem(QStringList() 
+                                       << "Name" 
                                        << "Size" << "Status" 
                                        << "Progress" << "DL speed" 
                                        << "UL speed" << "Seeds/Leechers"
-                                       << "ratio" << "ETA");
+                                       << "Ratio" << "ETA");
                        
                        return item;
                }