source: trunk/qt/torrent-model.h @ 8188

Last change on this file since 8188 was 8188, checked in by charles, 13 years ago

(trunk) add the Qt beta into svn

File size: 1.9 KB
Line 
1/*
2 * This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
3 *
4 * This file is licensed by the GPL version 2.  Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id:$
11 */
12
13#ifndef QTR_TORRENT_MODEL_H
14#define QTR_TORRENT_MODEL_H
15
16#include <QAbstractListModel>
17#include <QMap>
18#include <QSet>
19#include <QVector>
20
21#include "speed.h"
22#include "torrent.h"
23
24class Prefs;
25
26extern "C"
27{
28    struct tr_benc;
29};
30
31class TorrentModel: public QAbstractListModel
32{
33        Q_OBJECT
34
35    private:
36        typedef QMap<int,int> id_to_row_t;
37        typedef QMap<int,Torrent*> id_to_torrent_t;
38        typedef QVector<Torrent*> torrents_t;
39        id_to_row_t myIdToRow;
40        id_to_torrent_t myIdToTorrent;
41        torrents_t myTorrents;
42        Prefs& myPrefs;
43
44    public:
45        bool hasTorrent( const QString& hashString ) const;
46        virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
47        virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
48        enum Role { TorrentRole = Qt::UserRole };
49
50    public:
51        Torrent* getTorrentFromId( int id );
52        const Torrent* getTorrentFromId( int id ) const;
53
54    private:
55        QSet<int> getIds( ) const;
56        void addTorrent( Torrent * );
57
58    public:
59        Speed getUploadSpeed( ) const;
60        Speed getDownloadSpeed( ) const;
61
62    signals:
63        void torrentsAdded( QSet<int> );
64
65    public slots:
66        void updateTorrents( tr_benc * torrentList, bool isCompleteList );
67        void removeTorrents( tr_benc * torrentList );
68        void removeTorrent( int id );
69
70    private slots:
71        void onTorrentChanged( int propertyId );
72
73    public:
74        TorrentModel( Prefs& prefs );
75        virtual ~TorrentModel( );
76};
77
78#endif
Note: See TracBrowser for help on using the repository browser.