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 <Mailer/SOGoMailObject.h>
23 #import <SOGo/NSString+Utilities.h>
24 #import <SOGoUI/UIxComponent.h>
25 #import "UIxMailMainFrame.h"
28 #import <NGObjWeb/SoComponent.h>
30 @implementation UIxMailMainFrame
32 static NSString *treeRootClassName = nil;
35 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
37 treeRootClassName = [[ud stringForKey:@"SOGoMailTreeRootClass"] copy];
38 if (treeRootClassName)
39 NSLog(@"Note: use class '%@' as root for mail tree.", treeRootClassName);
41 treeRootClassName = @"SOGoMailAccounts";
45 [self->rootURL release];
46 [self->userRootURL release];
52 - (NSString *)treeRootClassName {
53 return treeRootClassName;
56 - (void)setHideFolderTree:(BOOL)_flag {
57 self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
59 - (BOOL)hideFolderTree {
60 return self->mmfFlags.hideFolderTree ? YES : NO;
63 - (NSString *) pageFormURL {
67 u = [[[self context] request] uri];
68 if ((r = [u rangeOfString:@"?"]).length > 0) {
69 /* has query parameters */
70 // TODO: this is ugly, create reusable link facility in SOPE
71 // TODO: remove 'search' and 'filterpopup', preserve sorting
76 qp = [[u substringFromIndex:(r.location + r.length)]
77 componentsSeparatedByString:@"&"];
79 ms = [NSMutableString stringWithCapacity:count * 12];
81 for (i = 0; i < count; i++) {
84 s = [qp objectAtIndex:i];
87 if ([s hasPrefix:@"search="]) continue;
88 if ([s hasPrefix:@"filterpopup="]) continue;
90 if ([ms length] > 0) [ms appendString:@"&"];
94 if ([ms length] == 0) {
95 /* no other query params */
96 u = [u substringToIndex:r.location];
99 u = [u substringToIndex:r.location + r.length];
100 u = [u stringByAppendingString:ms];
104 return [u hasSuffix:@"/"] ? @"view" : @"#";
107 - (BOOL)showLinkBanner {
111 - (NSString *)bannerToolbarStyle {
115 - (NSString *)bannerConsumeStyle {
120 // TODO: I think all this should be done by the clientObject?!
121 // TODO: is the stuff below necessary at all in the mailer frame?
123 - (NSString *)rootURL {
125 NSArray *traversalObjects;
127 if (self->rootURL != nil)
128 return self->rootURL;
130 ctx = [self context];
131 traversalObjects = [ctx objectTraversalStack];
132 self->rootURL = [[[traversalObjects objectAtIndex:0]
133 rootURLInContext:ctx]
135 return self->rootURL;
138 - (NSString *)userRootURL {
140 NSArray *traversalObjects;
142 if (self->userRootURL)
143 return self->userRootURL;
145 ctx = [self context];
146 traversalObjects = [ctx objectTraversalStack];
147 self->userRootURL = [[[[traversalObjects objectAtIndex:1]
148 baseURLInContext:ctx]
149 stringByAppendingString:@"/"]
151 return self->userRootURL;
154 - (NSString *)calendarRootURL {
155 return [[self userRootURL] stringByAppendingString:@"Calendar/"];
158 - (NSString *)contactsRootURL {
159 return [[self userRootURL] stringByAppendingString:@"Contacts/"];
164 - (BOOL)hasErrorText {
165 return [[[[self context] request] formValueForKey:@"error"] length] > 0
168 - (NSString *)errorText {
169 return [[[self context] request] formValueForKey:@"error"];
172 - (NSString *)errorAlertJavaScript {
175 if ([(errorText = [self errorText]) length] == 0)
178 // TODO: proper JavaScript escaping
179 errorText = [errorText stringByEscapingHTMLString];
180 errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
182 return [NSString stringWithFormat:
183 @"<script language=\"JavaScript\">"
185 @"</script>", errorText];
188 /* FIXME: migrated methods which might not work yet... */
190 - (NSString *) mailFolderName
192 NSMutableArray *mailboxes;
193 SOGoMailObject *currentObject;
195 mailboxes = [NSMutableArray new];
196 [mailboxes autorelease];
198 currentObject = [self clientObject];
199 while (![currentObject isKindOfClass: [SOGoMailAccounts class]])
201 [mailboxes insertObject: [currentObject nameInContainer] atIndex: 0];
202 currentObject = [currentObject container];
205 return [NSString stringWithFormat: @"/%@",
206 [mailboxes componentsJoinedByString: @"/"]];
212 NSString *inbox, *url, *parameter;
213 NSMutableDictionary *urlParams;
216 c = [[self clientObject] toManyRelationshipKeys];
219 urlParams = [NSMutableDictionary new];
220 [urlParams autorelease];
222 parameter = [self queryParameterForKey: @"mailto"];
224 [urlParams setObject: parameter
226 inbox = [NSString stringWithFormat: @"%@/INBOX",
227 [c objectAtIndex: 0]];
228 url = [inbox composeURLWithAction: @"compose"
229 parameters: urlParams
231 actionResult = [self redirectToLocation: url];
239 @end /* UIxMailMainFrame */