mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
move the advanced bar code into TorrentCell (finally)
This commit is contained in:
parent
87a2bd6479
commit
943c6e90a4
5 changed files with 179 additions and 175 deletions
|
@ -2116,11 +2116,6 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
||||||
return [fDisplayedTorrents count];
|
return [fDisplayedTorrents count];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) tableColumn row: (int) row
|
|
||||||
{
|
|
||||||
return [[fDisplayedTorrents objectAtIndex: row] infoForCurrentView];
|
|
||||||
}*/
|
|
||||||
|
|
||||||
- (BOOL) tableView: (NSTableView *) tableView writeRowsWithIndexes: (NSIndexSet *) indexes
|
- (BOOL) tableView: (NSTableView *) tableView writeRowsWithIndexes: (NSIndexSet *) indexes
|
||||||
toPasteboard: (NSPasteboard *) pasteboard
|
toPasteboard: (NSPasteboard *) pasteboard
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,9 +63,6 @@
|
||||||
|
|
||||||
int fOrderValue;
|
int fOrderValue;
|
||||||
|
|
||||||
NSBitmapImageRep * fBitmap;
|
|
||||||
int8_t * fPieces;
|
|
||||||
|
|
||||||
NSDictionary * fQuickPauseDict;
|
NSDictionary * fQuickPauseDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,8 +220,6 @@
|
||||||
- (NSNumber *) progressSortKey;
|
- (NSNumber *) progressSortKey;
|
||||||
- (NSNumber *) ratioSortKey;
|
- (NSNumber *) ratioSortKey;
|
||||||
|
|
||||||
- (NSImage *) advancedBar;
|
|
||||||
|
|
||||||
- (int) torrentID;
|
- (int) torrentID;
|
||||||
- (const tr_info_t *) torrentInfo;
|
- (const tr_info_t *) torrentInfo;
|
||||||
- (const tr_stat_t *) torrentStat;
|
- (const tr_stat_t *) torrentStat;
|
||||||
|
|
161
macosx/Torrent.m
161
macosx/Torrent.m
|
@ -25,11 +25,6 @@
|
||||||
#import "Torrent.h"
|
#import "Torrent.h"
|
||||||
#import "StringAdditions.h"
|
#import "StringAdditions.h"
|
||||||
|
|
||||||
#define BAR_HEIGHT 12.0
|
|
||||||
|
|
||||||
#define MAX_PIECES 324
|
|
||||||
#define BLANK_PIECE -99
|
|
||||||
|
|
||||||
static int static_lastid = 0;
|
static int static_lastid = 0;
|
||||||
|
|
||||||
@interface Torrent (Private)
|
@interface Torrent (Private)
|
||||||
|
@ -61,18 +56,6 @@ static int static_lastid = 0;
|
||||||
|
|
||||||
@implementation Torrent
|
@implementation Torrent
|
||||||
|
|
||||||
// Used to optimize drawing. They contain packed RGBA pixels for every color needed.
|
|
||||||
#define BE OSSwapBigToHostConstInt32
|
|
||||||
|
|
||||||
static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
|
||||||
kBlue = BE(0x50A0FFFF), //80, 160, 255
|
|
||||||
kBlue2 = BE(0x1E46B4FF), //30, 70, 180
|
|
||||||
kGray = BE(0x969696FF), //150, 150, 150
|
|
||||||
kGreen1 = BE(0x99FFCCFF), //153, 255, 204
|
|
||||||
kGreen2 = BE(0x66FF99FF), //102, 255, 153
|
|
||||||
kGreen3 = BE(0x00FF66FF), //0, 255, 102
|
|
||||||
kWhite = BE(0xFFFFFFFF); //255, 255, 255
|
|
||||||
|
|
||||||
- (id) initWithPath: (NSString *) path location: (NSString *) location forceDeleteTorrent: (BOOL) delete lib: (tr_handle_t *) lib
|
- (id) initWithPath: (NSString *) path location: (NSString *) location forceDeleteTorrent: (BOOL) delete lib: (tr_handle_t *) lib
|
||||||
{
|
{
|
||||||
self = [self initWithHash: nil path: path lib: lib
|
self = [self initWithHash: nil path: path lib: lib
|
||||||
|
@ -186,11 +169,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
|
|
||||||
[fQuickPauseDict release];
|
[fQuickPauseDict release];
|
||||||
|
|
||||||
[fBitmap release];
|
|
||||||
|
|
||||||
if (fPieces)
|
|
||||||
free(fPieces);
|
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1420,135 +1398,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
return [NSNumber numberWithFloat: [self ratio]];
|
return [NSNumber numberWithFloat: [self ratio]];
|
||||||
}
|
}
|
||||||
|
|
||||||
#warning move?
|
|
||||||
- (NSImage *) advancedBar
|
|
||||||
{
|
|
||||||
uint32_t * p;
|
|
||||||
uint8_t * bitmapData = [fBitmap bitmapData];
|
|
||||||
int bytesPerRow = [fBitmap bytesPerRow];
|
|
||||||
|
|
||||||
int pieceCount = [self pieceCount];
|
|
||||||
int8_t * piecesAvailablity = malloc(pieceCount);
|
|
||||||
[self getAvailability: piecesAvailablity size: pieceCount];
|
|
||||||
|
|
||||||
//lines 2 to 14: blue, green, or gray depending on piece availability
|
|
||||||
int i, h, index = 0;
|
|
||||||
float increment = (float)pieceCount / MAX_PIECES, indexValue = 0;
|
|
||||||
uint32_t color;
|
|
||||||
BOOL change;
|
|
||||||
for (i = 0; i < MAX_PIECES; i++)
|
|
||||||
{
|
|
||||||
change = NO;
|
|
||||||
if (piecesAvailablity[index] < 0)
|
|
||||||
{
|
|
||||||
if (fPieces[i] != -1)
|
|
||||||
{
|
|
||||||
color = kBlue;
|
|
||||||
fPieces[i] = -1;
|
|
||||||
change = YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (piecesAvailablity[index] == 0)
|
|
||||||
{
|
|
||||||
if (fPieces[i] != 0)
|
|
||||||
{
|
|
||||||
color = kGray;
|
|
||||||
fPieces[i] = 0;
|
|
||||||
change = YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (piecesAvailablity[index] <= 4)
|
|
||||||
{
|
|
||||||
if (fPieces[i] != 1)
|
|
||||||
{
|
|
||||||
color = kGreen1;
|
|
||||||
fPieces[i] = 1;
|
|
||||||
change = YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (piecesAvailablity[index] <= 8)
|
|
||||||
{
|
|
||||||
if (fPieces[i] != 2)
|
|
||||||
{
|
|
||||||
color = kGreen2;
|
|
||||||
fPieces[i] = 2;
|
|
||||||
change = YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (fPieces[i] != 3)
|
|
||||||
{
|
|
||||||
color = kGreen3;
|
|
||||||
fPieces[i] = 3;
|
|
||||||
change = YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (change)
|
|
||||||
{
|
|
||||||
//point to pixel (i, 2) and draw "vertically"
|
|
||||||
p = (uint32_t *)(bitmapData + 2 * bytesPerRow) + i;
|
|
||||||
for (h = 2; h < BAR_HEIGHT; h++)
|
|
||||||
{
|
|
||||||
p[0] = color;
|
|
||||||
p = (uint32_t *)((uint8_t *)p + bytesPerRow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
indexValue += increment;
|
|
||||||
index = (int)indexValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//determine percentage finished and available
|
|
||||||
int have = rintf((float)MAX_PIECES * [self progress]), avail;
|
|
||||||
if ([self progress] >= 1.0 || ![self isActive] || [self totalPeersConnected] <= 0)
|
|
||||||
avail = 0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float * piecesFinished = malloc(pieceCount * sizeof(float));
|
|
||||||
[self getAmountFinished: piecesFinished size: pieceCount];
|
|
||||||
|
|
||||||
float available = 0;
|
|
||||||
for (i = 0; i < pieceCount; i++)
|
|
||||||
if (piecesAvailablity[i] > 0)
|
|
||||||
available += 1.0 - piecesFinished[i];
|
|
||||||
|
|
||||||
avail = rintf(MAX_PIECES * available / (float)pieceCount);
|
|
||||||
if (have + avail > MAX_PIECES) //case if both end in .5 and all pieces are available
|
|
||||||
avail--;
|
|
||||||
|
|
||||||
free(piecesFinished);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(piecesAvailablity);
|
|
||||||
|
|
||||||
//first two lines: dark blue to show progression, green to show available
|
|
||||||
p = (uint32_t *)bitmapData;
|
|
||||||
for (i = 0; i < have; i++)
|
|
||||||
{
|
|
||||||
p[i] = kBlue2;
|
|
||||||
p[i + bytesPerRow / 4] = kBlue2;
|
|
||||||
}
|
|
||||||
for (; i < avail + have; i++)
|
|
||||||
{
|
|
||||||
p[i] = kGreen3;
|
|
||||||
p[i + bytesPerRow / 4] = kGreen3;
|
|
||||||
}
|
|
||||||
for (; i < MAX_PIECES; i++)
|
|
||||||
{
|
|
||||||
p[i] = kWhite;
|
|
||||||
p[i + bytesPerRow / 4] = kWhite;
|
|
||||||
}
|
|
||||||
|
|
||||||
//actually draw image
|
|
||||||
NSImage * bar = [[NSImage alloc] initWithSize: [fBitmap size]];
|
|
||||||
[bar addRepresentation: fBitmap];
|
|
||||||
[bar setScalesWhenResized: YES];
|
|
||||||
|
|
||||||
return [bar autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (int) torrentID
|
- (int) torrentID
|
||||||
{
|
{
|
||||||
return fID;
|
return fID;
|
||||||
|
@ -1666,16 +1515,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
|
|
||||||
[self createFileList];
|
[self createFileList];
|
||||||
|
|
||||||
//set up advanced bar
|
|
||||||
fBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
|
|
||||||
pixelsWide: MAX_PIECES pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
|
|
||||||
isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
|
||||||
|
|
||||||
fPieces = malloc(MAX_PIECES);
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < MAX_PIECES; i++)
|
|
||||||
fPieces[i] = BLANK_PIECE;
|
|
||||||
|
|
||||||
[self update];
|
[self update];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
NSUserDefaults * fDefaults;
|
NSUserDefaults * fDefaults;
|
||||||
|
|
||||||
NSMutableDictionary * nameAttributes, * statusAttributes;
|
NSMutableDictionary * nameAttributes, * statusAttributes;
|
||||||
|
|
||||||
|
NSBitmapImageRep * fBitmap;
|
||||||
|
int8_t * fPieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) toggleMinimalStatus;
|
- (void) toggleMinimalStatus;
|
||||||
|
|
|
@ -27,19 +27,34 @@
|
||||||
#import "StringAdditions.h"
|
#import "StringAdditions.h"
|
||||||
#import "CTGradientAdditions.h"
|
#import "CTGradientAdditions.h"
|
||||||
|
|
||||||
//also defined in Torrent.m
|
|
||||||
#define BAR_HEIGHT 12.0
|
#define BAR_HEIGHT 12.0
|
||||||
|
|
||||||
|
#define MAX_PIECES 324
|
||||||
|
#define BLANK_PIECE -99
|
||||||
|
|
||||||
@interface TorrentCell (Private)
|
@interface TorrentCell (Private)
|
||||||
|
|
||||||
- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point;
|
- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point;
|
||||||
- (void) buildSimpleBar: (float) width point: (NSPoint) point;
|
- (void) buildSimpleBar: (float) width point: (NSPoint) point;
|
||||||
- (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point;
|
- (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point;
|
||||||
|
- (NSImage *) advancedBar;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation TorrentCell
|
@implementation TorrentCell
|
||||||
|
|
||||||
|
// Used to optimize drawing. They contain packed RGBA pixels for every color needed.
|
||||||
|
#define BE OSSwapBigToHostConstInt32
|
||||||
|
|
||||||
|
static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
||||||
|
kBlue = BE(0x50A0FFFF), //80, 160, 255
|
||||||
|
kBlue2 = BE(0x1E46B4FF), //30, 70, 180
|
||||||
|
kGray = BE(0x969696FF), //150, 150, 150
|
||||||
|
kGreen1 = BE(0x99FFCCFF), //153, 255, 204
|
||||||
|
kGreen2 = BE(0x66FF99FF), //102, 255, 153
|
||||||
|
kGreen3 = BE(0x00FF66FF), //0, 255, 102
|
||||||
|
kWhite = BE(0xFFFFFFFF); //255, 255, 255
|
||||||
|
|
||||||
//only called one, so don't worry about release
|
//only called one, so don't worry about release
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
|
@ -62,6 +77,23 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) copyWithZone: (NSZone *) zone
|
||||||
|
{NSLog(@"copy");
|
||||||
|
TorrentCell * copy = [super copyWithZone: zone];
|
||||||
|
|
||||||
|
copy->fBitmap = nil;
|
||||||
|
copy->fPieces = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{NSLog(@"dealloc");
|
||||||
|
[fBitmap release];
|
||||||
|
if (fPieces)
|
||||||
|
free(fPieces);
|
||||||
|
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point
|
- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point
|
||||||
{
|
{
|
||||||
if (width <= 0.0)
|
if (width <= 0.0)
|
||||||
|
@ -172,10 +204,8 @@
|
||||||
|
|
||||||
- (void) buildAdvancedBar: (float) width point: (NSPoint) point
|
- (void) buildAdvancedBar: (float) width point: (NSPoint) point
|
||||||
{
|
{
|
||||||
Torrent * torrent = [self representedObject];
|
|
||||||
|
|
||||||
//place actual advanced bar
|
//place actual advanced bar
|
||||||
NSImage * image = [torrent advancedBar];
|
NSImage * image = [self advancedBar];
|
||||||
[image setSize: NSMakeSize(width, BAR_HEIGHT)];
|
[image setSize: NSMakeSize(width, BAR_HEIGHT)];
|
||||||
[image compositeToPoint: point operation: NSCompositeSourceOver];
|
[image compositeToPoint: point operation: NSCompositeSourceOver];
|
||||||
|
|
||||||
|
@ -193,6 +223,148 @@
|
||||||
[NSBezierPath strokeRect: NSInsetRect(barBounds, 0.5, 0.5)];
|
[NSBezierPath strokeRect: NSInsetRect(barBounds, 0.5, 0.5)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSImage *) advancedBar
|
||||||
|
{
|
||||||
|
if (!fBitmap)
|
||||||
|
fBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
|
||||||
|
pixelsWide: MAX_PIECES pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
|
||||||
|
isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
||||||
|
|
||||||
|
uint32_t * p;
|
||||||
|
uint8_t * bitmapData = [fBitmap bitmapData];
|
||||||
|
int bytesPerRow = [fBitmap bytesPerRow];
|
||||||
|
|
||||||
|
if (!fPieces)
|
||||||
|
{
|
||||||
|
fPieces = malloc(MAX_PIECES);
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < MAX_PIECES; i++)
|
||||||
|
fPieces[i] = BLANK_PIECE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Torrent * torrent = [self representedObject];
|
||||||
|
int pieceCount = [torrent pieceCount];
|
||||||
|
int8_t * piecesAvailablity = malloc(pieceCount);
|
||||||
|
[torrent getAvailability: piecesAvailablity size: pieceCount];
|
||||||
|
|
||||||
|
//lines 2 to 14: blue, green, or gray depending on piece availability
|
||||||
|
int i, h, index = 0;
|
||||||
|
float increment = (float)pieceCount / MAX_PIECES, indexValue = 0;
|
||||||
|
uint32_t color;
|
||||||
|
BOOL change;
|
||||||
|
for (i = 0; i < MAX_PIECES; i++)
|
||||||
|
{
|
||||||
|
change = NO;
|
||||||
|
if (piecesAvailablity[index] < 0)
|
||||||
|
{
|
||||||
|
if (fPieces[i] != -1)
|
||||||
|
{
|
||||||
|
color = kBlue;
|
||||||
|
fPieces[i] = -1;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (piecesAvailablity[index] == 0)
|
||||||
|
{
|
||||||
|
if (fPieces[i] != 0)
|
||||||
|
{
|
||||||
|
color = kGray;
|
||||||
|
fPieces[i] = 0;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (piecesAvailablity[index] <= 4)
|
||||||
|
{
|
||||||
|
if (fPieces[i] != 1)
|
||||||
|
{
|
||||||
|
color = kGreen1;
|
||||||
|
fPieces[i] = 1;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (piecesAvailablity[index] <= 8)
|
||||||
|
{
|
||||||
|
if (fPieces[i] != 2)
|
||||||
|
{
|
||||||
|
color = kGreen2;
|
||||||
|
fPieces[i] = 2;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (fPieces[i] != 3)
|
||||||
|
{
|
||||||
|
color = kGreen3;
|
||||||
|
fPieces[i] = 3;
|
||||||
|
change = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (change)
|
||||||
|
{
|
||||||
|
//point to pixel (i, 2) and draw "vertically"
|
||||||
|
p = (uint32_t *)(bitmapData + 2 * bytesPerRow) + i;
|
||||||
|
for (h = 2; h < BAR_HEIGHT; h++)
|
||||||
|
{
|
||||||
|
p[0] = color;
|
||||||
|
p = (uint32_t *)((uint8_t *)p + bytesPerRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
indexValue += increment;
|
||||||
|
index = (int)indexValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//determine percentage finished and available
|
||||||
|
int have = rintf((float)MAX_PIECES * [torrent progress]), avail;
|
||||||
|
if (![torrent isActive] || [torrent progress] >= 1.0 || [torrent totalPeersConnected] <= 0)
|
||||||
|
avail = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float * piecesFinished = malloc(pieceCount * sizeof(float));
|
||||||
|
[torrent getAmountFinished: piecesFinished size: pieceCount];
|
||||||
|
|
||||||
|
float available = 0;
|
||||||
|
for (i = 0; i < pieceCount; i++)
|
||||||
|
if (piecesAvailablity[i] > 0)
|
||||||
|
available += 1.0 - piecesFinished[i];
|
||||||
|
|
||||||
|
avail = rintf(MAX_PIECES * available / (float)pieceCount);
|
||||||
|
if (have + avail > MAX_PIECES) //case if both end in .5 and all pieces are available
|
||||||
|
avail--;
|
||||||
|
|
||||||
|
free(piecesFinished);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(piecesAvailablity);
|
||||||
|
|
||||||
|
//first two lines: dark blue to show progression, green to show available
|
||||||
|
p = (uint32_t *)bitmapData;
|
||||||
|
for (i = 0; i < have; i++)
|
||||||
|
{
|
||||||
|
p[i] = kBlue2;
|
||||||
|
p[i + bytesPerRow / 4] = kBlue2;
|
||||||
|
}
|
||||||
|
for (; i < avail + have; i++)
|
||||||
|
{
|
||||||
|
p[i] = kGreen3;
|
||||||
|
p[i + bytesPerRow / 4] = kGreen3;
|
||||||
|
}
|
||||||
|
for (; i < MAX_PIECES; i++)
|
||||||
|
{
|
||||||
|
p[i] = kWhite;
|
||||||
|
p[i + bytesPerRow / 4] = kWhite;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually draw image
|
||||||
|
NSImage * bar = [[NSImage alloc] initWithSize: [fBitmap size]];
|
||||||
|
[bar addRepresentation: fBitmap];
|
||||||
|
[bar setScalesWhenResized: YES];
|
||||||
|
|
||||||
|
return [bar autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) toggleMinimalStatus
|
- (void) toggleMinimalStatus
|
||||||
{
|
{
|
||||||
[fDefaults setBool: ![fDefaults boolForKey: @"SmallStatusRegular"] forKey: @"SmallStatusRegular"];
|
[fDefaults setBool: ![fDefaults boolForKey: @"SmallStatusRegular"] forKey: @"SmallStatusRegular"];
|
||||||
|
|
Loading…
Reference in a new issue