source: branches/CoreData/SapphireFrappliance/MetaData/Support/SapphireBasicDirectoryFunctions.h @ 573

Revision 573, 5.4 KB checked in by gbooker, 6 years ago (diff)

Some accellerations

Line 
1/*
2 * SapphireBasicDirectoryFunctions.h
3 * Sapphire
4 *
5 * Created by Graham Booker on Apr. 9, 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/* This file contains functions which are commonly used for all virtual directories.
22   It assumes the definition of a few instance variables, which can be set using defines in SapphireBasicDirectoryFunctionsDefines. */
23
24#ifndef RECURSIVE_FUNCTIONS_ALREADY_DEFINED
25/*Function to invoke a command on all files in a subtree*/
26- (void)invokeRecursivelyOnFiles:(NSInvocation *)fileInv
27{
28        NSArray *files = [self metaFiles];
29        if([files count])
30        {
31                SapphireFileMetaData *file;
32                NSEnumerator *fileEnum = [files objectEnumerator];
33                while((file = [fileEnum nextObject]) != nil)
34                {
35                        [fileInv invokeWithTarget:file];
36                }
37        }
38}
39
40- (BOOL)checkPredicate:(NSComparisonPredicate *)pred
41{
42        NSPredicate *fetchPred = [self metaFileFetchPredicate];
43        if(fetchPred != nil)
44        {
45                NSPredicate *final = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:pred, fetchPred, nil]];
46                return entityExists(SapphireFileMetaDataName, [self managedObjectContext], final);     
47        }
48       
49        NSArray *files = [self metaFiles];
50        int i, count = [files count];
51        for(i=0; i<count; i++)
52                if([pred evaluateWithObject:[files objectAtIndex:i]])
53                        return YES;
54       
55        NSArray *dirs = [self directories];
56        count = [dirs count];
57        for(i=0; i<count; i++)
58        {
59                NSString *dirName = [dirs objectAtIndex:i];
60                id <SapphireDirectory> dir = [self metaDataForDirectory:dirName];
61                if([pred evaluateWithObject:dir])
62                        return YES;
63        }
64       
65        return NO;
66}
67
68- (void)getSubFileMetasWithDelegate:(id <SapphireMetaDataScannerDelegate>)subDelegate skipDirectories:(NSMutableSet *)skip
69{
70}
71
72- (void)scanForNewFilesWithDelegate:(id <SapphireMetaDataScannerDelegate>)subDelegate skipDirectories:(NSMutableSet *)skip
73{
74}
75
76- (void)cancelImport
77{
78}
79
80- (void)resumeImport
81{
82}
83
84#endif
85
86- (BOOL)watchedValue
87{
88        NSComparisonPredicate *predicate = (NSComparisonPredicate *)[NSPredicate predicateWithFormat:@"watched == NO"];
89        BOOL ret = [self checkPredicate:predicate];
90        return !ret;
91}
92
93- (NSNumber *)watched
94{
95        return [NSNumber numberWithBool:[self watchedValue]];
96}
97
98- (void)setWatchedValue:(BOOL)watched
99{
100        [self setWatched:[NSNumber numberWithBool:watched]];
101}
102
103- (void)setWatched:(NSNumber *)watched
104{
105        SEL select = @selector(setWatched:);
106        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[SapphireFileMetaData class] instanceMethodSignatureForSelector:select]];
107        [inv setSelector:select];
108        [inv setArgument:&watched atIndex:2];
109        [self invokeRecursivelyOnFiles:inv];
110        [SapphireMetaDataSupport save:[self managedObjectContext]];
111}
112
113- (BOOL)favoriteValue
114{
115        NSComparisonPredicate *predicate = (NSComparisonPredicate *)[NSPredicate predicateWithFormat:@"favorite == YES"];
116        BOOL ret = [self checkPredicate:predicate];
117        return ret;
118}
119
120- (NSNumber *)favorite
121{
122        return [NSNumber numberWithBool:[self favoriteValue]];
123}
124
125- (void)setFavoriteValue:(BOOL)favorite
126{
127        [self setFavorite:[NSNumber numberWithBool:favorite]];
128}
129
130- (void)setFavorite:(NSNumber *)favorite
131{
132        SEL select = @selector(setFavorite:);
133        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[SapphireFileMetaData class] instanceMethodSignatureForSelector:select]];
134        [inv setSelector:select];
135        [inv setArgument:&favorite atIndex:2];
136        [self invokeRecursivelyOnFiles:inv];
137        [SapphireMetaDataSupport save:[self managedObjectContext]];
138}
139
140- (void)setFilterPredicate:(NSPredicate *)predicate
141{
142        [filterPredicate release];
143        filterPredicate = [predicate retain];
144}
145
146- (id <SapphireMetaDataDelegate>)delegate
147{
148        return delegate;
149}
150
151- (void)setDelegate:(id <SapphireMetaDataDelegate>)newDelegate
152{
153        [newDelegate retain];
154        [delegate release];
155        delegate = newDelegate;
156        if(delegate == nil)
157                [self refreshAllObjects];
158}
159
160- (NSMutableDictionary *)getDisplayedMetaDataInOrder:(NSArray * *)order;
161{
162        if(order != nil)
163                *order = nil;
164        return [NSMutableDictionary dictionaryWithObjectsAndKeys:
165                        [[self path] lastPathComponent], META_TITLE_KEY,
166                        nil];
167}
168
169- (void)setToReimportFromMask:(int)mask
170{
171        SEL select = @selector(setToReimportFromMask:);
172        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[SapphireFileMetaData class] instanceMethodSignatureForSelector:select]];
173        [inv setSelector:select];
174        NSNumber *num = [NSNumber numberWithInt:mask];
175        [inv setArgument:&num atIndex:2];
176        [self invokeRecursivelyOnFiles:inv];
177        [SapphireMetaDataSupport save:[self managedObjectContext]];
178}
179
180- (void)clearMetaData
181{
182        SEL select = @selector(clearMetaData);
183        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[SapphireFileMetaData class] instanceMethodSignatureForSelector:select]];
184        [inv setSelector:select];
185        [self invokeRecursivelyOnFiles:inv];
186        [SapphireMetaDataSupport save:[self managedObjectContext]];
187}
Note: See TracBrowser for help on using the repository browser.