Changeset 7 for Trunk/AILogSizeSort.m

Show
Ignore:
Timestamp:
09/28/08 23:47:08 (16 years ago)
Author:
jon
Message:

Victory! Abandoned caching in favor of direct comparison since the comparator method doesn't get called in the context of an AISortController instance. Looks like it's working great, though.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Trunk/AILogSizeSort.m

    r6 r7  
    3030- (void)didBecomeActiveFirstTime 
    3131{ 
    32         logSizeCache = [NSMutableDictionary dictionaryWithCapacity:64]; 
    33          
    34         NSEnumerator *groupEnumerator = [[[[adium contactController] contactList] listContacts] objectEnumerator]; 
    35          
    36         id group, contact; 
    37          
    38     while(group = [groupEnumerator nextObject]) 
    39         { 
    40                 NSEnumerator *contactEnumerator = [[group listContacts] objectEnumerator]; 
    41                  
    42                 NSMutableDictionary *sizes = [NSMutableDictionary dictionaryWithCapacity:64]; 
    43                  
    44                 while(contact = [contactEnumerator nextObject]) 
    45                 { 
    46                         [sizes setValue:[NSNumber numberWithUnsignedLongLong:[AILogSizeSort getContactLogSize:contact]] forKey:[contact UID]]; 
    47                 } 
    48  
    49                 [logSizeCache setValue:sizes forKey:[group UID]]; 
    50     } 
    51          
    52         AILog(@"Log size cache:"); 
    53         AILog(@"%@", logSizeCache); 
    5432} 
    5533 
     
    12199int logSizeSort(id objectA, id objectB, BOOL groups) 
    122100{ 
    123         return NSOrderedAscending; 
     101        if(groups) 
     102        { 
     103                // Keep groups in manual order (borrowed from ESStatusSort) 
     104                if ([objectA orderIndex] > [objectB orderIndex]) 
     105                { 
     106                        return NSOrderedDescending; 
     107                } 
     108                else 
     109                { 
     110                        return NSOrderedAscending; 
     111                } 
     112        } 
     113         
     114         
     115        NSNumber *sizeA = [NSNumber numberWithUnsignedLongLong:[AILogSizeSort getContactLogSize:objectA]]; 
     116        NSNumber *sizeB = [NSNumber numberWithUnsignedLongLong:[AILogSizeSort getContactLogSize:objectB]]; 
     117         
     118        if([sizeB compare:sizeA] == NSOrderedSame) 
     119        { 
     120                return [[objectA displayName] compare:[objectB displayName]]; 
     121        } 
     122        else 
     123        { 
     124                return [sizeB compare:sizeA]; 
     125        } 
    124126} 
    125127