From 3377bc4e0297ca3863d9c060003e580fca23a1e0 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Fri, 28 Dec 2007 21:37:06 +0000 Subject: [PATCH] flash orange in pieces in the advanced progress bar that just completed --- macosx/Torrent.h | 5 +++++ macosx/Torrent.m | 21 +++++++++++++++++++++ macosx/TorrentCell.h | 2 +- macosx/TorrentCell.m | 16 +++++++++++----- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 0e4d78512..e5517dc7f 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -61,6 +61,9 @@ typedef enum NSMenu * fFileMenu; + float * fPreviousFinishedPieces; + NSDate * fFinishedPiecesDate; + float fRatioLimit; int fRatioSetting; BOOL fFinishedSeeding, fWaitToStart, fError, fChecking, fStalled; @@ -86,6 +89,8 @@ typedef enum - (void) getAvailability: (int8_t *) tab size: (int) size; - (void) getAmountFinished: (float *) tab size: (int) size; +- (float *) getPreviousAmountFinished; +-(void) setPreviousAmountFinished: (float *) tab; - (void) update; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 1115ddeab..2ce9b962c 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -154,6 +154,9 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * if (fileStat) tr_torrentFilesFree(fileStat, [self fileCount]); + if (fPreviousFinishedPieces != NULL) + free(fPreviousFinishedPieces); + [fDownloadFolder release]; [fIncompleteFolder release]; @@ -212,6 +215,24 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * tr_torrentAmountFinished(fHandle, tab, size); } +- (float *) getPreviousAmountFinished +{ + if (fFinishedPiecesDate && [fFinishedPiecesDate timeIntervalSinceNow] < -1.0) + return fPreviousFinishedPieces; + else + return NULL; +} + +-(void) setPreviousAmountFinished: (float *) tab +{ + if (fPreviousFinishedPieces != NULL) + free(fPreviousFinishedPieces); + fPreviousFinishedPieces = tab; + + [fFinishedPiecesDate release]; + fFinishedPiecesDate = fPreviousFinishedPieces != NULL ? [[NSDate alloc] init] : nil; +} + - (void) update { fStat = tr_torrentStat(fHandle); diff --git a/macosx/TorrentCell.h b/macosx/TorrentCell.h index 7fad2c601..b9745d293 100644 --- a/macosx/TorrentCell.h +++ b/macosx/TorrentCell.h @@ -36,7 +36,7 @@ * fGreenGradient, * fLightGreenGradient, * fDarkGreenGradient, * fYellowGradient, * fRedGradient, * fTransparentGradient; - NSColor * fGrayColor, * fBlueColor, * fBlue1Color, * fBlue2Color, * fBlue3Color, * fBlue4Color; + NSColor * fGrayColor, * fBlueColor, * fBlue1Color, * fBlue2Color, * fBlue3Color, * fBlue4Color, * fOrangeColor; NSBitmapImageRep * fBitmap; } diff --git a/macosx/TorrentCell.m b/macosx/TorrentCell.m index 7fe929901..0be2a6be6 100644 --- a/macosx/TorrentCell.m +++ b/macosx/TorrentCell.m @@ -100,6 +100,7 @@ fBlue3Color = [[NSColor colorWithCalibratedRed: 0.6 green: 0.8 blue: 1.0 alpha: 1.0] retain]; fBlue4Color = [[NSColor colorWithCalibratedRed: 0.4 green: 0.6 blue: 1.0 alpha: 1.0] retain]; fBlueColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.4 blue: 0.8 alpha: 1.0] retain]; + fOrangeColor = [[NSColor orangeColor] retain]; fBarOverlayColor = [[NSColor colorWithDeviceWhite: 0.0 alpha: 0.2] retain]; } @@ -307,6 +308,7 @@ { [fBitmap release]; fBitmap = nil; + [[self representedObject] setPreviousAmountFinished: NULL]; [self drawRegularBar: barRect]; } @@ -453,12 +455,11 @@ pixelsWide: MAX_PIECES pixelsHigh: barRect.size.height bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0]; - #warning add flashing orange - Torrent * torrent = [self representedObject]; int pieceCount = MIN([torrent pieceCount], MAX_PIECES); - float * piecePercent = malloc(pieceCount * sizeof(float)); + float * piecePercent = malloc(pieceCount * sizeof(float)), + * previousPiecePercent = [torrent getPreviousAmountFinished]; [torrent getAmountFinished: piecePercent size: pieceCount]; int i, h, index; @@ -468,7 +469,12 @@ { index = i * increment; if (piecePercent[index] >= 1.0) - pieceColor = fBlueColor; + { + if (previousPiecePercent != NULL && previousPiecePercent[index] < 1.0) + pieceColor = fOrangeColor; + else + pieceColor = fBlueColor; + } else if (piecePercent[index] <= 0.0) pieceColor = fGrayColor; else if (piecePercent[index] <= 0.25) @@ -485,7 +491,7 @@ [fBitmap setColor: pieceColor atX: i y: h]; } - free(piecePercent); + [torrent setPreviousAmountFinished: piecePercent]; //actually draw image [fBitmap drawInRect: barRect];