2014-07-30 20:51:00 +02:00
|
|
|
/* iCalToDot+SOGo.m - this file is part of SOGo
|
2008-07-12 00:28:12 +02:00
|
|
|
*
|
2014-07-30 20:51:00 +02:00
|
|
|
* Copyright (C) 2008-2014 Inverse inc.
|
2008-07-12 00:28:12 +02:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSCalendarDate.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
#import <NGExtensions/NGCalendarDateRange.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
#import <NGCards/iCalAlarm.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <NGCards/iCalPerson.h>
|
2009-04-22 23:02:11 +02:00
|
|
|
#import <NGCards/iCalTrigger.h>
|
|
|
|
#import <NGCards/NSString+NGCards.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
#import "iCalRepeatableEntityObject+SOGo.h"
|
|
|
|
|
|
|
|
#import "iCalToDo+SOGo.h"
|
|
|
|
|
|
|
|
@implementation iCalToDo (SOGoExtensions)
|
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
- (NSMutableDictionary *) quickRecordFromContent: (NSString *) theContent
|
|
|
|
container: (id) theContainer
|
2008-07-12 00:28:12 +02:00
|
|
|
{
|
|
|
|
NSMutableDictionary *row;
|
2014-09-25 15:25:13 +02:00
|
|
|
NSCalendarDate *startDate, *dueDate, *completed;
|
2011-12-05 16:19:15 +01:00
|
|
|
NSArray *attendees, *categories;
|
|
|
|
NSString *uid, *title, *location, *status;
|
2008-07-12 00:28:12 +02:00
|
|
|
NSNumber *sequence;
|
|
|
|
id organizer, date;
|
|
|
|
id participants, partmails;
|
|
|
|
NSMutableString *partstates;
|
|
|
|
unsigned i, count, code;
|
|
|
|
iCalAccessClass accessClass;
|
|
|
|
|
|
|
|
/* extract values */
|
|
|
|
|
|
|
|
startDate = [self startDate];
|
|
|
|
dueDate = [self due];
|
|
|
|
uid = [self uid];
|
|
|
|
title = [self summary];
|
|
|
|
if (![title isNotNull])
|
|
|
|
title = @"";
|
|
|
|
location = [self location];
|
|
|
|
sequence = [self sequence];
|
|
|
|
accessClass = [self symbolicAccessClass];
|
2014-09-25 15:25:13 +02:00
|
|
|
completed = [self completed];
|
2008-07-12 00:28:12 +02:00
|
|
|
status = [[self status] uppercaseString];
|
|
|
|
|
|
|
|
attendees = [self attendees];
|
|
|
|
partmails = [attendees valueForKey: @"rfc822Email"];
|
|
|
|
partmails = [partmails componentsJoinedByString: @"\n"];
|
|
|
|
participants = [attendees valueForKey: @"cn"];
|
|
|
|
participants = [participants componentsJoinedByString: @"\n"];
|
|
|
|
|
|
|
|
/* build row */
|
|
|
|
|
|
|
|
row = [NSMutableDictionary dictionaryWithCapacity:8];
|
|
|
|
|
|
|
|
[row setObject: @"vtodo" forKey: @"c_component"];
|
|
|
|
|
|
|
|
if ([uid isNotNull])
|
|
|
|
[row setObject:uid forKey: @"c_uid"];
|
|
|
|
else
|
|
|
|
[self logWithFormat: @"WARNING: could not extract a uid from event!"];
|
|
|
|
|
|
|
|
[row setObject:[NSNumber numberWithBool:[self isRecurrent]]
|
|
|
|
forKey: @"c_iscycle"];
|
|
|
|
[row setObject:[NSNumber numberWithInt:[self priorityNumber]]
|
|
|
|
forKey: @"c_priority"];
|
|
|
|
|
|
|
|
[row setObject: [NSNumber numberWithBool: NO]
|
|
|
|
forKey: @"c_isallday"];
|
|
|
|
[row setObject: [NSNumber numberWithBool: NO]
|
|
|
|
forKey: @"c_isopaque"];
|
|
|
|
|
|
|
|
[row setObject: title forKey: @"c_title"];
|
|
|
|
if ([location isNotNull]) [row setObject: location forKey: @"c_location"];
|
|
|
|
if ([sequence isNotNull]) [row setObject: sequence forKey: @"c_sequence"];
|
|
|
|
|
|
|
|
if ([startDate isNotNull])
|
2008-07-16 23:48:54 +02:00
|
|
|
date = [self quickRecordDateAsNumber: startDate
|
|
|
|
withOffset: 0 forAllDay: NO];
|
2008-07-12 00:28:12 +02:00
|
|
|
else
|
|
|
|
date = [NSNull null];
|
|
|
|
[row setObject: date forKey: @"c_startdate"];
|
|
|
|
|
2008-07-16 23:48:54 +02:00
|
|
|
if ([dueDate isNotNull])
|
|
|
|
date = [self quickRecordDateAsNumber: dueDate
|
|
|
|
withOffset: 0 forAllDay: NO];
|
2008-07-12 00:28:12 +02:00
|
|
|
else
|
|
|
|
date = [NSNull null];
|
|
|
|
[row setObject: date forKey: @"c_enddate"];
|
|
|
|
|
|
|
|
if ([self isRecurrent])
|
|
|
|
{
|
2008-07-16 23:48:54 +02:00
|
|
|
[row setObject: iCalDistantFutureNumber forKey: @"c_cycleenddate"];
|
|
|
|
[row setObject: [self cycleInfo] forKey: @"c_cycleinfo"];
|
2008-07-12 00:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([participants length] > 0)
|
|
|
|
[row setObject:participants forKey: @"c_participants"];
|
|
|
|
if ([partmails length] > 0)
|
|
|
|
[row setObject:partmails forKey: @"c_partmails"];
|
|
|
|
|
2014-09-25 15:25:13 +02:00
|
|
|
if (completed || [status isNotNull])
|
2008-07-16 23:48:54 +02:00
|
|
|
{
|
|
|
|
code = 0; /* NEEDS-ACTION */
|
2014-09-25 15:25:13 +02:00
|
|
|
if (completed || [status isEqualToString: @"COMPLETED"])
|
2008-07-16 23:48:54 +02:00
|
|
|
code = 1;
|
|
|
|
else if ([status isEqualToString: @"IN-PROCESS"])
|
|
|
|
code = 2;
|
|
|
|
else if ([status isEqualToString: @"CANCELLED"])
|
|
|
|
code = 3;
|
|
|
|
[row setObject: [NSNumber numberWithInt: code] forKey: @"c_status"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* confirmed by default */
|
|
|
|
[row setObject:[NSNumber numberWithInt:1] forKey: @"c_status"];
|
|
|
|
}
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
[row setObject: [NSNumber numberWithUnsignedInt: accessClass]
|
|
|
|
forKey: @"c_classification"];
|
|
|
|
|
|
|
|
organizer = [self organizer];
|
2008-07-16 23:48:54 +02:00
|
|
|
if (organizer)
|
|
|
|
{
|
|
|
|
NSString *email;
|
2008-07-12 00:28:12 +02:00
|
|
|
|
2008-07-16 23:48:54 +02:00
|
|
|
email = [organizer valueForKey: @"rfc822Email"];
|
|
|
|
if (email)
|
|
|
|
[row setObject:email forKey: @"c_orgmail"];
|
|
|
|
}
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
/* construct partstates */
|
|
|
|
count = [attendees count];
|
|
|
|
partstates = [[NSMutableString alloc] initWithCapacity:count * 2];
|
2008-07-16 23:48:54 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
iCalPerson *p;
|
|
|
|
iCalPersonPartStat stat;
|
2008-07-12 00:28:12 +02:00
|
|
|
|
2008-07-16 23:48:54 +02:00
|
|
|
p = [attendees objectAtIndex:i];
|
|
|
|
stat = [p participationStatus];
|
|
|
|
if(i != 0)
|
|
|
|
[partstates appendString: @"\n"];
|
|
|
|
[partstates appendFormat: @"%d", stat];
|
|
|
|
}
|
2008-07-12 00:28:12 +02:00
|
|
|
[row setObject:partstates forKey: @"c_partstates"];
|
|
|
|
[partstates release];
|
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
/* handle alarms */
|
|
|
|
[self updateNextAlarmDateInRow: row forContainer: theContainer];
|
2009-04-22 23:02:11 +02:00
|
|
|
|
2011-12-05 16:19:15 +01:00
|
|
|
categories = [self categories];
|
|
|
|
if ([categories count] > 0)
|
|
|
|
[row setObject: [categories componentsJoinedByString: @","]
|
|
|
|
forKey: @"c_category"];
|
2010-05-18 20:35:47 +02:00
|
|
|
|
2015-05-13 19:12:15 +02:00
|
|
|
/* handle description */
|
|
|
|
if ([self comment])
|
|
|
|
[row setObject: [self comment] forKey: @"c_description"];
|
|
|
|
else
|
|
|
|
[row setObject: [NSNull null] forKey: @"c_description"];
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2014-09-12 14:34:15 +02:00
|
|
|
- (NSTimeInterval) occurenceInterval
|
2008-07-17 23:12:43 +02:00
|
|
|
{
|
|
|
|
return [[self due] timeIntervalSinceDate: [self startDate]];
|
|
|
|
}
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
@end
|