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