Added Q_FUNC_INFO macros to some functions.
[qtrapids] / src / client / 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 #include <qtrapids/info.hpp>
23 #include <qtrapids/dbus.hpp>
24
25 #include <QTreeWidget>
26
27
28 namespace qtrapids
29 {
30
31 class DownloadViewItem;
32
33 typedef QHash<QString, DownloadViewItem*> DownloadItems_t;
34
35 /**
36    @class DownloadView
37    @brief A view showing all downloaded torrents
38    @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
39 */
40 class DownloadView : public QTreeWidget
41 {
42         Q_OBJECT
43
44 public:
45         DownloadView(QWidget* parent);
46
47         ~DownloadView();
48
49         void updateItem(TorrentState const& info, ParamsMap_t other_info);
50         QString prepareRemoveSelected();
51         
52         /// Saves current view settings via QSettings
53         void saveView();
54         /// Reads view settigns via QSettings
55         void restoreView();
56         
57 private slots:
58         void on_itemClicked(QTreeWidgetItem * item, int column);
59
60 private:
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         // Used for saving view settings
66         QSettings settings_;
67         
68 private:
69         // Private functions.
70         void addItem_(TorrentState const& info, ParamsMap_t other_info);
71         void updateItem_(DownloadViewItem *item
72                          , TorrentState const& info, ParamsMap_t other_info);
73         void removeItem_(DownloadViewItem *item, TorrentState const& info);
74
75
76         static QString GetStatusString(TorrentStatus::Id status);
77         static QColor GetStatusColor(TorrentStatus::Id status);
78         
79 };
80
81
82 /**
83    @class DownloadViewItem
84    @brief Represents one item row of DownloadView
85 */
86 class DownloadViewItem : public QTreeWidgetItem
87 {
88
89 public:
90         DownloadViewItem(QTreeWidget* parent, int type) :
91                         QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {};
92
93         DownloadViewItem(QString hash, const QStringList& strings,
94                          int type = QTreeWidgetItem::UserType) :
95                         QTreeWidgetItem (strings, type = Type),
96                         hash_(hash) {}
97
98
99         /// @return An item comprising of string list, suitable for QTableView
100         /// header.
101         static DownloadViewItem *getHeaderItem() {
102                 DownloadViewItem *item
103                 = new DownloadViewItem("", QStringList()
104                                        << "Name"
105                                        << "Size" << "Status"
106                                        << "Progress" << "DL speed"
107                                        << "UL speed" << "Seeds/Leechers"
108                                        << "Ratio" << "ETA");
109
110                 return item;
111         }
112
113         /// @todo QTorrentHandle as one hidden column
114
115         QString getHash() const {
116                 return hash_;
117         }
118
119 private:
120         QString hash_;
121 };
122
123 } // namespace qtrapids
124
125 #endif // DOWNLOADVIEW_H
126