From 7b35cb1c4b7fa82f0c4a40c2a4dcf984fdf67dbf Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 17 Oct 2006 19:57:14 +0000 Subject: [PATCH] Monotone-Parent: dae7774a771ac5d0ee1d7c9aabe93acbf3db3085 Monotone-Revision: 71bb185f5f96c21cf62ca4dd2cadf54d83dc4f7c Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2006-10-17T19:57:14 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 4 + .../Appointments/SOGoAppointmentFolder.m | 135 +++++++++++++----- 2 files changed, 103 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa7df7f33..3fc4ce73a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2006-10-17 Wolfgang Sourdeau + * SoObjects/Appointments/SOGoAppointmentFolder.m + ([SOGoAppointmentFolder -doCalendarQuery:context]): now supports + the handling of time-ranges. + * UI/WebServerResources/ContactsUI.js: specify a notification type as parameters when onConfirmContactSelection in invoked. diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index ef867055b..dc2e464e4 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -183,21 +183,102 @@ static NSNumber *sharedYes = nil; [r appendContentString: @" \r\n"]; } +- (void) _appendTimeRange: (id ) timeRangeElement + toFilter: (NSMutableDictionary *) filter +{ + NSCalendarDate *parsedDate; + + parsedDate = [[timeRangeElement attribute: @"start"] asCalendarDate]; + [filter setObject: parsedDate forKey: @"start"]; + parsedDate = [[timeRangeElement attribute: @"end"] asCalendarDate]; + [filter setObject: parsedDate forKey: @"end"]; +} + +- (NSDictionary *) _parseCalendarFilter: (id ) filterElement +{ + NSMutableDictionary *filterData; + id parentNode; + id ranges; + NSString *componentName; + + parentNode = [filterElement parentNode]; + if ([[parentNode tagName] isEqualToString: @"comp-filter"] + && [[parentNode attribute: @"name"] isEqualToString: @"VCALENDAR"]) + { + componentName = [[filterElement attribute: @"name"] lowercaseString]; + filterData = [NSMutableDictionary new]; + [filterData autorelease]; + [filterData setObject: componentName forKey: @"name"]; + ranges = [filterElement getElementsByTagName: @"time-range"]; + if ([ranges count]) + [self _appendTimeRange: [ranges objectAtIndex: 0] + toFilter: filterData]; + } + else + filterData = nil; + + return filterData; +} + +- (NSArray *) _parseCalendarFilters: (id ) parentNode +{ + NSEnumerator *children; + id node; + NSMutableArray *filters; + NSDictionary *filter; + + filters = [NSMutableArray new]; + + children = [[parentNode getElementsByTagName: @"comp-filter"] objectEnumerator]; + node = [children nextObject]; + while (node) + { + filter = [self _parseCalendarFilter: node]; + if (filter) + [filters addObject: filter]; + node = [children nextObject]; + } + + return filters; +} + +- (void) _appendComponentsMatchingFilters: (NSArray *) filters + toResponse: (WOResponse *) response + inContext: (WOContext *) context +{ + NSArray *apts; + unsigned int count, max; + NSDictionary *currentFilter, *appointment; + NSEnumerator *appointments; + NSString *baseURL; + + baseURL = [self baseURLInContext: context]; + + max = [filters count]; + for (count = 0; count < max; count++) + { + currentFilter = [filters objectAtIndex: 0]; + apts = [self fetchCoreInfosFrom: [currentFilter objectForKey: @"start"] + to: [currentFilter objectForKey: @"end"] + component: [currentFilter objectForKey: @"name"]]; + appointments = [apts objectEnumerator]; + appointment = [appointments nextObject]; + while (appointment) + { + [self appendObject: appointment + withBaseURL: baseURL + toREPORTResponse: response]; + appointment = [appointments nextObject]; + } + } +} + - (id) doCalendarQuery: (id) context { WOResponse *r; - NSString *baseURL, *content; - NSArray *apts; - NSMutableArray *components; - NSEnumerator *appointments; - NSDictionary *appointment; + NSArray *filters; + id document; -// FIXME: this is f00ked UP -// FIXME: no, just kidding... actually we should take the date range into -// account otherwise all events will be returned. We should also manage the -// VTODO... and well, have a clean implementation. - - baseURL = [self baseURLInContext: context]; r = [context response]; [r setStatus: 207]; [r setContentEncoding: NSUTF8StringEncoding]; @@ -208,29 +289,11 @@ static NSNumber *sharedYes = nil; [r appendContentString: @"\r\n"]; - content = [[NSString alloc] initWithData: [[context request] content] - encoding: NSUTF8StringEncoding]; - [content autorelease]; - - components = [NSMutableArray new]; - if ([content indexOfString: @"VEVENT"] != NSNotFound - || [content indexOfString: @"vevent"] != NSNotFound) - [components addObject: @"vevent"]; - if ([content indexOfString: @"VTODO"] != NSNotFound - || [content indexOfString: @"vtodo"] != NSNotFound) - [components addObject: @"vtodo"]; - - apts = [self fetchCoreInfosFrom: nil to: nil component: components]; - [components release]; - appointments = [apts objectEnumerator]; - appointment = [appointments nextObject]; - while (appointment) - { - [self appendObject: appointment - withBaseURL: baseURL - toREPORTResponse: r]; - appointment = [appointments nextObject]; - } + document = [[context request] contentAsDOMDocument]; + filters = [self _parseCalendarFilters: [document documentElement]]; + [self _appendComponentsMatchingFilters: filters + toResponse: r + inContext: context]; [r appendContentString:@"\r\n"]; return r; @@ -342,7 +405,7 @@ static NSNumber *sharedYes = nil; nameFields = [[NSArray alloc] initWithObjects:@"c_name", nil]; qualifier = [EOQualifier qualifierWithQualifierFormat:@"uid = %@", _u]; - records = [_f fetchFields:nameFields matchingQualifier:qualifier]; + records = [_f fetchFields: nameFields matchingQualifier: qualifier]; if ([records count] == 1) return [[records objectAtIndex:0] valueForKey:@"c_name"]; @@ -594,7 +657,7 @@ static NSNumber *sharedYes = nil; r = [NGCalendarDateRange calendarDateRangeWithStartDate: _startDate endDate: _endDate]; dateSqlString - = [NSString stringWithFormat: @" AND (startdate > %d) AND (enddate < %d)", + = [NSString stringWithFormat: @" AND (startdate >= %d) AND (enddate <= %d)", (unsigned int) [_startDate timeIntervalSince1970], (unsigned int) [_endDate timeIntervalSince1970]]; }