formatting is changed according to last astyle settings
[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 prepareRemoveSelected();
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         void removeItem_(DownloadViewItem *item, TorrentState const& info);
62
63         // Maps torrent to downloadview item.
64         // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
65         DownloadItems_t items_;
66
67         // Private functions.
68         static QString GetStatusString(TorrentStatus::Id status);
69         static QColor GetStatusColor(TorrentStatus::Id status);
70 };
71
72
73 /**
74    @class DownloadViewItem
75    @brief Represents one item row of DownloadView
76 */
77 class DownloadViewItem : public QTreeWidgetItem
78 {
79
80 public:
81         DownloadViewItem(QTreeWidget* parent, int type) :
82                         QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {};
83
84         DownloadViewItem(QString hash, const QStringList& strings,
85                          int type = QTreeWidgetItem::UserType) :
86                         QTreeWidgetItem (strings, type = Type),
87                         hash_(hash) {}
88
89
90         /// @return An item comprising of string list, suitable for QTableView
91         /// header.
92         static DownloadViewItem *getHeaderItem() {
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                 return hash_;
108         }
109
110 private:
111         QString hash_;
112 };
113
114 } // namespace qtrapids
115
116 #endif // DOWNLOADVIEW_H
117