source: trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireDirector.m @ 1291

Revision 1291, 2.8 KB checked in by gbooker, 4 years ago (diff)

Added sort by duration and sorting by filesize.

Line 
1#import "SapphireDirector.h"
2#import "CoreDataSupportFunctions.h"
3#import "SapphireFileSorter.h"
4#import "SapphireMetaDataSupport.h"
5
6@implementation SapphireDirector
7
8static NSArray *allowedSorts = nil;
9
10+ (void)load
11{
12        allowedSorts = [[NSArray alloc] initWithObjects:[SapphireMovieTitleSorter sharedInstance], [SapphireDurationSorter sharedInstance], [SapphireFileSizeSorter sharedInstance], [SapphireDateSorter sharedInstance], [SapphireMovieIMDBRatingSorter sharedInstance], nil];
13}
14
15+ (SapphireDirector *)director:(NSString *)director inContext:(NSManagedObjectContext *)moc
16{
17        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", director];
18        return (SapphireDirector *)doSingleFetchRequest(SapphireDirectorName, moc, predicate);
19}
20
21+ (SapphireDirector *)createDirector:(NSString *)director inContext:(NSManagedObjectContext *)moc
22{
23        SapphireDirector *ret = [SapphireDirector director:director inContext:moc];
24        if(ret != nil)
25                return ret;
26       
27        ret = [NSEntityDescription insertNewObjectForEntityForName:SapphireDirectorName inManagedObjectContext:moc];
28        ret.name = director;
29        return ret;
30}
31
32+ (NSDictionary *)upgradeDirectorsVersion:(int)version fromContext:(NSManagedObjectContext *)oldMoc toContext:(NSManagedObjectContext *)newMoc
33{
34        NSMutableDictionary *lookup = [NSMutableDictionary dictionary];
35        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
36        NSArray *oldDirectors = doFetchRequest(SapphireDirectorName, oldMoc, nil);
37        NSEnumerator *directorEnum = [oldDirectors objectEnumerator];
38        NSManagedObject *oldDirector;
39        while((oldDirector = [directorEnum nextObject]) != nil)
40        {
41                SapphireDirector *newDirector = [NSEntityDescription insertNewObjectForEntityForName:SapphireDirectorName inManagedObjectContext:newMoc];
42                NSString *name = [oldDirector valueForKey:@"name"];
43                newDirector.name = name;
44                newDirector.sortMethod = [oldDirector valueForKey:@"sortMethod"];
45                [lookup setObject:newDirector forKey:name];
46        }
47        [pool drain];
48        return lookup;
49}
50
51- (NSPredicate *)metaFileFetchPredicate
52{
53        NSArray *movieIds = [self.moviesSet valueForKey:@"objectID"];
54        return [NSPredicate predicateWithFormat:@"movie IN %@", movieIds];
55}
56
57- (NSArray *)fileSorters
58{
59        return allowedSorts;
60}
61
62- (NSString *)path
63{
64        return [[super path] stringByAppendingPathComponent:self.name];
65}
66
67- (NSString *)classDefaultCoverPath
68{
69        return [[NSBundle bundleForClass:[self class]] pathForResource:@"video_H" ofType:@"png"];
70}
71
72- (BOOL)shouldDelete
73{
74        return [self.moviesSet count] == 0;
75}
76
77-(void)removeMovies:(NSSet*)removedMovies
78{
79        [super removeMovies:removedMovies];
80        if([self.moviesSet count] == 0)
81                [SapphireMetaDataSupport setObjectForPendingDelete:self];
82}
83
84- (void)removeMoviesObject:(SapphireMovie *)removedMovie
85{
86        [super removeMoviesObject:removedMovie];
87        if([self.moviesSet count] == 0)
88                [SapphireMetaDataSupport setObjectForPendingDelete:self];
89}
90
91@end
Note: See TracBrowser for help on using the repository browser.