Changeset 19
- Timestamp:
- 10/05/08 14:37:33 (16 years ago)
- Location:
- Trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
Trunk/AILogSizeSort.h
r18 r19 30 30 } 31 31 32 // Cache operations 33 -(void)createCacheEntryIfNil:(AIListContact *)listContact; 34 -(void)removeCacheEntry:(AIListContact *)listContact; 35 36 // Event handlers 37 -(void)contentObjectAdded:(NSNotification *)notification; 38 39 // Log operations 32 40 -(unsigned long long)getCachedLogSize:(AIListContact *)listContact; 33 41 +(unsigned long long)getContactLogSize:(AIListContact *)listContact; -
Trunk/AILogSizeSort.m
r18 r19 28 28 #import <AIUtilities/AIStringUtilities.h> 29 29 30 #import <Adium/AIAdiumProtocol.h> 31 #import <Adium/AIContentControllerProtocol.h> 30 32 #import <Adium/AIContactControllerProtocol.h> 31 33 #import <Adium/AIListObject.h> 32 34 #import <Adium/AIMetaContact.h> 33 35 34 #import <Adium/ESDebugAILog.h> 36 #import <Adium/AIChat.h> 37 #import <Adium/AIContentObject.h> 38 #import <Adium/AIContentMessage.h> 35 39 36 40 @implementation AILogSizeSort 37 41 42 #pragma mark AISortController obligations 43 38 44 /*! 39 45 * @brief Did become active first time … … 43 49 - (void)didBecomeActiveFirstTime 44 50 { 45 AILog(@"Sort by log size controller became active for first time.");46 51 logSizeCache = [[NSMutableDictionary alloc] init]; 47 AILog(@"%@", logSizeCache); 52 53 // Listen for content addition notifications 54 [[adium notificationCenter] addObserver:self 55 selector:@selector(contentObjectAdded:) 56 name:Content_ContentObjectAdded 57 object:nil]; 48 58 } 49 59 … … 59 69 */ 60 70 - (NSString *)displayName{ 61 return AILocalizedString(@"Sort Contacts by Log Size", nil);71 return AILocalizedString(@"Sort Contacts by Log Size", nil); 62 72 } 63 73 … … 77 87 78 88 #pragma mark Configuration 89 79 90 /*! 80 91 * @brief Window title when configuring the sort … … 117 128 } 118 129 130 #pragma mark Cache operations 131 132 /*! 133 * @brief Creates and populates a new cache entry for a contact if needed 134 */ 135 -(void)createCacheEntryIfNil:(AIListContact *)listContact 136 { 137 // Check for a match on the account name; create a new sub-dictionary if needed 138 if([logSizeCache valueForKey:[[listContact account] explicitFormattedUID]] == nil) 139 { 140 [logSizeCache setValue:[[NSMutableDictionary alloc] init] forKey:[[listContact account] explicitFormattedUID]]; 141 } 142 143 NSMutableDictionary *accountDictionary = [logSizeCache valueForKey:[[listContact account] explicitFormattedUID]]; 144 145 // If we don't already have a valid log size cached for this contact, create one 146 if([accountDictionary valueForKey:[listContact UID]] == nil) 147 { 148 [accountDictionary setValue:[NSNumber numberWithUnsignedLongLong:[AILogSizeSort getContactLogSize:listContact]] forKey: [listContact UID]]; 149 } 150 } 151 152 /*! 153 * @brief Invalidates a cached log size for a list contact 154 */ 155 -(void)removeCacheEntry:(AIListContact *)listContact 156 { 157 if([listContact isMemberOfClass:[AIMetaContact class]]) 158 { 159 // Recurse! Invalidate each sub-contact's cache entry. 160 id contact; 161 162 NSEnumerator *contactEnumerator = [[(AIMetaContact *)listContact listContacts] objectEnumerator]; 163 164 while(contact = [contactEnumerator nextObject]) 165 { 166 [self removeCacheEntry:contact]; 167 } 168 } 169 else 170 { 171 // Bail out if we don't know about the group this contact is in (there's nothing for us to do 172 // anyway). 173 if([logSizeCache valueForKey:[[listContact account] explicitFormattedUID]] == nil) { return; } 174 175 // Remove the cache entry for the dirty account. 176 [(NSMutableDictionary *)[logSizeCache valueForKey:[[listContact account] explicitFormattedUID]] setValue:nil forKey:[listContact UID]]; 177 } 178 } 179 180 #pragma mark Event handlers 181 182 /*! 183 * @brief Handles content send/receive events 184 * 185 * Handles content send/receive events. For one-on-one chats, the cached log size for a contact is 186 * invalidated (forcing a recalculation on the next sorting cycle). 187 */ 188 -(void)contentObjectAdded:(NSNotification *)notification 189 { 190 AIChat *chat = [notification object]; 191 192 if(![chat isGroupChat]) 193 { 194 [self removeCacheEntry:[chat listObject]]; 195 } 196 } 197 198 #pragma mark Log operations 199 200 /*! 201 * @brief Returns the cached log size for a list contact 202 */ 119 203 -(unsigned long long)getCachedLogSize:(AIListContact *)listContact 120 204 { 121 AILogWithSignature(@"Getting cached log size for %@/%@.", [[listContact account] explicitFormattedUID], [listContact UID]); 122 123 if([logSizeCache valueForKey:[[listContact account] explicitFormattedUID]] == nil) 124 { 125 [logSizeCache setValue:[[NSMutableDictionary alloc] init] forKey:[[listContact account] explicitFormattedUID]]; 126 } 205 [self createCacheEntryIfNil:listContact]; 127 206 128 207 NSMutableDictionary *accountDictionary = [logSizeCache valueForKey:[[listContact account] explicitFormattedUID]]; 129 130 if([accountDictionary valueForKey:[listContact UID]] == nil)131 {132 AILogWithSignature(@"\tNo cache hit.");133 [accountDictionary setValue:[NSNumber numberWithUnsignedLongLong:[AILogSizeSort getContactLogSize:listContact]] forKey: [listContact UID]];134 }135 136 AILogWithSignature(@"\tLog file size: %@", [accountDictionary valueForKey:[listContact UID]]);137 208 return [[accountDictionary valueForKey:[listContact UID]] unsignedLongLongValue]; 138 209 } … … 197 268 198 269 #pragma mark Sorting 270 199 271 /*! 200 272 * @brief Sort by log size … … 222 294 unsigned long long sizeB = 0; 223 295 296 // Attempt to use cached log sizes if possible, but fall back to dumber methods if something 297 // unforeseen happens. 224 298 if([sortController isMemberOfClass:[AILogSizeSort class]]) 225 299 {