2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QTR_TORRENT_H
|
|
|
|
#define QTR_TORRENT_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QMetaType>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QList>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
|
|
|
|
#include "speed.h"
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
struct tr_benc;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Prefs;
|
2010-07-27 19:43:32 +00:00
|
|
|
class QPixmap;
|
2009-04-09 18:55:47 +00:00
|
|
|
class QStyle;
|
|
|
|
|
|
|
|
struct Peer
|
|
|
|
{
|
|
|
|
QString address;
|
|
|
|
QString clientName;
|
|
|
|
bool clientIsChoked;
|
|
|
|
bool clientIsInterested;
|
2010-06-26 17:48:27 +00:00
|
|
|
QString flagStr;
|
2009-04-09 18:55:47 +00:00
|
|
|
bool isDownloadingFrom;
|
|
|
|
bool isEncrypted;
|
|
|
|
bool isIncoming;
|
|
|
|
bool isUploadingTo;
|
|
|
|
bool peerIsChoked;
|
|
|
|
bool peerIsInterested;
|
|
|
|
int port;
|
|
|
|
double progress;
|
|
|
|
Speed rateToClient;
|
|
|
|
Speed rateToPeer;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef QList<Peer> PeerList;
|
|
|
|
Q_DECLARE_METATYPE(Peer)
|
|
|
|
Q_DECLARE_METATYPE(PeerList)
|
|
|
|
|
2010-04-03 14:23:29 +00:00
|
|
|
struct TrackerStat
|
|
|
|
{
|
|
|
|
QString announce;
|
|
|
|
int announceState;
|
|
|
|
int downloadCount;
|
|
|
|
bool hasAnnounced;
|
|
|
|
bool hasScraped;
|
|
|
|
QString host;
|
|
|
|
int id;
|
|
|
|
bool isBackup;
|
|
|
|
int lastAnnouncePeerCount;
|
2010-08-01 14:51:28 +00:00
|
|
|
QString lastAnnounceResult;
|
2010-04-03 14:23:29 +00:00
|
|
|
int lastAnnounceStartTime;
|
|
|
|
bool lastAnnounceSucceeded;
|
|
|
|
int lastAnnounceTime;
|
|
|
|
bool lastAnnounceTimedOut;
|
|
|
|
QString lastScrapeResult;
|
|
|
|
int lastScrapeStartTime;
|
|
|
|
bool lastScrapeSucceeded;
|
|
|
|
int lastScrapeTime;
|
|
|
|
bool lastScrapeTimedOut;
|
|
|
|
int leecherCount;
|
|
|
|
int nextAnnounceTime;
|
|
|
|
int nextScrapeTime;
|
|
|
|
int scrapeState;
|
|
|
|
int seederCount;
|
|
|
|
int tier;
|
2010-07-27 19:43:32 +00:00
|
|
|
QPixmap getFavicon( ) const;
|
2010-04-03 14:23:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef QList<TrackerStat> TrackerStatsList;
|
|
|
|
Q_DECLARE_METATYPE(TrackerStat)
|
|
|
|
Q_DECLARE_METATYPE(TrackerStatsList)
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
struct TrFile
|
|
|
|
{
|
|
|
|
TrFile(): index(-1), priority(0), wanted(true), size(0), have(0) { }
|
|
|
|
int index;
|
|
|
|
int priority;
|
|
|
|
bool wanted;
|
|
|
|
uint64_t size;
|
|
|
|
uint64_t have;
|
|
|
|
QString filename;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef QList<TrFile> FileList;
|
|
|
|
Q_DECLARE_METATYPE(TrFile)
|
|
|
|
Q_DECLARE_METATYPE(FileList)
|
|
|
|
|
|
|
|
|
|
|
|
class Torrent: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ID,
|
|
|
|
UPLOAD_SPEED,
|
|
|
|
DOWNLOAD_SPEED,
|
|
|
|
DOWNLOAD_DIR,
|
|
|
|
ACTIVITY,
|
|
|
|
NAME,
|
|
|
|
ERROR,
|
2009-08-05 01:25:36 +00:00
|
|
|
ERROR_STRING,
|
2009-04-09 18:55:47 +00:00
|
|
|
SIZE_WHEN_DONE,
|
|
|
|
LEFT_UNTIL_DONE,
|
|
|
|
HAVE_UNCHECKED,
|
|
|
|
HAVE_VERIFIED,
|
2010-02-02 05:34:26 +00:00
|
|
|
DESIRED_AVAILABLE,
|
2009-04-09 18:55:47 +00:00
|
|
|
TOTAL_SIZE,
|
|
|
|
PIECE_SIZE,
|
|
|
|
PIECE_COUNT,
|
|
|
|
PEERS_GETTING_FROM_US,
|
|
|
|
PEERS_SENDING_TO_US,
|
|
|
|
WEBSEEDS_SENDING_TO_US,
|
|
|
|
PERCENT_DONE,
|
2009-12-03 17:23:53 +00:00
|
|
|
METADATA_PERCENT_DONE,
|
2009-04-09 18:55:47 +00:00
|
|
|
PERCENT_VERIFIED,
|
|
|
|
DATE_ACTIVITY,
|
|
|
|
DATE_ADDED,
|
|
|
|
DATE_STARTED,
|
|
|
|
DATE_CREATED,
|
|
|
|
PEERS_CONNECTED,
|
|
|
|
ETA,
|
|
|
|
RATIO,
|
|
|
|
DOWNLOADED_EVER,
|
|
|
|
UPLOADED_EVER,
|
|
|
|
FAILED_EVER,
|
|
|
|
TRACKERS,
|
2010-04-03 14:23:29 +00:00
|
|
|
TRACKERSTATS,
|
2009-04-09 18:55:47 +00:00
|
|
|
MIME_ICON,
|
|
|
|
SEED_RATIO_LIMIT,
|
|
|
|
SEED_RATIO_MODE,
|
2010-07-24 04:14:43 +00:00
|
|
|
SEED_IDLE_LIMIT,
|
|
|
|
SEED_IDLE_MODE,
|
2009-04-09 18:55:47 +00:00
|
|
|
DOWN_LIMIT,
|
|
|
|
DOWN_LIMITED,
|
|
|
|
UP_LIMIT,
|
|
|
|
UP_LIMITED,
|
|
|
|
HONORS_SESSION_LIMITS,
|
|
|
|
PEER_LIMIT,
|
|
|
|
HASH_STRING,
|
2010-04-06 02:34:45 +00:00
|
|
|
IS_FINISHED,
|
2009-04-09 18:55:47 +00:00
|
|
|
IS_PRIVATE,
|
2011-08-01 23:27:11 +00:00
|
|
|
IS_STALLED,
|
2009-04-09 18:55:47 +00:00
|
|
|
COMMENT,
|
|
|
|
CREATOR,
|
|
|
|
MANUAL_ANNOUNCE_TIME,
|
|
|
|
PEERS,
|
|
|
|
TORRENT_FILE,
|
2009-04-18 23:18:28 +00:00
|
|
|
BANDWIDTH_PRIORITY,
|
2011-08-01 22:24:24 +00:00
|
|
|
QUEUE_POSITION,
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
PROPERTY_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
Torrent( Prefs&, int id );
|
|
|
|
virtual ~Torrent( );
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void torrentChanged( int id );
|
2011-07-26 02:56:30 +00:00
|
|
|
void torrentCompleted( int id );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
enum Group
|
|
|
|
{
|
|
|
|
INFO, // info fields that only need to be loaded once
|
|
|
|
STAT, // commonly-used stats that should be refreshed often
|
|
|
|
STAT_EXTRA, // rarely used; only refresh if details dialog is open
|
|
|
|
DERIVED // doesn't come from RPC
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Property
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
const char * key;
|
|
|
|
int type;
|
|
|
|
int group;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Property myProperties[];
|
|
|
|
|
2010-06-16 03:02:17 +00:00
|
|
|
bool magnetTorrent;
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
public:
|
|
|
|
typedef QList<const char*> KeyList;
|
|
|
|
static const KeyList& getInfoKeys( );
|
|
|
|
static const KeyList& getStatKeys( );
|
|
|
|
static const KeyList& getExtraStatKeys( );
|
|
|
|
|
|
|
|
private:
|
|
|
|
static KeyList buildKeyList( Group group );
|
|
|
|
|
|
|
|
private:
|
|
|
|
QVariant myValues[PROPERTY_COUNT];
|
|
|
|
|
|
|
|
int getInt ( int key ) const;
|
|
|
|
bool getBool ( int key ) const;
|
|
|
|
QTime getTime ( int key ) const;
|
|
|
|
QIcon getIcon ( int key ) const;
|
|
|
|
double getDouble ( int key ) const;
|
|
|
|
qulonglong getSize ( int key ) const;
|
|
|
|
QString getString ( int key ) const;
|
|
|
|
QDateTime getDateTime ( int key ) const;
|
|
|
|
|
|
|
|
bool setInt ( int key, int value );
|
|
|
|
bool setBool ( int key, bool value );
|
|
|
|
bool setIcon ( int key, const QIcon& );
|
|
|
|
bool setDouble ( int key, double );
|
|
|
|
bool setString ( int key, const char * );
|
|
|
|
bool setSize ( int key, qulonglong );
|
|
|
|
bool setDateTime ( int key, const QDateTime& );
|
|
|
|
|
|
|
|
public:
|
2009-04-18 23:18:28 +00:00
|
|
|
int getBandwidthPriority( ) const { return getInt( BANDWIDTH_PRIORITY ); }
|
2009-04-09 18:55:47 +00:00
|
|
|
int id( ) const { return getInt( ID ); }
|
|
|
|
QString name( ) const { return getString( NAME ); }
|
|
|
|
QString creator( ) const { return getString( CREATOR ); }
|
|
|
|
QString comment( ) const { return getString( COMMENT ); }
|
|
|
|
QString getPath( ) const { return getString( DOWNLOAD_DIR ); }
|
2009-08-05 01:25:36 +00:00
|
|
|
QString getError( ) const;
|
2009-04-09 18:55:47 +00:00
|
|
|
QString hashString( ) const { return getString( HASH_STRING ); }
|
|
|
|
QString torrentFile( ) const { return getString( TORRENT_FILE ); }
|
|
|
|
bool hasError( ) const { return !getError( ).isEmpty( ); }
|
|
|
|
bool isDone( ) const { return getSize( LEFT_UNTIL_DONE ) == 0; }
|
2009-06-23 00:24:37 +00:00
|
|
|
bool isSeed( ) const { return haveVerified() >= totalSize(); }
|
2009-04-09 18:55:47 +00:00
|
|
|
bool isPrivate( ) const { return getBool( IS_PRIVATE ); }
|
|
|
|
bool getSeedRatio( double& setme ) const;
|
|
|
|
uint64_t haveVerified( ) const { return getSize( HAVE_VERIFIED ); }
|
2009-06-23 00:24:37 +00:00
|
|
|
uint64_t haveUnverified( ) const { return getSize( HAVE_UNCHECKED ); }
|
2010-02-02 05:34:26 +00:00
|
|
|
uint64_t desiredAvailable( ) const { return getSize( DESIRED_AVAILABLE ); }
|
2009-06-23 00:24:37 +00:00
|
|
|
uint64_t haveTotal( ) const { return haveVerified( ) + haveUnverified(); }
|
|
|
|
uint64_t totalSize( ) const { return getSize( TOTAL_SIZE ); }
|
2009-04-09 18:55:47 +00:00
|
|
|
uint64_t sizeWhenDone( ) const { return getSize( SIZE_WHEN_DONE ); }
|
|
|
|
uint64_t leftUntilDone( ) const { return getSize( LEFT_UNTIL_DONE ); }
|
|
|
|
uint64_t pieceSize( ) const { return getSize( PIECE_SIZE ); }
|
2009-12-03 17:23:53 +00:00
|
|
|
bool hasMetadata( ) const { return getDouble( METADATA_PERCENT_DONE ) >= 1.0; }
|
2010-06-16 03:02:17 +00:00
|
|
|
bool isMagnet( ) const { return magnetTorrent; }
|
2009-04-09 18:55:47 +00:00
|
|
|
int pieceCount( ) const { return getInt( PIECE_COUNT ); }
|
|
|
|
double ratio( ) const { return getDouble( RATIO ); }
|
2010-05-31 15:30:44 +00:00
|
|
|
double percentComplete( ) const { return haveTotal() / (double)totalSize(); }
|
2009-04-09 18:55:47 +00:00
|
|
|
double percentDone( ) const { return getDouble( PERCENT_DONE ); }
|
2009-12-03 17:23:53 +00:00
|
|
|
double metadataPercentDone( ) const { return getDouble( METADATA_PERCENT_DONE ); }
|
2009-04-09 18:55:47 +00:00
|
|
|
uint64_t downloadedEver( ) const { return getSize( DOWNLOADED_EVER ); }
|
|
|
|
uint64_t uploadedEver( ) const { return getSize( UPLOADED_EVER ); }
|
|
|
|
uint64_t failedEver( ) const { return getSize( FAILED_EVER ); }
|
|
|
|
int compareTracker( const Torrent& ) const;
|
2010-12-01 05:41:58 +00:00
|
|
|
int compareSeedRatio( const Torrent& ) const;
|
2009-04-09 18:55:47 +00:00
|
|
|
int compareRatio( const Torrent& ) const;
|
|
|
|
int compareETA( const Torrent& ) const;
|
2009-04-13 18:21:22 +00:00
|
|
|
bool hasETA( ) const { return getETA( ) >= 0; }
|
2009-04-09 18:55:47 +00:00
|
|
|
int getETA( ) const { return getInt( ETA ); }
|
|
|
|
QDateTime lastActivity( ) const { return getDateTime( DATE_ACTIVITY ); }
|
|
|
|
QDateTime lastStarted( ) const { return getDateTime( DATE_STARTED ); }
|
|
|
|
QDateTime dateAdded( ) const { return getDateTime( DATE_ADDED ); }
|
|
|
|
QDateTime dateCreated( ) const { return getDateTime( DATE_CREATED ); }
|
|
|
|
QDateTime manualAnnounceTime( ) const { return getDateTime( MANUAL_ANNOUNCE_TIME ); }
|
2009-04-10 04:33:31 +00:00
|
|
|
bool canManualAnnounce( ) const { return isReadyToTransfer() && (manualAnnounceTime()<=QDateTime::currentDateTime()); }
|
2012-10-07 17:51:56 +00:00
|
|
|
int peersWeAreDownloadingFrom( ) const { return getInt( PEERS_SENDING_TO_US ); }
|
|
|
|
int webseedsWeAreDownloadingFrom( ) const { return getInt( WEBSEEDS_SENDING_TO_US ); }
|
2009-04-09 18:55:47 +00:00
|
|
|
int peersWeAreUploadingTo( ) const { return getInt( PEERS_GETTING_FROM_US ); }
|
|
|
|
bool isUploading( ) const { return peersWeAreUploadingTo( ) > 0; }
|
|
|
|
int connectedPeers( ) const { return getInt( PEERS_CONNECTED ); }
|
|
|
|
int connectedPeersAndWebseeds( ) const { return connectedPeers( ) + getInt( WEBSEEDS_SENDING_TO_US ); }
|
2010-09-03 04:30:43 +00:00
|
|
|
Speed downloadSpeed( ) const { return Speed::fromBps( getSize( DOWNLOAD_SPEED ) ); }
|
|
|
|
Speed uploadSpeed( ) const { return Speed::fromBps( getSize( UPLOAD_SPEED ) ); }
|
2009-04-09 18:55:47 +00:00
|
|
|
double getVerifyProgress( ) const { return getDouble( PERCENT_VERIFIED ); }
|
|
|
|
bool hasFileSubstring( const QString& substr ) const;
|
|
|
|
bool hasTrackerSubstring( const QString& substr ) const;
|
2010-07-04 06:07:21 +00:00
|
|
|
Speed uploadLimit( ) const { return Speed::fromKBps( getInt( UP_LIMIT ) ); }
|
|
|
|
Speed downloadLimit( ) const { return Speed::fromKBps( getInt( DOWN_LIMIT ) ); }
|
2009-04-09 18:55:47 +00:00
|
|
|
bool uploadIsLimited( ) const { return getBool( UP_LIMITED ); }
|
|
|
|
bool downloadIsLimited( ) const { return getBool( DOWN_LIMITED ); }
|
|
|
|
bool honorsSessionLimits( ) const { return getBool( HONORS_SESSION_LIMITS ); }
|
|
|
|
int peerLimit( ) const { return getInt( PEER_LIMIT ); }
|
|
|
|
double seedRatioLimit( ) const { return getDouble( SEED_RATIO_LIMIT ); }
|
|
|
|
tr_ratiolimit seedRatioMode( ) const { return (tr_ratiolimit) getInt( SEED_RATIO_MODE ); }
|
2010-07-24 04:14:43 +00:00
|
|
|
int seedIdleLimit( ) const { return getInt( SEED_IDLE_LIMIT ); }
|
|
|
|
tr_idlelimit seedIdleMode( ) const { return (tr_idlelimit) getInt( SEED_IDLE_MODE ); }
|
2010-04-03 14:23:29 +00:00
|
|
|
TrackerStatsList trackerStats( ) const{ return myValues[TRACKERSTATS].value<TrackerStatsList>(); }
|
2010-07-30 22:31:31 +00:00
|
|
|
QStringList trackers() const { return myValues[TRACKERS].value<QStringList>(); }
|
2009-04-09 18:55:47 +00:00
|
|
|
PeerList peers( ) const{ return myValues[PEERS].value<PeerList>(); }
|
|
|
|
const FileList& files( ) const { return myFiles; }
|
2011-08-01 22:24:24 +00:00
|
|
|
int queuePosition( ) const { return getInt( QUEUE_POSITION ); }
|
2011-08-01 23:27:11 +00:00
|
|
|
bool isStalled( ) const { return getBool( IS_STALLED ); }
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
QString activityString( ) const;
|
|
|
|
tr_torrent_activity getActivity( ) const { return (tr_torrent_activity) getInt( ACTIVITY ); }
|
2010-04-06 02:34:45 +00:00
|
|
|
bool isFinished( ) const { return getBool( IS_FINISHED ); }
|
2009-04-09 18:55:47 +00:00
|
|
|
bool isPaused( ) const { return getActivity( ) == TR_STATUS_STOPPED; }
|
2010-08-01 17:43:35 +00:00
|
|
|
bool isWaitingToVerify( ) const { return getActivity( ) == TR_STATUS_CHECK_WAIT; }
|
2009-04-09 22:42:55 +00:00
|
|
|
bool isVerifying( ) const { return getActivity( ) == TR_STATUS_CHECK; }
|
2009-04-09 18:55:47 +00:00
|
|
|
bool isDownloading( ) const { return getActivity( ) == TR_STATUS_DOWNLOAD; }
|
2011-08-01 22:24:24 +00:00
|
|
|
bool isWaitingToDownload( ) const { return getActivity( ) == TR_STATUS_DOWNLOAD_WAIT; }
|
2010-03-31 19:42:30 +00:00
|
|
|
bool isSeeding( ) const { return getActivity( ) == TR_STATUS_SEED; }
|
2011-08-01 22:24:24 +00:00
|
|
|
bool isWaitingToSeed( ) const { return getActivity( ) == TR_STATUS_SEED_WAIT; }
|
2009-04-09 22:42:55 +00:00
|
|
|
bool isReadyToTransfer( ) const { return getActivity()==TR_STATUS_DOWNLOAD || getActivity()==TR_STATUS_SEED; }
|
2011-08-02 03:59:54 +00:00
|
|
|
bool isQueued( ) const { return isWaitingToDownload() || isWaitingToSeed(); }
|
2009-04-09 18:55:47 +00:00
|
|
|
void notifyComplete( ) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void update( tr_benc * dict );
|
2010-06-16 03:02:17 +00:00
|
|
|
void setMagnet( bool magnet ) { magnetTorrent = magnet; }
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const char * getMimeTypeString( ) const;
|
|
|
|
void updateMimeIcon( );
|
|
|
|
|
|
|
|
public:
|
|
|
|
QIcon getMimeTypeIcon( ) const { return getIcon( MIME_ICON ); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Prefs& myPrefs;
|
|
|
|
FileList myFiles;
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(const Torrent*)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|