transmission/macosx/NameCell.m

128 lines
4.4 KiB
Mathematica
Raw Normal View History

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.
*****************************************************************************/
#include "NameCell.h"
#include "Utils.h"
@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: @" (%@)",
stringForFileSize( stat->info.totalSize )];
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-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];
pen.x += 5; pen.y += 5;
2006-01-12 18:29:20 +00:00
string = [NSString stringWithFormat: @"%@%@",
stringFittingInWidth( fNameString, cellFrame.size.width -
35 - widthForString( fSizeString, 12 ), 12 ), fSizeString];
[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-12 18:29:20 +00:00
string = stringFittingInWidth( fPeersString,
cellFrame.size.width - 40, 10 );
[string drawAtPoint: pen withAttributes: attributes];
2006-01-12 17:43:21 +00:00
[view unlockFocus];
}
@end