]> err.no Git - scalable-opengroupware.org/commitdiff
moved tree navigation code from SoObjects to UI
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 9 Nov 2004 16:39:34 +0000 (16:39 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 9 Nov 2004 16:39:34 +0000 (16:39 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@450 d1b88da0-ebda-0310-925b-ed51d893ca5b

SOGo/SoObjects/Mailer/ChangeLog
SOGo/SoObjects/Mailer/GNUmakefile
SOGo/SoObjects/Mailer/SOGoMailBaseObject.h
SOGo/SoObjects/Mailer/SOGoMailTree.m [deleted file]
SOGo/SoObjects/Mailer/Version
SOGo/UI/Mailer/ChangeLog
SOGo/UI/Mailer/GNUmakefile
SOGo/UI/Mailer/UIxMailTree.m
SOGo/UI/Mailer/UIxMailTreeBlock.h [new file with mode: 0644]
SOGo/UI/Mailer/UIxMailTreeBlock.m [new file with mode: 0644]
SOGo/UI/Mailer/Version

index bd3ccc1e089ff986a1c518ecb3a1b4a465d936ba..077149597f59fbc78d0f6e672879a7f91991534d 100644 (file)
@@ -1,5 +1,7 @@
 2004-11-09  Helge Hess  <helge.hess@skyrix.com>
 
+       * moved all tree navigation code to UIxMailTree (v0.9.51)
+
        * SOGoMailBaseObject.m, SOGoMailAccounts.m: moved tree code to separate
          file (v0.9.50)
 
index 847b0a8783cdd8432b9a005a62397c8e6f168300..ef4c0b921b57dd95dd151eac05d39c246e3f5bf3 100644 (file)
@@ -21,8 +21,6 @@ Mailer_OBJC_FILES += \
        \
        SOGoDraftsFolder.m              \
        SOGoDraftObject.m               \
-       \
-       SOGoMailTree.m                  \
 
 Mailer_RESOURCE_FILES += \
        Version         \
index 8df1bbe4e13df8112c56951a9c7ef28df7f118f7..5b86150029a5480d67335b3a8719d3a88de643ba 100644 (file)
 
 @end
 
-@interface SOGoMailBaseObject(Tree)
-
-/* UI navigation */
-
-- (NSArray *)treeNavigationNodes;
-
-@end
-
 #endif /* __Mailer_SOGoMailBaseObject_H__ */
diff --git a/SOGo/SoObjects/Mailer/SOGoMailTree.m b/SOGo/SoObjects/Mailer/SOGoMailTree.m
deleted file mode 100644 (file)
index 0c3dd1d..0000000
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
-  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 <NGObjWeb/SoObject+SoDAV.h>
-#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) */
index a4adf0cd1d39a80dbed868b07a666dde4d7abc19..5d92fc8134b27737c428d8e094953aa50a37913d 100644 (file)
@@ -1,6 +1,6 @@
 # Version file
 
-SUBMINOR_VERSION:=50
+SUBMINOR_VERSION:=51
 
 # v0.9.44 requires NGMime    v4.3.194
 # v0.9.41 requires NGMime    v4.3.190
index 6dc546cc2914a3821c30aa4c7a9d80bfee354d50..481bdb1e40ebb2d25672723b963b5f066fe0bac8 100644 (file)
@@ -1,5 +1,7 @@
 2004-11-09  Helge Hess  <helge.hess@skyrix.com>
 
+       * UIxMailTree.m: added tree navigation code from SoObjects (v0.9.60)
+
        * UIxMailTree.m: removed unused code (v0.9.59)
 
        * UIxMailListView.m: flush mail caches in the getMail action (v0.9.58)
index 09a611293bc06acc25aa981a1ae66ab31bfbb709..09cd5ec0a7c1bf96f0d6071604e50d7245209c35 100644 (file)
@@ -19,6 +19,7 @@ MailerUI_OBJC_FILES += \
        \
        UIxMailMainFrame.m              \
        UIxMailTree.m                   \
+       UIxMailTreeBlock.m              \
        UIxMailToolbar.m                \
        \
        UIxMailAccountsView.m           \
index 29780be3966667d6a4db1bb424537bece4bc5da9..6bc9edf8434d9e75ea44711be5970e97bd9cffdf 100644 (file)
 }
 @end
 
+#include "UIxMailTreeBlock.h"
 #include <SOGo/SoObjects/Mailer/SOGoMailBaseObject.h>
 #include "common.h"
 #include <NGObjWeb/SoComponent.h>
+#include <NGObjWeb/SoObject+SoDAV.h>
+
 
 @implementation UIxMailTree
 
 
 /* navigation nodes */
 
+- (BOOL)isRootObject:(id)_object {
+  if (![_object isNotNull]) {
+    [self logWithFormat:@"WARNING(%s): got to root by nil lookup ...",
+           __PRETTY_FUNCTION__];
+    return YES;
+  }
+  
+  return [_object isKindOfClass:NSClassFromString(@"SOGoMailAccounts")];
+}
+
+- (NSString *)treeNavigationLinkForObject:(id)_object atDepth:(int)_depth {
+  NSString *link;
+  unsigned i;
+  
+  link = [[_object nameInContainer] stringByAppendingString:@"/"];
+  for (i = 0; i < _depth; i++)
+    link = [@"../" stringByAppendingString:link];
+  return link;
+}
+
+- (UIxMailTreeBlock *)treeNavigationBlockForLeafNode:(id)_o atDepth:(int)_d {
+  UIxMailTreeBlock *md;
+  id blocks;
+  
+  /* 
+     Trigger plus in treeview if it has subfolders. It is an optimization that
+     we do not generate blocks for folders which are not displayed anyway.
+  */
+  blocks = [[_o toManyRelationshipKeys] count] > 0
+    ? [[NSArray alloc] initWithObjects:@"FAKE", nil]
+    : nil;
+  
+  md = [UIxMailTreeBlock blockWithName:nil
+                        title:[_o davDisplayName]
+                        link:[self treeNavigationLinkForObject:_o atDepth:_d]
+                        isPathNode:NO isActiveNode:NO
+                        childBlocks:blocks];
+  return md;
+}
+
+- (UIxMailTreeBlock *)treeNavigationBlockForRootNode:(id)_object {
+  /* this generates the block for the clientObject */
+  UIxMailTreeBlock *md;
+  NSMutableArray      *blocks;
+  NSArray             *folders;
+  unsigned            i, count;
+  
+  /* process child folders */
+  
+  folders = [_object fetchSubfolders];
+  count   = [folders count];
+  blocks  = [NSMutableArray arrayWithCapacity:count];
+  for (i = 0; i < count; i++) {
+    id block;
+    
+    block = [self treeNavigationBlockForLeafNode:[folders objectAtIndex:i]
+                 atDepth:0];
+    if ([block isNotNull]) [blocks addObject:block];
+  }
+  if ([blocks count] == 0)
+    blocks = nil;
+  
+  /* build block */
+  
+  md = [UIxMailTreeBlock blockWithName:[_object nameInContainer]
+                        title:[_object davDisplayName]
+                        link:[@"../" stringByAppendingString:
+                                 [_object nameInContainer]]
+                        isPathNode:YES isActiveNode:YES
+                        childBlocks:blocks];
+  return md;
+}
+
+- (UIxMailTreeBlock *)treeNavigationBlockForActiveNode:(id)_object {
+  /* 
+     this generates the block for the clientObject (the object which has the 
+     focus)
+  */
+  UIxMailTreeBlock *md;
+  NSMutableArray   *blocks;
+  NSArray  *folders;
+  unsigned i, count;
+  
+  // TODO: maybe we can join the two implementations, this might not be
+  //       necessary
+  if ([self isRootObject:_object]) /* we are at the top */
+    return [self treeNavigationBlockForRootNode:_object];
+  
+  /* process child folders */
+  
+  folders = [_object fetchSubfolders];
+  count   = [folders count];
+  blocks  = [NSMutableArray arrayWithCapacity:count];
+  for (i = 0; i < count; i++) {
+    UIxMailTreeBlock *block;
+    
+    block = [self treeNavigationBlockForLeafNode:[folders objectAtIndex:i]
+                 atDepth:0];
+    if ([block isNotNull]) [blocks addObject:block];
+  }
+  if ([blocks count] == 0) blocks = nil;
+  
+  /* build block */
+  
+  md = [UIxMailTreeBlock blockWithName:[_object nameInContainer]
+                        title:[_object davDisplayName]
+                        link:@"."
+                        isPathNode:YES isActiveNode:YES
+                        childBlocks:blocks];
+  return md;
+}
+
+- (UIxMailTreeBlock *)treeNavigationBlockForObject:(id)_object
+  withActiveChildBlock:(UIxMailTreeBlock *)_activeChildBlock 
+  depth:(int)_depth
+{
+  UIxMailTreeBlock *md;
+  NSMutableArray   *blocks;
+  NSString         *activeName;
+  NSArray          *folders;
+  unsigned         i, count;
+  
+  if ([self isRootObject:_object]) /* we are at the top */
+    return _activeChildBlock;
+  
+  /* the following is not run on the OGoMailAccounts (root) object */
+  
+  activeName = [_activeChildBlock valueForKey:@"name"];
+  
+  /* process child folders */
+  
+  folders = [_object fetchSubfolders];
+  count   = [folders count];
+  blocks  = [NSMutableArray arrayWithCapacity:count];
+  for (i = 0; i < count; i++) {
+    UIxMailTreeBlock *block;
+    id folder;
+    
+    folder = [folders objectAtIndex:i];
+    block = [activeName isEqualToString:[folder nameInContainer]]
+      ? _activeChildBlock
+      : [self treeNavigationBlockForLeafNode:folder atDepth:_depth];
+    
+    if ([block isNotNull]) [blocks addObject:block];
+  }
+  if ([blocks count] == 0) blocks = nil;
+  
+  /* build block */
+  
+  md = [UIxMailTreeBlock blockWithName:[_object nameInContainer]
+                        title:[_object davDisplayName]
+                        link:[self treeNavigationLinkForObject:_object 
+                                   atDepth:(_depth + 1)] 
+                        isPathNode:YES isActiveNode:NO
+                        childBlocks:blocks];
+  
+  /* recurse up */
+  
+  return [self treeNavigationBlockForObject:[_object container] 
+              withActiveChildBlock:md
+              depth:(_depth + 1)];
+}
+
 - (id)buildNavigationNodesForObject:(id)_object {
-  return [_object treeNavigationNodes];
+  id block;
+  
+  block = [self treeNavigationBlockForActiveNode:_object];
+  
+  if ([self isRootObject:_object])
+    return block;
+  
+  /* the following returns the root block! */
+  block = [self treeNavigationBlockForObject:[_object container] 
+               withActiveChildBlock:block
+               depth:1];
+  return block;
 }
 
 /* tree */
diff --git a/SOGo/UI/Mailer/UIxMailTreeBlock.h b/SOGo/UI/Mailer/UIxMailTreeBlock.h
new file mode 100644 (file)
index 0000000..122e2b9
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+  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: UIxMailTree.m 278 2004-08-26 23:29:09Z helge $
+
+#import <Foundation/NSObject.h>
+
+@class NSString, NSArray;
+
+@interface UIxMailTreeBlock : NSObject
+{
+  NSString *name;
+  NSString *title;
+  NSString *link;
+  NSArray  *blocks;
+  struct {
+    int isPath:1;
+    int isActive:1;
+    int reserved:30;
+  } flags;
+}
+
++ (id)blockWithName:(NSString *)_name title:(NSString *)_title
+  link:(NSString *)_link isPathNode:(BOOL)_isPath isActiveNode:(BOOL)_isActive
+  childBlocks:(NSArray *)_blocks;
+
+- (id)initWithName:(NSString *)_name title:(NSString *)_title
+  link:(NSString *)_link isPathNode:(BOOL)_isPath isActiveNode:(BOOL)_isActive
+  childBlocks:(NSArray *)_blocks;
+
+@end
diff --git a/SOGo/UI/Mailer/UIxMailTreeBlock.m b/SOGo/UI/Mailer/UIxMailTreeBlock.m
new file mode 100644 (file)
index 0000000..ff29cca
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+  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: UIxMailTree.m 278 2004-08-26 23:29:09Z helge $
+
+#include "UIxMailTreeBlock.h"
+#include "common.h"
+
+@implementation UIxMailTreeBlock
+
++ (id)blockWithName:(NSString *)_name title:(NSString *)_title
+  link:(NSString *)_link isPathNode:(BOOL)_isPath isActiveNode:(BOOL)_isActive
+  childBlocks:(NSArray *)_blocks
+{
+  UIxMailTreeBlock *block;
+
+  block = [[self alloc] initWithName:_name title:_title link:_link
+                       isPathNode:_isPath isActiveNode:_isActive
+                       childBlocks:_blocks];
+  return [block autorelease];
+}
+
+- (id)initWithName:(NSString *)_name title:(NSString *)_title
+  link:(NSString *)_link isPathNode:(BOOL)_isPath isActiveNode:(BOOL)_isActive
+  childBlocks:(NSArray *)_blocks
+{
+  if ((self = [self init])) {
+    self->name   = [_name   copy];
+    self->title  = [_title  copy];
+    self->link   = [_link   copy];
+    self->blocks = [_blocks retain];
+    
+    self->flags.isPath   = _isPath   ? 1 : 0;
+    self->flags.isActive = _isActive ? 1 : 0;
+  }
+  return self;
+}
+
+- (void)dealloc {
+  [self->blocks release];
+  [self->name   release];
+  [self->title  release];
+  [self->link   release];
+  [super dealloc];
+}
+
+/* accessors */
+
+- (NSString *)name {
+  return self->name;
+}
+- (NSString *)title {
+  return self->title;
+}
+- (NSString *)link {
+  return self->link;
+}
+
+- (NSArray *)children {
+  return self->blocks;
+}
+
+- (BOOL)isPathNode {
+  return self->flags.isPath ? YES : NO;
+}
+- (BOOL)isActiveNode {
+  return self->flags.isActive ? YES : NO;
+}
+
+@end /* UIxMailTreeBlock */
index 156d56d8b915d2e5e498f1b07f2f02d9581acba2..9603d86c70a3254f1ea5b9d081907d1685d33330 100644 (file)
@@ -1,6 +1,6 @@
 # $Id$
 
-SUBMINOR_VERSION:=59
+SUBMINOR_VERSION:=60
 
 # v0.9.50 requires NGMime   v4.3.190
 # v0.9.43 requires NGObjWeb v4.3.73