Changeset 9203


Ignore:
Timestamp:
Sep 28, 2009, 3:42:35 AM (13 years ago)
Author:
livings124
Message:

fix favicons

Location:
trunk/macosx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoWindowController.h

    r9197 r9203  
    5454    IBOutlet NSButton * fRevealDataButton;
    5555   
     56    NSArray * fTrackers;
    5657    IBOutlet TrackerTableView * fTrackerTable;
    5758    TrackerCell * fTrackerCell;
     
    7677                        * fUploadLimitLabel, * fDownloadLimitLabel, * fPeersConnectLabel,
    7778                        * fPeersConnectField;
    78    
    79     NSArray * fTrackers;
    80     NSCache * fTrackerIconCache;
    81     NSMutableDictionary * fTrackerIconCacheLeopard;
    82     NSMutableSet * fTrackerIconLoading;
    8379   
    8480    NSString * fInitialString;
  • trunk/macosx/InfoWindowController.m

    r9200 r9203  
    9191- (BOOL) canQuickLookFile: (FileListNode *) item;
    9292
     93#warning lookie
    9394/*- (void) addTrackers;
    9495- (void) removeTrackers;*/
     
    202203    [self setWebSeedTableHidden: YES animate: NO];
    203204   
    204     if ([NSApp isOnSnowLeopardOrBetter])
    205         fTrackerIconCache = [[NSCache alloc] init];
    206     else
    207         fTrackerIconCacheLeopard = [[NSMutableDictionary alloc] init];
    208     fTrackerIconLoading = [[NSMutableSet alloc] init];
    209    
    210205    //set blank inspector
    211206    [self setInfoForTorrents: [NSArray array]];
     
    246241   
    247242    [fTrackerCell release];
    248    
    249     [fTrackerIconCache release];
    250     [fTrackerIconCacheLeopard release];
    251     [fTrackerIconLoading release];
    252243   
    253244    [fPreviewPanel release];
     
    901892    else if (tableView == fTrackerTable)
    902893    {
    903         //NSString * ident = [column identifier];
    904894        id item = [fTrackers objectAtIndex: row];
    905        
    906         #warning isn't used
    907         /*if ([ident isEqualToString: @"Icon"])
    908         {
    909             NSAssert([item isKindOfClass: [TrackerNode class]], @"Value passed to tracker table's icon row is not a TrackerNode!");
    910            
    911             NSURL * address = [NSURL URLWithString: [(TrackerNode *)item host]];
    912             NSArray * hostComponents = [[address host] componentsSeparatedByString: @"."];
    913            
    914             //let's try getting the tracker address without using any subdomains
    915             NSString * baseAddress;
    916             if ([hostComponents count] > 1)
    917                 baseAddress = [NSString stringWithFormat: @"http://%@.%@",
    918                                 [hostComponents objectAtIndex: [hostComponents count] - 2], [hostComponents lastObject]];
    919             else
    920                 baseAddress = [NSString stringWithFormat: @"http://%@", [hostComponents lastObject]];
    921            
    922             id icon = [NSApp isOnSnowLeopardOrBetter] ? [fTrackerIconCache objectForKey: baseAddress]
    923                                                     : [fTrackerIconCacheLeopard objectForKey: baseAddress];
    924             if (!icon && ![fTrackerIconLoading containsObject: baseAddress])
    925             {
    926                 [fTrackerIconLoading addObject: baseAddress];
    927                 [NSThread detachNewThreadSelector: @selector(loadTrackerIcon:) toTarget: self withObject: baseAddress];
    928             }
    929            
    930             return (icon && icon != [NSNull null]) ? icon : [NSImage imageNamed: @"FavIcon.png"];
    931         }*/
    932895       
    933896        if ([item isKindOfClass: [NSNumber class]])
     
    935898        else
    936899            return item;
    937 
    938900    }
    939901    return nil;
    940 }
    941 
    942 - (void) loadTrackerIcon: (NSString *) baseAddress
    943 {
    944     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    945    
    946     NSURL * favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.ico"]];
    947    
    948     NSURLRequest * request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
    949                                 timeoutInterval: 30.0];
    950     NSData * iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
    951     NSImage * icon = [[NSImage alloc] initWithData: iconData];
    952    
    953     if (icon)
    954     {
    955         [fTrackerIconCache setObject: icon forKey: baseAddress];
    956         [fTrackerIconCacheLeopard setObject: icon forKey: baseAddress];
    957         [icon release];
    958     }
    959     else
    960     {
    961         [fTrackerIconCache setObject: [NSNull null] forKey: baseAddress];
    962         [fTrackerIconCacheLeopard setObject: [NSNull null] forKey: baseAddress];
    963     }
    964    
    965     [fTrackerIconLoading removeObject: baseAddress];
    966 
    967     [pool drain];
    968902}
    969903
  • trunk/macosx/TrackerCell.m

    r9197 r9203  
    2424
    2525#import "TrackerCell.h"
     26#import "NSApplicationAdditions.h"
    2627#import "TrackerNode.h"
    2728
    28 #define PADDING_HORIZONAL 2.0
    29 #define PADDING_STATUS_HORIZONAL 4.0
     29#define PADDING_HORIZONAL 3.0
     30#define PADDING_STATUS_HORIZONAL 3.0
    3031#define ICON_SIZE 14.0
    31 #define PADDING_BETWEEN_IMAGE_AND_NAME 4.0
     32#define PADDING_BETWEEN_ICON_AND_NAME 4.0
     33#define PADDING_ABOVE_ICON 1.0
    3234#define PADDING_ABOVE_NAME 2.0
    3335#define PADDING_BETWEEN_LINES 1.0
     
    3638
    3739- (NSImage *) favIcon;
     40- (void) loadTrackerIcon: (NSString *) baseAddress;
    3841
    3942- (NSRect) imageRectForBounds: (NSRect) bounds;
     
    4851@implementation TrackerCell
    4952
     53//make the favicons accessible to all tracker cells
     54NSCache * fTrackerIconCache;
     55NSMutableDictionary * fTrackerIconCacheLeopard;
     56NSMutableSet * fTrackerIconLoading;
     57
     58+ (void) initialize
     59{
     60    if ([NSApp isOnSnowLeopardOrBetter])
     61        fTrackerIconCache = [[NSCache alloc] init];
     62    else
     63        fTrackerIconCacheLeopard = [[NSMutableDictionary alloc] init];
     64    fTrackerIconLoading = [[NSMutableSet alloc] init];
     65}
     66
    5067- (id) init
    5168{
     
    89106{
    90107    //icon
    91     [[self favIcon] drawInRect: [self imageRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
    92                     fraction: 1.0];
     108    if ([NSApp isOnSnowLeopardOrBetter])
     109        [[self favIcon] drawInRect: [self imageRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
     110                        fraction: 1.0 respectFlipped: YES hints: nil];
     111    else
     112    {
     113        NSImage * icon = [self favIcon];
     114        [icon setFlipped: YES];
     115        [icon drawInRect: [self imageRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
     116    }
     117
    93118   
    94119    NSColor * nameColor, * statusColor;
     
    126151@end
    127152
    128 
    129153@implementation TrackerCell (Private)
    130154
    131 #warning needed?
    132155- (NSImage *) favIcon
    133156{
    134     return [NSImage imageNamed: @"FavIcon.png"];
     157    NSURL * address = [NSURL URLWithString: [(TrackerNode *)[self objectValue] host]];
     158    NSArray * hostComponents = [[address host] componentsSeparatedByString: @"."];
     159   
     160    //let's try getting the tracker address without using any subdomains
     161    NSString * baseAddress;
     162    if ([hostComponents count] > 1)
     163        baseAddress = [NSString stringWithFormat: @"http://%@.%@",
     164                        [hostComponents objectAtIndex: [hostComponents count] - 2], [hostComponents lastObject]];
     165    else
     166        baseAddress = [NSString stringWithFormat: @"http://%@", [hostComponents lastObject]];
     167   
     168    id icon = [NSApp isOnSnowLeopardOrBetter] ? [fTrackerIconCache objectForKey: baseAddress]
     169                                            : [fTrackerIconCacheLeopard objectForKey: baseAddress];
     170    if (!icon && ![fTrackerIconLoading containsObject: baseAddress])
     171    {
     172        [fTrackerIconLoading addObject: baseAddress];
     173        [NSThread detachNewThreadSelector: @selector(loadTrackerIcon:) toTarget: self withObject: baseAddress];
     174    }
     175   
     176    return (icon && icon != [NSNull null]) ? icon : [NSImage imageNamed: @"FavIcon.png"];
     177}
     178
     179- (void) loadTrackerIcon: (NSString *) baseAddress
     180{
     181    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
     182   
     183    NSURL * favIconUrl = [NSURL URLWithString: [baseAddress stringByAppendingPathComponent: @"favicon.ico"]];
     184   
     185    NSURLRequest * request = [NSURLRequest requestWithURL: favIconUrl cachePolicy: NSURLRequestUseProtocolCachePolicy
     186                                timeoutInterval: 30.0];
     187    NSData * iconData = [NSURLConnection sendSynchronousRequest: request returningResponse: NULL error: NULL];
     188    NSImage * icon = [[NSImage alloc] initWithData: iconData];
     189   
     190    if (icon)
     191    {
     192        [fTrackerIconCache setObject: icon forKey: baseAddress];
     193        [fTrackerIconCacheLeopard setObject: icon forKey: baseAddress];
     194        [icon release];
     195    }
     196    else
     197    {
     198        [fTrackerIconCache setObject: [NSNull null] forKey: baseAddress];
     199        [fTrackerIconCacheLeopard setObject: [NSNull null] forKey: baseAddress];
     200    }
     201   
     202    [fTrackerIconLoading removeObject: baseAddress];
     203
     204    [pool drain];
    135205}
    136206
     
    139209    NSRect result = bounds;
    140210    result.origin.x += PADDING_HORIZONAL;
    141     result.origin.y += PADDING_ABOVE_NAME;
     211    result.origin.y += PADDING_ABOVE_ICON;
    142212    result.size = NSMakeSize(ICON_SIZE, ICON_SIZE);
    143213   
     
    150220   
    151221    NSRect result = bounds;
    152     result.origin.x += PADDING_HORIZONAL + ICON_SIZE + PADDING_BETWEEN_IMAGE_AND_NAME;
     222    result.origin.x += PADDING_HORIZONAL + ICON_SIZE + PADDING_BETWEEN_ICON_AND_NAME;
    153223    result.origin.y += PADDING_ABOVE_NAME;
    154224       
  • trunk/macosx/TrackerNode.h

    r9200 r9203  
    4040- (NSString *) lastScrapeStatusString;
    4141
    42 #if 0
    43 
    44 - (BOOL) isActive;
    45 - (int) tier;
    46 
    47 - (BOOL) isAnnouncing;
    48 - (BOOL) hasAnnounced;
    49 - (BOOL) willAnnounce;
    50 - (NSDate *) nextAnnounceDate;
    51 
    52 - (BOOL) isScraping;
    53 - (BOOL) hasScraped;
    54 - (BOOL) willScrape;
    55 - (NSDate *) nextScrapeDate;
    56 
    57 - (int) lastAnnouncePeerCount;
    58 - (NSString *) lastAnnounceResult;
    59 - (NSDate *) lastAnnounceDate;
    60 - (NSDate *) lastAnnounceStartDate;
    61 - (BOOL) lastAnnounceSucceeded;
    62 - (NSDate *) lastAnnounceDate;
    63 
    64 - (NSString *) lastScrapeResult;
    65 - (NSDate *) lastScrapeDate;
    66 - (NSDate *) lastScrapeStartDate;
    67 - (BOOL) lastScrapeSucceeded;
    68 - (NSDate *) lastScrapeDate;
    69 
    70 - (int) seederCount;
    71 - (int) leecherCount;
    72 - (int) downloadCount;
    73 
    74 #endif
    75 
    7642@end
  • trunk/macosx/TrackerNode.m

    r9202 r9203  
    9191}
    9292
    93 #warning consider "isActive"
    9493- (NSString *) nextAnnounceStatusString
    9594{
Note: See TracChangeset for help on using the changeset viewer.