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 #import <SoObjects/Mailer/SOGoMailObject.h>
23 #import <SoObjects/Mailer/SOGoMailAccounts.h>
24 #import <SoObjects/SOGo/NSString+Utilities.h>
25 #import <SoObjects/SOGo/NSObject+Utilities.h>
26 #import <SOGoUI/UIxComponent.h>
27 #import "UIxMailMainFrame.h"
30 #import <NGObjWeb/SoComponent.h>
32 @implementation UIxMailMainFrame
34 static NSString *treeRootClassName = nil;
37 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
39 treeRootClassName = [[ud stringForKey:@"SOGoMailTreeRootClass"] copy];
40 if (treeRootClassName)
41 NSLog(@"Note: use class '%@' as root for mail tree.", treeRootClassName);
43 treeRootClassName = @"SOGoMailAccounts";
47 [self->rootURL release];
48 [self->userRootURL release];
53 - (NSString *) mailAccounts
57 co = [self clientObject];
59 return [[co fetchAllIdentities] jsonRepresentation];
62 - (NSString *)treeRootClassName {
63 return treeRootClassName;
66 - (void)setHideFolderTree:(BOOL)_flag {
67 self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
69 - (BOOL)hideFolderTree {
70 return self->mmfFlags.hideFolderTree ? YES : NO;
73 - (NSString *) pageFormURL {
77 u = [[[self context] request] uri];
78 if ((r = [u rangeOfString:@"?"]).length > 0) {
79 /* has query parameters */
80 // TODO: this is ugly, create reusable link facility in SOPE
81 // TODO: remove 'search' and 'filterpopup', preserve sorting
86 qp = [[u substringFromIndex:(r.location + r.length)]
87 componentsSeparatedByString:@"&"];
89 ms = [NSMutableString stringWithCapacity:count * 12];
91 for (i = 0; i < count; i++) {
94 s = [qp objectAtIndex:i];
97 if ([s hasPrefix:@"search="]) continue;
98 if ([s hasPrefix:@"filterpopup="]) continue;
100 if ([ms length] > 0) [ms appendString:@"&"];
104 if ([ms length] == 0) {
105 /* no other query params */
106 u = [u substringToIndex:r.location];
109 u = [u substringToIndex:r.location + r.length];
110 u = [u stringByAppendingString:ms];
114 return [u hasSuffix:@"/"] ? @"view" : @"#";
117 - (BOOL)showLinkBanner {
121 - (NSString *)bannerToolbarStyle {
125 - (NSString *)bannerConsumeStyle {
130 // TODO: I think all this should be done by the clientObject?!
131 // TODO: is the stuff below necessary at all in the mailer frame?
133 - (NSString *)rootURL {
135 NSArray *traversalObjects;
137 if (self->rootURL != nil)
138 return self->rootURL;
140 ctx = [self context];
141 traversalObjects = [ctx objectTraversalStack];
142 self->rootURL = [[[traversalObjects objectAtIndex:0]
143 rootURLInContext:ctx]
145 return self->rootURL;
148 - (NSString *)userRootURL {
150 NSArray *traversalObjects;
152 if (self->userRootURL)
153 return self->userRootURL;
155 ctx = [self context];
156 traversalObjects = [ctx objectTraversalStack];
157 self->userRootURL = [[[[traversalObjects objectAtIndex:1]
158 baseURLInContext:ctx]
159 stringByAppendingString:@"/"]
161 return self->userRootURL;
164 - (NSString *)calendarRootURL {
165 return [[self userRootURL] stringByAppendingString:@"Calendar/"];
168 - (NSString *)contactsRootURL {
169 return [[self userRootURL] stringByAppendingString:@"Contacts/"];
174 - (BOOL)hasErrorText {
175 return [[[[self context] request] formValueForKey:@"error"] length] > 0
178 - (NSString *)errorText {
179 return [[[self context] request] formValueForKey:@"error"];
182 - (NSString *)errorAlertJavaScript {
185 if ([(errorText = [self errorText]) length] == 0)
188 // TODO: proper JavaScript escaping
189 errorText = [errorText stringByEscapingHTMLString];
190 errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
192 return [NSString stringWithFormat:
193 @"<script language=\"JavaScript\">"
195 @"</script>", errorText];
198 /* FIXME: migrated methods which might not work yet... */
199 // #warning check this
200 // - (NSString *) mailFolderName
202 // NSMutableArray *mailboxes;
203 // SOGoMailObject *currentObject;
205 // mailboxes = [NSMutableArray new];
206 // [mailboxes autorelease];
208 // currentObject = [self clientObject];
209 // while (![currentObject isKindOfClass: [SOGoMailAccounts class]])
211 // [mailboxes insertObject: [currentObject nameInContainer] atIndex: 0];
212 // currentObject = [currentObject container];
215 // return [NSString stringWithFormat: @"/%@",
216 // [mailboxes componentsJoinedByString: @"/"]];
222 NSString *inbox, *url, *parameter;
223 NSMutableDictionary *urlParams;
226 c = [[self clientObject] toManyRelationshipKeys];
229 urlParams = [NSMutableDictionary new];
230 [urlParams autorelease];
232 parameter = [self queryParameterForKey: @"mailto"];
234 [urlParams setObject: parameter
236 inbox = [NSString stringWithFormat: @"%@/INBOX",
237 [c objectAtIndex: 0]];
238 url = [inbox composeURLWithAction: @"compose"
239 parameters: urlParams
241 actionResult = [self redirectToLocation: url];
249 @end /* UIxMailMainFrame */