Clicking in general area of status string in minimal view will toggle between speeds and remaining time for downloading transfers.

This commit is contained in:
Mitchell Livingston 2006-07-25 00:59:14 +00:00
parent 42a838d155
commit 2d66761e19
5 changed files with 70 additions and 16 deletions

View File

@ -45,7 +45,7 @@
NSUserDefaults * fDefaults; NSUserDefaults * fDefaults;
NSImage * fIcon, * fIconFlipped, * fIconSmall; NSImage * fIcon, * fIconFlipped, * fIconSmall;
NSMutableString * fNameString, * fProgressString, * fStatusString, * fShortStatusString; NSMutableString * fNameString, * fProgressString, * fStatusString, * fShortStatusString, * fRemainingTimeString;
int fStopRatioSetting; int fStopRatioSetting;
float fRatioLimit; float fRatioLimit;
@ -114,9 +114,10 @@
- (BOOL) isPaused; - (BOOL) isPaused;
- (BOOL) justFinished; - (BOOL) justFinished;
- (NSString *) progressString; - (NSString *) progressString;
- (NSString *) statusString; - (NSString *) statusString;
- (NSString *) shortStatusString; - (NSString *) shortStatusString;
- (NSString *) remainingTimeString;
- (int) seeders; - (int) seeders;
- (int) leechers; - (int) leechers;

View File

@ -119,6 +119,7 @@
[fProgressString release]; [fProgressString release];
[fStatusString release]; [fStatusString release];
[fShortStatusString release]; [fShortStatusString release];
[fRemainingTimeString release];
} }
[super dealloc]; [super dealloc];
} }
@ -187,6 +188,7 @@
[fStatusString setString: tempString]; [fStatusString setString: tempString];
[fShortStatusString setString: tempString]; [fShortStatusString setString: tempString];
[fRemainingTimeString setString: tempString];
break; break;
@ -196,18 +198,27 @@
@"Downloading from %d of %d peer%s", [self peersUploading], [self totalPeers], @"Downloading from %d of %d peer%s", [self peersUploading], [self totalPeers],
[self totalPeers] == 1 ? "" : "s"]; [self totalPeers] == 1 ? "" : "s"];
[fRemainingTimeString setString: @""];
int eta = [self eta]; int eta = [self eta];
if (eta < 0) if (eta < 0)
{
[fRemainingTimeString setString: @"Unknown"];
[fProgressString appendString: @" - remaining time unknown"]; [fProgressString appendString: @" - remaining time unknown"];
else if (eta < 60) }
[fProgressString appendFormat: @" - %d sec remaining", eta];
else if (eta < 3600) //60 * 60
[fProgressString appendFormat: @" - %d min %02d sec remaining", eta / 60, eta % 60];
else if (eta < 86400) //24 * 60 * 60
[fProgressString appendFormat: @" - %d hr %02d min remaining", eta / 3600, (eta / 60) % 60];
else else
[fProgressString appendFormat: @" - %d day%s %d hr remaining", {
eta / 86400, eta / 86400 == 1 ? "" : "s", (eta / 3600) % 24]; if (eta < 60)
[fRemainingTimeString appendFormat: @"%d sec", eta];
else if (eta < 3600) //60 * 60
[fRemainingTimeString appendFormat: @"%d min %02d sec", eta / 60, eta % 60];
else if (eta < 86400) //24 * 60 * 60
[fRemainingTimeString appendFormat: @"%d hr %02d min", eta / 3600, (eta / 60) % 60];
else
[fRemainingTimeString appendFormat: @"%d day%s %d hr",
eta / 86400, eta / 86400 == 1 ? "" : "s", (eta / 3600) % 24];
[fProgressString appendFormat: @" - %@ remaining", fRemainingTimeString];
}
break; break;
@ -510,6 +521,11 @@
return fShortStatusString; return fShortStatusString;
} }
- (NSString *) remainingTimeString
{
return fRemainingTimeString;
}
- (int) seeders - (int) seeders
{ {
return fStat->seeders; return fStat->seeders;
@ -667,7 +683,8 @@
fProgressString = [[NSMutableString alloc] initWithCapacity: 50]; fProgressString = [[NSMutableString alloc] initWithCapacity: 50];
fStatusString = [[NSMutableString alloc] initWithCapacity: 75]; fStatusString = [[NSMutableString alloc] initWithCapacity: 75];
fShortStatusString = [[NSMutableString alloc] initWithCapacity: 50]; fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30];
fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30];
[self update]; [self update];
return self; return self;

View File

@ -31,10 +31,15 @@
@interface TorrentCell : NSCell @interface TorrentCell : NSCell
{ {
Torrent * fTorrent; Torrent * fTorrent;
BOOL fNormalStatus;
NSUserDefaults * fDefaults; NSUserDefaults * fDefaults;
} }
- (void) setTorrent: (Torrent *) torrent;
- (void) setTorrent: (Torrent *) torrent;
- (void) toggleMinimalStatus;
@end @end
#endif #endif

View File

@ -63,6 +63,8 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
{ {
if ((self = [super init])) if ((self = [super init]))
{ {
fNormalStatus = YES;
fDefaults = [NSUserDefaults standardUserDefaults]; fDefaults = [NSUserDefaults standardUserDefaults];
NSSize startSize = NSMakeSize(100.0, BAR_HEIGHT); NSSize startSize = NSMakeSize(100.0, BAR_HEIGHT);
@ -280,6 +282,11 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
[fProgressEndAdvanced compositeToPoint: point operation: NSCompositeSourceOver]; [fProgressEndAdvanced compositeToPoint: point operation: NSCompositeSourceOver];
} }
- (void) toggleMinimalStatus
{
fNormalStatus = !fNormalStatus;
}
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view
{ {
BOOL highlighted = [self isHighlighted] && [[self highlightColorWithFrame: cellFrame inView: view] BOOL highlighted = [self isHighlighted] && [[self highlightColorWithFrame: cellFrame inView: view]
@ -355,7 +362,10 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
//name and status string //name and status string
float mainWidth = cellFrame.size.width - iconSize.width - 3.0 * PADDING - EXTRA_NAME_SHIFT; float mainWidth = cellFrame.size.width - iconSize.width - 3.0 * PADDING - EXTRA_NAME_SHIFT;
NSAttributedString * statusString = [[[NSAttributedString alloc] initWithString: [fTorrent shortStatusString] NSString * realStatusString = !fNormalStatus && [fTorrent isActive] && [fTorrent progress] < 1.0
? [fTorrent remainingTimeString] : [fTorrent shortStatusString];
NSAttributedString * statusString = [[[NSAttributedString alloc] initWithString: realStatusString
attributes: statusAttributes] autorelease]; attributes: statusAttributes] autorelease];
NSAttributedString * nameString = [[fTorrent name] attributedStringFittingInWidth: NSAttributedString * nameString = [[fTorrent name] attributedStringFittingInWidth:
mainWidth - [statusString size].width - LINE_PADDING attributes: nameAttributes]; mainWidth - [statusString size].width - LINE_PADDING attributes: nameAttributes];

View File

@ -23,6 +23,7 @@
*****************************************************************************/ *****************************************************************************/
#import "TorrentTableView.h" #import "TorrentTableView.h"
#import "TorrentCell.h"
#import "Controller.h" #import "Controller.h"
#import "Torrent.h" #import "Torrent.h"
@ -41,6 +42,7 @@
- (BOOL) pointInPauseRect: (NSPoint) point; - (BOOL) pointInPauseRect: (NSPoint) point;
- (BOOL) pointInRevealRect: (NSPoint) point; - (BOOL) pointInRevealRect: (NSPoint) point;
- (BOOL) pointInIconRect: (NSPoint) point; - (BOOL) pointInIconRect: (NSPoint) point;
- (BOOL) pointInMinimalStatusRect: (NSPoint) point;
@end @end
@ -94,7 +96,12 @@
fClickPoint = NSZeroPoint; fClickPoint = NSZeroPoint;
} }
else if (![self pointInPauseRect: fClickPoint] && ![self pointInRevealRect: fClickPoint]) else if (![self pointInPauseRect: fClickPoint] && ![self pointInRevealRect: fClickPoint])
{
if ([self pointInMinimalStatusRect: fClickPoint])
[(TorrentCell *)[[self tableColumnWithIdentifier: @"Torrent"] dataCell] toggleMinimalStatus];
[super mouseDown: event]; [super mouseDown: event];
}
else; else;
[self display]; [self display];
@ -263,7 +270,7 @@
int row = [self rowAtPoint: point]; int row = [self rowAtPoint: point];
if (row < 0) if (row < 0)
return NO; return NO;
NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row]; NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row];
NSSize iconSize = [fDefaults boolForKey: @"SmallView"] ? [[[fTorrents objectAtIndex: row] iconSmall] size] NSSize iconSize = [fDefaults boolForKey: @"SmallView"] ? [[[fTorrents objectAtIndex: row] iconSmall] size]
: [[[fTorrents objectAtIndex: row] iconFlipped] size]; : [[[fTorrents objectAtIndex: row] iconFlipped] size];
@ -274,6 +281,20 @@
return NSPointInRect(point, iconRect); return NSPointInRect(point, iconRect);
} }
- (BOOL) pointInMinimalStatusRect: (NSPoint) point
{
int row = [self rowAtPoint: point];
if (row < 0 || ![fDefaults boolForKey: @"SmallView"])
return NO;
const STATUS_WIDTH = 130.0;
NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row];
NSRect statusRect = NSMakeRect(NSMaxX(cellRect) - STATUS_WIDTH, cellRect.origin.y,
STATUS_WIDTH, cellRect.size.height - BUTTON_WIDTH);
return NSPointInRect(point, statusRect);
}
- (BOOL) pointInPauseRect: (NSPoint) point - (BOOL) pointInPauseRect: (NSPoint) point
{ {
return NSPointInRect(point, [self pauseRectForRow: [self rowAtPoint: point]]); return NSPointInRect(point, [self pauseRectForRow: [self rowAtPoint: point]]);