]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/MailerUI/UIxMailMainFrame.m
added help button
[scalable-opengroupware.org] / SOGo / 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 #include "common.h"
44 #include <NGObjWeb/SoComponent.h>
45
46 @implementation UIxMailMainFrame
47
48 static NSString *treeRootClassName = nil;
49
50 + (void)initialize {
51   NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
52   
53   treeRootClassName = [[ud stringForKey:@"SOGoMailTreeRootClass"] copy];
54   if (treeRootClassName)
55     NSLog(@"Note: use class '%@' as root for mail tree.", treeRootClassName);
56   else
57     treeRootClassName = @"SOGoMailAccounts";
58 }
59
60 - (void)dealloc {
61   [self->item        release];
62   [self->title       release];
63   [self->rootURL     release];
64   [self->userRootURL release];
65   [super dealloc];
66 }
67
68 /* accessors */
69
70 - (NSString *)treeRootClassName {
71   return treeRootClassName;
72 }
73
74 - (void)setHideFolderTree:(BOOL)_flag {
75    self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
76 }
77 - (BOOL)hideFolderTree {
78   return self->mmfFlags.hideFolderTree ? YES : NO;
79 }
80
81 - (void)setHideFrame:(BOOL)_flag {
82    self->mmfFlags.hideFrame = _flag ? 1 : 0;
83 }
84 - (BOOL)hideFrame {
85   return self->mmfFlags.hideFrame ? YES : NO;
86 }
87
88 - (void)setTitle:(NSString *)_value {
89   ASSIGNCOPY(self->title, _value);
90 }
91 - (NSString *)title {
92   if ([self->title length] == 0)
93     return @"OpenGroupware.org";
94   
95   return self->title;
96 }
97
98 - (void)setItem:(id)_item {
99   ASSIGN(self->item, _item);
100 }
101 - (id)item {
102   return self->item;
103 }
104
105 - (NSString *)pageFormURL {
106   NSString *u;
107   
108   u = [[[self context] request] uri];
109   return [u hasSuffix:@"/"] ? @"view" : @"#";
110 }
111
112 - (BOOL)showLinkBanner {
113   if ([self hideFolderTree]) return NO;
114   return YES;
115 }
116 - (NSString *)bannerToolbarStyle {
117   return [self showLinkBanner] ? @"top: 58px;" : nil /* fallback to CSS */;
118 }
119 - (NSString *)bannerConsumeStyle {
120   return [self showLinkBanner] ? @"height: 116px;" : nil /* fallback to CSS */;
121 }
122
123 /* notifications */
124
125 - (void)sleep {
126   [self->item release]; self->item = nil;
127   [super sleep];
128 }
129
130 /* URL generation */
131 // TODO: I think all this should be done by the clientObject?!
132 // TODO: is the stuff below necessary at all in the mailer frame?
133
134 - (NSString *)rootURL {
135   WOContext *ctx;
136   NSArray   *traversalObjects;
137
138   if (self->rootURL != nil)
139     return self->rootURL;
140
141   ctx = [self context];
142   traversalObjects = [ctx objectTraversalStack];
143   self->rootURL = [[[traversalObjects objectAtIndex:0]
144                                       rootURLInContext:ctx]
145                                       copy];
146   return self->rootURL;
147 }
148
149 - (NSString *)userRootURL {
150   WOContext *ctx;
151   NSArray   *traversalObjects;
152
153   if (self->userRootURL)
154     return self->userRootURL;
155
156   ctx = [self context];
157   traversalObjects = [ctx objectTraversalStack];
158   self->userRootURL = [[[[traversalObjects objectAtIndex:1]
159                                            baseURLInContext:ctx]
160                                            stringByAppendingString:@"/"]
161                                            retain];
162   return self->userRootURL;
163 }
164
165 - (NSString *)calendarRootURL {
166   return [[self userRootURL] stringByAppendingString:@"Calendar/"];
167 }
168 - (NSString *)contactsRootURL {
169   return [[self userRootURL] stringByAppendingString:@"Contacts/"];
170 }
171
172 /* error handling */
173
174 - (BOOL)hasErrorText {
175   return [[[[self context] request] formValueForKey:@"error"] length] > 0
176     ? YES : NO;
177 }
178 - (NSString *)errorText {
179   return [[[self context] request] formValueForKey:@"error"];
180 }
181
182 - (NSString *)errorAlertJavaScript {
183   NSString *errorText;
184   
185   if ([(errorText = [self errorText]) length] == 0)
186     return nil;
187   
188   // TODO: proper JavaScript escaping
189   errorText = [errorText stringByEscapingHTMLString];
190   errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
191   
192   return [NSString stringWithFormat:
193                      @"<script language=\"JavaScript\">"
194                      @"alert(\"%@\");"
195                      @"</script>", errorText];
196 }
197
198 @end /* UIxMailMainFrame */