mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-21 03:15:25 +00:00
Fixes for import/export
Monotone-Parent: 3e7ac334a4ea19aa4ec2dcbc525628005ca75fb7 Monotone-Revision: d124c012f70febcfcbb9a2b5d4f3a20a7a001d7a Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-09-09T13:31:45 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -643,125 +643,4 @@ static BOOL shouldDisplayWeekend = NO;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
- (WOResponse *) exportAction
|
||||
{
|
||||
WOResponse *response;
|
||||
SOGoAppointmentFolder *folder;
|
||||
SOGoAppointmentObject *appt;
|
||||
NSArray *array, *values, *fields;
|
||||
NSMutableString *rc;
|
||||
iCalCalendar *calendar, *component;
|
||||
int i, count;
|
||||
|
||||
fields = [NSArray arrayWithObjects: @"c_name", @"c_content", nil];
|
||||
rc = [NSMutableString string];
|
||||
|
||||
response = [[WOResponse alloc] init];
|
||||
[response autorelease];
|
||||
|
||||
folder = [self clientObject];
|
||||
calendar = [iCalCalendar groupWithTag: @"vcalendar"];
|
||||
|
||||
array = [[folder ocsFolder] fetchFields: fields matchingQualifier: nil];
|
||||
count = [array count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
appt = [folder lookupName: [[array objectAtIndex: i] objectForKey: @"c_name"]
|
||||
inContext: [self context]
|
||||
acquire: NO];
|
||||
|
||||
component = [appt calendar: NO secure: NO];
|
||||
values = [component events];
|
||||
if (values && [values count])
|
||||
[calendar addChildren: values];
|
||||
values = [component todos];
|
||||
if (values && [values count])
|
||||
[calendar addChildren: values];
|
||||
values = [component journals];
|
||||
if (values && [values count])
|
||||
[calendar addChildren: values];
|
||||
values = [component freeBusys];
|
||||
if (values && [values count])
|
||||
[calendar addChildren: values];
|
||||
values = [component childrenWithTag: @"vtimezone"];
|
||||
if (values && [values count])
|
||||
[calendar addChildren: values];
|
||||
}
|
||||
NSLog ([calendar versitString]);
|
||||
|
||||
[response setHeader: @"text/calendar"
|
||||
forKey:@"content-type"];
|
||||
[response setHeader: @"attachment;filename=Calendar.ics"
|
||||
forKey: @"Content-Disposition"];
|
||||
[response setContent: [[calendar versitString] dataUsingEncoding: NSUTF8StringEncoding]];
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
- (WOResponse *) importAction
|
||||
{
|
||||
SOGoAppointmentFolder *folder;
|
||||
NSMutableDictionary *rc;
|
||||
NSArray *components;
|
||||
WORequest *request;
|
||||
WOResponse *response;
|
||||
NSString *fileContent;
|
||||
id data;
|
||||
iCalCalendar *additions;
|
||||
int i, count, imported;
|
||||
|
||||
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];
|
||||
[fileContent autorelease];
|
||||
}
|
||||
|
||||
if (fileContent && [fileContent length]
|
||||
&& [fileContent hasPrefix: @"BEGIN:"])
|
||||
{
|
||||
additions = [iCalCalendar parseSingleFromSource: fileContent];
|
||||
if (additions)
|
||||
{
|
||||
components = [additions events];
|
||||
count = [components count];
|
||||
for (i = 0; i < count; i++)
|
||||
if ([folder importComponent: [components objectAtIndex: i]])
|
||||
imported++;
|
||||
components = [additions todos];
|
||||
count = [components count];
|
||||
for (i = 0; i < count; i++)
|
||||
if ([folder importComponent: [components objectAtIndex: i]])
|
||||
imported++;
|
||||
components = [additions journals];
|
||||
count = [components count];
|
||||
for (i = 0; i < count; i++)
|
||||
if ([folder importComponent: [components objectAtIndex: i]])
|
||||
imported++;
|
||||
components = [additions freeBusys];
|
||||
count = [components count];
|
||||
for (i = 0; i < count; i++)
|
||||
if ([folder importComponent: [components objectAtIndex: i]])
|
||||
imported++;
|
||||
}
|
||||
}
|
||||
|
||||
[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;
|
||||
}
|
||||
|
||||
@end /* UIxCalView */
|
||||
|
||||
Reference in New Issue
Block a user