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 <SOGoUI/UIxComponent.h>
24 #import "UIxMailMainFrame.h"
27 #import <NGObjWeb/SoComponent.h>
29 @implementation UIxMailMainFrame
31 static NSString *treeRootClassName = nil;
34 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
36 treeRootClassName = [[ud stringForKey:@"SOGoMailTreeRootClass"] copy];
37 if (treeRootClassName)
38 NSLog(@"Note: use class '%@' as root for mail tree.", treeRootClassName);
40 treeRootClassName = @"SOGoMailAccounts";
44 [self->rootURL release];
45 [self->userRootURL release];
51 - (NSString *)treeRootClassName {
52 return treeRootClassName;
55 - (void)setHideFolderTree:(BOOL)_flag {
56 self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
58 - (BOOL)hideFolderTree {
59 return self->mmfFlags.hideFolderTree ? YES : NO;
62 - (NSString *) pageFormURL {
66 u = [[[self context] request] uri];
67 if ((r = [u rangeOfString:@"?"]).length > 0) {
68 /* has query parameters */
69 // TODO: this is ugly, create reusable link facility in SOPE
70 // TODO: remove 'search' and 'filterpopup', preserve sorting
75 qp = [[u substringFromIndex:(r.location + r.length)]
76 componentsSeparatedByString:@"&"];
78 ms = [NSMutableString stringWithCapacity:count * 12];
80 for (i = 0; i < count; i++) {
83 s = [qp objectAtIndex:i];
86 if ([s hasPrefix:@"search="]) continue;
87 if ([s hasPrefix:@"filterpopup="]) continue;
89 if ([ms length] > 0) [ms appendString:@"&"];
93 if ([ms length] == 0) {
94 /* no other query params */
95 u = [u substringToIndex:r.location];
98 u = [u substringToIndex:r.location + r.length];
99 u = [u stringByAppendingString:ms];
103 return [u hasSuffix:@"/"] ? @"view" : @"#";
106 - (BOOL)showLinkBanner {
110 - (NSString *)bannerToolbarStyle {
114 - (NSString *)bannerConsumeStyle {
119 // TODO: I think all this should be done by the clientObject?!
120 // TODO: is the stuff below necessary at all in the mailer frame?
122 - (NSString *)rootURL {
124 NSArray *traversalObjects;
126 if (self->rootURL != nil)
127 return self->rootURL;
129 ctx = [self context];
130 traversalObjects = [ctx objectTraversalStack];
131 self->rootURL = [[[traversalObjects objectAtIndex:0]
132 rootURLInContext:ctx]
134 return self->rootURL;
137 - (NSString *)userRootURL {
139 NSArray *traversalObjects;
141 if (self->userRootURL)
142 return self->userRootURL;
144 ctx = [self context];
145 traversalObjects = [ctx objectTraversalStack];
146 self->userRootURL = [[[[traversalObjects objectAtIndex:1]
147 baseURLInContext:ctx]
148 stringByAppendingString:@"/"]
150 return self->userRootURL;
153 - (NSString *)calendarRootURL {
154 return [[self userRootURL] stringByAppendingString:@"Calendar/"];
157 - (NSString *)contactsRootURL {
158 return [[self userRootURL] stringByAppendingString:@"Contacts/"];
163 - (BOOL)hasErrorText {
164 return [[[[self context] request] formValueForKey:@"error"] length] > 0
167 - (NSString *)errorText {
168 return [[[self context] request] formValueForKey:@"error"];
171 - (NSString *)errorAlertJavaScript {
174 if ([(errorText = [self errorText]) length] == 0)
177 // TODO: proper JavaScript escaping
178 errorText = [errorText stringByEscapingHTMLString];
179 errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
181 return [NSString stringWithFormat:
182 @"<script language=\"JavaScript\">"
184 @"</script>", errorText];
187 /* FIXME: migrated methods which might not work yet... */
189 - (NSString *) mailFolderName
191 NSMutableArray *mailboxes;
192 SOGoMailObject *currentObject;
194 mailboxes = [NSMutableArray new];
195 [mailboxes autorelease];
197 currentObject = [self clientObject];
198 while (![currentObject isKindOfClass: [SOGoMailAccounts class]])
200 [mailboxes insertObject: [currentObject nameInContainer] atIndex: 0];
201 currentObject = [currentObject container];
204 return [NSString stringWithFormat: @"/%@",
205 [mailboxes componentsJoinedByString: @"/"]];
211 NSString *inbox, *url, *parameter;
212 NSMutableDictionary *urlParams;
215 c = [[self clientObject] toManyRelationshipKeys];
218 urlParams = [NSMutableDictionary new];
219 [urlParams autorelease];
221 parameter = [self queryParameterForKey: @"mailto"];
223 [urlParams setObject: parameter
225 inbox = [NSString stringWithFormat: @"%@/INBOX",
226 [c objectAtIndex: 0]];
227 url = [inbox composeURLWithAction: @"compose"
228 parameters: urlParams
230 actionResult = [self redirectToLocation: url];
238 @end /* UIxMailMainFrame */