2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
22 #import <Foundation/NSUserDefaults.h>
23 #import <NGObjWeb/WOContext.h>
24 #import <NGObjWeb/WORequest.h>
25 #import <NGObjWeb/SoComponent.h>
26 #import <NGExtensions/NSString+misc.h>
28 #import <SoObjects/Mailer/SOGoMailObject.h>
29 #import <SoObjects/Mailer/SOGoMailAccounts.h>
30 #import <SoObjects/SOGo/NSDictionary+URL.h>
31 #import <SoObjects/SOGo/NSArray+Utilities.h>
32 #import <SoObjects/SOGo/SOGoUser.h>
33 #import <SOGoUI/UIxComponent.h>
35 #import "UIxMailMainFrame.h"
37 @implementation UIxMailMainFrame
39 - (void) _setupContext
42 NSString *login, *module;
43 SOGoMailAccounts *clientObject;
45 activeUser = [context activeUser];
46 login = [activeUser login];
47 clientObject = [self clientObject];
49 module = [clientObject nameInContainer];
51 ud = [activeUser userSettings];
52 moduleSettings = [ud objectForKey: module];
55 moduleSettings = [NSMutableDictionary new];
56 [moduleSettings autorelease];
58 [ud setObject: moduleSettings forKey: module];
62 - (NSString *) mailAccounts
64 NSArray *accounts, *accountNames;
66 accounts = [[context activeUser] mailAccounts];
67 accountNames = [accounts objectsForKey: @"name"];
69 return [accountNames jsonRepresentation];
72 - (NSString *) pageFormURL
77 u = [[[self context] request] uri];
78 if ((r = [u rangeOfString:@"?"]).length > 0) {
79 /* has query parameters */
80 // TODO: this is ugly, create reusable link facility in SOPE
81 // TODO: remove 'search' and 'filterpopup', preserve sorting
86 qp = [[u substringFromIndex:(r.location + r.length)]
87 componentsSeparatedByString:@"&"];
89 ms = [NSMutableString stringWithCapacity:count * 12];
91 for (i = 0; i < count; i++) {
94 s = [qp objectAtIndex:i];
97 if ([s hasPrefix:@"search="]) continue;
98 if ([s hasPrefix:@"filterpopup="]) continue;
100 if ([ms length] > 0) [ms appendString:@"&"];
104 if ([ms length] == 0) {
105 /* no other query params */
106 u = [u substringToIndex:r.location];
109 u = [u substringToIndex:r.location + r.length];
110 u = [u stringByAppendingString:ms];
114 return [u hasSuffix:@"/"] ? @"view" : @"#";
117 - (id <WOActionResults>) composeAction
120 NSString *firstAccount, *newLocation;
121 SOGoMailAccounts *co;
122 NSDictionary *formValues;
124 co = [self clientObject];
125 accounts = [[context activeUser] mailAccounts];
126 firstAccount = [[accounts objectsForKey: @"name"] objectAtIndex: 0];
127 formValues = [[context request] formValues];
128 newLocation = [NSString stringWithFormat: @"%@/%@/compose%@",
129 [co baseURLInContext: context],
131 [formValues asURLParameters]];
133 return [self redirectToLocation: newLocation];
136 - (WOResponse *) getFoldersStateAction
138 NSString *expandedFolders;
140 [self _setupContext];
141 expandedFolders = [moduleSettings objectForKey: @"ExpandedFolders"];
143 return [self responseWithStatus: 200 andString: expandedFolders];
146 - (WOResponse *) saveFoldersStateAction
149 NSString *expandedFolders;
151 [self _setupContext];
152 request = [context request];
153 expandedFolders = [request formValueForKey: @"expandedFolders"];
155 [moduleSettings setObject: expandedFolders
156 forKey: @"ExpandedFolders"];
160 return [self responseWithStatus: 204];
163 @end /* UIxMailMainFrame */