From 932815e4005594e135cad8d1cd7c5fc57fb9fd5b Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 3 Dec 2008 00:18:18 +0000 Subject: [PATCH] show a checkmark in the peer inspector for partial seeds and reflect that status in the tooltip --- macosx/InfoWindowController.m | 29 +++++++++++++++++++++++++++-- macosx/PeerProgressIndicatorCell.h | 3 +++ macosx/PeerProgressIndicatorCell.m | 7 ++++++- macosx/Torrent.m | 3 ++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index a04163b25..dd370cc96 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -28,6 +28,7 @@ #import "FileOutlineView.h" #import "FileOutlineController.h" #import "FileListNode.h" +#import "PeerProgressIndicatorCell.h" #import "TrackerTableView.h" #import "PiecesView.h" #import "QuickLookController.h" @@ -910,6 +911,21 @@ typedef enum return nil; } +- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn + row: (NSInteger) row +{ + if (tableView == fPeerTable) + { + NSString * ident = [tableColumn identifier]; + + if ([ident isEqualToString: @"Progress"]) + { + NSDictionary * peer = [fPeers objectAtIndex: row]; + [(PeerProgressIndicatorCell *)cell setSeed: [[peer objectForKey: @"Seed"] boolValue]]; + } + } +} + - (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn { if (tableView == fPeerTable) @@ -964,8 +980,17 @@ typedef enum NSDictionary * peer = [fPeers objectAtIndex: row]; NSMutableArray * components = [NSMutableArray arrayWithCapacity: 5]; - [components addObject: [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%", - "Inspector -> Peers tab -> table row tooltip"), [[peer objectForKey: @"Progress"] floatValue] * 100.0]]; + CGFloat progress = [[peer objectForKey: @"Progress"] floatValue]; + + NSString * seedStatus; + if (progress < 1.0 && [[peer objectForKey: @"Seed"] boolValue]) + seedStatus = [NSString stringWithFormat: @" (%@)", NSLocalizedString(@"Partial Seed", + "Inspector -> Peers tab -> table row tooltip")]; + else + seedStatus = @""; + + [components addObject: [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%%@", + "Inspector -> Peers tab -> table row tooltip"), progress * 100.0, seedStatus]]; if ([[peer objectForKey: @"Encryption"] boolValue]) [components addObject: NSLocalizedString(@"Encrypted Connection", "Inspector -> Peers tab -> table row tooltip")]; diff --git a/macosx/PeerProgressIndicatorCell.h b/macosx/PeerProgressIndicatorCell.h index 3790f1773..bffeac441 100644 --- a/macosx/PeerProgressIndicatorCell.h +++ b/macosx/PeerProgressIndicatorCell.h @@ -27,6 +27,9 @@ @interface PeerProgressIndicatorCell : NSLevelIndicatorCell { NSDictionary * fAttributes; + BOOL fSeed; } +- (void) setSeed: (BOOL) seed; + @end diff --git a/macosx/PeerProgressIndicatorCell.m b/macosx/PeerProgressIndicatorCell.m index c86423526..d093f876c 100644 --- a/macosx/PeerProgressIndicatorCell.m +++ b/macosx/PeerProgressIndicatorCell.m @@ -40,6 +40,11 @@ [super dealloc]; } +- (void) setSeed: (BOOL) seed +{ + fSeed = seed; +} + - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView { if ([[NSUserDefaults standardUserDefaults] boolForKey: @"DisplayPeerProgressBarNumber"]) @@ -58,7 +63,7 @@ } [super drawWithFrame: cellFrame inView: controlView]; - if ([self floatValue] >= 1.0f) + if (fSeed) { NSImage * checkImage = [NSImage imageNamed: @"CompleteCheck.png"]; [checkImage setFlipped: YES]; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 200c68131..691d7eae7 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1038,12 +1038,13 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo for (int i = 0; i < totalPeers; i++) { tr_peer_stat * peer = &peers[i]; - NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 9]; + NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 10]; [dict setObject: [NSNumber numberWithInt: peer->from] forKey: @"From"]; [dict setObject: [NSString stringWithUTF8String: peer->addr] forKey: @"IP"]; [dict setObject: [NSNumber numberWithInt: peer->port] forKey: @"Port"]; [dict setObject: [NSNumber numberWithFloat: peer->progress] forKey: @"Progress"]; + [dict setObject: [NSNumber numberWithBool: peer->isSeed] forKey: @"Seed"]; [dict setObject: [NSNumber numberWithBool: peer->isEncrypted] forKey: @"Encryption"]; [dict setObject: [NSString stringWithUTF8String: peer->client] forKey: @"Client"]; [dict setObject: [NSString stringWithUTF8String: peer->flagStr] forKey: @"Flags"];