]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailMainFrame.m
moved SOGo files up
[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 #include <SOGoUI/UIxComponent.h>
23
24 @interface UIxMailMainFrame : UIxComponent
25 {
26   NSString *title;
27   NSString *rootURL;
28   NSString *userRootURL;
29   id       item;
30   struct {
31     int hideFolderTree:1;
32     int hideFrame:1; /* completely disables all the frame around the comp. */
33     int reserved:30;
34   } mmfFlags;
35 }
36
37 - (NSString *)rootURL;
38 - (NSString *)userRootURL;
39 - (NSString *)calendarRootURL;
40
41 @end
42
43 @interface UIxMailPanelFrame : UIxMailMainFrame
44 @end
45
46 #include "common.h"
47 #include <NGObjWeb/SoComponent.h>
48
49 @implementation UIxMailMainFrame
50
51 static NSString *treeRootClassName = nil;
52
53 + (void)initialize {
54   NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
55   
56   treeRootClassName = [[ud stringForKey:@"SOGoMailTreeRootClass"] copy];
57   if (treeRootClassName)
58     NSLog(@"Note: use class '%@' as root for mail tree.", treeRootClassName);
59   else
60     treeRootClassName = @"SOGoMailAccounts";
61 }
62
63 - (void)dealloc {
64   [self->item        release];
65   [self->title       release];
66   [self->rootURL     release];
67   [self->userRootURL release];
68   [super dealloc];
69 }
70
71 /* accessors */
72
73 - (NSString *)treeRootClassName {
74   return treeRootClassName;
75 }
76
77 - (void)setHideFolderTree:(BOOL)_flag {
78    self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
79 }
80 - (BOOL)hideFolderTree {
81   return self->mmfFlags.hideFolderTree ? YES : NO;
82 }
83
84 - (void)setHideFrame:(BOOL)_flag {
85    self->mmfFlags.hideFrame = _flag ? 1 : 0;
86 }
87 - (BOOL)hideFrame {
88   return self->mmfFlags.hideFrame ? YES : NO;
89 }
90
91 - (void)setTitle:(NSString *)_value {
92   ASSIGNCOPY(self->title, _value);
93 }
94 - (NSString *)title {
95   if ([self->title length] == 0)
96     return @"OpenGroupware.org";
97   
98   return self->title;
99 }
100
101 - (void)setItem:(id)_item {
102   ASSIGN(self->item, _item);
103 }
104 - (id)item {
105   return self->item;
106 }
107
108 - (NSString *)pageFormURL {
109   NSString *u;
110   NSRange  r;
111   
112   u = [[[self context] request] uri];
113   if ((r = [u rangeOfString:@"?"]).length > 0) {
114     /* has query parameters */
115     // TODO: this is ugly, create reusable link facility in SOPE
116     // TODO: remove 'search' and 'filterpopup', preserve sorting
117     NSMutableString *ms;
118     NSArray  *qp;
119     unsigned i, count;
120     
121     qp    = [[u substringFromIndex:(r.location + r.length)] 
122                 componentsSeparatedByString:@"&"];
123     count = [qp count];
124     ms    = [NSMutableString stringWithCapacity:count * 12];
125     
126     for (i = 0; i < count; i++) {
127       NSString *s;
128       
129       s = [qp objectAtIndex:i];
130       
131       /* filter out */
132       if ([s hasPrefix:@"search="]) continue;
133       if ([s hasPrefix:@"filterpopup="]) continue;
134       
135       if ([ms length] > 0) [ms appendString:@"&"];
136       [ms appendString:s];
137     }
138     
139     if ([ms length] == 0) {
140       /* no other query params */
141       u = [u substringToIndex:r.location];
142     }
143     else {
144       u = [u substringToIndex:r.location + r.length];
145       u = [u stringByAppendingString:ms];
146     }
147     return u;
148   }
149   return [u hasSuffix:@"/"] ? @"view" : @"#";
150 }
151
152 - (BOOL)showLinkBanner {
153   if ([self hideFolderTree]) return NO;
154   return YES;
155 }
156 - (NSString *)bannerToolbarStyle {
157 #if 0 // 32x32
158   return [self showLinkBanner] ? @"top: 58px;" : nil /* fallback to CSS */;
159 #else // 24x24
160   return [self showLinkBanner] ? @"top: 58px;" : nil /* fallback to CSS */;
161 #endif
162 }
163 - (NSString *)bannerConsumeStyle {
164 #if 0 // 32x32
165   return [self showLinkBanner] ? @"height: 116px;" : nil /* fallback to CSS */;
166 #else // 24x24
167   return [self showLinkBanner] ? @"height: 110px;" : nil /* fallback to CSS */;
168 #endif
169 }
170
171 /* notifications */
172
173 - (void)sleep {
174   [self->item release]; self->item = nil;
175   [super sleep];
176 }
177
178 /* URL generation */
179 // TODO: I think all this should be done by the clientObject?!
180 // TODO: is the stuff below necessary at all in the mailer frame?
181
182 - (NSString *)rootURL {
183   WOContext *ctx;
184   NSArray   *traversalObjects;
185
186   if (self->rootURL != nil)
187     return self->rootURL;
188
189   ctx = [self context];
190   traversalObjects = [ctx objectTraversalStack];
191   self->rootURL = [[[traversalObjects objectAtIndex:0]
192                                       rootURLInContext:ctx]
193                                       copy];
194   return self->rootURL;
195 }
196
197 - (NSString *)userRootURL {
198   WOContext *ctx;
199   NSArray   *traversalObjects;
200
201   if (self->userRootURL)
202     return self->userRootURL;
203
204   ctx = [self context];
205   traversalObjects = [ctx objectTraversalStack];
206   self->userRootURL = [[[[traversalObjects objectAtIndex:1]
207                                            baseURLInContext:ctx]
208                                            stringByAppendingString:@"/"]
209                                            retain];
210   return self->userRootURL;
211 }
212
213 - (NSString *)calendarRootURL {
214   return [[self userRootURL] stringByAppendingString:@"Calendar/"];
215 }
216 - (NSString *)contactsRootURL {
217   return [[self userRootURL] stringByAppendingString:@"Contacts/"];
218 }
219
220 /* error handling */
221
222 - (BOOL)hasErrorText {
223   return [[[[self context] request] formValueForKey:@"error"] length] > 0
224     ? YES : NO;
225 }
226 - (NSString *)errorText {
227   return [[[self context] request] formValueForKey:@"error"];
228 }
229
230 - (NSString *)errorAlertJavaScript {
231   NSString *errorText;
232   
233   if ([(errorText = [self errorText]) length] == 0)
234     return nil;
235   
236   // TODO: proper JavaScript escaping
237   errorText = [errorText stringByEscapingHTMLString];
238   errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
239   
240   return [NSString stringWithFormat:
241                      @"<script language=\"JavaScript\">"
242                      @"alert(\"%@\");"
243                      @"</script>", errorText];
244 }
245
246 /* URLs */
247
248 - (NSString *)relativeHomePath {
249   return [self relativePathToUserFolderSubPath:@""];
250 }
251
252 - (NSString *)relativeCalendarPath {
253   return [self relativePathToUserFolderSubPath:@"Calendar/"];
254 }
255
256 - (NSString *)relativeContactsPath {
257   return [self relativePathToUserFolderSubPath:@"Contacts/"];
258 }
259
260 - (NSString *)relativeMailPath {
261   return [self relativePathToUserFolderSubPath:@"Mail/"];
262 }
263
264 @end /* UIxMailMainFrame */
265
266 @implementation UIxMailPanelFrame
267
268 - (BOOL)hideFolderTree {
269   return YES;
270 }
271 - (BOOL)showLinkBanner {
272   return NO;
273 }
274
275 @end /* UIxMailPanelFrame */