Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id: UIxMailTree.m 278 2004-08-26 23:29:09Z helge $
#include <SOGoUI/UIxComponent.h>
#include "UIxMailTreeBlock.h"
#include <SOGo/SoObjects/Mailer/SOGoMailBaseObject.h>
+#include <SOGo/SoObjects/Mailer/SOGoMailAccount.h>
#include "common.h"
#include <NGObjWeb/SoComponent.h>
#include <NGObjWeb/SoObject+SoDAV.h>
+/*
+ Support special icons:
+ tbtv_leaf_corner_17x17.gif
+ tbtv_inbox_17x17.gif
+ tbtv_drafts_17x17.gif
+ tbtv_sent_17x17.gif
+ tbtv_trash_17x17.gif
+*/
@implementation UIxMailTree
[super dealloc];
}
+/* icons */
+
+- (NSString *)defaultIconName {
+ return @"tbtv_leaf_corner_17x17.gif";
+}
+
+- (NSString *)iconNameForType:(NSString *)_type {
+ if (![_type isNotNull])
+ return [self defaultIconName];
+
+ //return @"tbtv_drafts_17x17.gif";
+
+ return [self defaultIconName];
+}
+
/* accessors */
- (void)setItem:(id)_item {
return self->item;
}
+- (NSString *)itemIconName {
+ // TODO: only called once!
+ NSString *ftype;
+
+ ftype = [[self item] valueForKey:@"outlookFolderClass"];
+ return [self iconNameForType:ftype];
+}
+
+/* fetching subfolders */
+
+- (NSArray *)fetchSubfoldersOfObject:(id)_object {
+ /* Walk over toManyRelationshipKeys and lookup the controllers for them. */
+ NSMutableArray *ma;
+ NSArray *names;
+ unsigned i, count;
+
+ if ((names = [_object toManyRelationshipKeys]) == nil)
+ return nil;
+
+ count = [names count];
+ ma = [NSMutableArray arrayWithCapacity:(count + 1)];
+ for (i = 0; i < count; i++) {
+ id folder;
+
+ folder = [_object lookupName:[names objectAtIndex:i] inContext:nil
+ acquire:NO];
+ if (folder == nil)
+ continue;
+ if ([folder isKindOfClass:[NSException class]])
+ continue;
+
+ [ma addObject:folder];
+ }
+ return ma;
+}
+
/* navigation nodes */
- (BOOL)isRootObject:(id)_object {
return YES;
}
+ // TODO: make this a parameter to make UIxMailTree reusable
return [_object isKindOfClass:NSClassFromString(@"SOGoMailAccounts")];
}
return link;
}
+- (NSString *)titleForObject:(id)_object {
+ // TODO: need to refactor for reuse!
+ NSString *ftype;
+ unsigned len;
+
+ ftype = [_object valueForKey:@"outlookFolderClass"];
+ len = [ftype length];
+
+ switch (len) {
+ case 8:
+ if ([ftype isEqualToString:@"IPF.Sent"])
+ return [self labelForKey:@"SentFolderName"];
+ break;
+ case 9:
+ if ([ftype isEqualToString:@"IPF.Inbox"])
+ return [self labelForKey:@"InboxFolderName"];
+ if ([ftype isEqualToString:@"IPF.Trash"])
+ return [self labelForKey:@"TrashFolderName"];
+ break;
+ case 10:
+ if ([ftype isEqualToString:@"IPF.Drafts"])
+ return [self labelForKey:@"DraftsFolderName"];
+ if ([ftype isEqualToString:@"IPF.Filter"])
+ return [self labelForKey:@"SieveFolderName"];
+ }
+
+ return [_object davDisplayName];
+}
+
- (UIxMailTreeBlock *)treeNavigationBlockForLeafNode:(id)_o atDepth:(int)_d {
UIxMailTreeBlock *md;
id blocks;
: nil;
md = [UIxMailTreeBlock blockWithName:nil
- title:[_o davDisplayName]
+ title:[self titleForObject:_o]
link:[self treeNavigationLinkForObject:_o atDepth:_d]
isPathNode:NO isActiveNode:NO
childBlocks:blocks];
}
- (UIxMailTreeBlock *)treeNavigationBlockForRootNode:(id)_object {
- /* this generates the block for the clientObject */
+ /*
+ This generates the block for the root object (root of the tree, we get
+ there by walking up the chain starting with the client object).
+ */
UIxMailTreeBlock *md;
- NSMutableArray *blocks;
- NSArray *folders;
- unsigned i, count;
+ NSMutableArray *blocks;
+ NSArray *folders;
+ unsigned i, count;
/* process child folders */
- folders = [_object fetchSubfolders];
+ folders = [self fetchSubfoldersOfObject:_object];
count = [folders count];
blocks = [NSMutableArray arrayWithCapacity:count];
for (i = 0; i < count; i++) {
/* build block */
md = [UIxMailTreeBlock blockWithName:[_object nameInContainer]
- title:[_object davDisplayName]
+ title:[self titleForObject:_object]
link:[@"../" stringByAppendingString:
[_object nameInContainer]]
isPathNode:YES isActiveNode:YES
- (UIxMailTreeBlock *)treeNavigationBlockForActiveNode:(id)_object {
/*
- this generates the block for the clientObject (the object which has the
+ This generates the block for the clientObject (the object which has the
focus)
*/
UIxMailTreeBlock *md;
/* process child folders */
- folders = [_object fetchSubfolders];
+ folders = [self fetchSubfoldersOfObject:_object];
count = [folders count];
blocks = [NSMutableArray arrayWithCapacity:count];
for (i = 0; i < count; i++) {
/* build block */
md = [UIxMailTreeBlock blockWithName:[_object nameInContainer]
- title:[_object davDisplayName]
+ title:[self titleForObject:_object]
link:@"."
isPathNode:YES isActiveNode:YES
childBlocks:blocks];
/* process child folders */
- folders = [_object fetchSubfolders];
+ folders = [self fetchSubfoldersOfObject:_object];
count = [folders count];
blocks = [NSMutableArray arrayWithCapacity:count];
for (i = 0; i < count; i++) {
/* build block */
md = [UIxMailTreeBlock blockWithName:[_object nameInContainer]
- title:[_object davDisplayName]
+ title:[self titleForObject:_object]
link:[self treeNavigationLinkForObject:_object
atDepth:(_depth + 1)]
isPathNode:YES isActiveNode:NO