1 /***************************************************************************
2 * Copyright (C) 2010 by Ixonos Plc *
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. *
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. *
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 QDECLARATIVEDOWNLOADLISTMODEL_H
19 #define QDECLARATIVEDOWNLOADLISTMODEL_H
22 #include <QDeclarativeParserStatus>
23 #include <QAbstractListModel>
24 #include <QtDeclarative>
25 #include <QModelIndex>
27 #include "qtrapids/dbus.hpp"
28 #include "qtrapids/info.hpp"
30 //#include "../DownloadView.h"
32 QT_MODULE(Declarative);
37 typedef QHash<QString, TorrentState> DownloadItems_t;
38 typedef QMap<int, QString> ItemIndex_t;
40 class QDeclarativeContext;
41 class QDeclarativeDownloadListModelPrivate;
43 class QDeclarativeDownloadListModel :
44 public QAbstractListModel, public QDeclarativeParserStatus
47 Q_INTERFACES(QDeclarativeParserStatus);
50 Q_PROPERTY(QString hash READ hash);
51 Q_PROPERTY(QString name READ name WRITE setName);
52 Q_PROPERTY(QString size READ size);
53 Q_PROPERTY(QString status READ status);
54 Q_PROPERTY(uint state READ state);
55 Q_PROPERTY(uint progress READ progress);
56 Q_PROPERTY(uint downRate READ downRate);
57 Q_PROPERTY(uint upRate READ upRate);
58 Q_PROPERTY(uint seeds READ seeds);
59 Q_PROPERTY(uint leeches READ leeches);
60 Q_PROPERTY(qulonglong ratio READ ratio);
61 Q_PROPERTY(qulonglong totaSize READ totalDone);
62 Q_PROPERTY(qulonglong totalDone READ totalDone);
66 QDeclarativeDownloadListModel(QObject *parent = 0);
67 virtual ~QDeclarativeDownloadListModel();
69 // TODO: Learn to use roles..
71 DownloadRole = Qt::UserRole + 1,
88 // Updates the torrent status in the model.
89 void updateItem(TorrentState const& info, ParamsMap_t other_info);
90 // Returns the hash of the torrent be removed.
91 QString prepareRemoveSelected();
93 // -- QAbstractListModel
94 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
95 virtual QVariant data(const QModelIndex &index, int role) const;
96 virtual bool insertRow(int row, const QModelIndex &parent);
97 virtual bool setData (const QModelIndex & index, const QVariant &value, int role = Qt::EditRole);
98 // -- End QAbstractListModel
100 // -- Overrides from QDeclarativeParserStatus
101 virtual void classBegin();
102 virtual void componentComplete();
103 // -- End QDeclarativeParserStatus
106 void downloadItemChanged(QString hash);
108 // Private functions.
110 Q_DISABLE_COPY(QDeclarativeDownloadListModel)
111 QDeclarativeDownloadListModelPrivate *d;
113 void addItem_(TorrentState const& info, ParamsMap_t other_info);
114 void updateItem_(TorrentState const& info, ParamsMap_t other_info);
115 void removeItem_(TorrentState const& info);
116 QString GetStatusString(TorrentStatus::Id status);
122 } // namespace qtrapids
124 // We need to declare the type
125 QML_DECLARE_TYPE(qtrapids::QDeclarativeDownloadListModel);