Skip to content

Commit

Permalink
Integrated Eric Blair's patch for favicon support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldandersen committed Jun 21, 2005
1 parent cd7e84e commit b4baed0
Show file tree
Hide file tree
Showing 12 changed files with 1,314 additions and 15 deletions.
7 changes: 7 additions & 0 deletions Application/AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#import "SFHFRatingCell.h"
#import "SFHFCircularCounterCell.h"
#import "SFHFCornerView.h"
#import "EBIconAndTextCell.h"
#import "EBFavIconUtils.h"
#import "defines.h"
#import "DCTypes.h"

Expand Down Expand Up @@ -74,6 +76,8 @@
NSMutableDictionary *posts;
NSArray *filteredTags;
NSArray *filteredPosts;

NSMutableDictionary *favIcons;

NSString *currentSearch;
DCAPITag *currentTagFilter;
Expand Down Expand Up @@ -107,6 +111,7 @@
- (void) refreshAll;
- (void) refreshTags;
- (void) refreshPostsWithDownload: (BOOL) download;
- (void) refreshFavIconsWithDownload: (BOOL) download;

/* Search/Tag Filtering */
- (IBAction) doSearch: (id) sender;
Expand Down Expand Up @@ -142,6 +147,8 @@
- (NSArray *) tagsArray;
- (void) resortTags;
- (void) renameTag: (NSString *) originalName to: (NSString *) newName withUpload: (BOOL) upload;
- (void) setFavIcons: (NSDictionary *) newFavIcons;
- (NSMutableDictionary *) favIcons;

/* UI setup */
- (void) setupTaglist;
Expand Down
86 changes: 83 additions & 3 deletions Application/AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ - (void) applicationDidFinishLaunching: (NSNotification *) aNotification {

[self setPosts: [NSMutableDictionary dictionaryWithCapacity: 0]];
[self setTags: [NSMutableDictionary dictionaryWithCapacity: 0]];
[self setFavIcons: [NSMutableDictionary dictionaryWithCapacity: 0]];

[self setupTaglist];
[self setupPostlist];
Expand Down Expand Up @@ -223,8 +224,12 @@ - (void) setupPostlist {
[starCell release];

NSTableColumn *descriptionColumn = [postList tableColumnWithIdentifier: @"description"];
NSCell *descriptionColumnCell = [descriptionColumn dataCell];
EBIconAndTextCell * descriptionColumnCell = [[EBIconAndTextCell alloc] initWithDefaultIcon:[NSImage imageNamed: @"default_favicon.tif"]];
[descriptionColumnCell setIconSize: NSMakeSize(13.0,13.0)];
[descriptionColumnCell setWraps: YES];
[descriptionColumnCell setFont: [[descriptionColumn dataCell] font]]; // Works, but there must be a better way to set default font
[descriptionColumn setDataCell: descriptionColumnCell];
[descriptionColumnCell release];

NSTableColumn *dateColumn = [postList tableColumnWithIdentifier: @"date"];
NSCell *dateColumnCell = [dateColumn dataCell];
Expand Down Expand Up @@ -266,6 +271,7 @@ - (void) refreshAll {
[spinnyThing startAnimation: self];
[self refreshPostsWithDownload: YES];
[self refreshTags];
[self refreshFavIconsWithDownload: NO];
[spinnyThing stopAnimation: self];

[pool release];
Expand Down Expand Up @@ -335,6 +341,32 @@ - (void) refreshPostsWithDownload: (BOOL) download {
[pool release];
}

- (void) refreshFavIconsWithDownload: (BOOL) download {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSArray * unfilteredURLs = [self urlsArray];
NSString * favIconPath;

NSEnumerator * urlEnum = [unfilteredURLs objectEnumerator];
NSString * currURLString;
NSURL * currURL;

while((currURLString = (NSString *)[urlEnum nextObject]) != nil) {
currURL = [NSURL URLWithString:currURLString];

if(currURL != nil) {
favIconPath = [EBFavIconUtils downloadFavIconForURL:currURL forceDownload: download];

if (favIconPath) {
[[self favIcons] setObject:favIconPath forKey:currURL];
}
}
}

[postList performSelectorOnMainThread: @selector(reloadData) withObject:nil waitUntilDone:NO];
[pool release];
}

- (NSArray *) selectedTags {
if ([tagList isRowSelected: 0]) {
return nil;
Expand Down Expand Up @@ -445,6 +477,19 @@ - (DCAPIClient *) client {
return [[client retain] autorelease];
}

- (void) setFavIcons: (NSDictionary *) newFavIcons {
@synchronized(favIcons) {
if (favIcons != newFavIcons) {
[favIcons release];
favIcons = [newFavIcons mutableCopy];
}
}
}

- (NSMutableDictionary *) favIcons {
return [[favIcons retain] autorelease];
}

- (void) setTags: (NSDictionary *) newTags {
@synchronized(tags) {
if (tags != newTags) {
Expand Down Expand Up @@ -916,7 +961,12 @@ - (BOOL) tableView: (NSTableView *) tableView writeRows: (NSArray *) rows toPast
}

if (tableView == postList) {
[pboard declareTypes: [NSArray arrayWithObjects: kDCAPIPostPboardType, NSURLPboardType, NSStringPboardType, nil] owner: self];
[pboard declareTypes: [NSArray arrayWithObjects: kDCAPIPostPboardType,
kWebURLsWithTitlesPboardType,
NSURLPboardType,
kWebURLPboardType,
kWebURLNamePboardType,
NSStringPboardType, nil] owner: self];

NSNumber *currentPostIndex = [rows objectAtIndex: 0];
DCAPIPost *currentPost = [[self filteredPosts] objectAtIndex: [currentPostIndex unsignedIntValue]];
Expand All @@ -925,7 +975,24 @@ - (BOOL) tableView: (NSTableView *) tableView writeRows: (NSArray *) rows toPast
NSURL *currentURL = [currentPost URL];
[pboard setString: [currentURL absoluteString] forType: NSStringPboardType];
[currentURL writeToPasteboard: pboard];


NSString *currentTitle = [currentPost description];

id plist = [NSArray arrayWithObjects:[NSArray arrayWithObject:[currentURL absoluteString]],
[NSArray arrayWithObject:[currentPost description]],
nil];
NSData * data = [NSPropertyListSerialization dataFromPropertyList:plist
format:NSPropertyListXMLFormat_v1_0
errorDescription:NULL];
NSString * string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];

[pboard setPropertyList:plist forType:kWebURLsWithTitlesPboardType];
[pboard setString:string forType:kWebURLsWithTitlesPboardType];
[pboard setData:data forType:kWebURLsWithTitlesPboardType];

[pboard setString:[currentURL absoluteString] forType:kWebURLPboardType];
[pboard setString:currentTitle forType:kWebURLNamePboardType];

return YES;
}

Expand Down Expand Up @@ -969,6 +1036,15 @@ - (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColum
}
}

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
if(aTableView == postList) {
if([[aTableColumn identifier] isEqualToString:@"description"]) {
DCAPIPost * currentPost = [[self filteredPosts] objectAtIndex: rowIndex];
[(EBIconAndTextCell *) aCell setFavIconPath: [[self favIcons] objectForKey: [currentPost URL]]];
}
}
}

// ----- beg implementation for postList tooltips -----
- (NSString *)tableView:(SFHFTableView *)tableView tooltipForItem:(id)item {
if (tableView == postList) {
Expand Down Expand Up @@ -1349,6 +1425,9 @@ - (IBAction) postNewLink: (id) sender {

DCAPIPost *newPost = [[DCAPIPost alloc] initWithURL: postURL description: postDescription extended: postExtended date: postDate tags: nil urlHash: nil];
[newPost setTagsFromString: postTags];

NSString * favIconPath = [EBFavIconUtils downloadFavIconForURL: [newPost valueForKey: @"URL"] forceDownload: NO];
[[self favIcons] setObject: favIconPath forKey: [newPost valueForKey: @"URL"]];

[NSThread detachNewThreadSelector: @selector(addPost:) toTarget: [self client] withObject: newPost];

Expand Down Expand Up @@ -1620,6 +1699,7 @@ - (void) dealloc {
[currentPostProperties release];
[loginProperties release];
[currentSearch release];
[favIcons release];
#ifdef AWOOSTER_CHANGES
[textIndex release];
#endif
Expand Down
Binary file added Art/default_favicon.tif
Binary file not shown.
Loading

0 comments on commit b4baed0

Please sign in to comment.