From 78b08324ea5f10c6afc7959034f21546814b72b7 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 27 Feb 2008 19:34:55 +0000 Subject: [PATCH] show amount selected in open window --- macosx/AddWindowController.h | 2 ++ macosx/AddWindowController.m | 37 ++++++++++++++++++++++++------------ macosx/Torrent.h | 1 + macosx/Torrent.m | 10 +++++++--- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/macosx/AddWindowController.h b/macosx/AddWindowController.h index 98fd33616..ba2b3467a 100644 --- a/macosx/AddWindowController.h +++ b/macosx/AddWindowController.h @@ -60,6 +60,8 @@ - (void) verifyLocalData: (id) sender; +- (void) updateStatusField: (NSNotification *) notification; + - (void) updateGroupMenu: (NSNotification *) notification; - (void) showGroupsWindow: (id) sender; diff --git a/macosx/AddWindowController.m b/macosx/AddWindowController.m index 3d7f38c9e..f8222910d 100644 --- a/macosx/AddWindowController.m +++ b/macosx/AddWindowController.m @@ -69,6 +69,9 @@ - (void) awakeFromNib { + [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(updateStatusField:) + name: @"TorrentFileCheckChange" object: fTorrent]; + [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(updateGroupMenu:) name: @"UpdateGroups" object: nil]; @@ -83,18 +86,7 @@ [fIconView setImage: icon]; [icon release]; - NSString * statusString = [NSString stringForFileSize: [fTorrent size]]; - if ([fTorrent folder]) - { - NSString * fileString; - int count = [fTorrent fileCount]; - if (count != 1) - fileString = [NSString stringWithFormat: NSLocalizedString(@"%d Files, ", "Add torrent -> info"), count]; - else - fileString = NSLocalizedString(@"1 File, ", "Add torrent -> info"); - statusString = [fileString stringByAppendingString: statusString]; - } - [fStatusField setStringValue: statusString]; + [self updateStatusField: nil]; [self setGroupsMenu]; [fGroupPopUp selectItemWithTag: -1]; @@ -212,6 +204,27 @@ [fFileController reloadData]; } +- (void) updateStatusField: (NSNotification *) notification +{ + NSString * statusString = [NSString stringForFileSize: [fTorrent size]]; + if ([fTorrent folder]) + statusString = [statusString stringByAppendingFormat: NSLocalizedString(@" (%@ selected)", "Add torrent -> info"), + [NSString stringForFileSize: [fTorrent totalSizeSelected]]]; + + if ([fTorrent folder]) + { + NSString * fileString; + int count = [fTorrent fileCount]; + if (count != 1) + fileString = [NSString stringWithFormat: NSLocalizedString(@"%d Files, ", "Add torrent -> info"), count]; + else + fileString = NSLocalizedString(@"1 File, ", "Add torrent -> info"); + statusString = [fileString stringByAppendingString: statusString]; + } + + [fStatusField setStringValue: statusString]; +} + - (void) updateGroupMenu: (NSNotification *) notification { [self setGroupsMenu]; diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 76d18296b..41dace2f2 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -216,6 +216,7 @@ typedef enum - (float) totalRate; - (uint64_t) haveVerified; - (uint64_t) haveTotal; +- (uint64_t) totalSizeSelected; - (uint64_t) downloadedTotal; - (uint64_t) uploadedTotal; - (uint64_t) failedHash; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index b3af41050..46bc74516 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -809,7 +809,6 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * - (float) progress { return fStat->percentComplete; - //return (float)[self haveTotal] / [self size]; } - (float) progressDone @@ -939,9 +938,8 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * { if ([fDefaults boolForKey: @"DisplayStatusProgressSelected"]) { - uint64_t have = [self haveTotal]; string = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@ selected (%.2f%%)", "Torrent -> progress string"), - [NSString stringForFileSize: have], [NSString stringForFileSize: have + [self sizeLeft]], + [NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self totalSizeSelected]], 100.0 * [self progressDone]]; } else @@ -1220,6 +1218,11 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * return [self haveVerified] + fStat->haveUnchecked; } +- (uint64_t) totalSizeSelected +{ + return [self haveTotal] + [self sizeLeft]; +} + - (uint64_t) downloadedTotal { return fStat->downloadedEver; @@ -1352,6 +1355,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * free(files); [self update]; + [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFileCheckChange" object: self]; } - (void) setFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet