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 <Foundation/NSUserDefaults.h>
23 #import <NGObjWeb/WORequest.h>
24 #import <NGObjWeb/SoComponent.h>
25 #import <NGExtensions/NSString+misc.h>
27 #import <SoObjects/Mailer/SOGoMailObject.h>
28 #import <SoObjects/Mailer/SOGoMailAccounts.h>
29 #import <SoObjects/SOGo/NSString+Utilities.h>
30 #import <SoObjects/SOGo/NSObject+Utilities.h>
31 #import <SOGoUI/UIxComponent.h>
33 #import "UIxMailMainFrame.h"
35 @implementation UIxMailMainFrame
37 static NSString *treeRootClassName = nil;
40 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
42 treeRootClassName = [[ud stringForKey:@"SOGoMailTreeRootClass"] copy];
43 if (treeRootClassName)
44 NSLog(@"Note: use class '%@' as root for mail tree.", treeRootClassName);
46 treeRootClassName = @"SOGoMailAccounts";
50 [self->rootURL release];
51 [self->userRootURL release];
56 - (NSString *) mailAccounts
60 co = [self clientObject];
62 return [[co fetchAllIdentities] jsonRepresentation];
65 - (NSString *)treeRootClassName {
66 return treeRootClassName;
69 - (void)setHideFolderTree:(BOOL)_flag {
70 self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
72 - (BOOL)hideFolderTree {
73 return self->mmfFlags.hideFolderTree ? YES : NO;
76 - (NSString *) pageFormURL {
80 u = [[[self context] request] uri];
81 if ((r = [u rangeOfString:@"?"]).length > 0) {
82 /* has query parameters */
83 // TODO: this is ugly, create reusable link facility in SOPE
84 // TODO: remove 'search' and 'filterpopup', preserve sorting
89 qp = [[u substringFromIndex:(r.location + r.length)]
90 componentsSeparatedByString:@"&"];
92 ms = [NSMutableString stringWithCapacity:count * 12];
94 for (i = 0; i < count; i++) {
97 s = [qp objectAtIndex:i];
100 if ([s hasPrefix:@"search="]) continue;
101 if ([s hasPrefix:@"filterpopup="]) continue;
103 if ([ms length] > 0) [ms appendString:@"&"];
107 if ([ms length] == 0) {
108 /* no other query params */
109 u = [u substringToIndex:r.location];
112 u = [u substringToIndex:r.location + r.length];
113 u = [u stringByAppendingString:ms];
117 return [u hasSuffix:@"/"] ? @"view" : @"#";
120 - (BOOL)showLinkBanner {
124 - (NSString *)bannerToolbarStyle {
128 - (NSString *)bannerConsumeStyle {
133 // TODO: I think all this should be done by the clientObject?!
134 // TODO: is the stuff below necessary at all in the mailer frame?
136 - (NSString *)rootURL {
138 NSArray *traversalObjects;
140 if (self->rootURL != nil)
141 return self->rootURL;
143 ctx = [self context];
144 traversalObjects = [ctx objectTraversalStack];
145 self->rootURL = [[[traversalObjects objectAtIndex:0]
146 rootURLInContext:ctx]
148 return self->rootURL;
151 - (NSString *)userRootURL {
153 NSArray *traversalObjects;
155 if (self->userRootURL)
156 return self->userRootURL;
158 ctx = [self context];
159 traversalObjects = [ctx objectTraversalStack];
160 self->userRootURL = [[[[traversalObjects objectAtIndex:1]
161 baseURLInContext:ctx]
162 stringByAppendingString:@"/"]
164 return self->userRootURL;
167 - (NSString *)calendarRootURL {
168 return [[self userRootURL] stringByAppendingString:@"Calendar/"];
171 - (NSString *)contactsRootURL {
172 return [[self userRootURL] stringByAppendingString:@"Contacts/"];
177 - (BOOL)hasErrorText {
178 return [[[[self context] request] formValueForKey:@"error"] length] > 0
181 - (NSString *)errorText {
182 return [[[self context] request] formValueForKey:@"error"];
185 - (NSString *)errorAlertJavaScript {
188 if ([(errorText = [self errorText]) length] == 0)
191 // TODO: proper JavaScript escaping
192 errorText = [errorText stringByEscapingHTMLString];
193 errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
195 return [NSString stringWithFormat:
196 @"<script language=\"JavaScript\">"
198 @"</script>", errorText];
201 /* FIXME: migrated methods which might not work yet... */
202 // #warning check this
203 // - (NSString *) mailFolderName
205 // NSMutableArray *mailboxes;
206 // SOGoMailObject *currentObject;
208 // mailboxes = [NSMutableArray new];
209 // [mailboxes autorelease];
211 // currentObject = [self clientObject];
212 // while (![currentObject isKindOfClass: [SOGoMailAccounts class]])
214 // [mailboxes insertObject: [currentObject nameInContainer] atIndex: 0];
215 // currentObject = [currentObject container];
218 // return [NSString stringWithFormat: @"/%@",
219 // [mailboxes componentsJoinedByString: @"/"]];
225 NSString *inbox, *url, *parameter;
226 NSMutableDictionary *urlParams;
229 c = [[self clientObject] toManyRelationshipKeys];
232 urlParams = [NSMutableDictionary new];
233 [urlParams autorelease];
235 parameter = [self queryParameterForKey: @"mailto"];
237 [urlParams setObject: parameter
239 inbox = [NSString stringWithFormat: @"%@/INBOX",
240 [c objectAtIndex: 0]];
241 url = [inbox composeURLWithAction: @"compose"
242 parameters: urlParams
244 actionResult = [self redirectToLocation: url];
252 @end /* UIxMailMainFrame */