2008-07-12 00:28:12 +02:00
|
|
|
/* iCalEvent+SOGo.m - this file is part of SOGo
|
|
|
|
*
|
2008-09-27 03:13:41 +02:00
|
|
|
* Copyright (C) 2008 Inverse inc.
|
2008-07-12 00:28:12 +02:00
|
|
|
* Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
|
|
|
|
- (NSMutableDictionary *) quickRecord
|
|
|
|
{
|
|
|
|
NSMutableDictionary *row;
|
2009-04-22 23:02:11 +02:00
|
|
|
NSCalendarDate *startDate, *dueDate, *nextAlarmDate;
|
2008-07-12 00:28:12 +02:00
|
|
|
NSArray *attendees;
|
2010-05-18 20:35:47 +02:00
|
|
|
NSString *uid, *title, *location, *status, *category;
|
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];
|
2009-04-22 23:02:11 +02:00
|
|
|
nextAlarmDate = nil;
|
2008-07-12 00:28:12 +02:00
|
|
|
uid = [self uid];
|
|
|
|
title = [self summary];
|
|
|
|
if (![title isNotNull])
|
|
|
|
title = @"";
|
|
|
|
location = [self location];
|
|
|
|
sequence = [self sequence];
|
|
|
|
accessClass = [self symbolicAccessClass];
|
|
|
|
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"];
|
|
|
|
|
2008-07-16 23:48:54 +02:00
|
|
|
if ([status isNotNull])
|
|
|
|
{
|
|
|
|
code = 0; /* NEEDS-ACTION */
|
|
|
|
if ([status isEqualToString: @"COMPLETED"])
|
|
|
|
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];
|
|
|
|
|
2009-04-22 23:02:11 +02:00
|
|
|
if ([self hasAlarms])
|
|
|
|
{
|
|
|
|
// We currently have the following limitations for alarms:
|
|
|
|
// - the component must not be recurrent;
|
|
|
|
// - only the first alarm is considered;
|
|
|
|
// - the alarm's action must be of type DISPLAY;
|
|
|
|
// - the alarm's trigger value type must be DURATION;
|
|
|
|
//
|
|
|
|
// Morever, we don't update the quick table if the property X-WebStatus
|
|
|
|
// of the trigger is set to "triggered".
|
|
|
|
|
|
|
|
iCalAlarm *anAlarm;
|
|
|
|
iCalTrigger *aTrigger;
|
|
|
|
NSString *webstatus;
|
|
|
|
NSTimeInterval anInterval;
|
|
|
|
|
|
|
|
anAlarm = [[self alarms] objectAtIndex: 0];
|
|
|
|
aTrigger = [anAlarm trigger];
|
|
|
|
anInterval = [[aTrigger value] durationAsTimeInterval];
|
|
|
|
|
|
|
|
if ([[anAlarm action] caseInsensitiveCompare: @"DISPLAY"] == NSOrderedSame &&
|
|
|
|
[[aTrigger valueType] caseInsensitiveCompare: @"DURATION"] == NSOrderedSame &&
|
|
|
|
![self isRecurrent])
|
|
|
|
{
|
|
|
|
webstatus = [aTrigger value: 0 ofAttribute: @"x-webstatus"];
|
|
|
|
if (!webstatus ||
|
|
|
|
[webstatus caseInsensitiveCompare: @"TRIGGERED"] != NSOrderedSame)
|
|
|
|
{
|
|
|
|
// Compute the next alarm date with respect to the due date
|
|
|
|
if ([dueDate isNotNull])
|
|
|
|
nextAlarmDate = [dueDate addTimeInterval: anInterval];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ([nextAlarmDate isNotNull])
|
|
|
|
[row setObject: [NSNumber numberWithInt: [nextAlarmDate timeIntervalSince1970]]
|
|
|
|
forKey: @"c_nextalarm"];
|
|
|
|
else
|
|
|
|
[row setObject: [NSNumber numberWithInt: 0] forKey: @"c_nextalarm"];
|
|
|
|
|
2010-05-18 20:35:47 +02:00
|
|
|
category = [self categories];
|
|
|
|
if ([category length] > 0)
|
|
|
|
[row setObject: category forKey: @"c_category"];
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
- (NGCalendarDateRange *) firstOccurenceRange
|
|
|
|
{
|
|
|
|
return [NGCalendarDateRange calendarDateRangeWithStartDate: [self startDate]
|
|
|
|
endDate: [self due]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) occurenceInterval
|
|
|
|
{
|
|
|
|
return [[self due] timeIntervalSinceDate: [self startDate]];
|
|
|
|
}
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
@end
|