Changeset 5528
- Timestamp:
- 05/22/08 15:41:30 (4 months ago)
- Files:
-
- WiredClient/trunk/WCNews.h (modified) (1 diff)
- WiredClient/trunk/WCNews.m (modified) (14 diffs)
- WiredClient/trunk/WCNewsPost.h (added)
- WiredClient/trunk/WCNewsPost.m (added)
- WiredClient/trunk/WiredClient.xcodeproj/project.pbxproj (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
WiredClient/trunk/WCNews.h
r4799 r5528 28 28 29 29 @interface WCNews : WCConnectionController { 30 IBOutlet WITextView *_newsTextView;30 IBOutlet WITextView *_newsTextView; 31 31 32 IBOutlet NSPanel *_postPanel;33 IBOutlet NSTextView *_postTextView;32 IBOutlet NSPanel *_postPanel; 33 IBOutlet NSTextView *_postTextView; 34 34 35 IBOutlet NSButton *_postButton;36 IBOutlet NSButton *_clearButton;35 IBOutlet NSButton *_postButton; 36 IBOutlet NSButton *_clearButton; 37 37 38 IBOutlet NSButton *_reloadButton;39 IBOutlet NSProgressIndicator *_progressIndicator;38 IBOutlet NSButton *_reloadButton; 39 IBOutlet NSProgressIndicator *_progressIndicator; 40 40 41 NSMutableA ttributedString *_news;42 WITextFilter *_newsFilter;43 WIDateFormatter *_dateFormatter;44 NSUInteger _unread;41 NSMutableArray *_posts; 42 WITextFilter *_newsFilter; 43 WIDateFormatter *_dateFormatter; 44 NSUInteger _unread; 45 45 46 NSString *_hiddenNews;46 NSString *_hiddenNews; 47 47 } 48 48 49 49 50 #define WCNewsDidAddPost @"WCNewsDidAddPost"51 #define WCNewsDidReadPost @"WCNewsDidReadPost"50 #define WCNewsDidAddPost @"WCNewsDidAddPost" 51 #define WCNewsDidReadPost @"WCNewsDidReadPost" 52 52 53 53 WiredClient/trunk/WCNews.m
r5249 r5528 28 28 29 29 #import "WCAccount.h" 30 #import "WCApplicationController.h" 30 31 #import "WCNews.h" 32 #import "WCNewsPost.h" 31 33 #import "WCPreferences.h" 32 34 … … 40 42 - (void)_readAllPosts; 41 43 42 - (NSAttributedString *)_postWithNick:(NSString *)nick date:(NSDate *)date message:(NSString *)message; 44 - (NSAttributedString *)_attributedStringForPost:(WCNewsPost *)post; 45 - (NSAttributedString *)_attributedStringForPosts; 43 46 44 47 @end … … 52 55 connection:connection]; 53 56 54 _ news = [[NSMutableAttributedStringalloc] init];57 _posts = [[NSMutableArray alloc] init]; 55 58 _newsFilter = [[WITextFilter alloc] initWithSelectors:@selector(filterURLs:), @selector(filterWiredSmilies:), 0]; 56 59 … … 62 65 name:WCPreferencesDidChange]; 63 66 67 [[NSNotificationCenter defaultCenter] 68 addObserver:self 69 selector:@selector(dateDidChange:) 70 name:WCDateDidChange]; 71 64 72 [[self connection] addObserver:self 65 73 selector:@selector(newsShouldAddNews:) … … 118 126 119 127 - (void)_reloadNews { 120 [ [_news mutableString] setString:@""];128 [_posts removeAllObjects]; 121 129 [_newsTextView setString:@""]; 122 130 [_newsTextView setNeedsDisplay:YES]; … … 140 148 #pragma mark - 141 149 142 - (NSAttributedString *)_ postWithNick:(NSString *)nick date:(NSDate *)date message:(NSString *)message{143 NSMutableAttributedString * post;150 - (NSAttributedString *)_attributedStringForPost:(WCNewsPost *)post { 151 NSMutableAttributedString *attributedString; 144 152 NSAttributedString *header, *entry; 145 153 NSDictionary *attributes; … … 153 161 NULL]; 154 162 string = [NSSWF:NSLS(@"From %@ (%@):\n", @"News header (nick, time)"), 155 nick,156 [_dateFormatter stringFromDate: date]];163 [post userNick], 164 [_dateFormatter stringFromDate:[post date]]]; 157 165 header = [NSAttributedString attributedStringWithString:string attributes:attributes]; 158 166 … … 163 171 NSForegroundColorAttributeName, 164 172 NULL]; 165 entry = [NSAttributedString attributedStringWithString:message attributes:attributes]; 166 167 post = [NSMutableAttributedString attributedString]; 168 [post appendAttributedString:header]; 169 [post appendAttributedString:entry]; 170 171 return post; 173 entry = [NSAttributedString attributedStringWithString:[post message] attributes:attributes]; 174 175 attributedString = [NSMutableAttributedString attributedString]; 176 [attributedString appendAttributedString:header]; 177 [attributedString appendAttributedString:entry]; 178 179 return [attributedString attributedStringByApplyingFilter:_newsFilter]; 180 } 181 182 183 184 - (NSAttributedString *)_attributedStringForPosts { 185 NSMutableAttributedString *attributedString; 186 NSUInteger i, count; 187 188 attributedString = [NSMutableAttributedString attributedString]; 189 count = [_posts count]; 190 191 for(i = 0; i < count; i++) { 192 [attributedString appendAttributedString:[self _attributedStringForPost:[_posts objectAtIndex:i]]]; 193 194 if(i != count - 1) 195 [[attributedString mutableString] appendString:@"\n\n"]; 196 } 197 198 return attributedString; 172 199 } 173 200 … … 184 211 185 212 - (void)dealloc { 186 [_ news release];213 [_posts release]; 187 214 [_newsFilter release]; 188 215 [_dateFormatter release]; … … 301 328 302 329 - (void)newsShouldAddNews:(NSNotification *)notification { 303 NSArray *fields; 304 NSString *nick, *date, *message; 305 NSAttributedString *post; 306 307 fields = [[notification userInfo] objectForKey:WCArgumentsKey]; 308 309 if([fields count] < 3) 310 return; 311 312 nick = [fields safeObjectAtIndex:0]; 313 date = [fields safeObjectAtIndex:1]; 314 message = [fields safeObjectAtIndex:2]; 315 316 post = [self _postWithNick:nick date:[NSDate dateWithISO8601String:date] message:message]; 317 [_news appendAttributedString:post]; 318 [[_news mutableString] appendString:@"\n\n"]; 330 WCNewsPost *post; 331 332 post = [WCNewsPost newsPostWithArguments:[[notification userInfo] objectForKey:WCArgumentsKey]]; 333 334 [_posts addObject:post]; 319 335 } 320 336 … … 322 338 323 339 - (void)newsShouldCompleteNews:(NSNotification *)notification { 324 NSRange range; 325 326 while([[_news mutableString] hasSuffix:@"\n"]) { 327 range = NSMakeRange([[_news mutableString] length] - 1, 1); 328 [[_news mutableString] deleteCharactersInRange:range]; 329 } 330 331 [[_newsTextView textStorage] setAttributedString:[_news attributedStringByApplyingFilter:_newsFilter]]; 340 [[_newsTextView textStorage] setAttributedString:[self _attributedStringForPosts]]; 341 332 342 [_progressIndicator stopAnimation:self]; 333 343 } … … 336 346 337 347 - (void)newsShouldAddNewNews:(NSNotification *)notification { 338 NSArray *fields; 339 NSString *nick, *date, *message; 340 NSAttributedString *post; 341 342 fields = [[notification userInfo] objectForKey:WCArgumentsKey]; 343 nick = [fields safeObjectAtIndex:0]; 344 date = [fields safeObjectAtIndex:1]; 345 message = [fields safeObjectAtIndex:2]; 346 347 post = [self _postWithNick:nick date:[NSDate dateWithISO8601String:date] message:message]; 348 [[_news mutableString] insertString:@"\n\n" atIndex:0]; 349 [_news insertAttributedString:[post attributedStringByApplyingFilter:_newsFilter] atIndex:0]; 350 [[_newsTextView textStorage] setAttributedString:_news]; 348 NSAttributedString *string; 349 WCNewsPost *post; 350 351 post = [WCNewsPost newsPostWithArguments:[[notification userInfo] objectForKey:WCArgumentsKey]]; 352 353 if([_posts count] == 0) 354 [_posts addObject:post]; 355 else 356 [_posts insertObject:post atIndex:0]; 357 358 string = [self _attributedStringForPost:post]; 359 360 if([_posts count] > 0) 361 [[[_newsTextView textStorage] mutableString] insertString:@"\n\n" atIndex:0]; 362 363 [[_newsTextView textStorage] insertAttributedString:string atIndex:0]; 351 364 352 365 if(![[self window] isVisible]) { … … 356 369 } 357 370 358 [[self connection] triggerEvent:WCEventsNewsPosted info1: nick info2:message];371 [[self connection] triggerEvent:WCEventsNewsPosted info1:[post userNick] info2:[post message]]; 359 372 } 360 373 … … 363 376 - (void)preferencesDidChange:(NSNotification *)notification { 364 377 [self _update]; 378 } 379 380 381 382 - (void)dateDidChange:(NSNotification *)notification { 383 [[_newsTextView textStorage] setAttributedString:[self _attributedStringForPosts]]; 365 384 } 366 385 WiredClient/trunk/WiredClient.xcodeproj/project.pbxproj
r5503 r5528 80 80 77E4287E0DD1DAD900703987 /* libssl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 77E4287D0DD1DAD700703987 /* libssl.dylib */; }; 81 81 77E428820DD1DAE500703987 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 77E428810DD1DAE500703987 /* libcrypto.dylib */; }; 82 77E49CB30DE59F3300703987 /* WCNewsPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 77E49CB20DE59F3300703987 /* WCNewsPost.m */; }; 82 83 77E555BC075346E4009A7557 /* GreenDrop.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 77E555BB075346E4009A7557 /* GreenDrop.tiff */; }; 83 84 77E555C5075346F3009A7557 /* YellowDrop.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 77E555C4075346F3009A7557 /* YellowDrop.tiff */; }; … … 328 329 77E4287D0DD1DAD700703987 /* libssl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libssl.dylib; path = /usr/lib/libssl.dylib; sourceTree = "<absolute>"; }; 329 330 77E428810DD1DAE500703987 /* libcrypto.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.dylib; path = /usr/lib/libcrypto.dylib; sourceTree = "<absolute>"; }; 331 77E49CB10DE59F3300703987 /* WCNewsPost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WCNewsPost.h; sourceTree = "<group>"; }; 332 77E49CB20DE59F3300703987 /* WCNewsPost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WCNewsPost.m; sourceTree = "<group>"; }; 330 333 77E555BB075346E4009A7557 /* GreenDrop.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = GreenDrop.tiff; sourceTree = "<group>"; }; 331 334 77E555C4075346F3009A7557 /* YellowDrop.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = YellowDrop.tiff; sourceTree = "<group>"; }; … … 818 821 A5DC7EDA057AAF2900736BBF /* WCNews.m */, 819 822 A5DC7ED9057AAF2900736BBF /* WCNews.h */, 823 77E49CB20DE59F3300703987 /* WCNewsPost.m */, 824 77E49CB10DE59F3300703987 /* WCNewsPost.h */, 820 825 ); 821 826 name = News; … … 1477 1482 778E8616096D27B500258FE6 /* WCMessagesWindow.m in Sources */, 1478 1483 A5DC7EEA057AAF2900736BBF /* WCNews.m in Sources */, 1484 77E49CB30DE59F3300703987 /* WCNewsPost.m in Sources */, 1479 1485 A5DC7ECA057AAEAD00736BBF /* WCPreferences.m in Sources */, 1480 1486 A5DC7F05057AAF6C00736BBF /* WCPreview.m in Sources */,
