]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailMainFrame.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1018 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxMailMainFrame.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import <Mailer/SOGoMailObject.h>
23 #import <SOGo/NSString+Utilities.h>
24 #import <SOGoUI/UIxComponent.h>
25 #import "UIxMailMainFrame.h"
26
27 #import "common.h"
28 #import <NGObjWeb/SoComponent.h>
29
30 @implementation UIxMailMainFrame
31
32 static NSString *treeRootClassName = nil;
33
34 + (void)initialize {
35   NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
36   
37   treeRootClassName = [[ud stringForKey:@"SOGoMailTreeRootClass"] copy];
38   if (treeRootClassName)
39     NSLog(@"Note: use class '%@' as root for mail tree.", treeRootClassName);
40   else
41     treeRootClassName = @"SOGoMailAccounts";
42 }
43
44 - (void)dealloc {
45   [self->rootURL     release];
46   [self->userRootURL release];
47   [super dealloc];
48 }
49
50 /* accessors */
51
52 - (NSString *)treeRootClassName {
53   return treeRootClassName;
54 }
55
56 - (void)setHideFolderTree:(BOOL)_flag {
57    self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
58 }
59 - (BOOL)hideFolderTree {
60   return self->mmfFlags.hideFolderTree ? YES : NO;
61 }
62
63 - (NSString *) pageFormURL {
64   NSString *u;
65   NSRange  r;
66   
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
72     NSMutableString *ms;
73     NSArray  *qp;
74     unsigned i, count;
75     
76     qp    = [[u substringFromIndex:(r.location + r.length)] 
77                 componentsSeparatedByString:@"&"];
78     count = [qp count];
79     ms    = [NSMutableString stringWithCapacity:count * 12];
80     
81     for (i = 0; i < count; i++) {
82       NSString *s;
83       
84       s = [qp objectAtIndex:i];
85       
86       /* filter out */
87       if ([s hasPrefix:@"search="]) continue;
88       if ([s hasPrefix:@"filterpopup="]) continue;
89       
90       if ([ms length] > 0) [ms appendString:@"&"];
91       [ms appendString:s];
92     }
93     
94     if ([ms length] == 0) {
95       /* no other query params */
96       u = [u substringToIndex:r.location];
97     }
98     else {
99       u = [u substringToIndex:r.location + r.length];
100       u = [u stringByAppendingString:ms];
101     }
102     return u;
103   }
104   return [u hasSuffix:@"/"] ? @"view" : @"#";
105 }
106
107 - (BOOL)showLinkBanner {
108   return YES;
109 }
110
111 - (NSString *)bannerToolbarStyle {
112   return nil;
113 }
114
115 - (NSString *)bannerConsumeStyle {
116   return nil;
117 }
118
119 /* URL generation */
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?
122
123 - (NSString *)rootURL {
124   WOContext *ctx;
125   NSArray   *traversalObjects;
126
127   if (self->rootURL != nil)
128     return self->rootURL;
129
130   ctx = [self context];
131   traversalObjects = [ctx objectTraversalStack];
132   self->rootURL = [[[traversalObjects objectAtIndex:0]
133                                       rootURLInContext:ctx]
134                                       copy];
135   return self->rootURL;
136 }
137
138 - (NSString *)userRootURL {
139   WOContext *ctx;
140   NSArray   *traversalObjects;
141
142   if (self->userRootURL)
143     return self->userRootURL;
144
145   ctx = [self context];
146   traversalObjects = [ctx objectTraversalStack];
147   self->userRootURL = [[[[traversalObjects objectAtIndex:1]
148                                            baseURLInContext:ctx]
149                                            stringByAppendingString:@"/"]
150                                            retain];
151   return self->userRootURL;
152 }
153
154 - (NSString *)calendarRootURL {
155   return [[self userRootURL] stringByAppendingString:@"Calendar/"];
156 }
157
158 - (NSString *)contactsRootURL {
159   return [[self userRootURL] stringByAppendingString:@"Contacts/"];
160 }
161
162 /* error handling */
163
164 - (BOOL)hasErrorText {
165   return [[[[self context] request] formValueForKey:@"error"] length] > 0
166     ? YES : NO;
167 }
168 - (NSString *)errorText {
169   return [[[self context] request] formValueForKey:@"error"];
170 }
171
172 - (NSString *)errorAlertJavaScript {
173   NSString *errorText;
174   
175   if ([(errorText = [self errorText]) length] == 0)
176     return nil;
177   
178   // TODO: proper JavaScript escaping
179   errorText = [errorText stringByEscapingHTMLString];
180   errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
181   
182   return [NSString stringWithFormat:
183                      @"<script language=\"JavaScript\">"
184                      @"alert(\"%@\");"
185                      @"</script>", errorText];
186 }
187
188 /* FIXME: migrated methods which might not work yet... */
189 #warning check this
190 - (NSString *) mailFolderName
191 {
192   NSMutableArray *mailboxes;
193   SOGoMailObject *currentObject;
194
195   mailboxes = [NSMutableArray new];
196   [mailboxes autorelease];
197
198   currentObject = [self clientObject];
199   while (![currentObject isKindOfClass: [SOGoMailAccounts class]])
200     {
201       [mailboxes insertObject: [currentObject nameInContainer] atIndex: 0];
202       currentObject = [currentObject container];
203     }
204
205   return [NSString stringWithFormat: @"/%@",
206                    [mailboxes componentsJoinedByString: @"/"]];
207 }
208
209 - (id) composeAction
210 {
211   NSArray *c;
212   NSString *inbox, *url, *parameter;
213   NSMutableDictionary *urlParams;
214   id actionResult;
215
216   c = [[self clientObject] toManyRelationshipKeys];
217   if ([c count] > 0)
218     {
219       urlParams = [NSMutableDictionary new];
220       [urlParams autorelease];
221
222       parameter = [self queryParameterForKey: @"mailto"];
223       if (parameter)
224         [urlParams setObject: parameter
225                    forKey: @"mailto"];
226       inbox = [NSString stringWithFormat: @"%@/INBOX",
227                         [c objectAtIndex: 0]];
228       url = [inbox composeURLWithAction: @"compose"
229                    parameters: urlParams
230                    andHash: NO];
231       actionResult = [self redirectToLocation: url];
232     }
233   else
234     actionResult = self;
235
236   return actionResult;
237 }
238
239 @end /* UIxMailMainFrame */