*/
#import <Foundation/NSUserDefaults.h>
+
+#import <NGObjWeb/WOContext.h>
#import <NGObjWeb/WORequest.h>
+#import <NGObjWeb/WOResponse.h>
#import <NGObjWeb/SoComponent.h>
#import <NGExtensions/NSString+misc.h>
#import <SoObjects/Mailer/SOGoMailObject.h>
#import <SoObjects/Mailer/SOGoMailAccounts.h>
-#import <SoObjects/SOGo/NSString+Utilities.h>
-#import <SoObjects/SOGo/NSObject+Utilities.h>
+#import <SoObjects/SOGo/NSDictionary+URL.h>
+#import <SoObjects/SOGo/NSArray+Utilities.h>
+#import <SoObjects/SOGo/SOGoUser.h>
#import <SOGoUI/UIxComponent.h>
#import "UIxMailMainFrame.h"
@implementation UIxMailMainFrame
-static NSString *treeRootClassName = nil;
+- (void) _setupContext
+{
+ SOGoUser *activeUser;
+ NSString *login, *module;
+ SOGoMailAccounts *clientObject;
-+ (void)initialize {
- NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
-
- treeRootClassName = [[ud stringForKey:@"SOGoMailTreeRootClass"] copy];
- if (treeRootClassName)
- NSLog(@"Note: use class '%@' as root for mail tree.", treeRootClassName);
- else
- treeRootClassName = @"SOGoMailAccounts";
-}
+ activeUser = [context activeUser];
+ login = [activeUser login];
+ clientObject = [self clientObject];
+
+ module = [clientObject nameInContainer];
-- (void)dealloc {
- [self->rootURL release];
- [self->userRootURL release];
- [super dealloc];
+ ud = [activeUser userSettings];
+ moduleSettings = [ud objectForKey: module];
+ if (!moduleSettings)
+ {
+ moduleSettings = [NSMutableDictionary new];
+ [moduleSettings autorelease];
+ }
+ [ud setObject: moduleSettings forKey: module];
}
/* accessors */
- (NSString *) mailAccounts
{
- SOGoMailAccounts *co;
-
- co = [self clientObject];
+ NSArray *accounts, *accountNames;
- return [[co fetchAllIdentities] jsonRepresentation];
-}
+ accounts = [[context activeUser] mailAccounts];
+ accountNames = [accounts objectsForKey: @"name"];
-- (NSString *)treeRootClassName {
- return treeRootClassName;
+ return [accountNames jsonRepresentation];
}
-- (void)setHideFolderTree:(BOOL)_flag {
- self->mmfFlags.hideFolderTree = _flag ? 1 : 0;
-}
-- (BOOL)hideFolderTree {
- return self->mmfFlags.hideFolderTree ? YES : NO;
-}
-
-- (NSString *) pageFormURL {
+- (NSString *) pageFormURL
+{
NSString *u;
NSRange r;
return [u hasSuffix:@"/"] ? @"view" : @"#";
}
-- (BOOL)showLinkBanner {
- return YES;
-}
-
-- (NSString *)bannerToolbarStyle {
- return nil;
-}
-
-- (NSString *)bannerConsumeStyle {
- return nil;
-}
-
-/* URL generation */
-// TODO: I think all this should be done by the clientObject?!
-// TODO: is the stuff below necessary at all in the mailer frame?
-
-- (NSString *)rootURL {
- WOContext *ctx;
- NSArray *traversalObjects;
-
- if (self->rootURL != nil)
- return self->rootURL;
-
- ctx = [self context];
- traversalObjects = [ctx objectTraversalStack];
- self->rootURL = [[[traversalObjects objectAtIndex:0]
- rootURLInContext:ctx]
- copy];
- return self->rootURL;
-}
-
-- (NSString *)userRootURL {
- WOContext *ctx;
- NSArray *traversalObjects;
-
- if (self->userRootURL)
- return self->userRootURL;
+- (id <WOActionResults>) composeAction
+{
+ NSArray *accounts;
+ NSString *firstAccount, *newLocation, *parameters;
+ SOGoMailAccounts *co;
+ NSDictionary *formValues;
- ctx = [self context];
- traversalObjects = [ctx objectTraversalStack];
- self->userRootURL = [[[[traversalObjects objectAtIndex:1]
- baseURLInContext:ctx]
- stringByAppendingString:@"/"]
- retain];
- return self->userRootURL;
-}
+ co = [self clientObject];
+ accounts = [[context activeUser] mailAccounts];
+ firstAccount = [[accounts objectsForKey: @"name"] objectAtIndex: 0];
+ formValues = [[context request] formValues];
+ parameters = [formValues count] > 0 ? [formValues asURLParameters] : @"?mailto=";
+ newLocation = [NSString stringWithFormat: @"%@/%@/compose%@",
+ [co baseURLInContext: context],
+ firstAccount,
+ parameters];
-- (NSString *)calendarRootURL {
- return [[self userRootURL] stringByAppendingString:@"Calendar/"];
+ return [self redirectToLocation: newLocation];
}
-- (NSString *)contactsRootURL {
- return [[self userRootURL] stringByAppendingString:@"Contacts/"];
-}
+- (WOResponse *) getFoldersStateAction
+{
+ NSString *expandedFolders;
-/* error handling */
+ [self _setupContext];
+ expandedFolders = [moduleSettings objectForKey: @"ExpandedFolders"];
-- (BOOL)hasErrorText {
- return [[[[self context] request] formValueForKey:@"error"] length] > 0
- ? YES : NO;
-}
-- (NSString *)errorText {
- return [[[self context] request] formValueForKey:@"error"];
+ return [self responseWithStatus: 200 andString: expandedFolders];
}
-- (NSString *)errorAlertJavaScript {
- NSString *errorText;
-
- if ([(errorText = [self errorText]) length] == 0)
- return nil;
-
- // TODO: proper JavaScript escaping
- errorText = [errorText stringByEscapingHTMLString];
- errorText = [errorText stringByReplacingString:@"\"" withString:@"'"];
+- (WOResponse *) saveFoldersStateAction
+{
+ WORequest *request;
+ NSString *expandedFolders;
- return [NSString stringWithFormat:
- @"<script language=\"JavaScript\">"
- @"alert(\"%@\");"
- @"</script>", errorText];
-}
-
-/* FIXME: migrated methods which might not work yet... */
-// #warning check this
-// - (NSString *) mailFolderName
-// {
-// NSMutableArray *mailboxes;
-// SOGoMailObject *currentObject;
-
-// mailboxes = [NSMutableArray new];
-// [mailboxes autorelease];
+ [self _setupContext];
+ request = [context request];
+ expandedFolders = [request formValueForKey: @"expandedFolders"];
-// currentObject = [self clientObject];
-// while (![currentObject isKindOfClass: [SOGoMailAccounts class]])
-// {
-// [mailboxes insertObject: [currentObject nameInContainer] atIndex: 0];
-// currentObject = [currentObject container];
-// }
+ [moduleSettings setObject: expandedFolders
+ forKey: @"ExpandedFolders"];
-// return [NSString stringWithFormat: @"/%@",
-// [mailboxes componentsJoinedByString: @"/"]];
-// }
-
-- (id) composeAction
-{
- NSArray *c;
- NSString *inbox, *url, *parameter;
- NSMutableDictionary *urlParams;
- id actionResult;
-
- c = [[self clientObject] toManyRelationshipKeys];
- if ([c count] > 0)
- {
- urlParams = [NSMutableDictionary new];
- [urlParams autorelease];
-
- parameter = [self queryParameterForKey: @"mailto"];
- if (parameter)
- [urlParams setObject: parameter
- forKey: @"mailto"];
- inbox = [NSString stringWithFormat: @"%@/folderINBOX",
- [c objectAtIndex: 0]];
- url = [inbox composeURLWithAction: @"compose"
- parameters: urlParams
- andHash: NO];
- actionResult = [self redirectToLocation: url];
- }
- else
- actionResult = self;
+ [ud synchronize];
- return actionResult;
+ return [self responseWithStatus: 204];
}
@end /* UIxMailMainFrame */