]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/MailerUI/UIxMailTreeBlock.m
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@900 d1b88da0-ebda-0310-925b-ed51d...
[scalable-opengroupware.org] / SOGo / UI / MailerUI / UIxMailTreeBlock.m
1 /*
2   Copyright (C) 2004-2005 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
22 #include "UIxMailTreeBlock.h"
23 #include "common.h"
24
25 @implementation UIxMailTreeBlock
26
27 id UIxMailTreeHasChildrenMarker = nil;
28
29 + (void)initialize {
30   // TODO: needs to be an array because the WETreeView requires a
31   //       children array
32   UIxMailTreeHasChildrenMarker = 
33     [[NSArray alloc] initWithObjects:@"FAKE", nil];
34 }
35
36 + (id)blockWithName:(NSString *)_name title:(NSString *)_title
37   iconName:(NSString *)_icon
38   link:(NSString *)_link isPathNode:(BOOL)_isPath isActiveNode:(BOOL)_isActive
39   childBlocks:(NSArray *)_blocks
40 {
41   UIxMailTreeBlock *block;
42
43   block = [[self alloc] initWithName:_name title:_title iconName:_icon
44                         link:_link
45                         isPathNode:_isPath isActiveNode:_isActive
46                         childBlocks:_blocks];
47   return [block autorelease];
48 }
49
50 - (id)initWithName:(NSString *)_name title:(NSString *)_title
51   iconName:(NSString *)_icon
52   link:(NSString *)_link isPathNode:(BOOL)_isPath isActiveNode:(BOOL)_isActive
53   childBlocks:(NSArray *)_blocks
54 {
55   if ((self = [self init])) {
56     self->name     = [_name   copy];
57     self->title    = [_title  copy];
58     self->iconName = [_icon copy];
59     self->link     = [_link   copy];
60     self->blocks   = [_blocks retain];
61     
62     self->flags.isPath   = _isPath   ? 1 : 0;
63     self->flags.isActive = _isActive ? 1 : 0;
64   }
65   return self;
66 }
67
68 - (void)dealloc {
69   [self->iconName release];
70   [self->blocks   release];
71   [self->name     release];
72   [self->title    release];
73   [self->link     release];
74   [super dealloc];
75 }
76
77 /* accessors */
78
79 - (NSString *)name {
80   return self->name;
81 }
82 - (NSString *)title {
83   return self->title;
84 }
85 - (NSString *)link {
86   return self->link;
87 }
88 - (NSString *)iconName {
89   return self->iconName;
90 }
91
92 - (BOOL)hasChildren {
93   if (self->blocks == UIxMailTreeHasChildrenMarker)
94     return YES;
95   return [self->blocks count] > 0 ? YES : NO;
96 }
97
98 - (BOOL)areChildrenLoaded {
99   return self->blocks != UIxMailTreeHasChildrenMarker ? YES : NO;
100 }
101
102 - (NSArray *)children {
103   if (self->blocks == UIxMailTreeHasChildrenMarker)
104     // TODO: print a warning
105     return self->blocks;
106   
107   return self->blocks;
108 }
109
110 - (BOOL)isPathNode {
111   return self->flags.isPath ? YES : NO;
112 }
113 - (BOOL)isActiveNode {
114   return self->flags.isActive ? YES : NO;
115 }
116
117 /* description */
118
119 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
120   if (self->name  != nil) [_ms appendFormat:@" name='%@'", self->name];
121   if (self->title != nil) [_ms appendFormat:@" title='%@'", self->title];
122   
123   if ([self isPathNode])   [_ms appendString:@" path"];
124   if ([self isActiveNode]) [_ms appendString:@" active"];
125
126   if (self->blocks == UIxMailTreeHasChildrenMarker)
127     [_ms appendString:@" has-children"];
128   else if ([self->blocks count] > 0)
129     [_ms appendFormat:@" children=%@", self->blocks];
130 }
131
132 - (NSString *)description {
133   NSMutableString *ms;
134
135   ms = [NSMutableString stringWithCapacity:64];
136   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
137   [self appendAttributesToDescription:ms];
138   [ms appendString:@">"];
139   return ms;
140 }
141
142 @end /* UIxMailTreeBlock */