]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailMainFrame.m
disabled banner
[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   return NO;
154 }
155 - (NSString *)bannerToolbarStyle {
156   return nil;
157 }
158 - (NSString *)bannerConsumeStyle {
159   return nil;
160 }
161
162 /* notifications */
163
164 - (void)sleep {
165   [self->item release]; self->item = nil;
166   [super sleep];
167 }
168
169 /* URL generation */
170 // TODO: I think all this should be done by the clientObject?!
171 // TODO: is the stuff below necessary at all in the mailer frame?
172
173 - (NSString *)rootURL {
174   WOContext *ctx;
175   NSArray   *traversalObjects;
176
177   if (self->rootURL != nil)
178     return self->rootURL;
179
180   ctx = [self context];
181   traversalObjects = [ctx objectTraversalStack];
182   self->rootURL = [[[traversalObjects objectAtIndex:0]
183                                       rootURLInContext:ctx]
184                                       copy];
185   return self->rootURL;
186 }
187
188 - (NSString *)userRootURL {
189   WOContext *ctx;
190   NSArray   *traversalObjects;
191
192   if (self->userRootURL)
193     return self->userRootURL;
194
195   ctx = [self context];
196   traversalObjects = [ctx objectTraversalStack];
197   self->userRootURL = [[[[traversalObjects objectAtIndex:1]
198                                            baseURLInContext:ctx]
199                                            stringByAppendingString:@"/"]
200                                            retain];
201   return self->userRootURL;
202 }
203
204 - (NSString *)calendarRootURL {
205   return [[self userRootURL] stringByAppendingString:@"Calendar/"];
206 }
207 - (NSString *)contactsRootURL {
208   return [[self userRootURL] stringByAppendingString:@"Contacts/"];
209 }
210
211 /* error handling */
212
213 - (BOOL)hasErrorText {
214   return [[[[self context] request] formValueForKey:@"error"] length] > 0
215     ? YES : NO;
216 }
217 - (NSString *)errorText {
218   return [[[self context] request] formValueForKey:@"error"];
219 }
220
221 - (NSString *)errorAlertJavaScript {
222   NSString *errorText;
223   
224   if ([(errorText = [self errorText]) length] == 0)
225     return nil;
226   
227   // TODO: proper JavaScript escaping
228   errorText = [errorText stringByEscapingHTMLString];
229   errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
230   
231   return [NSString stringWithFormat:
232                      @"<script language=\"JavaScript\">"
233                      @"alert(\"%@\");"
234                      @"</script>", errorText];
235 }
236
237 /* URLs */
238
239 - (NSString *)relativeHomePath {
240   return [self relativePathToUserFolderSubPath:@""];
241 }
242
243 - (NSString *)relativeCalendarPath {
244   return [self relativePathToUserFolderSubPath:@"Calendar/"];
245 }
246
247 - (NSString *)relativeContactsPath {
248   return [self relativePathToUserFolderSubPath:@"Contacts/"];
249 }
250
251 - (NSString *)relativeMailPath {
252   return [self relativePathToUserFolderSubPath:@"Mail/"];
253 }
254
255 @end /* UIxMailMainFrame */
256
257 @implementation UIxMailPanelFrame
258
259 - (BOOL)hideFolderTree {
260   return YES;
261 }
262 - (BOOL)showLinkBanner {
263   return NO;
264 }
265
266 @end /* UIxMailPanelFrame */