2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include <NGExtensions/NGFileFolderInfoDataSource.h>
24 #import <EOControl/EOFetchSpecification.h>
25 #import <EOControl/EOQualifier.h>
26 #import <EOControl/EOSortOrdering.h>
29 NGExtensions_DECLARE NSString *NSFileName = @"NSFileName";
30 NGExtensions_DECLARE NSString *NSFilePath = @"NSFilePath";
31 NGExtensions_DECLARE NSString *NSParentPath = @"NSParentPath";
32 NGExtensions_DECLARE NSString *NSTraverseLinks = @"NSTraverseLinks";
34 @implementation NGFileFolderInfoDataSource
36 - (id)initWithFolderPath:(NSString *)_path {
37 if ((self = [self init])) {
38 self->folderPath = [_path copy];
44 [self->fspec release];
45 [self->folderPath release];
51 - (void)setFetchSpecification:(EOFetchSpecification *)_fspec {
52 ASSIGN(self->fspec, _fspec);
54 - (EOFetchSpecification *)fetchSpecification {
60 - (NSArray *)_attributesForPaths:(NSEnumerator *)_paths
61 filterUsingQualifier:(EOQualifier *)_q
62 fileManager:(NSFileManager *)_fm
65 NSMutableDictionary *workArea;
70 ma = [NSMutableArray arrayWithCapacity:256];
71 workArea = [NSMutableDictionary dictionaryWithCapacity:32];
73 tlinks = [[[self->fspec hints] objectForKey:@"NSTraverseLinks"] boolValue];
75 while ((path = [_paths nextObject])) {
79 fullPath = [self->folderPath stringByAppendingPathComponent:path];
81 [workArea setDictionary:
82 [_fm fileAttributesAtPath:fullPath traverseLink:tlinks]];
83 [workArea setObject:path forKey:@"NSFileName"];
84 [workArea setObject:fullPath forKey:@"NSFilePath"];
85 [workArea setObject:self->folderPath forKey:@"NSParentPath"];
87 record = [[workArea copy] autorelease];
90 if (![(id<EOQualifierEvaluation>)_q evaluateWithObject:record])
95 /* add to result set */
96 [ma addObject:record];
99 result = [[ma copy] autorelease];
103 - (NSArray *)_fetchObjectsFromFileManager:(NSFileManager *)_fm {
104 NSAutoreleasePool *pool;
107 NSArray *sortOrderings;
109 if (![_fm fileExistsAtPath:self->folderPath isDirectory:&isDir])
110 /* path does not exist */
113 /* path is not a directory */
116 pool = [[NSAutoreleasePool alloc] init];
118 array = [_fm directoryContentsAtPath:self->folderPath];
120 if ([array count] == 0) {
121 /* no directory contents */
122 array = [array retain];
124 return [array autorelease];
127 array = [self _attributesForPaths:[array objectEnumerator]
128 filterUsingQualifier:[self->fspec qualifier]
131 if ((sortOrderings = [self->fspec sortOrderings]))
133 array = [array sortedArrayUsingKeyOrderArray:sortOrderings];
135 array = [array retain];
138 return [array autorelease];
141 - (NSArray *)fetchObjects {
144 fm = [NSFileManager defaultManager];
145 return [self _fetchObjectsFromFileManager:fm];
148 @end /* NGFileInfoDataSource */