2009-09-09 15:31:45 +02:00
|
|
|
/*
|
2012-04-19 20:16:50 +02:00
|
|
|
Copyright (C) 2006-2012 Inverse inc.
|
2009-09-09 15:31:45 +02:00
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
2012-04-19 20:16:50 +02:00
|
|
|
This file is part of SOGo
|
2009-09-09 15:31:45 +02:00
|
|
|
|
2012-04-19 20:16:50 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2009-09-09 15:31:45 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
2012-04-19 20:16:50 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2009-09-09 15:31:45 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2010-06-08 17:48:35 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2012-04-18 22:03:07 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2009-09-09 15:31:45 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2012-10-22 16:09:13 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
|
|
|
|
#import <NGCards/iCalCalendar.h>
|
2009-09-09 15:31:45 +02:00
|
|
|
|
2012-04-18 22:03:07 +02:00
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
|
|
|
|
2009-09-09 15:31:45 +02:00
|
|
|
#import <Appointments/SOGoAppointmentFolder.h>
|
2012-04-18 22:03:07 +02:00
|
|
|
#import <Appointments/SOGoWebAppointmentFolder.h>
|
2010-06-08 15:38:32 +02:00
|
|
|
#import <Appointments/SOGoAppointmentFolderICS.h>
|
2009-09-09 15:31:45 +02:00
|
|
|
|
|
|
|
#import "UIxCalFolderActions.h"
|
|
|
|
|
|
|
|
@implementation UIxCalFolderActions
|
|
|
|
|
|
|
|
- (WOResponse *) exportAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
2010-06-08 15:38:32 +02:00
|
|
|
SOGoAppointmentFolderICS *folderICS;
|
2010-06-08 17:48:35 +02:00
|
|
|
NSString *disposition;
|
2009-09-09 15:31:45 +02:00
|
|
|
|
2010-06-08 15:38:32 +02:00
|
|
|
folderICS = [self clientObject];
|
|
|
|
response = [self responseWithStatus: 200
|
|
|
|
andString: [folderICS contentAsString]];
|
|
|
|
[response setHeader: @"text/calendar; charset=utf-8"
|
|
|
|
forKey: @"content-type"];
|
2010-06-08 17:48:35 +02:00
|
|
|
disposition = [NSString stringWithFormat: @"attachment; filename=\"%@.ics\"",
|
|
|
|
[folderICS displayName]];
|
|
|
|
[response setHeader: disposition forKey: @"Content-Disposition"];
|
2010-06-08 15:38:32 +02:00
|
|
|
|
2009-09-09 15:31:45 +02:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) importAction
|
|
|
|
{
|
|
|
|
SOGoAppointmentFolder *folder;
|
|
|
|
NSMutableDictionary *rc;
|
|
|
|
WORequest *request;
|
|
|
|
WOResponse *response;
|
|
|
|
NSString *fileContent;
|
|
|
|
id data;
|
|
|
|
iCalCalendar *additions;
|
2009-09-10 19:26:57 +02:00
|
|
|
int imported;
|
2009-09-09 15:31:45 +02:00
|
|
|
|
|
|
|
imported = 0;
|
|
|
|
rc = [NSMutableDictionary dictionary];
|
|
|
|
request = [context request];
|
|
|
|
folder = [self clientObject];
|
|
|
|
data = [request formValueForKey: @"calendarFile"];
|
|
|
|
if ([data respondsToSelector: @selector(isEqualToString:)])
|
|
|
|
fileContent = (NSString *) data;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fileContent = [[NSString alloc] initWithData: (NSData *) data
|
|
|
|
encoding: NSUTF8StringEncoding];
|
2012-01-24 15:05:53 +01:00
|
|
|
if (fileContent == nil)
|
|
|
|
fileContent = [[NSString alloc] initWithData: (NSData *) data
|
|
|
|
encoding: NSISOLatin1StringEncoding];
|
2009-09-09 15:31:45 +02:00
|
|
|
[fileContent autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileContent && [fileContent length]
|
|
|
|
&& [fileContent hasPrefix: @"BEGIN:"])
|
|
|
|
{
|
|
|
|
additions = [iCalCalendar parseSingleFromSource: fileContent];
|
2009-09-10 19:26:57 +02:00
|
|
|
imported = [folder importCalendar: additions];
|
2009-09-09 15:31:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[rc setObject: [NSNumber numberWithInt: imported]
|
|
|
|
forKey: @"imported"];
|
|
|
|
|
|
|
|
response = [self responseWithStatus: 200];
|
|
|
|
[response setHeader: @"text/html"
|
|
|
|
forKey: @"content-type"];
|
|
|
|
[(WOResponse*)response appendContentString: [rc jsonRepresentation]];
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2012-04-18 22:03:07 +02:00
|
|
|
/* These methods are only available on instance of SOGoWebAppointmentFolder. */
|
|
|
|
- (WOResponse *) reloadAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
NSDictionary *results;
|
|
|
|
|
|
|
|
response = [self responseWithStatus: 200];
|
|
|
|
[response setHeader: @"application/json" forKey: @"content-type"];
|
|
|
|
results = [[self clientObject] loadWebCalendar];
|
|
|
|
[response appendContentString: [results jsonRepresentation]];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) setCredentialsAction
|
|
|
|
{
|
|
|
|
WORequest *request;
|
|
|
|
WOResponse *response;
|
|
|
|
NSString *username, *password;
|
|
|
|
|
|
|
|
request = [context request];
|
|
|
|
|
|
|
|
username = [[request formValueForKey: @"username"] stringByTrimmingSpaces];
|
|
|
|
password = [[request formValueForKey: @"password"] stringByTrimmingSpaces];
|
|
|
|
if ([username length] > 0 && [password length] > 0)
|
|
|
|
{
|
|
|
|
[[self clientObject] setUsername: username
|
|
|
|
andPassword: password];
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response
|
|
|
|
= (WOResponse *) [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"missing 'username' and/or"
|
|
|
|
@" 'password' parameters"];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2009-09-09 15:31:45 +02:00
|
|
|
@end /* UIxCalFolderActions */
|