From 52ad1f4e8847ea9199784cc4a17b22dadfc14adc Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 9 Nov 2004 15:02:56 +0000 Subject: [PATCH] mailtree cleanups git-svn-id: http://svn.opengroupware.org/SOGo/trunk@449 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Mailer/ChangeLog | 3 + SOGo/SoObjects/Mailer/GNUmakefile | 2 + SOGo/SoObjects/Mailer/SOGoMailAccounts.m | 69 ------- SOGo/SoObjects/Mailer/SOGoMailBaseObject.h | 4 + SOGo/SoObjects/Mailer/SOGoMailBaseObject.m | 120 +----------- SOGo/SoObjects/Mailer/SOGoMailTree.m | 216 +++++++++++++++++++++ SOGo/SoObjects/Mailer/Version | 2 +- SOGo/UI/Mailer/ChangeLog | 2 + SOGo/UI/Mailer/UIxMailTree.m | 44 ++--- SOGo/UI/Mailer/Version | 2 +- 10 files changed, 249 insertions(+), 215 deletions(-) create mode 100644 SOGo/SoObjects/Mailer/SOGoMailTree.m diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 1d7f9be3..bd3ccc1e 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,8 @@ 2004-11-09 Helge Hess + * SOGoMailBaseObject.m, SOGoMailAccounts.m: moved tree code to separate + file (v0.9.50) + * SOGoMailBaseObject.m, SOGoMailManager.m, SOGoMailConnectionEntry.m: added cache flush operations for getmail (v0.9.49) diff --git a/SOGo/SoObjects/Mailer/GNUmakefile b/SOGo/SoObjects/Mailer/GNUmakefile index ef4c0b92..847b0a87 100644 --- a/SOGo/SoObjects/Mailer/GNUmakefile +++ b/SOGo/SoObjects/Mailer/GNUmakefile @@ -21,6 +21,8 @@ Mailer_OBJC_FILES += \ \ SOGoDraftsFolder.m \ SOGoDraftObject.m \ + \ + SOGoMailTree.m \ Mailer_RESOURCE_FILES += \ Version \ diff --git a/SOGo/SoObjects/Mailer/SOGoMailAccounts.m b/SOGo/SoObjects/Mailer/SOGoMailAccounts.m index 27e9355d..6536f0b3 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailAccounts.m +++ b/SOGo/SoObjects/Mailer/SOGoMailAccounts.m @@ -80,75 +80,6 @@ return [NSException exceptionWithHTTPStatus:404 /* Not Found */]; } -/* tree navigation */ - -- (NSString *)treeNavigationLinkAtDepth:(int)_depth { - NSString *link; - unsigned i; - - link = [[self nameInContainer] stringByAppendingString:@"/"]; - for (i = 0; i < _depth; i++) - link = [@"../" stringByAppendingString:link]; - return link; -} - -- (id)treeNavigationBlockForLeafNodeAtDepth:(int)_depth { - NSMutableDictionary *md; - - md = [NSMutableDictionary dictionaryWithCapacity:4]; - [md setObject:[self davDisplayName] forKey:@"title"]; - [md setObject:[self treeNavigationLinkAtDepth:_depth] forKey:@"link"]; - - if ([[self toManyRelationshipKeys] count] > 0) - /* trigger plus in treeview */ - [md setObject:[NSArray arrayWithObject:@"FAKE"] forKey:@"children"]; - return md; -} - -- (id)treeNavigationBlockForActiveNode { - /* this generates the block for the clientObject */ - NSMutableDictionary *md; - NSMutableArray *blocks; - NSArray *folders; - unsigned i, count; - - /* process child folders */ - - folders = [self fetchSubfolders]; - count = [folders count]; - blocks = [NSMutableArray arrayWithCapacity:count]; - for (i = 0; i < count; i++) { - id block; - - block = [[folders objectAtIndex:i] - treeNavigationBlockForLeafNodeAtDepth:0]; - if ([block isNotNull]) [blocks addObject:block]; - } - - /* build block */ - - md = [NSMutableDictionary dictionaryWithCapacity:4]; - [md setObject:[NSNumber numberWithBool:YES] forKey:@"isActiveNode"]; - [md setObject:[NSNumber numberWithBool:YES] forKey:@"isPathNode"]; - [md setObject:[self davDisplayName] forKey:@"title"]; - [md setObject:[self nameInContainer] forKey:@"name"]; - [md setObject:[@"../" stringByAppendingString:[self nameInContainer]] - forKey:@"link"]; - if ([blocks count] > 0) - [md setObject:blocks forKey:@"children"]; - return md; -} - -- (id)treeNavigationBlockWithActiveChildBlock:(id)_activeChildBlock - depth:(int)_depth -{ - return _activeChildBlock; -} - -- (id)treeNavigationNodes { - return [self treeNavigationBlockForActiveNode]; -} - /* WebDAV */ - (BOOL)davIsCollection { diff --git a/SOGo/SoObjects/Mailer/SOGoMailBaseObject.h b/SOGo/SoObjects/Mailer/SOGoMailBaseObject.h index 4be1129d..8df1bbe4 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailBaseObject.h +++ b/SOGo/SoObjects/Mailer/SOGoMailBaseObject.h @@ -57,6 +57,10 @@ - (void)flushMailCaches; +@end + +@interface SOGoMailBaseObject(Tree) + /* UI navigation */ - (NSArray *)treeNavigationNodes; diff --git a/SOGo/SoObjects/Mailer/SOGoMailBaseObject.m b/SOGo/SoObjects/Mailer/SOGoMailBaseObject.m index 37a3a555..b242f697 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailBaseObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailBaseObject.m @@ -29,8 +29,9 @@ @implementation SOGoMailBaseObject -//static BOOL debugOn = YES; -static BOOL debugTree = NO; +#if 0 +static BOOL debugOn = YES; +#endif - (id)initWithImap4URL:(NSURL *)_url inContainer:(id)_container { NSString *n; @@ -144,121 +145,6 @@ static BOOL debugTree = NO; [[self mailManager] flushCachesForURL:[self imap4URL]]; } -/* UI navigation */ - -- (NSString *)treeNavigationLinkAtDepth:(int)_depth { - NSString *link; - unsigned i; - - link = [[self nameInContainer] stringByAppendingString:@"/"]; - for (i = 0; i < _depth; i++) - link = [@"../" stringByAppendingString:link]; - return link; -} - -- (id)treeNavigationBlockForLeafNodeAtDepth:(int)_depth { - NSMutableDictionary *md; - - md = [NSMutableDictionary dictionaryWithCapacity:4]; - [md setObject:[self davDisplayName] forKey:@"title"]; - [md setObject:[self treeNavigationLinkAtDepth:_depth] forKey:@"link"]; - - if ([[self toManyRelationshipKeys] count] > 0) - /* trigger plus in treeview */ - [md setObject:[NSArray arrayWithObject:@"FAKE"] forKey:@"children"]; - return md; -} - -- (id)treeNavigationBlockForActiveNode { - /* this generates the block for the clientObject */ - NSMutableDictionary *md; - NSMutableArray *blocks; - NSArray *folders; - unsigned i, count; - - /* process child folders */ - - folders = [self fetchSubfolders]; - count = [folders count]; - blocks = [NSMutableArray arrayWithCapacity:count]; - for (i = 0; i < count; i++) { - id block; - - block = [[folders objectAtIndex:i] - treeNavigationBlockForLeafNodeAtDepth:0]; - if ([block isNotNull]) [blocks addObject:block]; - } - - /* build block */ - - md = [NSMutableDictionary dictionaryWithCapacity:4]; - [md setObject:[NSNumber numberWithBool:YES] forKey:@"isActiveNode"]; - [md setObject:[NSNumber numberWithBool:YES] forKey:@"isPathNode"]; - [md setObject:[self davDisplayName] forKey:@"title"]; - [md setObject:[self nameInContainer] forKey:@"name"]; - [md setObject:@"." forKey:@"link"]; - if ([blocks count] > 0) - [md setObject:blocks forKey:@"children"]; - return md; -} - -- (id)treeNavigationBlockWithActiveChildBlock:(id)_activeChildBlock - depth:(int)_depth -{ - NSMutableDictionary *md; - NSMutableArray *blocks; - NSString *activeName; - NSArray *folders; - unsigned i, count; - - activeName = [_activeChildBlock valueForKey:@"name"]; - - /* process child folders */ - - folders = [self fetchSubfolders]; - count = [folders count]; - blocks = [NSMutableArray arrayWithCapacity:count]; - for (i = 0; i < count; i++) { - id folder; - id block; - - folder = [folders objectAtIndex:i]; - if ([activeName isEqualToString:[folder nameInContainer]]) { - block = _activeChildBlock; - } - else { - block = [folder treeNavigationBlockForLeafNodeAtDepth:_depth]; - } - if ([block isNotNull]) [blocks addObject:block]; - } - - /* build block */ - - md = [NSMutableDictionary dictionaryWithCapacity:4]; - [md setObject:[self davDisplayName] forKey:@"title"]; - [md setObject:[self nameInContainer] forKey:@"name"]; - [md setObject:[NSNumber numberWithBool:YES] forKey:@"isPathNode"]; - [md setObject:[self treeNavigationLinkAtDepth:(_depth + 1)] forKey:@"link"]; - if ([blocks count] > 0) - [md setObject:blocks forKey:@"children"]; - - /* recurse up */ - - return [[self container] treeNavigationBlockWithActiveChildBlock:md - depth:(_depth + 1)]; -} - -- (id)treeNavigationNodes { - id block; - - block = [self treeNavigationBlockForActiveNode]; - if (debugTree) [self logWithFormat:@"own block: %@", block]; - block = [[self container] treeNavigationBlockWithActiveChildBlock:block - depth:1]; - if (debugTree) [self logWithFormat:@" root block: %@", block]; - return block; -} - /* debugging */ - (NSString *)loggingPrefix { diff --git a/SOGo/SoObjects/Mailer/SOGoMailTree.m b/SOGo/SoObjects/Mailer/SOGoMailTree.m new file mode 100644 index 00000000..0c3dd1d9 --- /dev/null +++ b/SOGo/SoObjects/Mailer/SOGoMailTree.m @@ -0,0 +1,216 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id: SOGoMailAccounts.m 274 2004-08-26 13:10:49Z znek $ + +#include "SOGoMailBaseObject.h" +#include "SOGoMailAccounts.h" +#include +#include "common.h" + +static BOOL debugTree = NO; + +@implementation SOGoMailBaseObject(Tree) + +- (NSString *)treeNavigationLinkAtDepth:(int)_depth { + NSString *link; + unsigned i; + + link = [[self nameInContainer] stringByAppendingString:@"/"]; + for (i = 0; i < _depth; i++) + link = [@"../" stringByAppendingString:link]; + return link; +} + +- (id)treeNavigationBlockForLeafNodeAtDepth:(int)_depth { + NSMutableDictionary *md; + + md = [NSMutableDictionary dictionaryWithCapacity:4]; + [md setObject:[self davDisplayName] forKey:@"title"]; + [md setObject:[self treeNavigationLinkAtDepth:_depth] forKey:@"link"]; + + if ([[self toManyRelationshipKeys] count] > 0) + /* trigger plus in treeview */ + [md setObject:[NSArray arrayWithObject:@"FAKE"] forKey:@"children"]; + return md; +} + +- (id)treeNavigationBlockForActiveNode { + /* this generates the block for the clientObject */ + NSMutableDictionary *md; + NSMutableArray *blocks; + NSArray *folders; + unsigned i, count; + + /* process child folders */ + + folders = [self fetchSubfolders]; + count = [folders count]; + blocks = [NSMutableArray arrayWithCapacity:count]; + for (i = 0; i < count; i++) { + id block; + + block = [[folders objectAtIndex:i] + treeNavigationBlockForLeafNodeAtDepth:0]; + if ([block isNotNull]) [blocks addObject:block]; + } + + /* build block */ + + md = [NSMutableDictionary dictionaryWithCapacity:4]; + [md setObject:[NSNumber numberWithBool:YES] forKey:@"isActiveNode"]; + [md setObject:[NSNumber numberWithBool:YES] forKey:@"isPathNode"]; + [md setObject:[self davDisplayName] forKey:@"title"]; + [md setObject:[self nameInContainer] forKey:@"name"]; + [md setObject:@"." forKey:@"link"]; + if ([blocks count] > 0) + [md setObject:blocks forKey:@"children"]; + return md; +} + +- (id)treeNavigationBlockWithActiveChildBlock:(id)_activeChildBlock + depth:(int)_depth +{ + NSMutableDictionary *md; + NSMutableArray *blocks; + NSString *activeName; + NSArray *folders; + unsigned i, count; + + activeName = [_activeChildBlock valueForKey:@"name"]; + + /* process child folders */ + + folders = [self fetchSubfolders]; + count = [folders count]; + blocks = [NSMutableArray arrayWithCapacity:count]; + for (i = 0; i < count; i++) { + id folder; + id block; + + folder = [folders objectAtIndex:i]; + if ([activeName isEqualToString:[folder nameInContainer]]) { + block = _activeChildBlock; + } + else { + block = [folder treeNavigationBlockForLeafNodeAtDepth:_depth]; + } + if ([block isNotNull]) [blocks addObject:block]; + } + + /* build block */ + + md = [NSMutableDictionary dictionaryWithCapacity:4]; + [md setObject:[self davDisplayName] forKey:@"title"]; + [md setObject:[self nameInContainer] forKey:@"name"]; + [md setObject:[NSNumber numberWithBool:YES] forKey:@"isPathNode"]; + [md setObject:[self treeNavigationLinkAtDepth:(_depth + 1)] forKey:@"link"]; + if ([blocks count] > 0) + [md setObject:blocks forKey:@"children"]; + + /* recurse up */ + + return [[self container] treeNavigationBlockWithActiveChildBlock:md + depth:(_depth + 1)]; +} + +- (id)treeNavigationNodes { + id block; + + block = [self treeNavigationBlockForActiveNode]; + if (debugTree) [self logWithFormat:@"own block: %@", block]; + block = [[self container] treeNavigationBlockWithActiveChildBlock:block + depth:1]; + if (debugTree) [self logWithFormat:@" root block: %@", block]; + return block; +} + +@end /* SOGoMailBaseObject(Tree) */ + +@implementation SOGoMailAccounts(Tree) + +- (NSString *)treeNavigationLinkAtDepth:(int)_depth { + NSString *link; + unsigned i; + + link = [[self nameInContainer] stringByAppendingString:@"/"]; + for (i = 0; i < _depth; i++) + link = [@"../" stringByAppendingString:link]; + return link; +} + +- (id)treeNavigationBlockForLeafNodeAtDepth:(int)_depth { + NSMutableDictionary *md; + + md = [NSMutableDictionary dictionaryWithCapacity:4]; + [md setObject:[self davDisplayName] forKey:@"title"]; + [md setObject:[self treeNavigationLinkAtDepth:_depth] forKey:@"link"]; + + if ([[self toManyRelationshipKeys] count] > 0) + /* trigger plus in treeview */ + [md setObject:[NSArray arrayWithObject:@"FAKE"] forKey:@"children"]; + return md; +} + +- (id)treeNavigationBlockForActiveNode { + /* this generates the block for the clientObject */ + NSMutableDictionary *md; + NSMutableArray *blocks; + NSArray *folders; + unsigned i, count; + + /* process child folders */ + + folders = [self fetchSubfolders]; + count = [folders count]; + blocks = [NSMutableArray arrayWithCapacity:count]; + for (i = 0; i < count; i++) { + id block; + + block = [[folders objectAtIndex:i] + treeNavigationBlockForLeafNodeAtDepth:0]; + if ([block isNotNull]) [blocks addObject:block]; + } + + /* build block */ + + md = [NSMutableDictionary dictionaryWithCapacity:4]; + [md setObject:[NSNumber numberWithBool:YES] forKey:@"isActiveNode"]; + [md setObject:[NSNumber numberWithBool:YES] forKey:@"isPathNode"]; + [md setObject:[self davDisplayName] forKey:@"title"]; + [md setObject:[self nameInContainer] forKey:@"name"]; + [md setObject:[@"../" stringByAppendingString:[self nameInContainer]] + forKey:@"link"]; + if ([blocks count] > 0) + [md setObject:blocks forKey:@"children"]; + return md; +} + +- (id)treeNavigationBlockWithActiveChildBlock:(id)_activeChildBlock + depth:(int)_depth +{ + return _activeChildBlock; +} + +- (id)treeNavigationNodes { + return [self treeNavigationBlockForActiveNode]; +} + +@end /* SOGoMailAccounts(Tree) */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index e3b5ed09..a4adf0cd 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=49 +SUBMINOR_VERSION:=50 # v0.9.44 requires NGMime v4.3.194 # v0.9.41 requires NGMime v4.3.190 diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index cb81e431..6dc546cc 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,5 +1,7 @@ 2004-11-09 Helge Hess + * UIxMailTree.m: removed unused code (v0.9.59) + * UIxMailListView.m: flush mail caches in the getMail action (v0.9.58) 2004-10-29 Helge Hess diff --git a/SOGo/UI/Mailer/UIxMailTree.m b/SOGo/UI/Mailer/UIxMailTree.m index 32426ddf..29780be3 100644 --- a/SOGo/UI/Mailer/UIxMailTree.m +++ b/SOGo/UI/Mailer/UIxMailTree.m @@ -24,6 +24,7 @@ @interface UIxMailTree : UIxComponent { + id rootNodes; id item; } @end @@ -35,7 +36,8 @@ @implementation UIxMailTree - (void)dealloc { - [self->item release]; + [self->rootNodes release]; + [self->item release]; [super dealloc]; } @@ -48,42 +50,30 @@ return self->item; } -/* tree */ +/* navigation nodes */ -- (NSArray *)rootNodes { - return [NSArray arrayWithObject:[[self clientObject] treeNavigationNodes]]; +- (id)buildNavigationNodesForObject:(id)_object { + return [_object treeNavigationNodes]; } -- (NSArray *)itemChildNodes { - NSMutableArray *folders; - NSArray *names; - unsigned i, count; +/* tree */ + +- (NSArray *)rootNodes { + id navNode; - names = [[self item] toManyRelationshipKeys]; - count = [names count]; - folders = [NSMutableArray arrayWithCapacity:count]; - - for (i = 0; i < count; i++) { - id folder; - - folder = [[self item] lookupName:[names objectAtIndex:i] - inContext:[self context] - acquire:NO]; - if (folder) - [folders addObject:folder]; - } + if (self->rootNodes != nil) + return self->rootNodes; - return folders; -} - -- (BOOL)isItemExpanded { - return YES; + navNode = [self buildNavigationNodesForObject:[self clientObject]]; + self->rootNodes = [[NSArray alloc] initWithObjects:&navNode count:1]; + return self->rootNodes; } /* notifications */ - (void)sleep { - [self->item release]; self->item = nil; + [self->item release]; self->item = nil; + [self->rootNodes release]; self->rootNodes = nil; [super sleep]; } diff --git a/SOGo/UI/Mailer/Version b/SOGo/UI/Mailer/Version index 6b08a245..156d56d8 100644 --- a/SOGo/UI/Mailer/Version +++ b/SOGo/UI/Mailer/Version @@ -1,6 +1,6 @@ # $Id$ -SUBMINOR_VERSION:=58 +SUBMINOR_VERSION:=59 # v0.9.50 requires NGMime v4.3.190 # v0.9.43 requires NGObjWeb v4.3.73 -- 2.39.5