2006-01-12 17:43:21 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2005 Eric Petit
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2006-01-20 01:13:21 +00:00
|
|
|
#import "NameCell.h"
|
|
|
|
#import "StringAdditions.h"
|
|
|
|
#import "Utils.h"
|
2006-01-12 17:43:21 +00:00
|
|
|
|
|
|
|
@implementation NameCell
|
|
|
|
|
2006-01-12 18:53:05 +00:00
|
|
|
- (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:53:05 +00:00
|
|
|
fWhiteText = w;
|
|
|
|
|
2006-01-12 18:29:20 +00:00
|
|
|
fNameString = [NSString stringWithUTF8String: stat->info.name];
|
|
|
|
fSizeString = [NSString stringWithFormat: @" (%@)",
|
2006-01-20 01:13:21 +00:00
|
|
|
[NSString stringForFileSize: stat->info.totalSize]];
|
2006-01-29 19:18:03 +00:00
|
|
|
|
2006-01-31 04:19:31 +00:00
|
|
|
if( stat->folder )
|
|
|
|
fIcon = [[NSWorkspace sharedWorkspace] iconForFile:
|
|
|
|
[[NSString stringWithUTF8String: stat->folder]
|
|
|
|
stringByAppendingPathComponent: fNameString]];
|
|
|
|
else
|
|
|
|
/* XXX The torrent is still being opened, the destination hasn't
|
|
|
|
been chosen yet. It shouldn't be added to the table view so
|
|
|
|
soon */
|
|
|
|
fIcon = [[NSWorkspace sharedWorkspace] iconForFile: @"/System"];
|
2006-01-29 19:18:03 +00:00
|
|
|
[fIcon setFlipped: YES];
|
|
|
|
|
2006-01-12 18:29:20 +00:00
|
|
|
fTimeString = @"";
|
|
|
|
fPeersString = @"";
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:29:20 +00:00
|
|
|
if( stat->status & TR_STATUS_PAUSE )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:29:20 +00:00
|
|
|
fTimeString = [NSString stringWithFormat:
|
|
|
|
@"Paused (%.2f %%)", 100 * stat->progress];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:29:20 +00:00
|
|
|
else if( stat->status & TR_STATUS_CHECK )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:29:20 +00:00
|
|
|
fTimeString = [NSString stringWithFormat:
|
|
|
|
@"Checking existing files (%.2f %%)", 100 * stat->progress];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:29:20 +00:00
|
|
|
else if( stat->status & TR_STATUS_DOWNLOAD )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:29:20 +00:00
|
|
|
if( stat->eta < 0 )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:29:20 +00:00
|
|
|
fTimeString = [NSString stringWithFormat:
|
|
|
|
@"Finishing in --:--:-- (%.2f %%)", 100 * stat->progress];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-12 18:29:20 +00:00
|
|
|
fTimeString = [NSString stringWithFormat:
|
2006-01-12 17:43:21 +00:00
|
|
|
@"Finishing in %02d:%02d:%02d (%.2f %%)",
|
2006-01-12 18:29:20 +00:00
|
|
|
stat->eta / 3600, ( stat->eta / 60 ) % 60,
|
|
|
|
stat->eta % 60, 100 * stat->progress];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:29:20 +00:00
|
|
|
fPeersString = [NSString stringWithFormat:
|
2006-01-12 17:43:21 +00:00
|
|
|
@"Downloading from %d of %d peer%s",
|
2006-01-12 18:29:20 +00:00
|
|
|
stat->peersUploading, stat->peersTotal,
|
|
|
|
( stat->peersTotal == 1 ) ? "" : "s"];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:29:20 +00:00
|
|
|
else if( stat->status & TR_STATUS_SEED )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:29:20 +00:00
|
|
|
fTimeString = [NSString stringWithFormat:
|
2006-01-12 17:43:21 +00:00
|
|
|
@"Seeding, uploading to %d of %d peer%s",
|
2006-01-12 18:29:20 +00:00
|
|
|
stat->peersDownloading, stat->peersTotal,
|
|
|
|
( stat->peersTotal == 1 ) ? "" : "s"];
|
|
|
|
}
|
|
|
|
else if( stat->status & TR_STATUS_STOPPING )
|
|
|
|
{
|
|
|
|
fTimeString = @"Stopping...";
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:29:20 +00:00
|
|
|
|
|
|
|
if( ( stat->status & ( TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) ) &&
|
|
|
|
( stat->status & TR_TRACKER_ERROR ) )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:29:20 +00:00
|
|
|
fPeersString = [NSString stringWithFormat: @"%@%@",
|
|
|
|
@"Error: ", [NSString stringWithUTF8String: stat->error]];
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view
|
|
|
|
{
|
|
|
|
NSString * string;
|
|
|
|
NSPoint pen;
|
|
|
|
NSMutableDictionary * attributes;
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:29:20 +00:00
|
|
|
if( ![view lockFocusIfCanDraw] )
|
2006-01-12 17:43:21 +00:00
|
|
|
{
|
2006-01-12 18:29:20 +00:00
|
|
|
return;
|
2006-01-12 17:43:21 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 18:29:20 +00:00
|
|
|
pen = cellFrame.origin;
|
2006-01-29 19:18:03 +00:00
|
|
|
float cellWidth = cellFrame.size.width;
|
|
|
|
|
|
|
|
pen.x += 5;
|
|
|
|
pen.y += 5;
|
|
|
|
[fIcon drawAtPoint: pen fromRect:
|
|
|
|
NSMakeRect(0,0,[fIcon size].width,[fIcon size].height)
|
|
|
|
operation: NSCompositeSourceOver fraction: 1.0];
|
2006-01-12 18:29:20 +00:00
|
|
|
|
2006-01-12 18:53:05 +00:00
|
|
|
attributes = [NSMutableDictionary dictionaryWithCapacity: 2];
|
|
|
|
[attributes setObject: fWhiteText ? [NSColor whiteColor] :
|
|
|
|
[NSColor blackColor] forKey: NSForegroundColorAttributeName];
|
|
|
|
|
|
|
|
[attributes setObject: [NSFont messageFontOfSize: 12.0]
|
2006-01-12 17:43:21 +00:00
|
|
|
forKey: NSFontAttributeName];
|
|
|
|
|
2006-01-29 19:18:03 +00:00
|
|
|
pen.x += 37;
|
|
|
|
string = [[fNameString stringFittingInWidth: cellWidth -
|
|
|
|
72 - [fSizeString sizeWithAttributes: attributes].width
|
2006-01-20 01:13:21 +00:00
|
|
|
withAttributes: attributes] stringByAppendingString: fSizeString];
|
2006-01-12 18:29:20 +00:00
|
|
|
[string drawAtPoint: pen withAttributes: attributes];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
2006-01-12 18:53:05 +00:00
|
|
|
[attributes setObject: [NSFont messageFontOfSize: 10.0]
|
2006-01-12 17:43:21 +00:00
|
|
|
forKey: NSFontAttributeName];
|
|
|
|
|
|
|
|
pen.x += 5; pen.y += 20;
|
2006-01-12 18:29:20 +00:00
|
|
|
[fTimeString drawAtPoint: pen withAttributes: attributes];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
|
|
|
pen.x += 0; pen.y += 15;
|
2006-01-20 01:13:21 +00:00
|
|
|
string = [fPeersString stringFittingInWidth: cellFrame.size.width -
|
2006-01-29 19:18:03 +00:00
|
|
|
77 withAttributes: attributes];
|
2006-01-12 18:29:20 +00:00
|
|
|
[string drawAtPoint: pen withAttributes: attributes];
|
2006-01-12 17:43:21 +00:00
|
|
|
|
|
|
|
[view unlockFocus];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|