Client-server through DBus, cmake support
[qtrapids] / src / client / DownloadView.h
1 /***************************************************************************
2  *   Copyright (C) 2009 by Lassi Väätämöinen   *
3  *   lassi.vaatamoinen@ixonos.com   *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20 #ifndef DOWNLOADVIEW_H
21 #define DOWNLOADVIEW_H
22
23 #include <map>
24 #include <qtrapids/info.hpp>
25 #include <qtrapids/dbus.hpp>
26
27 #include <QTreeWidget>
28
29
30 namespace qtrapids
31 {
32
33     class DownloadViewItem;
34
35     typedef QHash<QString, DownloadViewItem*> DownloadItems_t;
36
37     /**
38        @class DownloadView
39        @brief A view showing all downloaded torrents
40        @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
41     */
42     class DownloadView : public QTreeWidget
43     {
44         Q_OBJECT
45                 
46         public:
47         DownloadView(QWidget* parent);
48
49         ~DownloadView();
50
51                 void updateItem(TorrentState const& info, ParamsMap_t other_info);
52                 QString removeSelected();
53                 
54     private slots:
55                 void on_itemClicked(QTreeWidgetItem * item, int column);
56         private:
57
58                 void addItem_(TorrentState const& info, ParamsMap_t other_info);
59                 void updateItem_(DownloadViewItem *item
60                          , TorrentState const& info, ParamsMap_t other_info);
61
62                 // Maps torrent to downloadview item.
63                 // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
64         DownloadItems_t items_;
65                 
66                 // Private functions.
67         static QString GetStatusString(TorrentStatus::Id status);
68         static QColor GetStatusColor(TorrentStatus::Id status);
69     };
70
71
72     /**
73        @class DownloadViewItem
74        @brief Represents one item row of DownloadView
75     */
76     class DownloadViewItem : public QTreeWidgetItem {
77         
78         public: 
79         DownloadViewItem(QTreeWidget* parent, int type) : 
80             QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {};
81                 
82         DownloadViewItem(QString hash, const QStringList& strings, 
83                          int type = QTreeWidgetItem::UserType) : 
84             QTreeWidgetItem (strings, type = Type),
85             hash_(hash)
86         {}
87                 
88                 
89         /// @return An item comprising of string list, suitable for QTableView
90                 /// header.
91                 static DownloadViewItem *getHeaderItem()
92                 {
93                         DownloadViewItem *item  
94                                 = new DownloadViewItem("", QStringList() 
95                                        << "Name" 
96                                        << "Size" << "Status" 
97                                        << "Progress" << "DL speed" 
98                                        << "UL speed" << "Seeds/Leechers"
99                                        << "Ratio" << "ETA");
100                         
101                         return item;
102                 }
103
104                 /// @todo QTorrentHandle as one hidden column
105
106         QString getHash() const 
107         { 
108             return hash_;
109         }
110
111     private:
112         QString hash_;
113     };
114
115 } // namespace qtrapids
116
117 #endif // DOWNLOADVIEW_H
118