2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
21 // $Id: UIxMailTree.m 278 2004-08-26 23:29:09Z helge $
23 #include <SOGoUI/UIxComponent.h>
25 @interface UIxMailTree : UIxComponent
32 #include "UIxMailTreeBlock.h"
33 #include <SOGo/SoObjects/Mailer/SOGoMailBaseObject.h>
35 #include <NGObjWeb/SoComponent.h>
36 #include <NGObjWeb/SoObject+SoDAV.h>
39 @implementation UIxMailTree
42 [self->rootNodes release];
49 - (void)setItem:(id)_item {
50 ASSIGN(self->item, _item);
56 /* navigation nodes */
58 - (BOOL)isRootObject:(id)_object {
59 if (![_object isNotNull]) {
60 [self warnWithFormat:@"(%s): got to root by nil lookup ...",
65 return [_object isKindOfClass:NSClassFromString(@"SOGoMailAccounts")];
68 - (NSString *)treeNavigationLinkForObject:(id)_object atDepth:(int)_depth {
72 link = [[_object nameInContainer] stringByAppendingString:@"/"];
73 for (i = 0; i < _depth; i++)
74 link = [@"../" stringByAppendingString:link];
78 - (UIxMailTreeBlock *)treeNavigationBlockForLeafNode:(id)_o atDepth:(int)_d {
83 Trigger plus in treeview if it has subfolders. It is an optimization that
84 we do not generate blocks for folders which are not displayed anyway.
86 blocks = [[_o toManyRelationshipKeys] count] > 0
87 ? [[NSArray alloc] initWithObjects:@"FAKE", nil]
90 md = [UIxMailTreeBlock blockWithName:nil
91 title:[_o davDisplayName]
92 link:[self treeNavigationLinkForObject:_o atDepth:_d]
93 isPathNode:NO isActiveNode:NO
98 - (UIxMailTreeBlock *)treeNavigationBlockForRootNode:(id)_object {
99 /* this generates the block for the clientObject */
100 UIxMailTreeBlock *md;
101 NSMutableArray *blocks;
105 /* process child folders */
107 folders = [_object fetchSubfolders];
108 count = [folders count];
109 blocks = [NSMutableArray arrayWithCapacity:count];
110 for (i = 0; i < count; i++) {
113 block = [self treeNavigationBlockForLeafNode:[folders objectAtIndex:i]
115 if ([block isNotNull]) [blocks addObject:block];
117 if ([blocks count] == 0)
122 md = [UIxMailTreeBlock blockWithName:[_object nameInContainer]
123 title:[_object davDisplayName]
124 link:[@"../" stringByAppendingString:
125 [_object nameInContainer]]
126 isPathNode:YES isActiveNode:YES
131 - (UIxMailTreeBlock *)treeNavigationBlockForActiveNode:(id)_object {
133 this generates the block for the clientObject (the object which has the
136 UIxMailTreeBlock *md;
137 NSMutableArray *blocks;
141 // TODO: maybe we can join the two implementations, this might not be
143 if ([self isRootObject:_object]) /* we are at the top */
144 return [self treeNavigationBlockForRootNode:_object];
146 /* process child folders */
148 folders = [_object fetchSubfolders];
149 count = [folders count];
150 blocks = [NSMutableArray arrayWithCapacity:count];
151 for (i = 0; i < count; i++) {
152 UIxMailTreeBlock *block;
154 block = [self treeNavigationBlockForLeafNode:[folders objectAtIndex:i]
156 if ([block isNotNull]) [blocks addObject:block];
158 if ([blocks count] == 0) blocks = nil;
162 md = [UIxMailTreeBlock blockWithName:[_object nameInContainer]
163 title:[_object davDisplayName]
165 isPathNode:YES isActiveNode:YES
170 - (UIxMailTreeBlock *)treeNavigationBlockForObject:(id)_object
171 withActiveChildBlock:(UIxMailTreeBlock *)_activeChildBlock
174 UIxMailTreeBlock *md;
175 NSMutableArray *blocks;
176 NSString *activeName;
180 if ([self isRootObject:_object]) /* we are at the top */
181 return _activeChildBlock;
183 /* the following is not run on the OGoMailAccounts (root) object */
185 activeName = [_activeChildBlock valueForKey:@"name"];
187 /* process child folders */
189 folders = [_object fetchSubfolders];
190 count = [folders count];
191 blocks = [NSMutableArray arrayWithCapacity:count];
192 for (i = 0; i < count; i++) {
193 UIxMailTreeBlock *block;
196 folder = [folders objectAtIndex:i];
197 block = [activeName isEqualToString:[folder nameInContainer]]
199 : [self treeNavigationBlockForLeafNode:folder atDepth:_depth];
201 if ([block isNotNull]) [blocks addObject:block];
203 if ([blocks count] == 0) blocks = nil;
207 md = [UIxMailTreeBlock blockWithName:[_object nameInContainer]
208 title:[_object davDisplayName]
209 link:[self treeNavigationLinkForObject:_object
210 atDepth:(_depth + 1)]
211 isPathNode:YES isActiveNode:NO
216 return [self treeNavigationBlockForObject:[_object container]
217 withActiveChildBlock:md
221 - (id)buildNavigationNodesForObject:(id)_object {
224 block = [self treeNavigationBlockForActiveNode:_object];
226 if ([self isRootObject:_object])
229 /* the following returns the root block! */
230 block = [self treeNavigationBlockForObject:[_object container]
231 withActiveChildBlock:block
238 - (NSArray *)rootNodes {
241 if (self->rootNodes != nil)
242 return self->rootNodes;
244 navNode = [self buildNavigationNodesForObject:[self clientObject]];
245 self->rootNodes = [[NSArray alloc] initWithObjects:&navNode count:1];
246 return self->rootNodes;
252 [self->item release]; self->item = nil;
253 [self->rootNodes release]; self->rootNodes = nil;
257 @end /* UIxMailTree */