Show
Ignore:
Timestamp:
10/14/09 23:11:11 (3 years ago)
Author:
gbooker
Message:

XML based virtual movie directories. Patch by skyy99_1111
Fixes #313

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/SapphireFrappliance/MetaData/Support/SapphireMovieDirectory.m

    r908 r934  
    2727#import "SapphireBasicDirectoryFunctionsImports.h" 
    2828#import "SapphireFileSorter.h" 
    29  
     29#import "SapphireMovieVirtualDirectoryImporter.h" 
     30#import "SapphireMovieVirtualDirectory.h" 
    3031#import "SapphireMovie.h" 
    3132#import "SapphireCast.h" 
     
    8990         
    9091        moc = [context retain]; 
    91  
     92         
     93        /*Define the static virtual directories*/ 
    9294        NSPredicate *allPred = [NSPredicate predicateWithFormat:@"movie != nil"]; 
    9395        SapphireFilteredFileDirectory *all = [[SapphireFilteredFileDirectory alloc] initWithPredicate:allPred Context:moc]; 
     
    99101        NSPredicate *oscarPred = [NSPredicate predicateWithFormat:@"movie.oscarsWon != 0"]; 
    100102        SapphireFilteredFileDirectory *oscar = [[SapphireFilteredFileDirectory alloc] initWithPredicate:oscarPred Context:moc]; 
    101          
    102         subDirs = [[NSArray alloc] initWithObjects: 
    103                            all, 
    104                            cast, 
    105                            director, 
    106                            genre, 
    107                            top250, 
    108                            oscar, 
    109                            nil]; 
    110         names = [[NSArray alloc] initWithObjects: 
    111                            BRLocalizedString( @"All Movies", @"Select all movies" ), 
    112                            BRLocalizedString( @"By Cast", @"Select movies based on cast members" ), 
    113                            BRLocalizedString( @"By Director", @"Select movies based on director" ), 
    114                            BRLocalizedString( @"By Genre", @"Select movies based on genre" ), 
    115                            BRLocalizedString( @"IMDB Top 250", @"Show movies in IMDb Top 250 only" ), 
    116                            BRLocalizedString( @"Academy Award Winning", @"Show Oscar winning movies only" ), 
    117                            nil]; 
    118          
     103 
     104        originalSubDirs = [[NSArray alloc] initWithObjects: 
     105                                           all, 
     106                                           cast, 
     107                                           director, 
     108                                           genre, 
     109                                           top250, 
     110                                           oscar, 
     111                                           nil]; 
     112         
     113        originalNames = [[NSArray alloc] initWithObjects: 
     114                                         BRLocalizedString( @"All Movies", @"Select all movies" ), 
     115                                         BRLocalizedString( @"By Cast", @"Select movies based on cast members" ), 
     116                                         BRLocalizedString( @"By Director", @"Select movies based on director" ), 
     117                                         BRLocalizedString( @"By Genre", @"Select movies based on genre" ), 
     118                                         BRLocalizedString( @"IMDB Top 250", @"Show movies in IMDb Top 250 only" ), 
     119                                         BRLocalizedString( @"Academy Award Winning", @"Show Oscar winning movies only" ), 
     120                                         nil]; 
     121                                          
    119122        SapphireFileSorter *titleSort = [SapphireMovieTitleSorter sharedInstance]; 
    120123        SapphireFileSorter *imdbRankSort = [SapphireMovieIMDBTop250RankSorter sharedInstance]; 
     
    124127         
    125128        NSString *moviePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"video_H" ofType:@"png"]; 
    126          
     129        vdImport = [[SapphireMovieVirtualDirectoryImporter alloc] initWithPath:[applicationSupportDir() stringByAppendingPathComponent:@"virtualDirs.xml"]]; 
     130        defaultSorters = [[NSArray alloc] initWithObjects:titleSort, dateSort, imdbRatingSort, nil]; 
     131         
     132        /*Finish the static directory setup*/ 
    127133        [all setPath:VIRTUAL_DIR_ALL_PATH]; 
    128134        [all setCoverArtPath:moviePath]; 
     
    157163- (void) dealloc 
    158164{ 
     165        [originalSubDirs release]; 
     166        [originalNames release]; 
    159167        [subDirs release]; 
    160168        [names release]; 
     169        [virtualDirs release]; 
     170        [defaultSorters release]; 
     171        [vdImport release]; 
    161172        Basic_Directory_Function_Deallocs 
    162173        [super dealloc]; 
     
    209220- (void)reloadDirectoryContents 
    210221{ 
     222        /*Import any defined movie virtual directories*/ 
     223        NSArray *newVirtualDirs = [vdImport virtualDirectories]; 
     224        if(![virtualDirs isEqualToArray:newVirtualDirs]) 
     225        { 
     226                [virtualDirs release]; 
     227                [names release]; 
     228                [subDirs release]; 
     229                virtualDirs = [newVirtualDirs retain]; 
     230                names = [originalNames mutableCopy]; 
     231                subDirs = [originalSubDirs mutableCopy]; 
     232                 
     233                NSString *moviePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"video_H" ofType:@"png"]; 
     234                NSEnumerator *mvdEnum = [newVirtualDirs objectEnumerator]; 
     235                SapphireMovieVirtualDirectory *virtualDir; 
     236                while((virtualDir = [mvdEnum nextObject]) != nil) 
     237                { 
     238                        SapphireFilteredFileDirectory *custom = [[SapphireFilteredFileDirectory alloc] initWithPredicate:[virtualDir predicate] Context:moc]; 
     239                        [subDirs addObject:custom]; 
     240                        [names addObject:BRLocalizedString([virtualDir title], [virtualDir description])]; 
     241                        [custom setPath:[[VIRTUAL_DIR_ROOT_PATH stringByAppendingString:@"/"] stringByAppendingString:[virtualDir description]]]; 
     242                        [custom setCoverArtPath:moviePath]; // Change this to be part of the XML? 
     243                        [custom setFileSorters:defaultSorters]; 
     244                        NSLog(@"Added %@, %@: %@", [names lastObject], [virtualDir predicate],[subDirs lastObject]); 
     245                        [custom release]; 
     246                } 
     247        } 
     248         
    211249        [subDirs makeObjectsPerformSelector:@selector(setFilterPredicate:) withObject:filterPredicate]; 
    212250        [delegate directoryContentsChanged];