2007-11-18 11:16:25 +01:00
|
|
|
/* iCalEvent+SOGo.m - this file is part of SOGo
|
|
|
|
*
|
2011-01-14 03:54:33 +01:00
|
|
|
* Copyright (C) 2007-2011 Inverse inc.
|
2007-11-18 11:16:25 +01:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
2011-01-14 03:54:33 +01:00
|
|
|
* Francis Lachapelle <flachapelle@inverse.ca>
|
2007-11-18 11:16:25 +01: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.
|
|
|
|
*/
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#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-21 16:34:22 +02:00
|
|
|
#import <NGCards/iCalAlarm.h>
|
2011-01-14 03:54:33 +01:00
|
|
|
#import <NGCards/iCalDateTime.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <NGCards/iCalEvent.h>
|
|
|
|
#import <NGCards/iCalPerson.h>
|
2009-04-21 16:34:22 +02:00
|
|
|
#import <NGCards/iCalTrigger.h>
|
|
|
|
#import <NGCards/NSString+NGCards.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
#import "iCalRepeatableEntityObject+SOGo.h"
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
#import "iCalEvent+SOGo.h"
|
|
|
|
|
|
|
|
@implementation iCalEvent (SOGoExtensions)
|
|
|
|
|
|
|
|
- (BOOL) isStillRelevant
|
|
|
|
{
|
2008-12-12 19:43:14 +01:00
|
|
|
NSCalendarDate *now, *lastRecurrence;
|
2008-11-12 17:12:23 +01:00
|
|
|
BOOL isStillRelevent;
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
now = [NSCalendarDate calendarDate];
|
|
|
|
|
2008-11-12 17:12:23 +01:00
|
|
|
if ([self isRecurrent])
|
2008-12-12 19:43:14 +01:00
|
|
|
{
|
|
|
|
lastRecurrence = [self lastPossibleRecurrenceStartDate];
|
|
|
|
isStillRelevent = (lastRecurrence == nil || [lastRecurrence earlierDate: now] == now);
|
|
|
|
}
|
2008-11-12 17:12:23 +01:00
|
|
|
else
|
2008-12-12 19:43:14 +01:00
|
|
|
isStillRelevent = ([[self endDate] earlierDate: now] == now);
|
2008-11-12 17:12:23 +01:00
|
|
|
|
|
|
|
return isStillRelevent;
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
- (NSMutableDictionary *) quickRecord
|
|
|
|
{
|
|
|
|
NSMutableDictionary *row;
|
2009-04-21 16:34:22 +02:00
|
|
|
NSCalendarDate *startDate, *endDate, *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-16 23:48:54 +02:00
|
|
|
NSNumber *sequence;
|
2008-07-12 00:28:12 +02:00
|
|
|
id organizer;
|
|
|
|
id participants, partmails;
|
|
|
|
NSMutableString *partstates;
|
|
|
|
unsigned int i, count, boolTmp;
|
|
|
|
BOOL isAllDay;
|
|
|
|
iCalAccessClass accessClass;
|
|
|
|
|
|
|
|
/* extract values */
|
2008-07-16 23:48:54 +02:00
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
startDate = [self startDate];
|
|
|
|
endDate = [self endDate];
|
|
|
|
uid = [self uid];
|
|
|
|
title = [self summary];
|
|
|
|
if (![title isNotNull])
|
|
|
|
title = @"";
|
|
|
|
location = [self location];
|
|
|
|
sequence = [self sequence];
|
|
|
|
accessClass = [self symbolicAccessClass];
|
|
|
|
isAllDay = [self isAllDay];
|
|
|
|
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: @"vevent" forKey: @"c_component"];
|
|
|
|
|
|
|
|
if ([uid isNotNull])
|
|
|
|
[row setObject:uid forKey: @"c_uid"];
|
|
|
|
else
|
|
|
|
[self logWithFormat: @"WARNING: could not extract a uid from event!"];
|
|
|
|
|
|
|
|
boolTmp = ((isAllDay) ? 1 : 0);
|
|
|
|
[row setObject: [NSNumber numberWithInt: boolTmp]
|
|
|
|
forKey: @"c_isallday"];
|
|
|
|
boolTmp = (([self isRecurrent]) ? 1 : 0);
|
|
|
|
[row setObject: [NSNumber numberWithInt: boolTmp]
|
|
|
|
forKey: @"c_iscycle"];
|
|
|
|
boolTmp = (([self isOpaque]) ? 1 : 0);
|
|
|
|
[row setObject: [NSNumber numberWithInt: boolTmp]
|
|
|
|
forKey: @"c_isopaque"];
|
|
|
|
[row setObject: [NSNumber numberWithInt: [self priorityNumber]]
|
|
|
|
forKey: @"c_priority"];
|
|
|
|
|
|
|
|
[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
|
|
|
{
|
2009-10-21 20:03:01 +02:00
|
|
|
// if (isAllDay)
|
|
|
|
// NSLog (@"start date...");
|
2008-07-16 23:48:54 +02:00
|
|
|
[row setObject: [self quickRecordDateAsNumber: startDate
|
|
|
|
withOffset: 0 forAllDay: isAllDay]
|
|
|
|
forKey: @"c_startdate"];
|
|
|
|
}
|
2008-07-12 00:28:12 +02:00
|
|
|
if ([endDate isNotNull])
|
2008-07-16 23:48:54 +02:00
|
|
|
[row setObject: [self quickRecordDateAsNumber: endDate
|
|
|
|
withOffset: ((isAllDay) ? -1 : 0)
|
|
|
|
forAllDay: isAllDay]
|
|
|
|
forKey: @"c_enddate"];
|
|
|
|
|
|
|
|
if ([self isRecurrent])
|
2008-07-12 00:28:12 +02:00
|
|
|
{
|
2008-07-16 23:48:54 +02:00
|
|
|
NSCalendarDate *date;
|
|
|
|
|
|
|
|
date = [self lastPossibleRecurrenceStartDate];
|
|
|
|
if (!date)
|
2008-07-12 00:28:12 +02:00
|
|
|
{
|
2008-07-16 23:48:54 +02:00
|
|
|
/* this could also be *nil*, but in the end it makes the fetchspecs
|
|
|
|
more complex - thus we set it to a "reasonable" distant future */
|
|
|
|
date = iCalDistantFuture;
|
2008-07-12 00:28:12 +02:00
|
|
|
}
|
2008-07-16 23:48:54 +02:00
|
|
|
[row setObject: [self quickRecordDateAsNumber: date
|
|
|
|
withOffset: 0 forAllDay: NO]
|
|
|
|
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])
|
|
|
|
{
|
|
|
|
int code = 1;
|
2008-07-12 00:28:12 +02:00
|
|
|
|
2008-07-16 23:48:54 +02:00
|
|
|
if ([status isEqualToString: @"TENTATIVE"])
|
|
|
|
code = 2;
|
|
|
|
else if ([status isEqualToString: @"CANCELLED"])
|
|
|
|
code = 0;
|
|
|
|
[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];
|
|
|
|
if (organizer)
|
|
|
|
{
|
|
|
|
NSString *email;
|
|
|
|
|
|
|
|
email = [organizer valueForKey: @"rfc822Email"];
|
|
|
|
if (email)
|
|
|
|
[row setObject:email forKey: @"c_orgmail"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct partstates */
|
|
|
|
count = [attendees count];
|
|
|
|
partstates = [[NSMutableString alloc] initWithCapacity:count * 2];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
iCalPerson *p;
|
|
|
|
iCalPersonPartStat stat;
|
|
|
|
|
|
|
|
p = [attendees objectAtIndex:i];
|
|
|
|
stat = [p participationStatus];
|
|
|
|
if (i)
|
|
|
|
[partstates appendString: @"\n"];
|
|
|
|
[partstates appendFormat: @"%d", stat];
|
|
|
|
}
|
|
|
|
[row setObject:partstates forKey: @"c_partstates"];
|
|
|
|
[partstates release];
|
|
|
|
|
2010-08-13 23:28:15 +02:00
|
|
|
nextAlarmDate = nil;
|
|
|
|
if (![self isRecurrent] && [self hasAlarms])
|
2009-04-21 16:34:22 +02:00
|
|
|
{
|
|
|
|
// We currently have the following limitations for alarms:
|
2010-08-13 23:28:15 +02:00
|
|
|
// - the component must not be recurrent;
|
2009-04-21 16:34:22 +02:00
|
|
|
// - only the first alarm is considered;
|
|
|
|
// - the alarm's action must be of type DISPLAY;
|
2009-04-22 23:02:11 +02:00
|
|
|
// - 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".
|
2009-04-21 16:34:22 +02:00
|
|
|
iCalAlarm *anAlarm;
|
2010-08-13 23:28:15 +02:00
|
|
|
NSString *webstatus;
|
2009-04-21 16:34:22 +02:00
|
|
|
|
|
|
|
anAlarm = [[self alarms] objectAtIndex: 0];
|
2010-08-13 23:28:15 +02:00
|
|
|
if ([[anAlarm action] caseInsensitiveCompare: @"DISPLAY"]
|
|
|
|
== NSOrderedSame)
|
|
|
|
{
|
|
|
|
webstatus = [[anAlarm trigger] value: 0 ofAttribute: @"x-webstatus"];
|
|
|
|
if (!webstatus
|
|
|
|
|| ([webstatus caseInsensitiveCompare: @"TRIGGERED"]
|
|
|
|
!= NSOrderedSame))
|
|
|
|
nextAlarmDate = [anAlarm nextAlarmDate];
|
|
|
|
}
|
2009-04-21 16:34:22 +02:00
|
|
|
}
|
|
|
|
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"];
|
2009-04-21 16:34:22 +02:00
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:54:33 +01:00
|
|
|
/**
|
|
|
|
* Extract the start and end dates from the event, from which all recurrence
|
|
|
|
* calculations will be based on.
|
|
|
|
* @return the range of the first occurrence.
|
|
|
|
*/
|
2008-07-17 23:12:43 +02:00
|
|
|
- (NGCalendarDateRange *) firstOccurenceRange
|
|
|
|
{
|
2011-01-14 03:54:33 +01:00
|
|
|
iCalDateTime *firstStartDate, *firstEndDate;
|
|
|
|
NGCalendarDateRange *firstRange;
|
|
|
|
|
|
|
|
firstStartDate = (iCalDateTime *)[self uniqueChildWithTag: @"dtstart"];
|
|
|
|
firstEndDate = (iCalDateTime *)[self uniqueChildWithTag: @"dtend"];
|
|
|
|
firstRange = [NGCalendarDateRange calendarDateRangeWithStartDate: [[[firstStartDate values] lastObject] asCalendarDate]
|
|
|
|
endDate: [[[firstEndDate values] lastObject] asCalendarDate]];
|
|
|
|
|
|
|
|
return firstRange;
|
2008-07-17 23:12:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) occurenceInterval
|
|
|
|
{
|
|
|
|
return [[self endDate] timeIntervalSinceDate: [self startDate]];
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
@end
|