Changeset 9822


Ignore:
Timestamp:
Dec 26, 2009, 12:02:20 AM (12 years ago)
Author:
livings124
Message:

assorted code cleanup

Location:
trunk/macosx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/BadgeView.m

    r9732 r9822  
    136136    //string is in center of image
    137137    NSRect stringRect;
    138     stringRect.origin.x = NSMinX(badgeRect) + (NSWidth(badgeRect) - stringSize.width) * 0.5;
    139     stringRect.origin.y = NSMinY(badgeRect) + (NSHeight(badgeRect) - stringSize.height) * 0.5
    140                             + (quit ? 2.0 : 1.0); //adjust for shadow, extra for quit
     138    stringRect.origin.x = NSMidX(badgeRect) - stringSize.width * 0.5;
     139    stringRect.origin.y = NSMidY(badgeRect) - stringSize.height * 0.5 + (quit ? 2.0 : 1.0); //adjust for shadow, extra for quit
    141140    stringRect.size = stringSize;
    142141   
  • trunk/macosx/Controller.m

    r9812 r9822  
    21842184        [allTorrents sortUsingDescriptors: [NSArray arrayWithObject: groupDescriptor]];
    21852185       
    2186         NSMutableArray * groupTorrents;
     2186        TorrentGroup * group = nil;
    21872187        NSInteger lastGroupValue = -2, currentOldGroupIndex = 0;
    21882188        for (Torrent * torrent in allTorrents)
    21892189        {
    2190             NSInteger groupValue = [torrent groupValue];
     2190            const NSInteger groupValue = [torrent groupValue];
    21912191            if (groupValue != lastGroupValue)
    21922192            {
    21932193                lastGroupValue = groupValue;
    21942194               
    2195                 TorrentGroup * group = nil;
     2195                group = nil;
    21962196               
    21972197                //try to see if the group already exists
     
    22152215                    group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
    22162216                [fDisplayedTorrents addObject: group];
    2217                
    2218                 groupTorrents = [group torrents];
    22192217            }
    22202218           
    2221             [groupTorrents addObject: torrent];
     2219            NSAssert(group != nil, @"No group object to add torrents to");
     2220            [[group torrents] addObject: torrent];
    22222221        }
    22232222    }
  • trunk/macosx/PeerProgressIndicatorCell.m

    r9739 r9822  
    2424
    2525#import "PeerProgressIndicatorCell.h"
     26#import "NSApplicationAdditions.h"
    2627
    2728@implementation PeerProgressIndicatorCell
     
    7576        {
    7677            NSImage * checkImage = [NSImage imageNamed: @"CompleteCheck.png"];
    77             [checkImage setFlipped: YES];
    7878           
    79             NSSize imageSize = [checkImage size];
    80             NSRect rect = NSMakeRect(cellFrame.origin.x + (cellFrame.size.width - imageSize.width) * 0.5,
    81                         cellFrame.origin.y + (cellFrame.size.height - imageSize.height) * 0.5, imageSize.width, imageSize.height);
    82             [checkImage drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
     79            const NSSize imageSize = [checkImage size];
     80            const NSRect rect = NSMakeRect(NSMidX(cellFrame) - imageSize.width * 0.5, NSMidY(cellFrame) - imageSize.height * 0.5,
     81                                            imageSize.width, imageSize.height);
     82           
     83            if ([NSApp isOnSnowLeopardOrBetter])
     84                [checkImage drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0 respectFlipped: YES
     85                        hints: nil];
     86            else
     87            {
     88                [checkImage setFlipped: YES];
     89                [checkImage drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
     90            }
    8391        }
    8492    }
  • trunk/macosx/Torrent.h

    r9726 r9822  
    211211//methods require fileStats to have been updated recently to be accurate
    212212- (CGFloat) fileProgress: (FileListNode *) node;
    213 - (BOOL) canChangeDownloadCheckForFile: (NSInteger) index;
     213- (BOOL) canChangeDownloadCheckForFile: (NSUInteger) index;
    214214- (BOOL) canChangeDownloadCheckForFiles: (NSIndexSet *) indexSet;
    215215- (NSInteger) checkForFiles: (NSIndexSet *) indexSet;
  • trunk/macosx/Torrent.m

    r9805 r9822  
    10241024                                                    "Torrent -> status string"), [self peersSendingToUs]];
    10251025               
    1026                 NSInteger webSeedCount = fStat->webseedsSendingToUs;
     1026                const NSInteger webSeedCount = fStat->webseedsSendingToUs;
    10271027                if (webSeedCount > 0)
    10281028                {
     
    12761276- (CGFloat) fileProgress: (FileListNode *) node
    12771277{
    1278     if ([self isComplete])
    1279         return 1.0;
    1280    
    1281     if ([self fileCount] == 1)
     1278    if ([self fileCount] == 1 || [self isComplete])
    12821279        return [self progress];
    12831280   
     
    13031300}
    13041301
    1305 - (BOOL) canChangeDownloadCheckForFile: (NSInteger) index
     1302- (BOOL) canChangeDownloadCheckForFile: (NSUInteger) index
    13061303{
    13071304    NSAssert2(index < [self fileCount], @"Index %d is greater than file count %d", index, [self fileCount]);
     
    13241321        [self updateFileStat];
    13251322   
    1326     for (NSInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
     1323    for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
    13271324        if (fFileStat[index].progress < 1.0)
    13281325            return YES;
     
    13331330{
    13341331    BOOL onState = NO, offState = NO;
    1335     for (NSInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
     1332    for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
    13361333    {
    13371334        if (tr_torrentGetFileDL(fHandle, index) || ![self canChangeDownloadCheckForFile: index])
     
    13631360{
    13641361    const NSUInteger count = [indexSet count];
    1365     tr_file_index_t * files = malloc(count * sizeof(tr_file_index_t));
     1362    tr_file_index_t * files = tr_malloc(count * sizeof(tr_file_index_t));
    13661363    for (NSUInteger index = [indexSet firstIndex], i = 0; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index], i++)
    13671364        files[i] = index;
    13681365   
    13691366    tr_torrentSetFilePriorities(fHandle, files, count, priority);
    1370     free(files);
     1367    tr_free(files);
    13711368}
    13721369
    13731370- (BOOL) hasFilePriority: (tr_priority_t) priority forIndexes: (NSIndexSet *) indexSet
    13741371{
    1375     for (NSInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
     1372    for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
    13761373        if (priority == tr_torrentGetFilePriority(fHandle, index) && [self canChangeDownloadCheckForFile: index])
    13771374            return YES;
     
    13821379{
    13831380    BOOL low = NO, normal = NO, high = NO;
    1384     NSMutableSet * priorities = [NSMutableSet setWithCapacity: 3];
    1385    
    1386     for (NSInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
     1381    NSMutableSet * priorities = [NSMutableSet setWithCapacity: MIN([indexSet count], 3)];
     1382   
     1383    for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
    13871384    {
    13881385        if (![self canChangeDownloadCheckForFile: index])
Note: See TracChangeset for help on using the changeset viewer.