]> granicus.if.org Git - transmission/commitdiff
assorted code cleanup
authorMitchell Livingston <livings124@transmissionbt.com>
Sat, 26 Dec 2009 00:02:20 +0000 (00:02 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Sat, 26 Dec 2009 00:02:20 +0000 (00:02 +0000)
macosx/BadgeView.m
macosx/Controller.m
macosx/PeerProgressIndicatorCell.m
macosx/Torrent.h
macosx/Torrent.m

index 6550a91aba572190e72b8097b3c5d93c23f82851..490e26a725385fcd04f4c52ee3b2d6f5524d921e 100644 (file)
     
     //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];
index d82c61733974ecb8d015601e9b26d0f4dfa7b5c0..9dbf2b0023d5b1661bbd722f8a3b83c96bb2a1e7 100644 (file)
@@ -2183,16 +2183,16 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
         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++)
@@ -2214,11 +2214,10 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
                 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
index b7be5a2ec1c048893386e75ce5b9d62d8a9979c7..505ac85dcad1ff473795632d34bd84307b84ef04 100644 (file)
@@ -23,6 +23,7 @@
  *****************************************************************************/
 
 #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];
+            }
         }
     }
 }
index 00aae71d756ef4a83209a916f68bff4e2b03271b..7b6330ccb79389901bcd5a8da2419846b13ad987 100644 (file)
 
 //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;
index 3c9a44053d4f4e54f1dccce602f93fa9f81b2028..fa02d240e98038644c211bb10c09b6af0e79d37b 100644 (file)
@@ -1023,7 +1023,7 @@ int trashDataFile(const char * filename)
                     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;
@@ -1275,10 +1275,7 @@ int trashDataFile(const char * filename)
 
 - (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)
@@ -1302,7 +1299,7 @@ int trashDataFile(const char * filename)
     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]);
     
@@ -1323,7 +1320,7 @@ int trashDataFile(const char * filename)
     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;
@@ -1332,7 +1329,7 @@ int trashDataFile(const char * filename)
 - (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;
@@ -1362,17 +1359,17 @@ int trashDataFile(const char * filename)
 - (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;
@@ -1381,9 +1378,9 @@ int trashDataFile(const char * filename)
 - (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;