//string is in center of image
NSRect stringRect;
- stringRect.origin.x = NSMinX(badgeRect) + (NSWidth(badgeRect) - stringSize.width) * 0.5;
- stringRect.origin.y = NSMinY(badgeRect) + (NSHeight(badgeRect) - stringSize.height) * 0.5
- + (quit ? 2.0 : 1.0); //adjust for shadow, extra for quit
+ stringRect.origin.x = NSMidX(badgeRect) - stringSize.width * 0.5;
+ stringRect.origin.y = NSMidY(badgeRect) - stringSize.height * 0.5 + (quit ? 2.0 : 1.0); //adjust for shadow, extra for quit
stringRect.size = stringSize;
[string drawInRect: stringRect withAttributes: fAttributes];
NSSortDescriptor * groupDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"groupOrderValue" ascending: YES] autorelease];
[allTorrents sortUsingDescriptors: [NSArray arrayWithObject: groupDescriptor]];
- NSMutableArray * groupTorrents;
+ TorrentGroup * group = nil;
NSInteger lastGroupValue = -2, currentOldGroupIndex = 0;
for (Torrent * torrent in allTorrents)
{
- NSInteger groupValue = [torrent groupValue];
+ const NSInteger groupValue = [torrent groupValue];
if (groupValue != lastGroupValue)
{
lastGroupValue = groupValue;
- TorrentGroup * group = nil;
+ group = nil;
//try to see if the group already exists
for (; currentOldGroupIndex < [oldTorrentGroups count]; currentOldGroupIndex++)
if (!group)
group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
[fDisplayedTorrents addObject: group];
-
- groupTorrents = [group torrents];
}
- [groupTorrents addObject: torrent];
+ NSAssert(group != nil, @"No group object to add torrents to");
+ [[group torrents] addObject: torrent];
}
}
else
*****************************************************************************/
#import "PeerProgressIndicatorCell.h"
+#import "NSApplicationAdditions.h"
@implementation PeerProgressIndicatorCell
if (fSeed)
{
NSImage * checkImage = [NSImage imageNamed: @"CompleteCheck.png"];
- [checkImage setFlipped: YES];
- NSSize imageSize = [checkImage size];
- NSRect rect = NSMakeRect(cellFrame.origin.x + (cellFrame.size.width - imageSize.width) * 0.5,
- cellFrame.origin.y + (cellFrame.size.height - imageSize.height) * 0.5, imageSize.width, imageSize.height);
- [checkImage drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
+ const NSSize imageSize = [checkImage size];
+ const NSRect rect = NSMakeRect(NSMidX(cellFrame) - imageSize.width * 0.5, NSMidY(cellFrame) - imageSize.height * 0.5,
+ imageSize.width, imageSize.height);
+
+ if ([NSApp isOnSnowLeopardOrBetter])
+ [checkImage drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0 respectFlipped: YES
+ hints: nil];
+ else
+ {
+ [checkImage setFlipped: YES];
+ [checkImage drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
+ }
}
}
}
//methods require fileStats to have been updated recently to be accurate
- (CGFloat) fileProgress: (FileListNode *) node;
-- (BOOL) canChangeDownloadCheckForFile: (NSInteger) index;
+- (BOOL) canChangeDownloadCheckForFile: (NSUInteger) index;
- (BOOL) canChangeDownloadCheckForFiles: (NSIndexSet *) indexSet;
- (NSInteger) checkForFiles: (NSIndexSet *) indexSet;
- (void) setFileCheckState: (NSInteger) state forIndexes: (NSIndexSet *) indexSet;
string = [NSString stringWithFormat: NSLocalizedString(@"Downloading from %d of 1 peer",
"Torrent -> status string"), [self peersSendingToUs]];
- NSInteger webSeedCount = fStat->webseedsSendingToUs;
+ const NSInteger webSeedCount = fStat->webseedsSendingToUs;
if (webSeedCount > 0)
{
NSString * webSeedString;
- (CGFloat) fileProgress: (FileListNode *) node
{
- if ([self isComplete])
- return 1.0;
-
- if ([self fileCount] == 1)
+ if ([self fileCount] == 1 || [self isComplete])
return [self progress];
if (!fFileStat)
return fFlatFileList;
}
-- (BOOL) canChangeDownloadCheckForFile: (NSInteger) index
+- (BOOL) canChangeDownloadCheckForFile: (NSUInteger) index
{
NSAssert2(index < [self fileCount], @"Index %d is greater than file count %d", index, [self fileCount]);
if (!fFileStat)
[self updateFileStat];
- for (NSInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
+ for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
if (fFileStat[index].progress < 1.0)
return YES;
return NO;
- (NSInteger) checkForFiles: (NSIndexSet *) indexSet
{
BOOL onState = NO, offState = NO;
- for (NSInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
+ for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
{
if (tr_torrentGetFileDL(fHandle, index) || ![self canChangeDownloadCheckForFile: index])
onState = YES;
- (void) setFilePriority: (tr_priority_t) priority forIndexes: (NSIndexSet *) indexSet
{
const NSUInteger count = [indexSet count];
- tr_file_index_t * files = malloc(count * sizeof(tr_file_index_t));
+ tr_file_index_t * files = tr_malloc(count * sizeof(tr_file_index_t));
for (NSUInteger index = [indexSet firstIndex], i = 0; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index], i++)
files[i] = index;
tr_torrentSetFilePriorities(fHandle, files, count, priority);
- free(files);
+ tr_free(files);
}
- (BOOL) hasFilePriority: (tr_priority_t) priority forIndexes: (NSIndexSet *) indexSet
{
- for (NSInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
+ for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
if (priority == tr_torrentGetFilePriority(fHandle, index) && [self canChangeDownloadCheckForFile: index])
return YES;
return NO;
- (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet
{
BOOL low = NO, normal = NO, high = NO;
- NSMutableSet * priorities = [NSMutableSet setWithCapacity: 3];
+ NSMutableSet * priorities = [NSMutableSet setWithCapacity: MIN([indexSet count], 3)];
- for (NSInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
+ for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
{
if (![self canChangeDownloadCheckForFile: index])
continue;