Reverted invalid commit 82
[qtrapids] / src / qml-client / DownloadView.h
diff --git a/src/qml-client/DownloadView.h b/src/qml-client/DownloadView.h
new file mode 100644 (file)
index 0000000..4bac449
--- /dev/null
@@ -0,0 +1,126 @@
+/***************************************************************************
+ *   Copyright (C) 2010 by Ixonos Plc   *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; version 2 of the License.               *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+#ifndef DOWNLOADVIEW_H
+#define DOWNLOADVIEW_H
+
+#include <map>
+#include <qtrapids/info.hpp>
+#include <qtrapids/dbus.hpp>
+
+#include <QTreeWidget>
+
+
+namespace qtrapids
+{
+
+class DownloadViewItem;
+
+typedef QHash<QString, DownloadViewItem*> DownloadItems_t;
+
+/**
+   @class DownloadView
+   @brief A view showing all downloaded torrents
+   @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
+*/
+class DownloadView : public QTreeWidget
+{
+       Q_OBJECT
+
+public:
+       DownloadView(QWidget* parent);
+
+       ~DownloadView();
+
+       void updateItem(TorrentState const& info, ParamsMap_t other_info);
+       QString prepareRemoveSelected();
+       
+       /// Saves current view settings via QSettings
+       void saveView();
+       /// Reads view settigns via QSettings
+       void restoreView();
+       
+private slots:
+       void on_itemClicked(QTreeWidgetItem * item, int column);
+
+private:
+
+       // Maps torrent to downloadview item.
+       // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
+       DownloadItems_t items_;
+       // Used for saving view settings
+       QSettings settings_;
+       
+private:
+       // Private functions.
+       void addItem_(TorrentState const& info, ParamsMap_t other_info);
+       void updateItem_(DownloadViewItem *item
+                        , TorrentState const& info, ParamsMap_t other_info);
+       void removeItem_(DownloadViewItem *item, TorrentState const& info);
+
+
+       static QString GetStatusString(TorrentStatus::Id status);
+       static QColor GetStatusColor(TorrentStatus::Id status);
+       
+};
+
+
+/**
+   @class DownloadViewItem
+   @brief Represents one item row of DownloadView
+*/
+class DownloadViewItem : public QTreeWidgetItem
+{
+
+public:
+       DownloadViewItem(QTreeWidget* parent, int type) :
+                       QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {};
+
+       DownloadViewItem(QString hash, const QStringList& strings,
+                        int type = QTreeWidgetItem::UserType) :
+                       QTreeWidgetItem (strings, type = Type),
+                       hash_(hash) {}
+
+
+       /// @return An item comprising of string list, suitable for QTableView
+       /// header.
+       static DownloadViewItem *getHeaderItem() {
+               DownloadViewItem *item
+               = new DownloadViewItem("", QStringList()
+                                      << "Name"
+                                      << "Size" << "Status"
+                                      << "Progress" << "DL speed"
+                                      << "UL speed" << "Seeds/Leechers"
+                                      << "Ratio" << "ETA");
+
+               return item;
+       }
+
+       /// @todo QTorrentHandle as one hidden column
+
+       QString getHash() const {
+               return hash_;
+       }
+
+private:
+       QString hash_;
+};
+
+} // namespace qtrapids
+
+#endif // DOWNLOADVIEW_H
+