From f2bbae3fd836780342b970a32d902a0462f041f5 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Thu, 31 Dec 2009 03:19:54 +0000 Subject: [PATCH] some more insignificant changes I have sitting around locally --- libtransmission/torrent.c | 2 +- macosx/AboutWindowController.m | 2 +- macosx/FileNameCell.m | 52 ++++++++++++++++------------------ macosx/FileOutlineController.m | 2 +- macosx/FilterButton.m | 2 +- macosx/NSStringAdditions.m | 4 ++- macosx/Torrent.m | 12 +++++--- 7 files changed, 40 insertions(+), 36 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 14a8b696b..61eff640b 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -1125,7 +1125,7 @@ tr_torrentFiles( const tr_torrent * tor, for( i=0; iinfo.files[i].length : fileBytesCompleted( tor, i ); walk->bytesCompleted = b; - walk->progress = tor->info.files[i].length > 0.0 ? ( (float)b / tor->info.files[i].length ) : 1.0; + walk->progress = tor->info.files[i].length > 0 ? ( (float)b / tor->info.files[i].length ) : 1.0; } if( fileCount ) diff --git a/macosx/AboutWindowController.m b/macosx/AboutWindowController.m index edf6a7dc0..822e3bfe3 100644 --- a/macosx/AboutWindowController.m +++ b/macosx/AboutWindowController.m @@ -47,7 +47,7 @@ AboutWindowController * fAboutBoxInstance = nil; [[NSBundle mainBundle] pathForResource: @"Credits" ofType: @"rtf"] documentAttributes: nil] autorelease]]; //size license button - const CGFloat oldButtonWidth = [fLicenseButton frame].size.width; + const CGFloat oldButtonWidth = NSWidth([fLicenseButton frame]); [fLicenseButton setTitle: NSLocalizedString(@"License", "About window -> license button")]; [fLicenseButton sizeToFit]; diff --git a/macosx/FileNameCell.m b/macosx/FileNameCell.m index 55a3c6bc0..652c64cb3 100644 --- a/macosx/FileNameCell.m +++ b/macosx/FileNameCell.m @@ -29,13 +29,13 @@ #import "NSApplicationAdditions.h" #import "NSStringAdditions.h" -#define PADDING_HORIZONAL 2.0f -#define IMAGE_FOLDER_SIZE 16.0f -#define IMAGE_ICON_SIZE 32.0f -#define PADDING_BETWEEN_IMAGE_AND_TITLE 4.0f -#define PADDING_ABOVE_TITLE_FILE 2.0f -#define PADDING_BELOW_STATUS_FILE 2.0f -#define PADDING_BETWEEN_NAME_AND_FOLDER_STATUS 4.0f +#define PADDING_HORIZONAL 2.0 +#define IMAGE_FOLDER_SIZE 16.0 +#define IMAGE_ICON_SIZE 32.0 +#define PADDING_BETWEEN_IMAGE_AND_TITLE 4.0 +#define PADDING_ABOVE_TITLE_FILE 2.0 +#define PADDING_BELOW_STATUS_FILE 2.0 +#define PADDING_BETWEEN_NAME_AND_FOLDER_STATUS 4.0 @interface FileNameCell (Private) @@ -57,11 +57,11 @@ [paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail]; fTitleAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys: - [NSFont messageFontOfSize: 12.0f], NSFontAttributeName, + [NSFont messageFontOfSize: 12.0], NSFontAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil]; fStatusAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys: - [NSFont messageFontOfSize: 9.0f], NSFontAttributeName, + [NSFont messageFontOfSize: 9.0], NSFontAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil]; [paragraphStyle release]; @@ -100,7 +100,7 @@ result.origin.x += PADDING_HORIZONAL; const CGFloat IMAGE_SIZE = [(FileListNode *)[self objectValue] isFolder] ? IMAGE_FOLDER_SIZE : IMAGE_ICON_SIZE; - result.origin.y += (result.size.height - IMAGE_SIZE) * 0.5f; + result.origin.y += (result.size.height - IMAGE_SIZE) * 0.5; result.size = NSMakeSize(IMAGE_SIZE, IMAGE_SIZE); return result; @@ -150,44 +150,43 @@ - (NSRect) rectForTitleWithString: (NSAttributedString *) string inBounds: (NSRect) bounds { - NSSize titleSize = [string size]; - - NSRect result = bounds; + const NSSize titleSize = [string size]; + NSRect result; if (![(FileListNode *)[self objectValue] isFolder]) { - result.origin.x += PADDING_HORIZONAL + IMAGE_ICON_SIZE + PADDING_BETWEEN_IMAGE_AND_TITLE; - result.origin.y += PADDING_ABOVE_TITLE_FILE; + result.origin.x = NSMinX(bounds) + PADDING_HORIZONAL + IMAGE_ICON_SIZE + PADDING_BETWEEN_IMAGE_AND_TITLE; + result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE_FILE; } else { - result.origin.x += PADDING_HORIZONAL + IMAGE_FOLDER_SIZE + PADDING_BETWEEN_IMAGE_AND_TITLE; - result.origin.y += (result.size.height - titleSize.height) * 0.5f; + result.origin.x = NSMinX(bounds) + PADDING_HORIZONAL + IMAGE_FOLDER_SIZE + PADDING_BETWEEN_IMAGE_AND_TITLE; + result.origin.y = NSMidY(bounds) - titleSize.height * 0.5; } - result.size = titleSize; - result.size.width = MIN(result.size.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL); + result.size.height = titleSize.height; + result.size.width = MIN(titleSize.width, NSMaxX(bounds) - NSMinX(result) - PADDING_HORIZONAL); return result; } - (NSRect) rectForStatusWithString: (NSAttributedString *) string withTitleRect: (NSRect) titleRect inBounds: (NSRect) bounds; { - NSSize statusSize = [string size]; + const NSSize statusSize = [string size]; NSRect result; if (![(FileListNode *)[self objectValue] isFolder]) { - result.origin.x = bounds.origin.x + PADDING_HORIZONAL + IMAGE_ICON_SIZE + PADDING_BETWEEN_IMAGE_AND_TITLE; + result.origin.x = NSMinX(bounds) + PADDING_HORIZONAL + IMAGE_ICON_SIZE + PADDING_BETWEEN_IMAGE_AND_TITLE; result.origin.y = NSMaxY(bounds) - PADDING_BELOW_STATUS_FILE - statusSize.height; } else { result.origin.x = NSMaxX(titleRect) + PADDING_BETWEEN_NAME_AND_FOLDER_STATUS; - result.origin.y = NSMaxY(titleRect) - statusSize.height - 1.0f; + result.origin.y = NSMaxY(titleRect) - statusSize.height - 1.0; } - result.size = statusSize; - result.size.width = MIN(result.size.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL); + result.size.height = statusSize.height; + result.size.width = NSMaxX(bounds) - NSMaxX(result) - PADDING_HORIZONAL; return result; } @@ -203,9 +202,8 @@ Torrent * torrent = [(FileOutlineView *)[self controlView] torrent]; FileListNode * node = (FileListNode *)[self objectValue]; - CGFloat progress = [torrent fileProgress: node]; - NSString * percentString = progress == 1.0f ? @"100%" : [NSString localizedStringWithFormat: @"%.2f%%", progress * 100.0f]; - + const CGFloat progress = [torrent fileProgress: node]; + NSString * percentString = progress == 1.0 ? @"100%" : [NSString localizedStringWithFormat: @"%.2f%%", progress * 100.0]; NSString * status = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Inspector -> Files tab -> file status string"), percentString, [NSString stringForFileSize: [node size]]]; diff --git a/macosx/FileOutlineController.m b/macosx/FileOutlineController.m index 797a08339..39a00838a 100644 --- a/macosx/FileOutlineController.m +++ b/macosx/FileOutlineController.m @@ -161,7 +161,7 @@ typedef enum - (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id) item { if ([[tableColumn identifier] isEqualToString: @"Check"]) - return [NSNumber numberWithInt: [fTorrent checkForFiles: [(FileListNode *)item indexes]]]; + return [NSNumber numberWithInteger: [fTorrent checkForFiles: [(FileListNode *)item indexes]]]; else return item; } diff --git a/macosx/FilterButton.m b/macosx/FilterButton.m index 04d8fed87..3d9070640 100644 --- a/macosx/FilterButton.m +++ b/macosx/FilterButton.m @@ -30,7 +30,7 @@ { if ((self = [super initWithCoder: coder])) { - fCount = NSUIntegerMax; + fCount = NSNotFound; } return self; } diff --git a/macosx/NSStringAdditions.m b/macosx/NSStringAdditions.m index d445b15ac..c08649846 100644 --- a/macosx/NSStringAdditions.m +++ b/macosx/NSStringAdditions.m @@ -122,10 +122,12 @@ + (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds maxFields: (NSUInteger) max { + NSAssert(max > 0, @"Cannot generate a time string with no fields"); + NSMutableArray * timeArray = [NSMutableArray arrayWithCapacity: MIN(max, 4)]; NSUInteger remaining = seconds; //causes problems for some users when it's a uint64_t - if (max > 0 && seconds >= (24 * 60 * 60)) + if (seconds >= (24 * 60 * 60)) { const NSUInteger days = remaining / (24 * 60 * 60); if (days == 1) diff --git a/macosx/Torrent.m b/macosx/Torrent.m index fa02d240e..04e917886 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1251,7 +1251,7 @@ int trashDataFile(const char * filename) - (void) checkGroupValueForRemoval: (NSNotification *) notification { - if (fGroupValue != -1 && [[[notification userInfo] objectForKey: @"Index"] intValue] == fGroupValue) + if (fGroupValue != -1 && [[[notification userInfo] objectForKey: @"Index"] integerValue] == fGroupValue) fGroupValue = -1; } @@ -1614,13 +1614,17 @@ int trashDataFile(const char * filename) { tr_file * file = &fInfo->files[i]; - NSMutableArray * pathComponents = [[[NSString stringWithUTF8String: file->name] pathComponents] mutableCopy]; + NSString * fullPath = [NSString stringWithUTF8String: file->name]; + NSMutableArray * pathComponents = [[NSMutableArray alloc] initWithArray: [fullPath pathComponents]]; + NSAssert1([pathComponents count] >= 2, @"Not enough components in path %@", fullPath); + NSString * path = [pathComponents objectAtIndex: 0]; NSString * name = [pathComponents objectAtIndex: 1]; - [pathComponents removeObjectsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, 2)]]; - if ([pathComponents count] > 0) + if ([pathComponents count] > 2) { + [pathComponents removeObjectsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, 2)]]; + //determine if folder node already exists FileListNode * node; for (node in fileList) -- 2.40.0