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);
35 class QDeclarativeContext;
40 typedef QHash<QString, TorrentState> DownloadItems_t;
41 typedef QMap<int, QString> ItemIndex_t;
43 class QDeclarativeDownloadListModelPrivate;
45 class QDeclarativeDownloadListModel :
46 public QAbstractListModel, public QDeclarativeParserStatus
49 Q_INTERFACES(QDeclarativeParserStatus);
52 Q_PROPERTY(QString hash READ hash);
53 Q_PROPERTY(QString name READ name WRITE setName);
54 Q_PROPERTY(QString size READ size);
55 Q_PROPERTY(QString status READ status);
56 Q_PROPERTY(uint state READ state);
57 Q_PROPERTY(uint progress READ progress);
58 Q_PROPERTY(uint downRate READ downRate);
59 Q_PROPERTY(uint upRate READ upRate);
60 Q_PROPERTY(uint seeds READ seeds);
61 Q_PROPERTY(uint leeches READ leeches);
62 Q_PROPERTY(qulonglong ratio READ ratio);
63 Q_PROPERTY(qulonglong totaSize READ totalDone);
64 Q_PROPERTY(qulonglong totalDone READ totalDone);
68 QDeclarativeDownloadListModel(QObject *parent = 0);
69 virtual ~QDeclarativeDownloadListModel();
71 // TODO: Learn to use roles..
73 DownloadRole = Qt::UserRole + 1,
90 // Updates the torrent status in the model.
91 void updateItem(TorrentState const& info, ParamsMap_t other_info);
92 // Returns the hash of the torrent be removed.
93 QString prepareRemoveSelected();
95 // -- QAbstractListModel
96 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
97 virtual QVariant data(const QModelIndex &index, int role) const;
98 virtual bool insertRow(int row, const QModelIndex &parent);
99 virtual bool setData (const QModelIndex & index, const QVariant &value, int role = Qt::EditRole);
100 // -- End QAbstractListModel
102 // -- Overrides from QDeclarativeParserStatus
103 virtual void classBegin();
104 virtual void componentComplete();
105 // -- End QDeclarativeParserStatus
108 void downloadItemChanged(QString hash);
110 // Private functions.
112 Q_DISABLE_COPY(QDeclarativeDownloadListModel)
113 QDeclarativeDownloadListModelPrivate *d;
115 void addItem_(TorrentState const& info, ParamsMap_t other_info);
116 void updateItem_(TorrentState const& info, ParamsMap_t other_info);
117 void removeItem_(TorrentState const& info);
118 QString GetStatusString(TorrentStatus::Id status);
124 } // namespace qtrapids
126 // We need to declare the type
127 QML_DECLARE_TYPE(qtrapids::QDeclarativeDownloadListModel);