Changeset 5490

Show
Ignore:
Timestamp:
05/02/08 14:58:58 (2 weeks ago)
Author:
morris
Message:

Tip user about the Flip4Mac component if opening WMV file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Spiral/trunk/SPApplicationController.h

    r5471 r5490  
    5959- (BOOL)openFile:(NSString *)path withPlaylistFile:(SPPlaylistFile *)file; 
    6060- (BOOL)openURL:(WIURL *)url withPlaylistFile:(SPPlaylistFile *)file; 
    61 - (BOOL)hasPerianInstalled; 
    6261- (void)scheduleUpdateCheck; 
    6362 
  • Spiral/trunk/SPApplicationController.m

    r5485 r5490  
    3939#import "SPWiiRemote.h" 
    4040 
     41#define SPFilenameErrorKey                              @"SPFilenameErrorKey" 
     42#define SPRecoveryURLErrorKey                   @"SPRecoveryURLErrorKey" 
     43 
     44 
    4145static SPApplicationController                  *SPSharedApplicationController; 
    4246 
     
    4650- (SPRemoteContext)_remoteContext; 
    4751- (void)_handleRemoteAction:(SPRemoteAction)action; 
     52 
     53- (BOOL)_hasQuicktimeComponentWithName:(NSString *)name; 
     54- (BOOL)_hasPerianInstalled; 
     55- (BOOL)_hasFlip4MacWMVImportInstalled; 
    4856 
    4957@end 
     
    199207} 
    200208 
     209 
     210 
     211#pragma mark - 
     212 
     213- (BOOL)_hasQuicktimeComponentWithName:(NSString *)name { 
     214        NSString                *libraryPath, *componentPath; 
     215         
     216        for(libraryPath in NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES)) { 
     217                componentPath = [libraryPath stringByAppendingPathComponent:[NSSWF:@"Quicktime/%@.component", name]]; 
     218                 
     219                if([[NSFileManager defaultManager] fileExistsAtPath:componentPath]) 
     220                        return YES; 
     221        } 
     222         
     223        return NO; 
     224} 
     225 
     226 
     227 
     228- (BOOL)_hasPerianInstalled { 
     229        return [self _hasQuicktimeComponentWithName:@"Perian"]; 
     230} 
     231 
     232 
     233 
     234- (BOOL)_hasFlip4MacWMVImportInstalled { 
     235        return [self _hasQuicktimeComponentWithName:@"Flip4Mac WMV Import"]; 
     236} 
     237 
    201238@end 
    202239 
     
    251288- (NSError *)application:(NSApplication *)application willPresentError:(NSError *)error { 
    252289        NSMutableDictionary             *userInfo; 
    253         NSString                                *recoverySuggestion; 
     290        NSString                                *filename, *recoverySuggestion; 
    254291         
    255292        if([error domain] == NSOSStatusErrorDomain && [error code] == -2048) { 
     
    263300                        recoverySuggestion = NSLS(@"The file is not a movie file.", @"Error description"); 
    264301                 
    265                 if(![self hasPerianInstalled]) { 
     302                filename = [[error userInfo] objectForKey:SPFilenameErrorKey]; 
     303                 
     304                if([[[filename pathExtension] lowercaseString] isEqualToString:@"wmv"] && ![self _hasFlip4MacWMVImportInstalled]) { 
     305                        recoverySuggestion = [recoverySuggestion stringByAppendingFormat:@"\n\n%@", 
     306                                NSLS(@"Try installing Flip4Mac WMV, a free QuickTime component that adds native support for the Windows Media file format.", 
     307                                         @"Error recovery suggestion")]; 
     308                 
     309                        [userInfo setObject:[NSArray arrayWithObjects: 
     310                                                                NSLS(@"OK", @"Error button title"), 
     311                                                                NSLS(@"Flip4Mac WMV Homepage", @"Error button title"), 
     312                                                                NULL] 
     313                                                 forKey:NSLocalizedRecoveryOptionsErrorKey]; 
     314                        [userInfo setObject:self forKey:NSRecoveryAttempterErrorKey]; 
     315                        [userInfo setObject:[WIURL URLWithString:@"http://www.flip4mac.com/wmv_download.htm"] forKey:SPRecoveryURLErrorKey]; 
     316                } 
     317                else if(![self _hasPerianInstalled]) { 
    266318                        recoverySuggestion = [recoverySuggestion stringByAppendingFormat:@"\n\n%@", 
    267319                                NSLS(@"Try installing Perian, a free QuickTime component that adds native support for many popular video formats.", 
     
    274326                                                 forKey:NSLocalizedRecoveryOptionsErrorKey]; 
    275327                        [userInfo setObject:self forKey:NSRecoveryAttempterErrorKey]; 
     328                        [userInfo setObject:[WIURL URLWithString:@"http://www.perian.org/"] forKey:SPRecoveryURLErrorKey]; 
    276329                } 
    277330                 
     
    283336         
    284337        return error; 
     338} 
     339 
     340 
     341 
     342- (BOOL)attemptRecoveryFromError:(NSError *)error optionIndex:(NSUInteger)optionIndex { 
     343        if(optionIndex == 1) 
     344                [[NSWorkspace sharedWorkspace] openURL:[[[error userInfo] objectForKey:SPRecoveryURLErrorKey] URL]]; 
     345         
     346        return NO; 
    285347} 
    286348 
     
    560622        if(!movie) { 
    561623                if(error) { 
    562                         if(![[controller movieController] isInFullscreen]) 
     624                        if(![[controller movieController] isInFullscreen]) { 
     625                                error = [error errorByAddingUserInfo: 
     626                                        [NSDictionary dictionaryWithObject:[url lastPathComponent] forKey:SPFilenameErrorKey]]; 
     627 
    563628                                [[NSDocumentController sharedDocumentController] presentError:error]; 
     629                        } 
    564630                } 
    565631                 
     
    582648         
    583649        return YES; 
    584 } 
    585  
    586  
    587  
    588 - (BOOL)hasPerianInstalled { 
    589         NSString                *libraryPath, *perianPath; 
    590         BOOL                    hasPerian = NO; 
    591          
    592         for(libraryPath in NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES)) { 
    593                 perianPath = [libraryPath stringByAppendingPathComponent:@"QuickTime/Perian.component"]; 
    594                  
    595                 if([[NSFileManager defaultManager] fileExistsAtPath:perianPath]) { 
    596                         hasPerian = YES; 
    597                          
    598                         break; 
    599                 } 
    600         } 
    601          
    602         return hasPerian; 
    603650} 
    604651