add63a6cf69d467c566ca4f6a74529e01c90ed73
[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         /// Saves current view settings via QSettings
55         void saveView();
56         /// Reads view settigns via QSettings
57         void restoreView();
58         
59 private slots:
60         void on_itemClicked(QTreeWidgetItem * item, int column);
61
62 private:
63
64         // Maps torrent to downloadview item.
65         // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
66         DownloadItems_t items_;
67         // Used for saving view settings
68         QSettings settings_;
69         
70 private:
71         // Private functions.
72         void addItem_(TorrentState const& info, ParamsMap_t other_info);
73         void updateItem_(DownloadViewItem *item
74                          , TorrentState const& info, ParamsMap_t other_info);
75         void removeItem_(DownloadViewItem *item, TorrentState const& info);
76
77
78         static QString GetStatusString(TorrentStatus::Id status);
79         static QColor GetStatusColor(TorrentStatus::Id status);
80         
81 };
82
83
84 /**
85    @class DownloadViewItem
86    @brief Represents one item row of DownloadView
87 */
88 class DownloadViewItem : public QTreeWidgetItem
89 {
90
91 public:
92         DownloadViewItem(QTreeWidget* parent, int type) :
93                         QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {};
94
95         DownloadViewItem(QString hash, const QStringList& strings,
96                          int type = QTreeWidgetItem::UserType) :
97                         QTreeWidgetItem (strings, type = Type),
98                         hash_(hash) {}
99
100
101         /// @return An item comprising of string list, suitable for QTableView
102         /// header.
103         static DownloadViewItem *getHeaderItem() {
104                 DownloadViewItem *item
105                 = new DownloadViewItem("", QStringList()
106                                        << "Name"
107                                        << "Size" << "Status"
108                                        << "Progress" << "DL speed"
109                                        << "UL speed" << "Seeds/Leechers"
110                                        << "Ratio" << "ETA");
111
112                 return item;
113         }
114
115         /// @todo QTorrentHandle as one hidden column
116
117         QString getHash() const {
118                 return hash_;
119         }
120
121 private:
122         QString hash_;
123 };
124
125 } // namespace qtrapids
126
127 #endif // DOWNLOADVIEW_H
128