]> err.no Git - sope/blob - sope-core/NGExtensions/FdExt.subproj/NSFileManager+Extensions.m
renamed packages as discussed in the developer list
[sope] / sope-core / NGExtensions / FdExt.subproj / NSFileManager+Extensions.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "NSFileManager+Extensions.h"
24 #include "NGFileFolderInfoDataSource.h"
25 #include <EOControl/EOGlobalID.h>
26 #include "common.h"
27
28 @interface NSFileManagerGlobalID : EOGlobalID < NSCopying >
29 {
30 @public
31   NSString *path;
32 }
33 @end
34
35 // TODO: support -lastException
36 // TODO: add stuff like -dictionaryAtPath:, -arrayAtPath:, -propertyListAtPath:
37
38 @implementation NSFileManager(ExtendedFileManagerImp)
39
40 /* path modifications */
41
42 - (NSString *)standardizePath:(NSString *)_path {
43   if (![_path isAbsolutePath])
44     _path = [[self currentDirectoryPath] stringByAppendingPathComponent:_path];
45   
46   return [_path stringByStandardizingPath];
47 }
48 - (NSString *)resolveSymlinksInPath:(NSString *)_path {
49   return [_path stringByResolvingSymlinksInPath];
50 }
51 - (NSString *)expandTildeInPath:(NSString *)_path {
52   return [_path stringByExpandingTildeInPath];
53 }
54
55 /* feature check */
56
57 - (BOOL)supportsVersioningAtPath:(NSString *)_path {
58   return NO;
59 }
60 - (BOOL)supportsLockingAtPath:(NSString *)_path {
61   return NO;
62 }
63 - (BOOL)supportsFolderDataSourceAtPath:(NSString *)_path {
64   return YES;
65 }
66
67 - (BOOL)supportsFeature:(NSString *)_featureURI atPath:(NSString *)_path {
68   if ([_featureURI isEqualToString:NGFileManagerFeature_DataSources])
69     return YES;
70   
71   return NO;
72 }
73
74 /* writing */
75
76 - (BOOL)writeContents:(NSData *)_content atPath:(NSString *)_path {
77   return [_content writeToFile:_path atomically:YES];
78 }
79
80 /* global-IDs */
81
82 - (EOGlobalID *)globalIDForPath:(NSString *)_path {
83   NSFileManagerGlobalID *gid;
84   
85   _path = [self standardizePath:_path];
86   
87   gid = [[NSFileManagerGlobalID alloc] init];
88   gid->path = [_path copy];
89   return [gid autorelease];
90 }
91 - (NSString *)pathForGlobalID:(EOGlobalID *)_gid {
92   NSFileManagerGlobalID *gid;
93   
94   if (![_gid isKindOfClass:[NSFileManagerGlobalID class]])
95     /* not a gid we can handle ... */
96     return nil;
97   
98   gid = (NSFileManagerGlobalID *)_gid;
99   return gid->path;
100 }
101
102 /* datasources (work on folders) */
103
104 - (EODataSource *)dataSourceAtPath:(NSString *)_path {
105   return
106     [[[NGFileFolderInfoDataSource alloc] initWithFolderPath:_path] autorelease];
107 }
108
109 - (EODataSource *)dataSource {
110   return [self dataSourceAtPath:[self currentDirectoryPath]];
111 }
112
113 /* trash */
114
115 - (BOOL)supportsTrashFolderAtPath:(NSString *)_path {
116   return NO;
117 }
118 - (NSString *)trashFolderForPath:(NSString *)_path {
119   return nil;
120 }
121
122 - (BOOL)trashFileAtPath:(NSString *)_path handler:(id)_handler {
123   // TODO: support trashfolder on MacOSX ?
124   return NO;
125 }
126
127 @end /* NSFileManager(ExtendedFileManagerImp) */
128
129 @implementation NSFileManagerGlobalID
130
131 - (void)dealloc {
132   [self->path release];
133   [super dealloc];
134 }
135
136 /* NSCopying */
137
138 - (id)copyWithZone:(NSZone *)_zone {
139   /* global IDs are immutable, so we can return an retained object ... */
140   return [self retain];
141 }
142
143 /* description */
144
145 - (NSString *)description {
146   NSMutableString *ms = [NSMutableString stringWithCapacity:32];
147   
148   [ms appendFormat:@"<0x%08X[%@]", self, NSStringFromClass([self class])];
149   [ms appendFormat:@" path=%@", self->path];
150   [ms appendString:@">"];
151   return ms;
152 }
153
154 @end /* NSFileManagerGlobalID */