Differentiate between valid amount downloaded and total amount downloaded, showing the valid amount in the main window.

This commit is contained in:
Mitchell Livingston 2006-06-14 03:00:27 +00:00
parent 4c9421cfa4
commit 69fee0da51
7 changed files with 47 additions and 38 deletions

View File

@ -12,7 +12,8 @@
fDataLocationField = NSTextField;
fDateStartedField = NSTextField;
fDownloadRateField = NSTextField;
fDownloadedField = NSTextField;
fDownloadedTotalField = NSTextField;
fDownloadedValidField = NSTextField;
fDownloadingFromField = NSTextField;
fFileTable = NSTableView;
fHashField = NSTextField;
@ -32,7 +33,7 @@
fTorrentLocationField = NSTextField;
fTrackerField = NSTextField;
fUploadRateField = NSTextField;
fUploadedField = NSTextField;
fUploadedTotalField = NSTextField;
fUploadingToField = NSTextField;
};
SUPERCLASS = NSWindowController;

View File

@ -40,8 +40,8 @@
* fDateStartedField,
* fStateField, * fPercentField,
* fDownloadRateField, * fUploadRateField,
* fDownloadedField, * fUploadedField, * fRatioField,
* fSeedersField, * fLeechersField,
* fDownloadedValidField, * fDownloadedTotalField, * fUploadedTotalField,
* fRatioField, * fSeedersField, * fLeechersField,
* fConnectedPeersField, * fDownloadingFromField, * fUploadingToField;
IBOutlet NSTableView * fFileTable;

View File

@ -34,8 +34,9 @@
#define TAB_OPTIONS_IDENT @"Options"
#define TAB_FILES_IDENT @"Files"
#define TAB_INFO_HEIGHT 191.0
#define TAB_STATUS_HEIGHT 241.0
//15 spacing at the bottom of each tab
#define TAB_INFO_HEIGHT 196.0
#define TAB_STATUS_HEIGHT 262.0
#define TAB_OPTIONS_HEIGHT 82.0
#define TAB_FILES_HEIGHT 250.0
@ -105,8 +106,9 @@
[fDownloadRateField setStringValue: @""];
[fUploadRateField setStringValue: @""];
[fDownloadedField setStringValue: @""];
[fUploadedField setStringValue: @""];
[fDownloadedValidField setStringValue: @""];
[fDownloadedTotalField setStringValue: @""];
[fUploadedTotalField setStringValue: @""];
}
[fImageView setImage: fAppIcon];
@ -236,8 +238,8 @@
int numberSelected = [fTorrents count];
if (numberSelected > 0)
{
float downloadRate = 0, uploadRate = 0;
uint64_t downloaded = 0, uploaded = 0;
float downloadRate = 0, uploadRate = 0, downloadedValid;
uint64_t downloadedTotal = 0, uploadedTotal = 0;
Torrent * torrent;
NSEnumerator * enumerator = [fTorrents objectEnumerator];
while ((torrent = [enumerator nextObject]))
@ -245,15 +247,17 @@
downloadRate += [torrent downloadRate];
uploadRate += [torrent uploadRate];
downloaded += [torrent downloaded];
uploaded += [torrent uploaded];
downloadedValid += [torrent downloadedValid];
downloadedTotal += [torrent downloadedTotal];
uploadedTotal += [torrent uploadedTotal];
}
[fDownloadRateField setStringValue: [NSString stringForSpeed: downloadRate]];
[fUploadRateField setStringValue: [NSString stringForSpeed: uploadRate]];
[fDownloadedField setStringValue: [NSString stringForFileSize: downloaded]];
[fUploadedField setStringValue: [NSString stringForFileSize: uploaded]];
[fDownloadedValidField setStringValue: [NSString stringForFileSize: downloadedValid]];
[fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
[fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
if (numberSelected == 1)
{
@ -279,7 +283,7 @@
stringWithInt: [torrent peersDownloading]] : @"N/A"];
[fRatioField setStringValue: [NSString stringForRatioWithDownload:
downloaded upload: uploaded]];
downloadedTotal upload: uploadedTotal]];
}
}
}

View File

@ -107,8 +107,9 @@
- (float) downloadRate;
- (float) uploadRate;
- (uint64_t) downloaded;
- (uint64_t) uploaded;
- (float) downloadedValid;
- (uint64_t) downloadedTotal;
- (uint64_t) uploadedTotal;
- (NSArray *) fileList;

View File

@ -35,7 +35,7 @@
- (id) initForSuccessWithDate: (NSDate *) date stopRatioSetting: (NSNumber *)
stopRatioSetting ratioLimit: (NSNumber *) ratioLimit;
- (void) trashPath: (NSString *) path;
- (void) trashFile: (NSString *) path;
@end
@ -47,11 +47,8 @@
id torrent = [self initWithPath: path lib: lib date: nil
stopRatioSetting: nil ratioLimit: nil];
if (!torrent)
return nil;
if (fPrivateTorrent && [fDefaults boolForKey: @"DeleteOriginalTorrent"])
[self trashPath: path];
if (torrent && fPrivateTorrent && [fDefaults boolForKey: @"DeleteOriginalTorrent"])
[self trashFile: path];
return torrent;
}
@ -59,19 +56,20 @@
- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib
{
//load from saved torrent file if set to, otherwise try to load from where torrent file should be
id torrent;
NSNumber * privateCopy;
if ((privateCopy = [history objectForKey: @"PrivateCopy"]) && [privateCopy boolValue])
self = [self initWithHash: [history objectForKey: @"TorrentHash"]
torrent = [self initWithHash: [history objectForKey: @"TorrentHash"]
lib: lib date: [history objectForKey: @"Date"]
stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
ratioLimit: [history objectForKey: @"RatioLimit"]];
else
self = [self initWithPath: [history objectForKey: @"TorrentPath"]
torrent = [self initWithPath: [history objectForKey: @"TorrentPath"]
lib: lib date: [history objectForKey: @"Date"]
stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
ratioLimit: [history objectForKey: @"RatioLimit"]];
if (self)
if (torrent)
{
NSString * downloadFolder;
if (!(downloadFolder = [history objectForKey: @"DownloadFolder"]))
@ -83,7 +81,7 @@
if (!(paused = [history objectForKey: @"Paused"]) || [paused isEqualToString: @"NO"])
[self start];
}
return self;
return torrent;
}
- (NSDictionary *) history
@ -156,11 +154,11 @@
[fProgressString setString: @""];
if ([self progress] < 1.0)
[fProgressString appendFormat: @"%@ of %@ (%.2f%%)", [NSString stringForFileSize:
[self downloaded]], [NSString stringForFileSize: [self size]], 100 * [self progress]];
[self downloadedValid]], [NSString stringForFileSize: [self size]], 100 * [self progress]];
else
[fProgressString appendFormat: @"%@, uploaded %@ (ratio: %@)", [NSString stringForFileSize:
[self size]], [NSString stringForFileSize: [self uploaded]],
[NSString stringForRatioWithDownload: [self downloaded] upload: [self uploaded]]];
[self size]], [NSString stringForFileSize: [self uploadedTotal]],
[NSString stringForRatioWithDownload: [self downloadedTotal] upload: [self uploadedTotal]]];
switch( fStat->status )
{
@ -265,8 +263,8 @@
- (float) ratio
{
float downloaded = [self downloaded];
return downloaded > 0 ? (float)[self uploaded] / downloaded : -1;
float downloaded = [self downloadedTotal];
return downloaded > 0 ? (float)[self uploadedTotal] / downloaded : -1;
}
- (int) stopRatioSetting
@ -298,7 +296,7 @@
- (void) trashData
{
[self trashPath: [self dataLocation]];
[self trashFile: [self dataLocation]];
}
- (NSImage *) icon
@ -458,12 +456,17 @@
return fStat->rateUpload;
}
- (uint64_t) downloaded
- (float) downloadedValid
{
return [self progress] * [self size];
}
- (uint64_t) downloadedTotal
{
return fStat->downloaded;
}
- (uint64_t) uploaded
- (uint64_t) uploadedTotal
{
return fStat->uploaded;
}
@ -573,7 +576,7 @@
}
- (void) trashPath: (NSString *) path
- (void) trashFile: (NSString *) path
{
if( ![[NSWorkspace sharedWorkspace] performFileOperation:
NSWorkspaceRecycleOperation source:

View File

@ -136,11 +136,10 @@ static uint32_t kRed = 0xFF6450FF, //255, 100, 80
{
float completedWidth = [fTorrent progress] * width,
remainingWidth = width - completedWidth;
NSImage * barLeftEnd, * barRightEnd;
BOOL isActive = [fTorrent isActive];
//left end
NSImage * barLeftEnd;
if (remainingWidth == width)
barLeftEnd = fProgressEndWhite;
else if (isActive)
@ -159,6 +158,7 @@ static uint32_t kRed = 0xFF6450FF, //255, 100, 80
[self placeBar: fProgressWhite width: remainingWidth point: point];
//right end
NSImage * barRightEnd;
if (completedWidth < width)
barRightEnd = fProgressEndWhite;
else if (isActive)