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,
148
Torrent( Prefs&, int id );
152
void torrentChanged( int id );
158
INFO, // info fields that only need to be loaded once
159
STAT, // commonly-used stats that should be refreshed often
160
STAT_EXTRA, // rarely used; only refresh if details dialog is open
161
DERIVED // doesn't come from RPC
172
static Property myProperties[];
175
typedef QList<const char*> KeyList;
176
static const KeyList& getInfoKeys( );
177
static const KeyList& getStatKeys( );
178
static const KeyList& getExtraStatKeys( );
181
static KeyList buildKeyList( Group group );
184
QVariant myValues[PROPERTY_COUNT];
186
int getInt ( int key ) const;
187
bool getBool ( int key ) const;
188
QTime getTime ( int key ) const;
189
QIcon getIcon ( int key ) const;
190
double getDouble ( int key ) const;
191
qulonglong getSize ( int key ) const;
192
QString getString ( int key ) const;
193
QDateTime getDateTime ( int key ) const;
195
bool setInt ( int key, int value );
196
bool setBool ( int key, bool value );
197
bool setIcon ( int key, const QIcon& );
198
bool setDouble ( int key, double );
199
bool setString ( int key, const char * );
200
bool setSize ( int key, qulonglong );
201
bool setDateTime ( int key, const QDateTime& );
204
int getBandwidthPriority( ) const { return getInt( BANDWIDTH_PRIORITY ); }
205
int id( ) const { return getInt( ID ); }
206
QString name( ) const { return getString( NAME ); }
207
QString creator( ) const { return getString( CREATOR ); }
208
QString comment( ) const { return getString( COMMENT ); }
209
QString getPath( ) const { return getString( DOWNLOAD_DIR ); }
210
QString getError( ) const { return getString( ERROR ); }
211
QString hashString( ) const { return getString( HASH_STRING ); }
212
QString scrapeResponse( ) const { return getString( SCRAPE_RESPONSE ); }
213
QString announceResponse( ) const { return getString( ANNOUNCE_RESPONSE ); }
214
QString announceUrl( ) const { return getString( ANNOUNCE_URL ); }
215
QString torrentFile( ) const { return getString( TORRENT_FILE ); }
216
bool hasError( ) const { return !getError( ).isEmpty( ); }
217
bool isDone( ) const { return getSize( LEFT_UNTIL_DONE ) == 0; }
218
bool isSeed( ) const { return haveVerified() >= getSize( TOTAL_SIZE ); }
219
bool isPrivate( ) const { return getBool( IS_PRIVATE ); }
220
bool getSeedRatio( double& setme ) const;
221
uint64_t haveVerified( ) const { return getSize( HAVE_VERIFIED ); }
222
uint64_t haveTotal( ) const { return haveVerified( ) + getSize( HAVE_UNCHECKED ); }
223
uint64_t sizeWhenDone( ) const { return getSize( SIZE_WHEN_DONE ); }
224
uint64_t leftUntilDone( ) const { return getSize( LEFT_UNTIL_DONE ); }
225
uint64_t pieceSize( ) const { return getSize( PIECE_SIZE ); }
226
int pieceCount( ) const { return getInt( PIECE_COUNT ); }
227
double ratio( ) const { return getDouble( RATIO ); }
228
double percentDone( ) const { return getDouble( PERCENT_DONE ); }
229
uint64_t downloadedEver( ) const { return getSize( DOWNLOADED_EVER ); }
230
uint64_t uploadedEver( ) const { return getSize( UPLOADED_EVER ); }
231
uint64_t failedEver( ) const { return getSize( FAILED_EVER ); }
232
int compareTracker( const Torrent& ) const;
233
int compareRatio( const Torrent& ) const;
234
int compareETA( const Torrent& ) const;
235
bool hasETA( ) const { return getETA( ) >= 0; }
236
int getETA( ) const { return getInt( ETA ); }
237
QDateTime lastActivity( ) const { return getDateTime( DATE_ACTIVITY ); }
238
QDateTime lastStarted( ) const { return getDateTime( DATE_STARTED ); }
239
QDateTime dateAdded( ) const { return getDateTime( DATE_ADDED ); }
240
QDateTime dateCreated( ) const { return getDateTime( DATE_CREATED ); }
241
QDateTime lastAnnounceTime( ) const { return getDateTime( LAST_ANNOUNCE_TIME ); }
242
QDateTime lastScrapeTime( ) const { return getDateTime( LAST_SCRAPE_TIME ); }
243
QDateTime manualAnnounceTime( ) const { return getDateTime( MANUAL_ANNOUNCE_TIME ); }
244
QDateTime nextAnnounceTime( ) const { return getDateTime( NEXT_ANNOUNCE_TIME ); }
245
QDateTime nextScrapeTime( ) const { return getDateTime( NEXT_SCRAPE_TIME ); }
246
bool canManualAnnounce( ) const { return isReadyToTransfer() && (manualAnnounceTime()<=QDateTime::currentDateTime()); }
247
int peersWeAreDownloadingFrom( ) const { return getInt( PEERS_SENDING_TO_US ) + getInt( WEBSEEDS_SENDING_TO_US ); }
248
int peersWeAreUploadingTo( ) const { return getInt( PEERS_GETTING_FROM_US ); }
249
bool isUploading( ) const { return peersWeAreUploadingTo( ) > 0; }
250
int connectedPeers( ) const { return getInt( PEERS_CONNECTED ); }
251
int connectedPeersAndWebseeds( ) const { return connectedPeers( ) + getInt( WEBSEEDS_SENDING_TO_US ); }
252
Speed downloadSpeed( ) const { return Speed::fromBps( getInt( DOWNLOAD_SPEED ) ); }
253
Speed uploadSpeed( ) const { return Speed::fromBps( getInt( UPLOAD_SPEED ) ); }
254
Speed swarmSpeed( ) const { return Speed::fromKbps( getInt( SWARM_SPEED ) ); }
255
double getVerifyProgress( ) const { return getDouble( PERCENT_VERIFIED ); }
256
bool hasFileSubstring( const QString& substr ) const;
257
bool hasTrackerSubstring( const QString& substr ) const;
258
Speed uploadLimit( ) const { return Speed::fromKbps( getInt( UP_LIMIT ) ); }
259
Speed downloadLimit( ) const { return Speed::fromKbps( getInt( DOWN_LIMIT ) ); }
260
bool uploadIsLimited( ) const { return getBool( UP_LIMITED ); }
261
bool downloadIsLimited( ) const { return getBool( DOWN_LIMITED ); }
262
bool honorsSessionLimits( ) const { return getBool( HONORS_SESSION_LIMITS ); }
263
int peerLimit( ) const { return getInt( PEER_LIMIT ); }
264
double seedRatioLimit( ) const { return getDouble( SEED_RATIO_LIMIT ); }
265
tr_ratiolimit seedRatioMode( ) const { return (tr_ratiolimit) getInt( SEED_RATIO_MODE ); }
266
int seeders() const { return getInt( SEEDERS ); }
267
int leechers() const { return getInt( LEECHERS ); }
268
int timesCompleted() const { return getInt( TIMES_COMPLETED ); }
269
PeerList peers( ) const{ return myValues[PEERS].value<PeerList>(); }
270
const FileList& files( ) const { return myFiles; }
273
QString activityString( ) const;
274
tr_torrent_activity getActivity( ) const { return (tr_torrent_activity) getInt( ACTIVITY ); }
275
bool isPaused( ) const { return getActivity( ) == TR_STATUS_STOPPED; }
276
bool isVerifying( ) const { return getActivity( ) == TR_STATUS_CHECK; }
277
bool isDownloading( ) const { return getActivity( ) == TR_STATUS_DOWNLOAD; }
278
bool isReadyToTransfer( ) const { return getActivity()==TR_STATUS_DOWNLOAD || getActivity()==TR_STATUS_SEED; }
279
void notifyComplete( ) const;
282
void update( tr_benc * dict );
285
const char * getMimeTypeString( ) const;
286
void updateMimeIcon( );
289
QIcon getMimeTypeIcon( ) const { return getIcon( MIME_ICON ); }
296
Q_DECLARE_METATYPE(const Torrent*)