source: branches/CoreData/SapphireFrappliance/MetaData/Support/SapphireEntityDirectory.m @ 626

Revision 626, 3.7 KB checked in by gbooker, 6 years ago (diff)

Massive speed increase of the tvshow, cast, director, and genre virtual directories. Some of these are now even faster than the old ones.

Line 
1/*
2 * SapphireEntityDirectory.h
3 * Sapphire
4 *
5 * Created by Graham Booker on May 26, 2008.
6 * Copyright 2008 Sapphire Development Team and/or www.nanopi.net
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License as published by the Free Software Foundation; either version 3 of the License,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15 * Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with this program; if not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21#import "SapphireEntityDirectory.h"
22#import "CoreDataSupportFunctions.h"
23#import "SapphireBasicDirectoryFunctionsImports.h"
24
25@implementation SapphireEntityDirectory
26
27- (id)initWithEntityFetch:(EntityFetchFunction)fetch inContext:(NSManagedObjectContext *)context;
28{
29        self = [super init];
30        if(self == nil)
31                return self;
32       
33        fetchFunction = fetch;
34        moc = [context retain];
35        nameKey = [@"name" retain];
36        Basic_Directory_Function_Inits
37       
38        return self;
39}
40
41- (void) dealloc
42{
43        [moc release];
44        [entities release];
45        [nameKey release];
46        [fetchPredicate release];
47        [path release];
48        [notificationName release];
49        [[NSNotificationCenter defaultCenter] removeObserver:self];
50        Basic_Directory_Function_Deallocs
51        [super dealloc];
52}
53
54- (void)setNameKey:(NSString *)key
55{
56        [nameKey release];
57        nameKey = [key retain];
58}
59
60- (NSArray *)files
61{
62        return [NSArray array];
63}
64
65- (NSArray *)directories
66{
67        return [[entities allKeys] sortedArrayUsingSelector:@selector(nameCompare:)];
68}
69
70- (NSArray *)metaFiles
71{
72        return [NSArray array];
73}
74
75- (NSPredicate *)metaFileFetchPredicate
76{
77        return fetchPredicate;
78}
79
80- (void)setMetaFileFetchPredicate:(NSPredicate *)predicate
81{
82        [fetchPredicate release];
83        fetchPredicate = [predicate retain];
84}
85
86- (SapphireFileMetaData *)metaDataForFile:(NSString *)file
87{
88        return nil;
89}
90
91- (id <SapphireDirectory>)metaDataForDirectory:(NSString *)directory
92{
93        id <SapphireDirectory> ret = [entities objectForKey:directory];
94        [ret setFilterPredicate:filterPredicate];
95        return ret;
96}
97
98- (void)reloadDirectoryContents
99{
100        NSArray *objects = fetchFunction(moc, filterPredicate);
101        int i, count = [objects count];
102        NSMutableDictionary *newData = [[NSMutableDictionary alloc] init];
103        for(i=0; i<count; i++)
104        {
105                id obj = [objects objectAtIndex:i];
106                NSString *key = [obj valueForKey:nameKey];
107                if(key != nil)
108                        [newData setObject:obj forKey:key];
109        }
110        [entities release];
111        entities = [[NSDictionary alloc] initWithDictionary:newData];
112        [newData release];
113        [delegate directoryContentsChanged];
114}
115
116- (void)setPath:(NSString *)newPath
117{
118        [path release];
119        path = [newPath retain];
120}
121
122- (NSString *)path
123{
124        return path;
125}
126
127- (void)setNotificationName:(NSString *)notification
128{
129        [notificationName release];
130        notificationName = [notification retain];
131        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearPredicateCache) name:notificationName object:nil];
132}
133
134- (NSManagedObjectContext *)managedObjectContext
135{
136        return moc;
137}
138
139- (BOOL)isDeleted
140{
141        return NO;
142}
143
144- (NSString *)coverArtPath
145{
146        return nil;
147}
148
149- (void)refreshAllObjects
150{
151        NSEnumerator *objEnum;
152        NSManagedObject *obj;
153       
154        objEnum = [entities objectEnumerator];
155        while((obj = [objEnum nextObject]) != nil)
156        {
157                [moc refreshObject:obj mergeChanges:NO];
158        }
159}
160
161- (id <SapphireDirectory>)parentDirectory
162{
163        return nil;
164}
165
166#include "SapphireBasicDirectoryFunctions.h"
167
168@end
Note: See TracBrowser for help on using the repository browser.