~ubuntu-branches/ubuntu/maverick/transmission/maverick

« back to all changes in this revision

Viewing changes to qt/torrent-model.h

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Klimonda
  • Date: 2009-05-22 21:57:30 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (2.1.18 sid) (1.3.8 upstream)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20090522215730-ly5kgv5aw9ig2u82
Tags: upstream-1.61
ImportĀ upstreamĀ versionĀ 1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
24
class Prefs;
 
25
 
 
26
extern "C"
 
27
{
 
28
    struct tr_benc;
 
29
};
 
30
 
 
31
class 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
        void clear( );
 
46
        bool hasTorrent( const QString& hashString ) const;
 
47
        virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
 
48
        virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
 
49
        enum Role { TorrentRole = Qt::UserRole };
 
50
 
 
51
    public:
 
52
        Torrent* getTorrentFromId( int id );
 
53
        const Torrent* getTorrentFromId( int id ) const;
 
54
 
 
55
    private:
 
56
        QSet<int> getIds( ) const;
 
57
        void addTorrent( Torrent * );
 
58
 
 
59
    public:
 
60
        Speed getUploadSpeed( ) const;
 
61
        Speed getDownloadSpeed( ) const;
 
62
 
 
63
    signals:
 
64
        void torrentsAdded( QSet<int> );
 
65
 
 
66
    public slots:
 
67
        void updateTorrents( tr_benc * torrentList, bool isCompleteList );
 
68
        void removeTorrents( tr_benc * torrentList );
 
69
        void removeTorrent( int id );
 
70
 
 
71
    private slots:
 
72
        void onTorrentChanged( int propertyId );
 
73
 
 
74
    public:
 
75
        TorrentModel( Prefs& prefs );
 
76
        virtual ~TorrentModel( );
 
77
};
 
78
 
 
79
#endif