Changeset 6141


Ignore:
Timestamp:
Jun 11, 2008, 4:28:33 PM (13 years ago)
Author:
livings124
Message:

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

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r6136 r6141  
    1414   + Option to only show the add window when manually adding transfers
    1515   + Status strings are toggled from the action button (they are no longer clickable)
    16    + Colors in pieces bar and pieces view more accurately reflect their corresponding values
     16   + Colors in pieces bar and pieces box more accurately reflect their corresponding values
    1717- GTK+
    1818   + Add preferences options to inhibit hibernation and to toggle the tray icon
  • trunk/macosx/Controller.m

    r6137 r6141  
    20042004    enumerator = [previousTorrents objectEnumerator];
    20052005    while ((torrent = [enumerator nextObject]))
    2006         [torrent setPreviousAmountFinished: NULL];
     2006        [torrent setPreviousFinishedPieces: nil];
    20072007   
    20082008    //place torrents into groups
  • trunk/macosx/Torrent.h

    r6088 r6141  
    5858    NSArray * fFileList;
    5959   
    60     float * fPreviousFinishedPieces;
    61     NSDate * fFinishedPiecesDate;
     60    NSIndexSet * fPreviousFinishedIndexes;
     61    NSDate * fPreviousFinishedIndexesDate;
    6262   
    6363    float fRatioLimit;
     
    8888- (void) getAvailability: (int8_t *) tab size: (int) size;
    8989- (void) getAmountFinished: (float *) tab size: (int) size;
    90 - (float *) getPreviousAmountFinished;
    91 -(void) setPreviousAmountFinished: (float *) tab;
     90- (NSIndexSet *) previousFinishedPieces;
     91-(void) setPreviousFinishedPieces: (NSIndexSet *) indexes;
    9292
    9393- (void) update;
  • trunk/macosx/Torrent.m

    r6125 r6141  
    169169        tr_torrentFilesFree(fFileStat, [self fileCount]);
    170170   
    171     tr_free(fPreviousFinishedPieces);
    172     [fFinishedPiecesDate release];
     171    [fPreviousFinishedIndexes release];
     172    [fPreviousFinishedIndexesDate release];
    173173   
    174174    [fNameString release];
     
    240240}
    241241
    242 - (float *) getPreviousAmountFinished
    243 {
    244     //if the torrent hasn't been seen in a bit, and therefore hasn't been refreshed, return NULL
    245     if (fFinishedPiecesDate && [fFinishedPiecesDate timeIntervalSinceNow] > -2.0)
    246         return fPreviousFinishedPieces;
     242- (NSIndexSet *) previousFinishedPieces
     243{
     244    //if the torrent hasn't been seen in a bit, and therefore hasn't been refreshed, return nil
     245    if (fPreviousFinishedIndexesDate && [fPreviousFinishedIndexesDate timeIntervalSinceNow] > -2.0)
     246        return fPreviousFinishedIndexes;
    247247    else
    248         return NULL;
    249 }
    250 
    251 -(void) setPreviousAmountFinished: (float *) tab
    252 {
    253     tr_free(fPreviousFinishedPieces);
    254     fPreviousFinishedPieces = tab;
    255    
    256     [fFinishedPiecesDate release];
    257     fFinishedPiecesDate = tab != NULL ? [[NSDate alloc] init] : nil;
     248        return nil;
     249}
     250
     251-(void) setPreviousFinishedPieces: (NSIndexSet *) indexes
     252{
     253    [fPreviousFinishedIndexes release];
     254    fPreviousFinishedIndexes = [indexes retain];
     255   
     256    [fPreviousFinishedIndexesDate release];
     257    fPreviousFinishedIndexesDate = indexes != nil ? [[NSDate alloc] init] : nil;
    258258}
    259259
  • trunk/macosx/TorrentCell.m

    r6127 r6141  
    590590    else
    591591    {
    592         [[self representedObject] setPreviousAmountFinished: NULL];
     592        [[self representedObject] setPreviousFinishedPieces: nil];
    593593       
    594594        [self drawRegularBar: barRect];
     
    736736   
    737737    int pieceCount = MIN([torrent pieceCount], MAX_PIECES);
    738     float * piecesPercent = malloc(pieceCount * sizeof(float)),
    739         * previousPiecePercent = [torrent getPreviousAmountFinished];
     738    float * piecesPercent = malloc(pieceCount * sizeof(float));
    740739    [torrent getAmountFinished: piecesPercent size: pieceCount];
    741740   
     
    744743                                    isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
    745744   
     745    NSIndexSet * previousFinishedIndexes = [torrent previousFinishedPieces];
     746    NSMutableIndexSet * finishedIndexes = [NSMutableIndexSet indexSet];
     747   
    746748    int i;
    747749    for (i = 0; i < pieceCount; i++)
    748750    {
    749751        NSColor * pieceColor;
    750         if (piecesPercent[i] == 1.0 && previousPiecePercent != NULL && previousPiecePercent[i] < 1.0)
    751             pieceColor = [NSColor orangeColor];
     752        if (piecesPercent[i] == 1.0)
     753        {
     754            if (previousFinishedIndexes && ![previousFinishedIndexes containsIndex: i])
     755                pieceColor = [NSColor orangeColor];
     756            else
     757                pieceColor = fBluePieceColor;
     758            [finishedIndexes addIndex: i];
     759        }
    752760        else
    753761            pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[i] ofColor: fBluePieceColor];
     
    757765    }
    758766   
    759     [torrent setPreviousAmountFinished: piecesPercent]; //holds onto piecePercent, so no need to release it here
     767    free(piecesPercent);
     768   
     769    [torrent setPreviousFinishedPieces: [finishedIndexes count] > 0 ? finishedIndexes : nil]; //don't bother saving if none are complete
    760770   
    761771    //actually draw image
    762772    [bitmap drawInRect: barRect];
    763    
    764773    [bitmap release];
    765774}
Note: See TracChangeset for help on using the changeset viewer.