2 Copyright (C) 2004-2005 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
22 #include <SOGoUI/UIxComponent.h>
24 @class NSArray, NSDictionary;
26 @interface UIxMailToolbar : UIxComponent
28 NSArray *toolbarConfig;
29 NSArray *toolbarGroup;
30 NSDictionary *buttonInfo;
34 #include <SoObjects/Mailer/SOGoMailBaseObject.h>
36 #include <NGObjWeb/SoComponent.h>
38 @implementation UIxMailToolbar
41 [self->toolbarGroup release];
42 [self->toolbarConfig release];
43 [self->buttonInfo release];
50 [self->toolbarGroup release]; self->toolbarGroup = nil;
51 [self->toolbarConfig release]; self->toolbarConfig = nil;
52 [self->buttonInfo release]; self->buttonInfo = nil;
58 - (void)setToolbarGroup:(id)_group {
59 ASSIGN(self->toolbarGroup, _group);
62 return self->toolbarGroup;
65 - (void)setButtonInfo:(id)_info {
66 ASSIGN(self->buttonInfo, _info);
69 return self->buttonInfo;
74 - (WOResourceManager *)pageResourceManager {
75 WOResourceManager *rm;
77 if ((rm = [[[self context] page] resourceManager]) != nil)
80 return [[self application] resourceManager];
83 - (id)loadToolbarConfigFromResourceNamed:(NSString *)_name {
85 Note: we cannot cache by name because we don't know how the resource
86 manager will look up the name.
87 Both, the clientObject and the page might be different.
89 Of course the resourcemanager will cache the resource path and we
90 cache the parsed content for a given path;
92 static NSMutableDictionary *pathToConfig = nil;
93 WOResourceManager *rm;
96 NSString *fw, *rn, *path;
98 r = [_name rangeOfString:@"/"];
100 fw = [_name substringToIndex:r.location];
101 rn = [_name substringFromIndex:(r.location + r.length)];
108 rm = [self pageResourceManager];
109 path = [rm pathForResourceNamed:rn inFramework:fw
110 languages:[[self context] resourceLookupLanguages]];
112 [self errorWithFormat:@"Did not find toolbar resource: %@", _name];
116 if ((tb = [pathToConfig objectForKey:path]) != nil)
117 return [tb isNotNull] ? tb : nil;
119 if ((tb = [NSArray arrayWithContentsOfFile:path]) == nil)
120 [self errorWithFormat:@"Could not load toolbar resource: %@", _name];
122 if (pathToConfig == nil)
123 pathToConfig = [[NSMutableDictionary alloc] initWithCapacity:32];
124 [pathToConfig setObject:(tb ? tb : (id)[NSNull null]) forKey:path];
129 - (id)toolbarConfig {
132 if (self->toolbarConfig != nil)
133 return [self->toolbarConfig isNotNull] ? self->toolbarConfig : nil;
135 tb = [[self clientObject] lookupName:@"toolbar" inContext:[self context]
137 if ([tb isKindOfClass:[NSException class]]) {
138 [self errorWithFormat:
139 @"not toolbar configuration found on SoObject: %@ (%@)",
140 [self clientObject], [[self clientObject] soClass]];
141 self->toolbarConfig = [[NSNull null] retain];
145 if ([tb isKindOfClass:[NSString class]])
146 tb = [self loadToolbarConfigFromResourceNamed:tb];
148 self->toolbarConfig = [tb retain];
149 return self->toolbarConfig;
154 - (NSString *)buttonLabel {
155 WOResourceManager *rm;
156 NSString *key, *label;
158 key = [[self buttonInfo] valueForKey:@"label"];
160 /* lookup resource manager */
162 if ((rm = [self pageResourceManager]) == nil)
163 rm = [[WOApplication application] resourceManager];
165 [self warnWithFormat:@"missing resource manager!"];
169 label = [rm stringForKey:key inTableNamed:nil withDefaultValue:key
170 languages:[[self context] resourceLookupLanguages]];
174 /* enable/disable buttons */
176 - (BOOL)isButtonEnabled {
177 // TODO: replace 'enabled' with WOAssociation when this gets a dynamic
181 if ((onOffKey = [[self buttonInfo] valueForKey:@"enabled"]) == nil)
184 return [[[[self context] page] valueForKeyPath:onOffKey] boolValue];
187 @end /* UIxMailToolbar */