mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-06 00:45:09 +00:00
Monotone-Parent: ec26e4feb9dc5cfb50ec5b138bec4a05141934c6
Monotone-Revision: 3a3e7e985adac6637eacd797235cdf6c4eae70cb Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-06-12T15:33:08 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
2007-06-12 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* OGoContentStore/OCSiCalFieldExtractor.m ([OCSiCalFieldExtractor
|
||||
-extractQuickFieldsFromEvent:_event]): reduce the seconds/70 of
|
||||
the end date of all day events of 1 so that they stay on their
|
||||
real last day.
|
||||
|
||||
2007-06-11 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* UI/Scheduler/UIxCalMonthView.m: no longer retrieve appointments.
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
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 SOGo; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA.
|
||||
*/
|
||||
@@ -27,25 +27,24 @@
|
||||
|
||||
@implementation OCSiCalFieldExtractor
|
||||
|
||||
static OCSiCalFieldExtractor *extractor = nil;
|
||||
static NSCalendarDate *distantFuture = nil;
|
||||
static NSNumber *distantFutureNumber = nil;
|
||||
static NSCalendarDate *distantFuture = nil;
|
||||
static NSNumber *distantFutureNumber = nil;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
static BOOL didInit = NO;
|
||||
|
||||
if (didInit) return;
|
||||
didInit = YES;
|
||||
|
||||
distantFuture = [[NSCalendarDate distantFuture] retain];
|
||||
/* INT_MAX due to Postgres constraint */
|
||||
distantFutureNumber = [[NSNumber numberWithUnsignedInt:INT_MAX] retain];
|
||||
if (!distantFuture)
|
||||
{
|
||||
distantFuture = [[NSCalendarDate distantFuture] retain];
|
||||
/* INT_MAX due to Postgres constraint */
|
||||
distantFutureNumber = [[NSNumber numberWithUnsignedInt: INT_MAX] retain];
|
||||
}
|
||||
}
|
||||
|
||||
+ (id) sharedICalFieldExtractor
|
||||
{
|
||||
if (extractor == nil)
|
||||
static OCSiCalFieldExtractor *extractor = nil;
|
||||
|
||||
if (!extractor)
|
||||
extractor = [self new];
|
||||
|
||||
return extractor;
|
||||
@@ -55,99 +54,117 @@ static NSNumber *distantFutureNumber = nil;
|
||||
|
||||
- (NSNumber *) numberForDate: (NSCalendarDate *) _date
|
||||
{
|
||||
if (_date == distantFuture)
|
||||
return distantFutureNumber;
|
||||
|
||||
return [NSNumber numberWithUnsignedInt:[_date timeIntervalSince1970]];
|
||||
return ((_date == distantFuture)
|
||||
? distantFutureNumber
|
||||
: [NSNumber numberWithUnsignedInt: [_date timeIntervalSince1970]]);
|
||||
}
|
||||
|
||||
- (NSMutableDictionary *) extractQuickFieldsFromEvent: (iCalEvent *) _event
|
||||
{
|
||||
NSMutableDictionary *row;
|
||||
NSCalendarDate *startDate, *endDate;
|
||||
NSArray *attendees;
|
||||
NSString *uid, *title, *location, *status;
|
||||
NSNumber *sequence;
|
||||
id organizer;
|
||||
id participants, partmails;
|
||||
NSMutableString *partstates;
|
||||
unsigned i, count;
|
||||
NSCalendarDate *startDate, *endDate;
|
||||
NSArray *attendees;
|
||||
NSString *uid, *title, *location, *status;
|
||||
NSNumber *sequence, *dateNumber;
|
||||
id organizer;
|
||||
id participants, partmails;
|
||||
NSMutableString *partstates;
|
||||
unsigned int i, count;
|
||||
BOOL isAllDay;
|
||||
iCalAccessClass accessClass;
|
||||
|
||||
if (_event == nil)
|
||||
return nil;
|
||||
|
||||
/* extract values */
|
||||
|
||||
startDate = [_event startDate];
|
||||
endDate = [_event endDate];
|
||||
uid = [_event uid];
|
||||
title = [_event summary];
|
||||
location = [_event location];
|
||||
sequence = [_event sequence];
|
||||
accessClass = [_event symbolicAccessClass];
|
||||
status = [[_event status] uppercaseString];
|
||||
|
||||
startDate = [_event startDate];
|
||||
endDate = [_event endDate];
|
||||
uid = [_event uid];
|
||||
title = [_event summary];
|
||||
location = [_event location];
|
||||
sequence = [_event sequence];
|
||||
accessClass = [_event symbolicAccessClass];
|
||||
isAllDay = [_event isAllDay];
|
||||
status = [[_event status] uppercaseString];
|
||||
|
||||
attendees = [_event attendees];
|
||||
partmails = [attendees valueForKey:@"rfc822Email"];
|
||||
partmails = [partmails componentsJoinedByString:@"\n"];
|
||||
participants = [attendees valueForKey:@"cn"];
|
||||
participants = [participants componentsJoinedByString:@"\n"];
|
||||
attendees = [_event 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: @"component"];
|
||||
|
||||
|
||||
if ([uid isNotNull])
|
||||
[row setObject:uid forKey:@"uid"];
|
||||
[row setObject:uid forKey: @"uid"];
|
||||
else
|
||||
[self logWithFormat:@"WARNING: could not extract a uid from event!"];
|
||||
[self logWithFormat: @"WARNING: could not extract a uid from event!"];
|
||||
|
||||
[row setObject:[NSNumber numberWithBool: [_event isAllDay]]
|
||||
|
||||
[row setObject: [NSNumber numberWithBool: isAllDay]
|
||||
forKey: @"isallday"];
|
||||
[row setObject:[NSNumber numberWithBool: [_event isRecurrent]]
|
||||
[row setObject: [NSNumber numberWithBool: [_event isRecurrent]]
|
||||
forKey: @"iscycle"];
|
||||
[row setObject:[NSNumber numberWithBool: [_event isOpaque]]
|
||||
[row setObject: [NSNumber numberWithBool: [_event isOpaque]]
|
||||
forKey: @"isopaque"];
|
||||
[row setObject:[NSNumber numberWithInt: [_event priorityNumber]]
|
||||
[row setObject: [NSNumber numberWithInt: [_event priorityNumber]]
|
||||
forKey: @"priority"];
|
||||
|
||||
if ([title isNotNull]) [row setObject: title forKey:@"title"];
|
||||
if ([location isNotNull]) [row setObject: location forKey:@"location"];
|
||||
if ([sequence isNotNull]) [row setObject: sequence forKey:@"sequence"];
|
||||
if ([title isNotNull]) [row setObject: title forKey: @"title"];
|
||||
if ([location isNotNull]) [row setObject: location forKey: @"location"];
|
||||
if ([sequence isNotNull]) [row setObject: sequence forKey: @"sequence"];
|
||||
|
||||
if ([startDate isNotNull])
|
||||
[row setObject: [self numberForDate: startDate] forKey:@"startdate"];
|
||||
[row setObject: [self numberForDate: startDate]
|
||||
forKey: @"startdate"];
|
||||
if ([endDate isNotNull])
|
||||
[row setObject: [self numberForDate: endDate] forKey:@"enddate"];
|
||||
{
|
||||
if (endDate == distantFuture)
|
||||
dateNumber = distantFutureNumber;
|
||||
else
|
||||
{
|
||||
if (isAllDay)
|
||||
i = 1;
|
||||
else
|
||||
i = 0;
|
||||
dateNumber
|
||||
= [NSNumber numberWithUnsignedInt:
|
||||
[endDate timeIntervalSince1970] - i];
|
||||
}
|
||||
[row setObject: dateNumber forKey: @"enddate"];
|
||||
}
|
||||
|
||||
if ([_event isRecurrent]) {
|
||||
NSCalendarDate *date;
|
||||
|
||||
|
||||
date = [_event lastPossibleRecurrenceStartDate];
|
||||
if (!date) {
|
||||
/* this could also be *nil*, but in the end it makes the fetchspecs
|
||||
more complex - thus we set it to a "reasonable" distant future */
|
||||
more complex - thus we set it to a "reasonable" distant future */
|
||||
date = distantFuture;
|
||||
}
|
||||
[row setObject:[self numberForDate:date] forKey:@"cycleenddate"];
|
||||
[row setObject:[_event cycleInfo] forKey:@"cycleinfo"];
|
||||
[row setObject:[self numberForDate:date] forKey: @"cycleenddate"];
|
||||
[row setObject:[_event cycleInfo] forKey: @"cycleinfo"];
|
||||
}
|
||||
|
||||
if ([participants length] > 0)
|
||||
[row setObject: participants forKey:@"participants"];
|
||||
[row setObject: participants forKey: @"participants"];
|
||||
if ([partmails length] > 0)
|
||||
[row setObject: partmails forKey:@"partmails"];
|
||||
[row setObject: partmails forKey: @"partmails"];
|
||||
|
||||
if ([status isNotNull]) {
|
||||
int code = 1;
|
||||
|
||||
if ([status isEqualToString:@"TENTATIVE"])
|
||||
|
||||
if ([status isEqualToString: @"TENTATIVE"])
|
||||
code = 2;
|
||||
else if ([status isEqualToString:@"CANCELLED"])
|
||||
else if ([status isEqualToString: @"CANCELLED"])
|
||||
code = 0;
|
||||
[row setObject:[NSNumber numberWithInt:code] forKey:@"status"];
|
||||
[row setObject:[NSNumber numberWithInt:code] forKey: @"status"];
|
||||
}
|
||||
else {
|
||||
/* confirmed by default */
|
||||
@@ -160,26 +177,26 @@ static NSNumber *distantFutureNumber = nil;
|
||||
organizer = [_event organizer];
|
||||
if (organizer) {
|
||||
NSString *email;
|
||||
|
||||
email = [organizer valueForKey:@"rfc822Email"];
|
||||
|
||||
email = [organizer valueForKey: @"rfc822Email"];
|
||||
if (email)
|
||||
[row setObject:email forKey:@"orgmail"];
|
||||
[row setObject:email forKey: @"orgmail"];
|
||||
}
|
||||
|
||||
|
||||
/* construct partstates */
|
||||
count = [attendees count];
|
||||
partstates = [[NSMutableString alloc] initWithCapacity:count * 2];
|
||||
count = [attendees count];
|
||||
partstates = [[NSMutableString alloc] initWithCapacity:count * 2];
|
||||
for ( i = 0; i < count; i++) {
|
||||
iCalPerson *p;
|
||||
iCalPerson *p;
|
||||
iCalPersonPartStat stat;
|
||||
|
||||
p = [attendees objectAtIndex:i];
|
||||
|
||||
p = [attendees objectAtIndex:i];
|
||||
stat = [p participationStatus];
|
||||
if(i != 0)
|
||||
[partstates appendString:@"\n"];
|
||||
[partstates appendFormat:@"%d", stat];
|
||||
[partstates appendString: @"\n"];
|
||||
[partstates appendFormat: @"%d", stat];
|
||||
}
|
||||
[row setObject:partstates forKey:@"partstates"];
|
||||
[row setObject:partstates forKey: @"partstates"];
|
||||
[partstates release];
|
||||
return row;
|
||||
}
|
||||
@@ -187,35 +204,35 @@ static NSNumber *distantFutureNumber = nil;
|
||||
- (NSMutableDictionary *) extractQuickFieldsFromTodo: (iCalToDo *) _task
|
||||
{
|
||||
NSMutableDictionary *row;
|
||||
NSCalendarDate *startDate, *dueDate;
|
||||
NSArray *attendees;
|
||||
NSString *uid, *title, *location, *status;
|
||||
NSNumber *sequence;
|
||||
id organizer, date;
|
||||
id participants, partmails;
|
||||
NSMutableString *partstates;
|
||||
unsigned i, count, code;
|
||||
NSCalendarDate *startDate, *dueDate;
|
||||
NSArray *attendees;
|
||||
NSString *uid, *title, *location, *status;
|
||||
NSNumber *sequence;
|
||||
id organizer, date;
|
||||
id participants, partmails;
|
||||
NSMutableString *partstates;
|
||||
unsigned i, count, code;
|
||||
iCalAccessClass accessClass;
|
||||
|
||||
if (_task == nil)
|
||||
return nil;
|
||||
|
||||
/* extract values */
|
||||
|
||||
startDate = [_task startDate];
|
||||
dueDate = [_task due];
|
||||
uid = [_task uid];
|
||||
title = [_task summary];
|
||||
location = [_task location];
|
||||
sequence = [_task sequence];
|
||||
accessClass = [_task symbolicAccessClass];
|
||||
status = [[_task status] uppercaseString];
|
||||
|
||||
startDate = [_task startDate];
|
||||
dueDate = [_task due];
|
||||
uid = [_task uid];
|
||||
title = [_task summary];
|
||||
location = [_task location];
|
||||
sequence = [_task sequence];
|
||||
accessClass = [_task symbolicAccessClass];
|
||||
status = [[_task status] uppercaseString];
|
||||
|
||||
attendees = [_task attendees];
|
||||
partmails = [attendees valueForKey:@"rfc822Email"];
|
||||
partmails = [partmails componentsJoinedByString:@"\n"];
|
||||
participants = [attendees valueForKey:@"cn"];
|
||||
participants = [participants componentsJoinedByString:@"\n"];
|
||||
attendees = [_task attendees];
|
||||
partmails = [attendees valueForKey: @"rfc822Email"];
|
||||
partmails = [partmails componentsJoinedByString: @"\n"];
|
||||
participants = [attendees valueForKey: @"cn"];
|
||||
participants = [participants componentsJoinedByString: @"\n"];
|
||||
|
||||
/* build row */
|
||||
|
||||
@@ -224,19 +241,19 @@ static NSNumber *distantFutureNumber = nil;
|
||||
[row setObject: @"vtodo" forKey: @"component"];
|
||||
|
||||
if ([uid isNotNull])
|
||||
[row setObject:uid forKey:@"uid"];
|
||||
[row setObject:uid forKey: @"uid"];
|
||||
else
|
||||
[self logWithFormat:@"WARNING: could not extract a uid from event!"];
|
||||
[self logWithFormat: @"WARNING: could not extract a uid from event!"];
|
||||
|
||||
[row setObject:[NSNumber numberWithBool:[_task isRecurrent]]
|
||||
forKey:@"iscycle"];
|
||||
forKey: @"iscycle"];
|
||||
[row setObject:[NSNumber numberWithInt:[_task priorityNumber]]
|
||||
forKey:@"priority"];
|
||||
forKey: @"priority"];
|
||||
|
||||
if ([title isNotNull]) [row setObject: title forKey:@"title"];
|
||||
if ([location isNotNull]) [row setObject: location forKey:@"location"];
|
||||
if ([sequence isNotNull]) [row setObject: sequence forKey:@"sequence"];
|
||||
|
||||
if ([title isNotNull]) [row setObject: title forKey: @"title"];
|
||||
if ([location isNotNull]) [row setObject: location forKey: @"location"];
|
||||
if ([sequence isNotNull]) [row setObject: sequence forKey: @"sequence"];
|
||||
|
||||
if ([startDate isNotNull])
|
||||
date = [self numberForDate: startDate];
|
||||
else
|
||||
@@ -250,23 +267,23 @@ static NSNumber *distantFutureNumber = nil;
|
||||
[row setObject: date forKey: @"enddate"];
|
||||
|
||||
if ([participants length] > 0)
|
||||
[row setObject:participants forKey:@"participants"];
|
||||
[row setObject:participants forKey: @"participants"];
|
||||
if ([partmails length] > 0)
|
||||
[row setObject:partmails forKey:@"partmails"];
|
||||
[row setObject:partmails forKey: @"partmails"];
|
||||
|
||||
if ([status isNotNull]) {
|
||||
code = 0; /* NEEDS-ACTION */
|
||||
if ([status isEqualToString:@"COMPLETED"])
|
||||
if ([status isEqualToString: @"COMPLETED"])
|
||||
code = 1;
|
||||
else if ([status isEqualToString:@"IN-PROCESS"])
|
||||
else if ([status isEqualToString: @"IN-PROCESS"])
|
||||
code = 2;
|
||||
else if ([status isEqualToString:@"CANCELLED"])
|
||||
else if ([status isEqualToString: @"CANCELLED"])
|
||||
code = 3;
|
||||
[row setObject: [NSNumber numberWithInt: code] forKey:@"status"];
|
||||
[row setObject: [NSNumber numberWithInt: code] forKey: @"status"];
|
||||
}
|
||||
else {
|
||||
/* confirmed by default */
|
||||
[row setObject:[NSNumber numberWithInt:1] forKey:@"status"];
|
||||
[row setObject:[NSNumber numberWithInt:1] forKey: @"status"];
|
||||
}
|
||||
|
||||
[row setObject: [NSNumber numberWithUnsignedInt: accessClass]
|
||||
@@ -275,26 +292,26 @@ static NSNumber *distantFutureNumber = nil;
|
||||
organizer = [_task organizer];
|
||||
if (organizer) {
|
||||
NSString *email;
|
||||
|
||||
email = [organizer valueForKey:@"rfc822Email"];
|
||||
|
||||
email = [organizer valueForKey: @"rfc822Email"];
|
||||
if (email)
|
||||
[row setObject:email forKey:@"orgmail"];
|
||||
[row setObject:email forKey: @"orgmail"];
|
||||
}
|
||||
|
||||
|
||||
/* construct partstates */
|
||||
count = [attendees count];
|
||||
partstates = [[NSMutableString alloc] initWithCapacity:count * 2];
|
||||
count = [attendees count];
|
||||
partstates = [[NSMutableString alloc] initWithCapacity:count * 2];
|
||||
for ( i = 0; i < count; i++) {
|
||||
iCalPerson *p;
|
||||
iCalPerson *p;
|
||||
iCalPersonPartStat stat;
|
||||
|
||||
p = [attendees objectAtIndex:i];
|
||||
|
||||
p = [attendees objectAtIndex:i];
|
||||
stat = [p participationStatus];
|
||||
if(i != 0)
|
||||
[partstates appendString:@"\n"];
|
||||
[partstates appendFormat:@"%d", stat];
|
||||
[partstates appendString: @"\n"];
|
||||
[partstates appendFormat: @"%d", stat];
|
||||
}
|
||||
[row setObject:partstates forKey:@"partstates"];
|
||||
[row setObject:partstates forKey: @"partstates"];
|
||||
[partstates release];
|
||||
return row;
|
||||
}
|
||||
@@ -304,20 +321,20 @@ static NSNumber *distantFutureNumber = nil;
|
||||
NSArray *elements;
|
||||
CardGroup *element;
|
||||
unsigned int count;
|
||||
|
||||
|
||||
elements = [ical allObjects];
|
||||
count = [elements count];
|
||||
if (count)
|
||||
{
|
||||
if (count > 1)
|
||||
[self logWithFormat:
|
||||
@"WARNING: given calendar contains more than one event: %@",
|
||||
ical];
|
||||
[self logWithFormat:
|
||||
@"WARNING: given calendar contains more than one event: %@",
|
||||
ical];
|
||||
element = [elements objectAtIndex: 0];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self logWithFormat:@"ERROR: given calendar contains no elements: %@", ical];
|
||||
[self logWithFormat: @"ERROR: given calendar contains no elements: %@", ical];
|
||||
element = nil;
|
||||
}
|
||||
|
||||
@@ -328,33 +345,33 @@ static NSNumber *distantFutureNumber = nil;
|
||||
NSAutoreleasePool *pool;
|
||||
NSDictionary *fields;
|
||||
id cal;
|
||||
|
||||
|
||||
if ([_content length] == 0)
|
||||
return nil;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
cal = [iCalCalendar parseSingleFromSource: _content];
|
||||
|
||||
|
||||
fields = nil;
|
||||
if (cal)
|
||||
{
|
||||
if ([cal isKindOfClass:[iCalCalendar class]])
|
||||
cal = [self firstElementFromCalendar: cal];
|
||||
cal = [self firstElementFromCalendar: cal];
|
||||
|
||||
if ([cal isKindOfClass:[iCalEvent class]])
|
||||
fields = [[self extractQuickFieldsFromEvent:cal] retain];
|
||||
fields = [[self extractQuickFieldsFromEvent:cal] retain];
|
||||
else if ([cal isKindOfClass:[iCalToDo class]])
|
||||
fields = [[self extractQuickFieldsFromTodo:cal] retain];
|
||||
fields = [[self extractQuickFieldsFromTodo:cal] retain];
|
||||
else if ([cal isNotNull]) {
|
||||
[self logWithFormat:@"ERROR: unexpected iCalendar parse result: %@",
|
||||
cal];
|
||||
[self logWithFormat: @"ERROR: unexpected iCalendar parse result: %@",
|
||||
cal];
|
||||
}
|
||||
}
|
||||
else
|
||||
[self logWithFormat:@"ERROR: parsing source didn't return anything"];
|
||||
[self logWithFormat: @"ERROR: parsing source didn't return anything"];
|
||||
|
||||
[pool release];
|
||||
|
||||
|
||||
return [fields autorelease];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user