2
* This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
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.
21
#include <QStringList>
23
#include <QTemporaryFile>
26
#include <libtransmission/transmission.h>
44
bool clientIsInterested;
45
bool isDownloadingFrom;
50
bool peerIsInterested;
57
typedef QList<Peer> PeerList;
58
Q_DECLARE_METATYPE(Peer)
59
Q_DECLARE_METATYPE(PeerList)
63
TrFile(): index(-1), priority(0), wanted(true), size(0), have(0) { }
72
typedef QList<TrFile> FileList;
73
Q_DECLARE_METATYPE(TrFile)
74
Q_DECLARE_METATYPE(FileList)
77
class Torrent: public QObject
100
PEERS_GETTING_FROM_US,
102
WEBSEEDS_SENDING_TO_US,
123
HONORS_SESSION_LIMITS,
131
MANUAL_ANNOUNCE_TIME,
147
Torrent( Prefs&, int id );
151
void torrentChanged( int id );
157
INFO, // info fields that only need to be loaded once
158
STAT, // commonly-used stats that should be refreshed often
159
STAT_EXTRA, // rarely used; only refresh if details dialog is open
160
DERIVED // doesn't come from RPC
171
static Property myProperties[];
174
typedef QList<const char*> KeyList;
175
static const KeyList& getInfoKeys( );
176
static const KeyList& getStatKeys( );
177
static const KeyList& getExtraStatKeys( );
180
static KeyList buildKeyList( Group group );
183
QVariant myValues[PROPERTY_COUNT];
185
int getInt ( int key ) const;
186
bool getBool ( int key ) const;
187
QTime getTime ( int key ) const;
188
QIcon getIcon ( int key ) const;
189
double getDouble ( int key ) const;
190
qulonglong getSize ( int key ) const;
191
QString getString ( int key ) const;
192
QDateTime getDateTime ( int key ) const;
194
bool setInt ( int key, int value );
195
bool setBool ( int key, bool value );
196
bool setIcon ( int key, const QIcon& );
197
bool setDouble ( int key, double );
198
bool setString ( int key, const char * );
199
bool setSize ( int key, qulonglong );
200
bool setDateTime ( int key, const QDateTime& );
203
int id( ) const { return getInt( ID ); }
204
QString name( ) const { return getString( NAME ); }
205
QString creator( ) const { return getString( CREATOR ); }
206
QString comment( ) const { return getString( COMMENT ); }
207
QString getPath( ) const { return getString( DOWNLOAD_DIR ); }
208
QString getError( ) const { return getString( ERROR ); }
209
QString hashString( ) const { return getString( HASH_STRING ); }
210
QString scrapeResponse( ) const { return getString( SCRAPE_RESPONSE ); }
211
QString announceResponse( ) const { return getString( ANNOUNCE_RESPONSE ); }
212
QString announceUrl( ) const { return getString( ANNOUNCE_URL ); }
213
QString torrentFile( ) const { return getString( TORRENT_FILE ); }
214
bool hasError( ) const { return !getError( ).isEmpty( ); }
215
bool isDone( ) const { return getSize( LEFT_UNTIL_DONE ) == 0; }
216
bool isSeed( ) const { return haveVerified() >= getSize( TOTAL_SIZE ); }
217
bool isPrivate( ) const { return getBool( IS_PRIVATE ); }
218
bool getSeedRatio( double& setme ) const;
219
uint64_t haveVerified( ) const { return getSize( HAVE_VERIFIED ); }
220
uint64_t haveTotal( ) const { return haveVerified( ) + getSize( HAVE_UNCHECKED ); }
221
uint64_t sizeWhenDone( ) const { return getSize( SIZE_WHEN_DONE ); }
222
uint64_t leftUntilDone( ) const { return getSize( LEFT_UNTIL_DONE ); }
223
uint64_t pieceSize( ) const { return getSize( PIECE_SIZE ); }
224
int pieceCount( ) const { return getInt( PIECE_COUNT ); }
225
double ratio( ) const { return getDouble( RATIO ); }
226
double percentDone( ) const { return getDouble( PERCENT_DONE ); }
227
uint64_t downloadedEver( ) const { return getSize( DOWNLOADED_EVER ); }
228
uint64_t uploadedEver( ) const { return getSize( UPLOADED_EVER ); }
229
uint64_t failedEver( ) const { return getSize( FAILED_EVER ); }
230
int compareTracker( const Torrent& ) const;
231
int compareRatio( const Torrent& ) const;
232
int compareETA( const Torrent& ) const;
233
tr_bool hasETA( ) const { return getETA( ) >= 0; }
234
int getETA( ) const { return getInt( ETA ); }
235
QDateTime lastActivity( ) const { return getDateTime( DATE_ACTIVITY ); }
236
QDateTime lastStarted( ) const { return getDateTime( DATE_STARTED ); }
237
QDateTime dateAdded( ) const { return getDateTime( DATE_ADDED ); }
238
QDateTime dateCreated( ) const { return getDateTime( DATE_CREATED ); }
239
QDateTime lastAnnounceTime( ) const { return getDateTime( LAST_ANNOUNCE_TIME ); }
240
QDateTime lastScrapeTime( ) const { return getDateTime( LAST_SCRAPE_TIME ); }
241
QDateTime manualAnnounceTime( ) const { return getDateTime( MANUAL_ANNOUNCE_TIME ); }
242
QDateTime nextAnnounceTime( ) const { return getDateTime( NEXT_ANNOUNCE_TIME ); }
243
QDateTime nextScrapeTime( ) const { return getDateTime( NEXT_SCRAPE_TIME ); }
244
bool canManualAnnounce( ) const { return !isPaused() && (manualAnnounceTime()<=QDateTime::currentDateTime()); }
245
int peersWeAreDownloadingFrom( ) const { return getInt( PEERS_SENDING_TO_US ) + getInt( WEBSEEDS_SENDING_TO_US ); }
246
int peersWeAreUploadingTo( ) const { return getInt( PEERS_GETTING_FROM_US ); }
247
bool isUploading( ) const { return peersWeAreUploadingTo( ) > 0; }
248
int connectedPeers( ) const { return getInt( PEERS_CONNECTED ); }
249
int connectedPeersAndWebseeds( ) const { return connectedPeers( ) + getInt( WEBSEEDS_SENDING_TO_US ); }
250
Speed downloadSpeed( ) const { return Speed::fromBps( getInt( DOWNLOAD_SPEED ) ); }
251
Speed uploadSpeed( ) const { return Speed::fromBps( getInt( UPLOAD_SPEED ) ); }
252
Speed swarmSpeed( ) const { return Speed::fromKbps( getInt( SWARM_SPEED ) ); }
253
double getVerifyProgress( ) const { return getDouble( PERCENT_VERIFIED ); }
254
bool hasFileSubstring( const QString& substr ) const;
255
bool hasTrackerSubstring( const QString& substr ) const;
256
Speed uploadLimit( ) const { return Speed::fromKbps( getInt( UP_LIMIT ) ); }
257
Speed downloadLimit( ) const { return Speed::fromKbps( getInt( DOWN_LIMIT ) ); }
258
bool uploadIsLimited( ) const { return getBool( UP_LIMITED ); }
259
bool downloadIsLimited( ) const { return getBool( DOWN_LIMITED ); }
260
bool honorsSessionLimits( ) const { return getBool( HONORS_SESSION_LIMITS ); }
261
int peerLimit( ) const { return getInt( PEER_LIMIT ); }
262
double seedRatioLimit( ) const { return getDouble( SEED_RATIO_LIMIT ); }
263
tr_ratiolimit seedRatioMode( ) const { return (tr_ratiolimit) getInt( SEED_RATIO_MODE ); }
264
int seeders() const { return getInt( SEEDERS ); }
265
int leechers() const { return getInt( LEECHERS ); }
266
int timesCompleted() const { return getInt( TIMES_COMPLETED ); }
267
PeerList peers( ) const{ return myValues[PEERS].value<PeerList>(); }
268
const FileList& files( ) const { return myFiles; }
271
QString activityString( ) const;
272
tr_torrent_activity getActivity( ) const { return (tr_torrent_activity) getInt( ACTIVITY ); }
273
bool isPaused( ) const { return getActivity( ) == TR_STATUS_STOPPED; }
274
bool isChecking( ) const { return getActivity( ) == TR_STATUS_CHECK || getActivity( ) == TR_STATUS_CHECK_WAIT; }
275
bool isDownloading( ) const { return getActivity( ) == TR_STATUS_DOWNLOAD; }
276
void notifyComplete( ) const;
279
void update( tr_benc * dict );
282
const char * getMimeTypeString( ) const;
283
void updateMimeIcon( );
286
QIcon getMimeTypeIcon( ) const { return getIcon( MIME_ICON ); }
293
Q_DECLARE_METATYPE(const Torrent*)