2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include <NGExtensions/NGFileFolderInfoDataSource.h>
23 #import <EOControl/EOFetchSpecification.h>
24 #import <EOControl/EOQualifier.h>
25 #import <EOControl/EOSortOrdering.h>
28 NGExtensions_DECLARE NSString *NSFileName = @"NSFileName";
29 NGExtensions_DECLARE NSString *NSFilePath = @"NSFilePath";
30 NGExtensions_DECLARE NSString *NSParentPath = @"NSParentPath";
31 NGExtensions_DECLARE NSString *NSTraverseLinks = @"NSTraverseLinks";
33 @implementation NGFileFolderInfoDataSource
35 - (id)initWithFolderPath:(NSString *)_path {
36 if ((self = [self init])) {
37 self->folderPath = [_path copy];
43 [self->fspec release];
44 [self->folderPath release];
50 - (void)setFetchSpecification:(EOFetchSpecification *)_fspec {
51 ASSIGN(self->fspec, _fspec);
53 - (EOFetchSpecification *)fetchSpecification {
59 - (NSArray *)_attributesForPaths:(NSEnumerator *)_paths
60 filterUsingQualifier:(EOQualifier *)_q
61 fileManager:(NSFileManager *)_fm
64 NSMutableDictionary *workArea;
69 ma = [NSMutableArray arrayWithCapacity:256];
70 workArea = [NSMutableDictionary dictionaryWithCapacity:32];
72 tlinks = [[[self->fspec hints] objectForKey:@"NSTraverseLinks"] boolValue];
74 while ((path = [_paths nextObject])) {
78 fullPath = [self->folderPath stringByAppendingPathComponent:path];
80 [workArea setDictionary:
81 [_fm fileAttributesAtPath:fullPath traverseLink:tlinks]];
82 [workArea setObject:path forKey:@"NSFileName"];
83 [workArea setObject:fullPath forKey:@"NSFilePath"];
84 [workArea setObject:self->folderPath forKey:@"NSParentPath"];
86 record = [[workArea copy] autorelease];
89 if (![(id<EOQualifierEvaluation>)_q evaluateWithObject:record])
94 /* add to result set */
95 [ma addObject:record];
98 result = [[ma copy] autorelease];
102 - (NSArray *)_fetchObjectsFromFileManager:(NSFileManager *)_fm {
103 NSAutoreleasePool *pool;
106 NSArray *sortOrderings;
108 if (![_fm fileExistsAtPath:self->folderPath isDirectory:&isDir])
109 /* path does not exist */
112 /* path is not a directory */
115 pool = [[NSAutoreleasePool alloc] init];
117 array = [_fm directoryContentsAtPath:self->folderPath];
119 if ([array count] == 0) {
120 /* no directory contents */
121 array = [array retain];
123 return [array autorelease];
126 array = [self _attributesForPaths:[array objectEnumerator]
127 filterUsingQualifier:[self->fspec qualifier]
130 if ((sortOrderings = [self->fspec sortOrderings]))
132 array = [array sortedArrayUsingKeyOrderArray:sortOrderings];
134 array = [array retain];
137 return [array autorelease];
140 - (NSArray *)fetchObjects {
143 fm = [NSFileManager defaultManager];
144 return [self _fetchObjectsFromFileManager:fm];
147 @end /* NGFileInfoDataSource */