]> err.no Git - scalable-opengroupware.org/blob - OGoContentStore/OCSFolder.m
2bde8671bec7f8eb4eb11c57d81267beef37df82
[scalable-opengroupware.org] / OGoContentStore / OCSFolder.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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 "OCSFolder.h"
24 #include "OCSFolderManager.h"
25 #include "OCSFolderType.h"
26 #include "OCSChannelManager.h"
27 #include "NSURL+OCS.h"
28 #include "EOAdaptorChannel+OCS.h"
29 #include "common.h"
30
31 @implementation OCSFolder
32
33 static BOOL debugOn = YES;
34
35 + (void)initialize {
36   NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
37   
38   debugOn = [ud boolForKey:@"OCSFolderDebugEnabled"];
39 }
40
41 - (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId
42   folderTypeName:(NSString *)_ftname folderType:(OCSFolderType *)_ftype
43   location:(NSURL *)_loc quickLocation:(NSURL *)_qloc
44   folderManager:(OCSFolderManager *)_fm
45 {
46   if ((self = [super init])) {
47     self->folderManager  = [_fm    retain];
48     self->folderInfo     = [_ftype retain];
49     
50     self->folderId       = [_folderId copy];
51     self->folderName     = [[_path lastPathComponent] copy];
52     self->path           = [_path   copy];
53     self->location       = [_loc    retain];
54     self->quickLocation  = [_qloc   retain];
55     self->folderTypeName = [_ftname copy];
56   }
57   return self;
58 }
59 - (id)init {
60   return [self initWithPath:nil primaryKey:nil
61                folderTypeName:nil folderType:nil 
62                location:nil quickLocation:nil
63                folderManager:nil];
64 }
65
66 - (void)dealloc {
67   [self->folderManager  release];
68   [self->folderInfo     release];
69   [self->folderId       release];
70   [self->folderName     release];
71   [self->path           release];
72   [self->location       release];
73   [self->quickLocation  release];
74   [self->folderTypeName release];
75   [super dealloc];
76 }
77
78 /* accessors */
79
80 - (NSNumber *)folderId {
81   return self->folderId;
82 }
83
84 - (NSString *)folderName {
85   return self->folderName;
86 }
87 - (NSString *)path {
88   return self->path;
89 }
90
91 - (NSURL *)location {
92   return self->location;
93 }
94 - (NSURL *)quickLocation {
95   return self->quickLocation;
96 }
97
98 - (NSString *)folderTypeName {
99   return self->folderTypeName;
100 }
101
102 - (OCSFolderManager *)folderManager {
103   return self->folderManager;
104 }
105 - (OCSChannelManager *)channelManager {
106   return [[self folderManager] channelManager];
107 }
108
109 - (NSString *)storeTableName {
110   return [[self location] ocsTableName];
111 }
112 - (NSString *)quickTableName {
113   return [[self quickLocation] ocsTableName];
114 }
115
116 /* channels */
117
118 - (EOAdaptorChannel *)acquireStoreChannel {
119   return [[self channelManager] acquireOpenChannelForURL:[self location]];
120 }
121 - (EOAdaptorChannel *)acquireQuickChannel {
122   return [[self channelManager] acquireOpenChannelForURL:[self quickLocation]];
123 }
124
125 - (void)releaseChannel:(EOAdaptorChannel *)_channel {
126   [[self channelManager] releaseChannel:_channel];
127   if (debugOn) [self debugWithFormat:@"released channel: %@", _channel];
128 }
129
130 - (BOOL)canConnectStore {
131   return [[self channelManager] canConnect:[self location]];
132 }
133 - (BOOL)canConnectQuick {
134   return [[self channelManager] canConnect:[self quickLocation]];
135 }
136
137 /* operations */
138
139 - (NSArray *)subFolderNames {
140   return [[self folderManager] listSubFoldersAtPath:[self path]
141                                recursive:NO];
142 }
143 - (NSArray *)allSubFolderNames {
144   return [[self folderManager] listSubFoldersAtPath:[self path]
145                                recursive:YES];
146 }
147
148 /* description */
149
150 - (NSString *)description {
151   NSMutableString *ms;
152   id tmp;
153   
154   ms = [NSMutableString stringWithCapacity:256];
155   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
156
157   if (self->folderId)
158     [ms appendFormat:@" id=%@", self->folderId];
159   else
160     [ms appendString:@" no-id"];
161
162   if ((tmp = [self path]))           [ms appendFormat:@" path=%@", tmp];
163   if ((tmp = [self folderTypeName])) [ms appendFormat:@" type=%@", tmp];
164   if ((tmp = [self location]))
165     [ms appendFormat:@" loc=%@", [tmp absoluteString]];
166   
167   [ms appendString:@">"];
168   return ms;
169 }
170
171 @end /* OCSFolder */