Code formatting/indentation unified in trunk
[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
91     /// @return An item comprising of string list, suitable for QTableView
92     /// header.
93     static DownloadViewItem *getHeaderItem()
94     {
95         DownloadViewItem *item
96         = new DownloadViewItem("", QStringList()
97                                << "Name"
98                                << "Size" << "Status"
99                                << "Progress" << "DL speed"
100                                << "UL speed" << "Seeds/Leechers"
101                                << "Ratio" << "ETA");
102
103         return item;
104     }
105
106     /// @todo QTorrentHandle as one hidden column
107
108     QString getHash() const
109     {
110         return hash_;
111     }
112
113 private:
114     QString hash_;
115 };
116
117 } // namespace qtrapids
118
119 #endif // DOWNLOADVIEW_H
120