#1869 Move the finished state to libtransmission. This setting is now remembered between launches. This also causes torrents that hit the seed ratio to not have this setting changed to unlimited until start.

This commit is contained in:
Mitchell Livingston
2010-04-02 17:57:25 +00:00
parent 01ae1dbe37
commit 6a4954e867
8 changed files with 35 additions and 20 deletions

View File

@@ -153,6 +153,7 @@
haveValid | number | tr_stat
honorsSessionLimits | boolean | tr_torrent
id | number | tr_torrent
isFinished | boolean | tr_stat
isPrivate | boolean | tr_torrent
leftUntilDone | number | tr_stat
magnetLink | number | n/a
@@ -590,5 +591,4 @@
------+---------+-----------+----------------+-------------------------------
9 | 2.00 | yes | session-set | new arg "start-added-torrents"
| 2.00 | yes | session-set | new arg "trash-original-torrent-files"
| 2.00 | yes | session-get | new arg "start-added-torrents"
| 2.00 | yes | session-get | new arg "trash-original-torrent-files"
| 2.00 | yes | torrent-get | new arg "isFinished"

View File

@@ -30,6 +30,9 @@
#include "version.h"
#include "web.h"
#define RPC_VERSION 9
#define RPC_VERSION_MIN 1
#define RECENTLY_ACTIVE_SECONDS 60
#define TR_N_ELEMENTS( ary ) ( sizeof( ary ) / sizeof( *ary ) )
@@ -502,6 +505,8 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
tr_bencDictAddBool( d, key, tr_torrentUsesSessionLimits( tor ) );
else if( tr_streq( key, keylen, "id" ) )
tr_bencDictAddInt( d, key, st->id );
else if( tr_streq( key, keylen, "isFinished" ) )
tr_bencDictAddBool( d, key, st->finished );
else if( tr_streq( key, keylen, "isPrivate" ) )
tr_bencDictAddBool( d, key, tr_torrentIsPrivate( tor ) );
else if( tr_streq( key, keylen, "leftUntilDone" ) )
@@ -1306,8 +1311,8 @@ sessionGet( tr_session * s,
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, tr_sessionGetPeerPortRandomOnStart( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, tr_sessionIsPortForwardingEnabled( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_RENAME_PARTIAL_FILES, tr_sessionIsIncompleteFileNamingEnabled( s ) );
tr_bencDictAddInt ( d, "rpc-version", 8 );
tr_bencDictAddInt ( d, "rpc-version-minimum", 1 );
tr_bencDictAddInt ( d, "rpc-version", RPC_VERSION );
tr_bencDictAddInt ( d, "rpc-version-minimum", RPC_VERSION_MIN );
tr_bencDictAddReal( d, "seedRatioLimit", tr_sessionGetRatioLimit( s ) );
tr_bencDictAddBool( d, "seedRatioLimited", tr_sessionIsRatioLimited( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_START, !tr_sessionGetPaused( s ) );

View File

@@ -1052,6 +1052,8 @@ tr_torrentStat( tr_torrent * tor )
break;
}
s->finished = s->percentDone == 1.0 && checkSeedRatio && (s->ratio >= seedRatio || s->ratio == TR_RATIO_INF);
if( !checkSeedRatio || s->ratio >= seedRatio || s->ratio == TR_RATIO_INF )
s->percentRatio = 1.0;
else if( s->ratio == TR_RATIO_NA )
@@ -1375,6 +1377,10 @@ torrentStart( tr_torrent * tor )
if( !tor->isRunning )
{
/* allow finished torrents to be resumed */
if( tor->stats.finished )
tr_torrentSetRatioMode( tor, TR_RATIOLIMIT_UNLIMITED );
tr_verifyRemove( tor );
/* corresponds to the peer_id sent as a tracker request parameter.
@@ -2615,9 +2621,6 @@ tr_torrentCheckSeedRatio( tr_torrent * tor )
{
tr_torrentStop( tor );
/* set to no ratio limit to allow easy restarting */
tr_torrentSetRatioMode( tor, TR_RATIOLIMIT_UNLIMITED );
/* maybe notify the client */
if( tor->ratio_limit_hit_func != NULL )
tor->ratio_limit_hit_func( tor, tor->ratio_limit_hit_func_user_data );

View File

@@ -1821,6 +1821,10 @@ typedef struct tr_stat
/** The last time we uploaded or downloaded piece data on this torrent. */
time_t activityDate;
/** A torrent is considered finished if it has met its seed ratio.
As a result, only paused torrent can be finished. */
tr_bool finished;
}
tr_stat;

View File

@@ -47,7 +47,7 @@
NSIndexSet * fPreviousFinishedIndexes;
NSDate * fPreviousFinishedIndexesDate;
BOOL fFinishedSeeding, fWaitToStart, fStalled;
BOOL fWaitToStart, fStalled;
NSInteger fGroupValue;
@@ -161,6 +161,7 @@
- (BOOL) isCheckingWaiting;
- (BOOL) allDownloaded;
- (BOOL) isComplete;
- (BOOL) isFinishedSeeding;
- (BOOL) isError;
- (BOOL) isAnyErrorOrWarning;
- (NSString *) errorMessage;

View File

@@ -283,7 +283,6 @@ int trashDataFile(const char * filename)
- (void) startTransfer
{
fWaitToStart = NO;
fFinishedSeeding = NO;
if (![self isActive] && [self alertForRemainingDiskSpace])
{
@@ -821,6 +820,11 @@ int trashDataFile(const char * filename)
return [self progress] >= 1.0;
}
- (BOOL) isFinishedSeeding
{
return fStat->finished;
}
- (BOOL) isError
{
return fStat->error == TR_STAT_LOCAL_ERROR;
@@ -986,8 +990,8 @@ int trashDataFile(const char * filename)
switch (fStat->error)
{
case TR_STAT_LOCAL_ERROR: string = NSLocalizedString(@"Error", "Torrent -> status string"); break;
case TR_STAT_TRACKER_ERROR: string = NSLocalizedString(@"Tracker returned an error", "Torrent -> status string"); break;
case TR_STAT_TRACKER_WARNING: string = NSLocalizedString(@"Tracker returned a warning", "Torrent -> status string"); break;
case TR_STAT_TRACKER_ERROR: string = NSLocalizedString(@"Tracker returned error", "Torrent -> status string"); break;
case TR_STAT_TRACKER_WARNING: string = NSLocalizedString(@"Tracker returned warning", "Torrent -> status string"); break;
default: NSAssert(NO, @"unknown error state");
}
@@ -1006,7 +1010,7 @@ int trashDataFile(const char * filename)
? [NSLocalizedString(@"Waiting to download", "Torrent -> status string") stringByAppendingEllipsis]
: [NSLocalizedString(@"Waiting to seed", "Torrent -> status string") stringByAppendingEllipsis];
}
else if (fFinishedSeeding)
else if ([self isFinishedSeeding])
string = NSLocalizedString(@"Seeding complete", "Torrent -> status string");
else
string = NSLocalizedString(@"Paused", "Torrent -> status string");
@@ -1085,7 +1089,7 @@ int trashDataFile(const char * filename)
? [NSLocalizedString(@"Waiting to download", "Torrent -> status string") stringByAppendingEllipsis]
: [NSLocalizedString(@"Waiting to seed", "Torrent -> status string") stringByAppendingEllipsis];
}
else if (fFinishedSeeding)
else if ([self isFinishedSeeding])
string = NSLocalizedString(@"Seeding complete", "Torrent -> status string");
else
string = NSLocalizedString(@"Paused", "Torrent -> status string");
@@ -1589,8 +1593,6 @@ int trashDataFile(const char * filename)
tr_torrentSetMetadataCallback(fHandle, metadataCallback, self);
fHashString = [[NSString alloc] initWithUTF8String: fInfo->hashString];
fFinishedSeeding = NO;
fWaitToStart = waitToStart && [waitToStart boolValue];
fResumeOnWake = NO;
@@ -1739,8 +1741,6 @@ int trashDataFile(const char * filename)
fStat = tr_torrentStat(fHandle);
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentStoppedForRatio" object: self];
fFinishedSeeding = YES;
}
- (void) metadataRetrieved

View File

@@ -651,7 +651,7 @@
//actually draw image
if ([NSApp isOnSnowLeopardOrBetter])
[bitmap drawInRect: barRect fromRect: NSZeroRect operation: NSCompositeSourceOver
fraction: ([fDefaults boolForKey: @"SmallView"] ? 0.125 : 1.0) respectFlipped: YES hints: nil];
fraction: ([fDefaults boolForKey: @"SmallView"] ? 0.2 : 1.0) respectFlipped: YES hints: nil];
else
[bitmap drawInRect: barRect];

View File

@@ -42,7 +42,7 @@ Torrent._DynamicFields = [ 'downloadedEver', 'error', 'errorString', 'eta',
'haveUnchecked', 'haveValid', 'leftUntilDone', 'metadataPercentComplete', 'peersConnected',
'peersGettingFromUs', 'peersSendingToUs', 'rateDownload', 'rateUpload',
'recheckProgress', 'sizeWhenDone', 'status', 'trackerStats',
'uploadedEver', 'uploadRatio', 'seedRatioLimit', 'seedRatioMode', 'downloadDir' ]
'uploadedEver', 'uploadRatio', 'seedRatioLimit', 'seedRatioMode', 'downloadDir', 'isFinished' ]
Torrent.prototype =
{
@@ -243,7 +243,8 @@ Torrent.prototype =
switch( this.state() ) {
case Torrent._StatusSeeding: return 'Seeding';
case Torrent._StatusDownloading: return 'Downloading';
case Torrent._StatusPaused: return 'Paused';
case Torrent._StatusPaused: return this._isFinishedSeeding ? 'Seeding complete'
: 'Paused';
case Torrent._StatusChecking: return 'Verifying local data';
case Torrent._StatusWaitingToCheck: return 'Waiting to verify';
default: return 'error';
@@ -391,6 +392,7 @@ Torrent.prototype =
this._state = data.status;
this._download_dir = data.downloadDir;
this._metadataPercentComplete = data.metadataPercentComplete;
this._isFinishedSeeding = data.isFinished;
if (data.fileStats)
this.refreshFileModel( data );