1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-09 05:14:09 +00:00

store the completed pieces of the pieces bar as an index set

This commit is contained in:
Mitchell Livingston 2008-06-11 16:28:33 +00:00
parent f0229ed8ad
commit ecc8214601
5 changed files with 34 additions and 25 deletions

2
NEWS
View file

@ -13,7 +13,7 @@ http://trac.transmissionbt.com/query?group=component&milestone=1.30&order=severi
+ Transfers can be dragged to different groups
+ Option to only show the add window when manually adding transfers
+ Status strings are toggled from the action button (they are no longer clickable)
+ Colors in pieces bar and pieces view more accurately reflect their corresponding values
+ Colors in pieces bar and pieces box more accurately reflect their corresponding values
- GTK+
+ Add preferences options to inhibit hibernation and to toggle the tray icon
- Daemon

View file

@ -2003,7 +2003,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
[previousTorrents removeObjectsInArray: allTorrents];
enumerator = [previousTorrents objectEnumerator];
while ((torrent = [enumerator nextObject]))
[torrent setPreviousAmountFinished: NULL];
[torrent setPreviousFinishedPieces: nil];
//place torrents into groups
BOOL groupRows = [fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter];

View file

@ -57,8 +57,8 @@ typedef enum
tr_file_stat * fFileStat;
NSArray * fFileList;
float * fPreviousFinishedPieces;
NSDate * fFinishedPiecesDate;
NSIndexSet * fPreviousFinishedIndexes;
NSDate * fPreviousFinishedIndexesDate;
float fRatioLimit;
int fRatioSetting;
@ -87,8 +87,8 @@ typedef enum
- (void) getAvailability: (int8_t *) tab size: (int) size;
- (void) getAmountFinished: (float *) tab size: (int) size;
- (float *) getPreviousAmountFinished;
-(void) setPreviousAmountFinished: (float *) tab;
- (NSIndexSet *) previousFinishedPieces;
-(void) setPreviousFinishedPieces: (NSIndexSet *) indexes;
- (void) update;

View file

@ -168,8 +168,8 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
if (fFileStat)
tr_torrentFilesFree(fFileStat, [self fileCount]);
tr_free(fPreviousFinishedPieces);
[fFinishedPiecesDate release];
[fPreviousFinishedIndexes release];
[fPreviousFinishedIndexesDate release];
[fNameString release];
[fHashString release];
@ -239,22 +239,22 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
tr_torrentAmountFinished(fHandle, tab, size);
}
- (float *) getPreviousAmountFinished
- (NSIndexSet *) previousFinishedPieces
{
//if the torrent hasn't been seen in a bit, and therefore hasn't been refreshed, return NULL
if (fFinishedPiecesDate && [fFinishedPiecesDate timeIntervalSinceNow] > -2.0)
return fPreviousFinishedPieces;
//if the torrent hasn't been seen in a bit, and therefore hasn't been refreshed, return nil
if (fPreviousFinishedIndexesDate && [fPreviousFinishedIndexesDate timeIntervalSinceNow] > -2.0)
return fPreviousFinishedIndexes;
else
return NULL;
return nil;
}
-(void) setPreviousAmountFinished: (float *) tab
-(void) setPreviousFinishedPieces: (NSIndexSet *) indexes
{
tr_free(fPreviousFinishedPieces);
fPreviousFinishedPieces = tab;
[fPreviousFinishedIndexes release];
fPreviousFinishedIndexes = [indexes retain];
[fFinishedPiecesDate release];
fFinishedPiecesDate = tab != NULL ? [[NSDate alloc] init] : nil;
[fPreviousFinishedIndexesDate release];
fPreviousFinishedIndexesDate = indexes != nil ? [[NSDate alloc] init] : nil;
}
#warning when queue and seeding options are folded into libt, no need to call this on all torrents - use tr_torrentGetStatus

View file

@ -589,7 +589,7 @@
}
else
{
[[self representedObject] setPreviousAmountFinished: NULL];
[[self representedObject] setPreviousFinishedPieces: nil];
[self drawRegularBar: barRect];
}
@ -735,20 +735,28 @@
Torrent * torrent = [self representedObject];
int pieceCount = MIN([torrent pieceCount], MAX_PIECES);
float * piecesPercent = malloc(pieceCount * sizeof(float)),
* previousPiecePercent = [torrent getPreviousAmountFinished];
float * piecesPercent = malloc(pieceCount * sizeof(float));
[torrent getAmountFinished: piecesPercent size: pieceCount];
NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
pixelsWide: pieceCount pixelsHigh: 1 bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
NSIndexSet * previousFinishedIndexes = [torrent previousFinishedPieces];
NSMutableIndexSet * finishedIndexes = [NSMutableIndexSet indexSet];
int i;
for (i = 0; i < pieceCount; i++)
{
NSColor * pieceColor;
if (piecesPercent[i] == 1.0 && previousPiecePercent != NULL && previousPiecePercent[i] < 1.0)
pieceColor = [NSColor orangeColor];
if (piecesPercent[i] == 1.0)
{
if (previousFinishedIndexes && ![previousFinishedIndexes containsIndex: i])
pieceColor = [NSColor orangeColor];
else
pieceColor = fBluePieceColor;
[finishedIndexes addIndex: i];
}
else
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[i] ofColor: fBluePieceColor];
@ -756,11 +764,12 @@
[bitmap setColor: pieceColor atX: i y: 0];
}
[torrent setPreviousAmountFinished: piecesPercent]; //holds onto piecePercent, so no need to release it here
free(piecesPercent);
[torrent setPreviousFinishedPieces: [finishedIndexes count] > 0 ? finishedIndexes : nil]; //don't bother saving if none are complete
//actually draw image
[bitmap drawInRect: barRect];
[bitmap release];
}