X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=sope-ical%2FNGiCal%2FiCalEvent.m;h=39749a77134139269ba720fcb8e9ce39ad80c487;hb=0877357b1db7e211d48acacbd5029e972c92d120;hp=72fb3a95d7e3bc2bea1717639d7da878a9bab78e;hpb=41d08ad5eb7a18343b4af6a2079cd515a9b7a57d;p=sope diff --git a/sope-ical/NGiCal/iCalEvent.m b/sope-ical/NGiCal/iCalEvent.m index 72fb3a95..39749a77 100644 --- a/sope-ical/NGiCal/iCalEvent.m +++ b/sope-ical/NGiCal/iCalEvent.m @@ -1,20 +1,20 @@ /* - Copyright (C) 2000-2004 SKYRIX Software AG + Copyright (C) 2000-2005 SKYRIX Software AG - This file is part of OpenGroupware.org. + This file is part of SOPE. - OGo is free software; you can redistribute it and/or modify it under + SOPE is free software; you can redistribute it and/or modify it under 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. - OGo is distributed in the hope that it will be useful, but WITHOUT ANY + SOPE 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 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 + License along with SOPE; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -22,7 +22,9 @@ #include "iCalEvent.h" #include "iCalPerson.h" #include "iCalEventChanges.h" +#include "iCalRecurrenceRule.h" #include "iCalRenderer.h" +#include #include "common.h" @interface NSString(DurationTimeInterval) @@ -31,12 +33,36 @@ @implementation iCalEvent ++ (int)version { + return [super version] + 0 /* v0 */; +} ++ (void)initialize { + NSAssert2([super version] == 0, + @"invalid superclass (%@) version %i !", + NSStringFromClass([self superclass]), [super version]); +} + - (void)dealloc { - [self->duration release]; - [self->endDate release]; + [self->endDate release]; + [self->duration release]; + [self->transparency release]; [super dealloc]; } +/* NSCopying */ + +- (id)copyWithZone:(NSZone *)_zone { + iCalEvent *new; + + new = [super copyWithZone:_zone]; + + new->endDate = [self->endDate copyWithZone:_zone]; + new->duration = [self->duration copyWithZone:_zone]; + new->transparency = [self->transparency copyWithZone:_zone]; + + return new; +} + /* accessors */ - (void)setEndDate:(NSCalendarDate *)_date { @@ -61,10 +87,6 @@ return self->endDate ? YES : NO; } -- (void)setTransp:(NSString *)_transp { - /* ignore transp ... (used by Evo 'TRANSP:OPAQUE') */ -} - - (void)setDuration:(NSString *)_value { ASSIGNCOPY(self->duration, _value); } @@ -106,6 +128,94 @@ return 0.0; } +- (void)setTransparency:(NSString *)_transparency { + ASSIGNCOPY(self->transparency, _transparency); +} +- (NSString *)transparency { + return self->transparency; +} + +/* convenience */ + +- (BOOL)isOpaque { + NSString *s; + + s = [self transparency]; + if (s && [[s uppercaseString] isEqualToString:@"TRANSPARENT"]) + return NO; + return YES; /* default is OPAQUE, see RFC2445, Section 4.8.2.7 */ +} + +/* TODO: FIX THIS! + The problem is, that startDate/endDate are inappropriately modelled here. + We'd need to have a special iCalDate in order to fix all the mess. + For the time being, we chose allday to mean 00:00 - 23:59 in startDate's + timezone. +*/ +- (BOOL)isAllDay { + NSCalendarDate *ed; + + if (![self hasEndDate]) + return NO; + + ed = [[[self endDate] copy] autorelease]; + [ed setTimeZone:[self->startDate timeZone]]; + if (([self->startDate hourOfDay] == 0) && + ([self->startDate minuteOfHour] == 0) && + ([ed hourOfDay] == 23) && + ([ed minuteOfHour] == 59)) + return YES; + return NO; +} + +- (BOOL)isWithinCalendarDateRange:(NGCalendarDateRange *)_range { + if (![self isRecurrent]) { + if (self->startDate && self->endDate) { + NGCalendarDateRange *r; + + r = [NGCalendarDateRange calendarDateRangeWithStartDate:self->startDate + endDate:self->endDate]; + return [_range containsDateRange:r]; + } + else { + return [_range containsDate:self->startDate]; + } + } + else { + NGCalendarDateRange *fir; + + fir = [NGCalendarDateRange calendarDateRangeWithStartDate:self->startDate + endDate:self->endDate]; + + return [self isWithinCalendarDateRange:_range + firstInstanceCalendarDateRange:fir]; + } + return NO; +} + +- (NSArray *)recurrenceRangesWithinCalendarDateRange:(NGCalendarDateRange *)_r { + NGCalendarDateRange *fir; + + if (![self isRecurrent]) + return nil; + + fir = [NGCalendarDateRange calendarDateRangeWithStartDate:self->startDate + endDate:self->endDate]; + return [self recurrenceRangesWithinCalendarDateRange:_r + firstInstanceCalendarDateRange:fir]; +} + +- (NSCalendarDate *)lastPossibleRecurrenceStartDate { + NGCalendarDateRange *fir; + + if (![self isRecurrent]) + return nil; + + fir = [NGCalendarDateRange calendarDateRangeWithStartDate:self->startDate + endDate:self->endDate]; + return [self lastPossibleRecurrenceStartDateUsingFirstInstanceCalendarDateRange:fir]; +} + /* ical typing */ - (NSString *)entityName {