diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 85d2cf6f9..8d60cd085 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -45,7 +45,7 @@ NSUserDefaults * fDefaults; NSImage * fIcon, * fIconFlipped, * fIconSmall; - NSMutableString * fNameString, * fProgressString, * fStatusString, * fShortStatusString; + NSMutableString * fNameString, * fProgressString, * fStatusString, * fShortStatusString, * fRemainingTimeString; int fStopRatioSetting; float fRatioLimit; @@ -114,9 +114,10 @@ - (BOOL) isPaused; - (BOOL) justFinished; -- (NSString *) progressString; -- (NSString *) statusString; -- (NSString *) shortStatusString; +- (NSString *) progressString; +- (NSString *) statusString; +- (NSString *) shortStatusString; +- (NSString *) remainingTimeString; - (int) seeders; - (int) leechers; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 88c039ea5..d39cb2646 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -119,6 +119,7 @@ [fProgressString release]; [fStatusString release]; [fShortStatusString release]; + [fRemainingTimeString release]; } [super dealloc]; } @@ -187,6 +188,7 @@ [fStatusString setString: tempString]; [fShortStatusString setString: tempString]; + [fRemainingTimeString setString: tempString]; break; @@ -196,18 +198,27 @@ @"Downloading from %d of %d peer%s", [self peersUploading], [self totalPeers], [self totalPeers] == 1 ? "" : "s"]; + [fRemainingTimeString setString: @""]; int eta = [self eta]; if (eta < 0) + { + [fRemainingTimeString setString: @"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 - [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; @@ -510,6 +521,11 @@ return fShortStatusString; } +- (NSString *) remainingTimeString +{ + return fRemainingTimeString; +} + - (int) seeders { return fStat->seeders; @@ -667,7 +683,8 @@ fProgressString = [[NSMutableString alloc] initWithCapacity: 50]; fStatusString = [[NSMutableString alloc] initWithCapacity: 75]; - fShortStatusString = [[NSMutableString alloc] initWithCapacity: 50]; + fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30]; + fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30]; [self update]; return self; diff --git a/macosx/TorrentCell.h b/macosx/TorrentCell.h index 0284eb5f3..8c2d11545 100644 --- a/macosx/TorrentCell.h +++ b/macosx/TorrentCell.h @@ -31,10 +31,15 @@ @interface TorrentCell : NSCell { Torrent * fTorrent; + BOOL fNormalStatus; NSUserDefaults * fDefaults; } -- (void) setTorrent: (Torrent *) torrent; + +- (void) setTorrent: (Torrent *) torrent; + +- (void) toggleMinimalStatus; + @end #endif diff --git a/macosx/TorrentCell.m b/macosx/TorrentCell.m index c18e54767..611cd445e 100644 --- a/macosx/TorrentCell.m +++ b/macosx/TorrentCell.m @@ -63,6 +63,8 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 { if ((self = [super init])) { + fNormalStatus = YES; + fDefaults = [NSUserDefaults standardUserDefaults]; 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]; } +- (void) toggleMinimalStatus +{ + fNormalStatus = !fNormalStatus; +} + - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) 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 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]; NSAttributedString * nameString = [[fTorrent name] attributedStringFittingInWidth: mainWidth - [statusString size].width - LINE_PADDING attributes: nameAttributes]; diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 5af9cf60e..89f913545 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -23,6 +23,7 @@ *****************************************************************************/ #import "TorrentTableView.h" +#import "TorrentCell.h" #import "Controller.h" #import "Torrent.h" @@ -41,6 +42,7 @@ - (BOOL) pointInPauseRect: (NSPoint) point; - (BOOL) pointInRevealRect: (NSPoint) point; - (BOOL) pointInIconRect: (NSPoint) point; +- (BOOL) pointInMinimalStatusRect: (NSPoint) point; @end @@ -94,7 +96,12 @@ fClickPoint = NSZeroPoint; } else if (![self pointInPauseRect: fClickPoint] && ![self pointInRevealRect: fClickPoint]) + { + if ([self pointInMinimalStatusRect: fClickPoint]) + [(TorrentCell *)[[self tableColumnWithIdentifier: @"Torrent"] dataCell] toggleMinimalStatus]; + [super mouseDown: event]; + } else; [self display]; @@ -263,7 +270,7 @@ int row = [self rowAtPoint: point]; if (row < 0) return NO; - + NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row]; NSSize iconSize = [fDefaults boolForKey: @"SmallView"] ? [[[fTorrents objectAtIndex: row] iconSmall] size] : [[[fTorrents objectAtIndex: row] iconFlipped] size]; @@ -274,6 +281,20 @@ 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 { return NSPointInRect(point, [self pauseRectForRow: [self rowAtPoint: point]]);