Changeset 626
- Timestamp:
- 07/05/08 22:26:31 (6 months ago)
- Files:
-
- branches/CoreData/SapphireFrappliance/FRAppliance/SapphireApplianceController.m (modified) (2 diffs)
- branches/CoreData/SapphireFrappliance/MetaData/Support/SapphireEntityDirectory.h (modified) (3 diffs)
- branches/CoreData/SapphireFrappliance/MetaData/Support/SapphireEntityDirectory.m (modified) (6 diffs)
- branches/CoreData/SapphireFrappliance/MetaData/Support/SapphireMovieDirectory.m (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/CoreData/SapphireFrappliance/FRAppliance/SapphireApplianceController.m
r608 r626 27 27 #import "SapphireBrowser.h" 28 28 #import "SapphireDirectoryMetaData.h" 29 #import "SapphireFileMetaData.h" 29 30 #import "SapphireSettings.h" 30 31 #import "SapphireTheme.h" 31 32 #import "SapphireCollectionDirectory.h" 33 #import "CoreDataSupportFunctions.h" 34 #import "SapphireEpisode.h" 32 35 33 36 #import "SapphireImporterDataMenu.h" … … 336 339 } 337 340 341 NSArray *showEntityFetch(NSManagedObjectContext *moc, NSPredicate *filterPredicate) 342 { 343 NSPredicate *fetchPredicate = [NSPredicate predicateWithFormat:@"tvEpisode != nil"]; 344 NSPredicate *finalPred; 345 if(filterPredicate == nil) 346 finalPred = fetchPredicate; 347 else 348 finalPred = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:filterPredicate, fetchPredicate, nil]]; 349 NSArray *files = doFetchRequest(SapphireFileMetaDataName, moc, finalPred); 350 351 NSSet *epIds = [NSSet setWithArray:[files valueForKeyPath:@"tvEpisode.objectID"]]; 352 NSPredicate *epPred = [NSPredicate predicateWithFormat:@"SELF IN %@", epIds]; 353 NSArray *episodes = doFetchRequest(SapphireEpisodeName, moc, epPred); 354 355 NSSet *showIds = [NSSet setWithArray:[episodes valueForKeyPath:@"tvShow.objectID"]]; 356 NSPredicate *showPred = [NSPredicate predicateWithFormat:@"SELF IN %@", showIds]; 357 358 return doFetchRequest(SapphireTVShowName, moc, showPred); 359 } 360 338 361 - (SapphireBrowser *)tvBrowser 339 362 { 340 363 BRTexture *predicateGem = [SapphireApplianceController gemForPredicate:[SapphireApplianceController predicate]]; 341 SapphireEntityDirectory *tvDir = [[SapphireEntityDirectory alloc] initWithEntity Name:SapphireTVShowName usingFilter:nilinContext:moc];364 SapphireEntityDirectory *tvDir = [[SapphireEntityDirectory alloc] initWithEntityFetch:showEntityFetch inContext:moc]; 342 365 [tvDir setMetaFileFetchPredicate:[NSPredicate predicateWithFormat:@"tvEpisode != nil"]]; 343 366 SapphireBrowser *tvBrowser = [[SapphireBrowser alloc] initWithScene:[self scene] metaData:tvDir]; branches/CoreData/SapphireFrappliance/MetaData/Support/SapphireEntityDirectory.h
r595 r626 22 22 #import "SapphireBasicDirectoryFunctionsDefines.h" 23 23 24 typedef NSArray* (*EntityFetchFunction)(NSManagedObjectContext *context, NSPredicate *filterPredicate); 25 24 26 /*! 25 27 * @brief A directory containing all of a particular managed object class … … 29 31 @interface SapphireEntityDirectory : NSObject <SapphireDirectory> { 30 32 NSManagedObjectContext *moc; /*!< @brief The context*/ 31 NSString *name; /*!< @brief The name of the entity to fetch*/33 EntityFetchFunction fetchFunction; /*!< @brief The function to fetch entities*/ 32 34 NSDictionary *entities; /*!< @brief The cached entity list*/ 33 35 NSString *nameKey; /*!< @brief The key to fetch the name of an entity*/ … … 42 44 * @brief Creates a new entity directory 43 45 * 44 * @param entityName The name of the entity to fetch46 * @param fetch The function to fetch entities 45 47 * @param context The context to use 46 * @param filter Filter to filter entity objects47 48 * @return The entity directory 48 49 */ 49 - (id)initWithEntity Name:(NSString *)entityName usingFilter:(NSPredicate *)filterinContext:(NSManagedObjectContext *)context;50 - (id)initWithEntityFetch:(EntityFetchFunction)fetch inContext:(NSManagedObjectContext *)context; 50 51 51 52 /*! branches/CoreData/SapphireFrappliance/MetaData/Support/SapphireEntityDirectory.m
r620 r626 25 25 @implementation SapphireEntityDirectory 26 26 27 - (id)initWithEntity Name:(NSString *)entityName usingFilter:(NSPredicate *)filter inContext:(NSManagedObjectContext *)context27 - (id)initWithEntityFetch:(EntityFetchFunction)fetch inContext:(NSManagedObjectContext *)context; 28 28 { 29 29 self = [super init]; … … 31 31 return self; 32 32 33 name = [entityName retain];33 fetchFunction = fetch; 34 34 moc = [context retain]; 35 35 nameKey = [@"name" retain]; 36 fetchFilter = [filter retain];37 36 Basic_Directory_Function_Inits 38 37 … … 42 41 - (void) dealloc 43 42 { 44 [name release];45 43 [moc release]; 46 44 [entities release]; … … 50 48 [notificationName release]; 51 49 [[NSNotificationCenter defaultCenter] removeObserver:self]; 52 [fetchFilter release];53 50 Basic_Directory_Function_Deallocs 54 51 [super dealloc]; … … 94 91 - (id <SapphireDirectory>)metaDataForDirectory:(NSString *)directory 95 92 { 96 return [entities objectForKey:directory]; 93 id <SapphireDirectory> ret = [entities objectForKey:directory]; 94 [ret setFilterPredicate:filterPredicate]; 95 return ret; 97 96 } 98 97 99 98 - (void)reloadDirectoryContents 100 99 { 101 NSArray *objects = doFetchRequest(name, moc, fetchFilter);100 NSArray *objects = fetchFunction(moc, filterPredicate); 102 101 int i, count = [objects count]; 103 102 NSMutableDictionary *newData = [[NSMutableDictionary alloc] init]; … … 105 104 { 106 105 id obj = [objects objectAtIndex:i]; 107 if(filterPredicate != nil && ![obj containsFileMatchingFilterPredicate:filterPredicate])108 continue;109 106 NSString *key = [obj valueForKey:nameKey]; 110 107 if(key != nil) 111 {112 [obj setFilterPredicate:filterPredicate];113 108 [newData setObject:obj forKey:key]; 114 }115 109 } 116 110 [entities release]; branches/CoreData/SapphireFrappliance/MetaData/Support/SapphireMovieDirectory.m
r610 r626 19 19 */ 20 20 21 #import <SapphireCompatClasses/SapphireFrontRowCompat.h> 22 21 23 #import "SapphireMovieDirectory.h" 22 24 #import "SapphireEntityDirectory.h" … … 31 33 #import "SapphireGenre.h" 32 34 35 NSArray *multiMovieEntityFetch(NSString *name, NSString *keyFromMovie, NSManagedObjectContext *moc, NSPredicate *filterPredicate) 36 { 37 NSPredicate *fetchPredicate = [NSPredicate predicateWithFormat:@"movie != nil"]; 38 NSPredicate *finalPred; 39 if(filterPredicate == nil) 40 finalPred = fetchPredicate; 41 else 42 finalPred = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:filterPredicate, fetchPredicate, nil]]; 43 NSArray *files = doFetchRequest(SapphireFileMetaDataName, moc, finalPred); 44 NSSet *movieIds = [NSSet setWithArray:[files valueForKeyPath:@"movie.objectID"]]; 45 46 NSPredicate *entPred; 47 if([SapphireFrontRowCompat usingTakeTwo] || ![SapphireFrontRowCompat usingFrontRow]) 48 { 49 /* Damn you Apple for not making take 2 Leopard. Not only does this make obj C 2 not available, 50 but it also means that I have to content with a crippled and slower core data. The else block here 51 executes on Leopard at several times the speed, but on Tiger throws the exception: 52 "to-many key not allowed here" even though it can be done through a JOIN in the SQL!!!!!*/ 53 NSPredicate *moviePred = [NSPredicate predicateWithFormat:@"SELF IN %@", movieIds]; 54 NSArray *movies = doFetchRequest(SapphireMovieName, moc, moviePred); 55 NSArray *entSet = [movies valueForKeyPath:[NSString stringWithFormat:@"@distinctUnionOfSets.%@.objectID", keyFromMovie]]; 56 57 entPred = [NSPredicate predicateWithFormat:@"SELF IN %@", entSet]; 58 } 59 else 60 entPred = [NSPredicate predicateWithFormat:@"ANY movies IN %@", movieIds]; 61 return doFetchRequest(name, moc, entPred); 62 } 63 64 NSArray *castEntityFetch(NSManagedObjectContext *moc, NSPredicate *filterPredicate) 65 { 66 return multiMovieEntityFetch(SapphireCastName, @"cast", moc, filterPredicate); 67 } 68 69 NSArray *directorEntityFetch(NSManagedObjectContext *moc, NSPredicate *filterPredicate) 70 { 71 return multiMovieEntityFetch(SapphireDirectorName, @"directors", moc, filterPredicate); 72 } 73 74 NSArray *genreEntityFetch(NSManagedObjectContext *moc, NSPredicate *filterPredicate) 75 { 76 return multiMovieEntityFetch(SapphireGenreName, @"genres", moc, filterPredicate); 77 } 78 33 79 @implementation SapphireMovieDirectory 34 80 … … 42 88 43 89 NSPredicate *allPred = [NSPredicate predicateWithFormat:@"movie != nil"]; 44 NSPredicate *majorCastPred = [NSPredicate predicateWithFormat:@"hasMajorRole = TRUE"];45 90 SapphireFilteredFileDirectory *all = [[SapphireFilteredFileDirectory alloc] initWithPredicate:allPred Context:moc]; 46 SapphireEntityDirectory *cast = [[SapphireEntityDirectory alloc] initWithEntity Name:SapphireCastName usingFilter:majorCastPredinContext:moc];47 SapphireEntityDirectory *director = [[SapphireEntityDirectory alloc] initWithEntity Name:SapphireDirectorName usingFilter:nilinContext:moc];48 SapphireEntityDirectory *genre = [[SapphireEntityDirectory alloc] initWithEntity Name:SapphireGenreName usingFilter:nilinContext:moc];91 SapphireEntityDirectory *cast = [[SapphireEntityDirectory alloc] initWithEntityFetch:castEntityFetch inContext:moc]; 92 SapphireEntityDirectory *director = [[SapphireEntityDirectory alloc] initWithEntityFetch:directorEntityFetch inContext:moc]; 93 SapphireEntityDirectory *genre = [[SapphireEntityDirectory alloc] initWithEntityFetch:genreEntityFetch inContext:moc]; 49 94 NSPredicate *top250Pred = [NSPredicate predicateWithFormat:@"movie.imdbTop250Ranking != 0"]; 50 95 SapphireFilteredFileDirectory *top250 = [[SapphireFilteredFileDirectory alloc] initWithPredicate:top250Pred Context:moc];
