Added Q_FUNC_INFO macros to some functions.
[qtrapids] / src / gui / DownloadView.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Ixonos Plc   *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; version 2 of the License.               *
7  *                                                                         *
8  *   This program is distributed in the hope that it will be useful,       *
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
11  *   GNU General Public License for more details.                          *
12  *                                                                         *
13  *   You should have received a copy of the GNU General Public License     *
14  *   along with this program; if not, write to the                         *
15  *   Free Software Foundation, Inc.,                                       *
16  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
17  ***************************************************************************/
18 #ifndef DOWNLOADVIEW_H
19 #define DOWNLOADVIEW_H
20
21 #include <map>
22
23 #include <QTreeWidget>
24
25 #include "QBittorrentSession.h"
26
27 class DownloadViewItem;
28 class QTimer;
29
30 /**
31         @class DownloadView
32         @brief A view showing all downloaded torrents
33         @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
34 */
35 class DownloadView : public QTreeWidget
36 {
37         Q_OBJECT
38
39 public:
40         DownloadView(QWidget* parent);
41
42         ~DownloadView();
43
44         void newItem(qtrapids::QTorrentHandle handle);
45         void updateItem(qtrapids::QTorrentHandle handle);
46         qtrapids::QTorrentHandle removeSelected();
47         void removeItem(qtrapids::QTorrentHandle handle);
48         void setRefreshInterval(int msec);
49
50 private slots:
51         void on_itemClicked(QTreeWidgetItem * item, int column);
52         void on_timeout();
53
54 private:
55         // Maps torrent to downloadview item.
56         // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
57         std::map<qtrapids::QTorrentHandle, DownloadViewItem*> items_;
58         QTimer *timer_;
59
60         // Private functions.
61         QString GetStatusString(qtrapids::QTorrentHandle::State const& status) const;
62         QColor GetStatusColor(qtrapids::QTorrentHandle::State const& status) const;
63         void UpdateView();
64
65
66 };
67
68
69 /**
70         @class DownloadViewItem
71         @brief Represents one item row of DownloadView
72 */
73 class DownloadViewItem : public QTreeWidgetItem
74 {
75
76 public:
77         DownloadViewItem(QTreeWidget* parent, int type) :
78                         QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {};
79
80         DownloadViewItem(const QStringList& strings,
81                          int type = QTreeWidgetItem::UserType) :
82                         QTreeWidgetItem (strings, type = Type) {};
83
84
85         /// @return An item comprising of string list, suitable for QTableView
86         /// header.
87         static DownloadViewItem *getHeaderItem() {
88                 DownloadViewItem *item
89                 = new DownloadViewItem(QStringList()
90                                        << "Name"
91                                        << "Size" << "Status"
92                                        << "Progress" << "DL speed"
93                                        << "UL speed" << "Seeds/Leechers"
94                                        << "Ratio" << "ETA");
95
96                 return item;
97         }
98
99         /// @todo QTorrentHandle as one hidden column
100 };
101
102 #endif