Monotone-Parent: 467dc56666485b20c968357bff135be6a192df0c

Monotone-Revision: 81ebf97febc5675193974e8834acc35e001494f1

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-03-18T15:20:38
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2007-03-18 15:20:38 +00:00
parent 84bba82435
commit d26f7a625a
7 changed files with 982 additions and 1239 deletions
+208 -264
View File
@@ -55,11 +55,12 @@
{
if ((self = [super init]))
{
component = nil;
[self setPrivacy: @"PUBLIC"];
[self setCheckForConflicts: NO];
[self setIsCycleEndNever];
componentOwner = @"";
componentLoaded = NO;
attendeesNames = nil;
attendeesEmails = nil;
}
return self;
@@ -67,31 +68,102 @@
- (void) dealloc
{
[iCalString release];
[errorText release];
[item release];
[startDate release];
[cycleUntilDate release];
[title release];
[location release];
[organizer release];
[comment release];
[participants release];
[resources release];
[priority release];
[categories release];
[cycle release];
[cycleEnd release];
[url release];
[attendeesNames release];
[attendeesEmails release];
[super dealloc];
}
- (void) _loadAttendees
{
NSEnumerator *attendees;
iCalPerson *currentAttendee;
NSMutableString *names, *emails;
names = [NSMutableString new];
emails = [NSMutableString new];
attendees = [[component attendees] objectEnumerator];
currentAttendee = [attendees nextObject];
while (currentAttendee)
{
NSLog (@"currentCN: %@", [currentAttendee cn]);
[names appendFormat: @"%@,", [currentAttendee cn]];
[emails appendFormat: @"%@,", [currentAttendee rfc822Email]];
currentAttendee = [attendees nextObject];
}
if ([names length] > 0)
{
ASSIGN (attendeesNames, [names substringToIndex: [names length] - 1]);
ASSIGN (attendeesEmails,
[emails substringToIndex: [emails length] - 1]);
}
[names release];
[emails release];
}
/* warning: we use this method which will be triggered by the template system
when the page is instantiated, but we should find another and cleaner way of
doing this... for example, when the clientObject is set */
- (void) setComponent: (iCalRepeatableEntityObject *) newComponent
{
// iCalRecurrenceRule *rrule;
SOGoObject *co;
if (!component)
{
component = newComponent;
co = [self clientObject];
componentOwner = [co ownerInContext: nil];
ASSIGN (title, [component summary]);
ASSIGN (location, [component location]);
ASSIGN (comment, [component comment]);
ASSIGN (url, [[component url] absoluteString]);
ASSIGN (privacy, [component accessClass]);
ASSIGN (priority, [component priority]);
ASSIGN (status, [component status]);
ASSIGN (categories, [[component categories] commaSeparatedValues]);
ASSIGN (organizer, [component organizer]);
[self _loadAttendees];
}
// /* cycles */
// if ([component isRecurrent])
// {
// rrule = [[component recurrenceRules] objectAtIndex: 0];
// [self adjustCycleControlsForRRule: rrule];
// }
}
- (void) setSaveURL: (NSString *) newSaveURL
{
saveURL = newSaveURL;
}
- (NSString *) saveURL
{
return saveURL;
}
/* accessors */
- (void) setItem: (id) _item
{
ASSIGN(item, _item);
ASSIGN (item, _item);
}
- (id) item
@@ -114,34 +186,9 @@
return [self labelForKey: [NSString stringWithFormat: @"status_%@", item]];
}
- (void) setErrorText: (NSString *) _txt
{
ASSIGNCOPY(errorText, _txt);
}
- (NSString *) errorText
{
return errorText;
}
- (BOOL) hasErrorText
{
return [errorText length] > 0 ? YES : NO;
}
- (void) setStartDate: (NSCalendarDate *) _date
{
ASSIGN(startDate, _date);
}
- (NSCalendarDate *) startDate
{
return startDate;
}
- (void) setTitle: (NSString *) _value
{
ASSIGNCOPY(title, _value);
ASSIGN (title, _value);
}
- (NSString *) title
@@ -151,7 +198,7 @@
- (void) setUrl: (NSString *) _url
{
ASSIGNCOPY(url, _url);
ASSIGN (url, _url);
}
- (NSString *) url
@@ -159,9 +206,29 @@
return url;
}
- (void) setAttendeesNames: (NSString *) newAttendeesNames
{
ASSIGN (attendeesNames, newAttendeesNames);
}
- (NSString *) attendeesNames
{
return attendeesNames;
}
- (void) setAttendeesEmails: (NSString *) newAttendeesEmails
{
ASSIGN (attendeesEmails, newAttendeesEmails);
}
- (NSString *) attendeesEmails
{
return attendeesEmails;
}
- (void) setLocation: (NSString *) _value
{
ASSIGNCOPY(location, _value);
ASSIGN (location, _value);
}
- (NSString *) location
@@ -171,7 +238,7 @@
- (void) setComment: (NSString *) _value
{
ASSIGNCOPY(comment, _value);
ASSIGN (comment, _value);
}
- (NSString *) comment
@@ -179,28 +246,34 @@
return comment;
}
- (NSArray *) categoryItems
- (NSArray *) categoryList
{
// TODO: make this configurable?
/*
Tasks categories will be modified as follow :
by default (a simple logo or no logo at all),
task,
outside,
meeting,
holidays,
phone.
*/
static NSArray *categoryItems = nil;
if (!categoryItems)
{
categoryItems = [NSArray arrayWithObjects: @"APPOINTMENT",
@"NOT IN OFFICE",
@"MEETING",
@"HOLIDAY",
@"PHONE CALL",
nil];
categoryItems = [NSArray arrayWithObjects: @"ANNIVERSARY",
@"BIRTHDAY",
@"BUSINESS",
@"CALLS",
@"CLIENTS",
@"COMPETITION",
@"CUSTOMER",
@"FAVORITES",
@"FOLLOW UP",
@"GIFTS",
@"HOLIDAYS",
@"IDEAS",
@"ISSUES",
@"MISCELLANEOUS",
@"PERSONAL",
@"PROJECTS",
@"PUBLIC HOLIDAY",
@"STATUS",
@"SUPPLIERS",
@"TRAVEL",
@"VACATION",
nil];
[categoryItems retain];
}
@@ -209,7 +282,7 @@
- (void) setCategories: (NSArray *) _categories
{
ASSIGN(categories, _categories);
ASSIGN (categories, _categories);
}
- (NSArray *) categories
@@ -219,7 +292,7 @@
- (NSString *) itemCategoryText
{
return [[self labelForKey: item] stringByEscapingHTMLString];
return [self labelForKey: [NSString stringWithFormat: @"category_%@", item]];
}
/* priorities */
@@ -234,7 +307,7 @@
if (!priorities)
{
priorities = [NSArray arrayWithObjects:@"0", @"5", @"1", nil];
priorities = [NSArray arrayWithObjects: @"0", @"5", @"1", nil];
[priorities retain];
}
@@ -243,7 +316,7 @@
- (void) setPriority: (NSString *) _priority
{
ASSIGN(priority, _priority);
ASSIGN (priority, _priority);
}
- (NSString *) priority
@@ -267,7 +340,7 @@
- (void) setPrivacy: (NSString *) _privacy
{
ASSIGN(privacy, _privacy);
ASSIGN (privacy, _privacy);
}
- (NSString *) privacy
@@ -290,7 +363,7 @@
- (void) setStatus: (NSString *) _status
{
ASSIGN(status, _status);
ASSIGN (status, _status);
}
- (NSString *) status
@@ -298,36 +371,6 @@
return status;
}
- (void) setParticipants: (NSArray *) _parts
{
ASSIGN(participants, _parts);
}
- (NSArray *) participants
{
return participants;
}
- (void) setResources: (NSArray *) _res
{
ASSIGN(resources, _res);
}
- (NSArray *) resources
{
return resources;
}
- (void) setCheckForConflicts: (BOOL) _checkForConflicts
{
checkForConflicts = _checkForConflicts;
}
- (BOOL) checkForConflicts
{
return checkForConflicts;
}
- (NSArray *) cycles
{
NSBundle *bundle;
@@ -337,7 +380,7 @@
if (!cycles)
{
bundle = [NSBundle bundleForClass:[self class]];
path = [bundle pathForResource:@"cycles" ofType:@"plist"];
path = [bundle pathForResource: @"cycles" ofType: @"plist"];
NSAssert(path != nil, @"Cannot find cycles.plist!");
cycles = [[NSArray arrayWithContentsOfFile:path] retain];
NSAssert(cycles != nil, @"Cannot instantiate cycles from cycles.plist!");
@@ -348,7 +391,7 @@
- (void) setCycle: (NSDictionary *) _cycle
{
ASSIGN(cycle, _cycle);
ASSIGN (cycle, _cycle);
}
- (NSDictionary *) cycle
@@ -365,21 +408,21 @@
{
NSString *key;
key = [(NSDictionary *)item objectForKey:@"label"];
key = [(NSDictionary *)item objectForKey: @"label"];
return [self labelForKey:key];
}
- (void) setCycleUntilDate: (NSCalendarDate *) _cycleUntilDate
{
NSCalendarDate *until;
// NSCalendarDate *until;
/* copy hour/minute/second from startDate */
until = [_cycleUntilDate hour: [startDate hourOfDay]
minute: [startDate minuteOfHour]
second: [startDate secondOfMinute]];
[until setTimeZone: [startDate timeZone]];
ASSIGN(cycleUntilDate, until);
// /* copy hour/minute/second from startDate */
// until = [_cycleUntilDate hour: [startDate hourOfDay]
// minute: [startDate minuteOfHour]
// second: [startDate secondOfMinute]];
// [until setTimeZone: [startDate timeZone]];
// ASSIGN (cycleUntilDate, until);
}
- (NSCalendarDate *) cycleUntilDate
@@ -394,7 +437,7 @@
if (![self hasCycle])
return nil;
ruleRep = [cycle objectForKey:@"rule"];
ruleRep = [cycle objectForKey: @"rule"];
rule = [iCalRecurrenceRule recurrenceRuleWithICalRepresentation:ruleRep];
if (cycleUntilDate && [self isCycleEndUntil])
@@ -405,20 +448,20 @@
- (void) adjustCycleControlsForRRule: (iCalRecurrenceRule *) _rrule
{
NSDictionary *c;
NSCalendarDate *until;
// NSDictionary *c;
// NSCalendarDate *until;
c = [self cycleMatchingRRule:_rrule];
[self setCycle:c];
// c = [self cycleMatchingRRule:_rrule];
// [self setCycle:c];
until = [[[_rrule untilDate] copy] autorelease];
if (!until)
until = startDate;
else
[self setIsCycleEndUntil];
// until = [[[_rrule untilDate] copy] autorelease];
// if (!until)
// until = startDate;
// else
// [self setIsCycleEndUntil];
[until setTimeZone:[[self clientObject] userTimeZone]];
[self setCycleUntilDate:until];
// [until setTimeZone:[[self clientObject] userTimeZone]];
// [self setCycleUntilDate:until];
}
/*
@@ -448,11 +491,11 @@
NSString *cr;
c = [cycles objectAtIndex:i];
cr = [c objectForKey:@"rule"];
cr = [c objectForKey: @"rule"];
if ([cr isEqualToString:cycleRep])
return c;
}
[self warnWithFormat:@"No default cycle for rrule found! -> %@", _rrule];
[self warnWithFormat: @"No default cycle for rrule found! -> %@", _rrule];
return nil;
}
@@ -473,7 +516,7 @@
- (void) setCycleEnd: (NSString *) _cycleEnd
{
ASSIGNCOPY(cycleEnd, _cycleEnd);
ASSIGN (cycleEnd, _cycleEnd);
}
- (NSString *) cycleEnd
@@ -483,18 +526,17 @@
- (BOOL) isCycleEndUntil
{
return (cycleEnd &&
[cycleEnd isEqualToString:@"cycle_end_until"]);
return (cycleEnd && [cycleEnd isEqualToString: @"cycle_end_until"]);
}
- (void) setIsCycleEndUntil
{
[self setCycleEnd:@"cycle_end_until"];
[self setCycleEnd: @"cycle_end_until"];
}
- (void) setIsCycleEndNever
{
[self setCycleEnd:@"cycle_end_never"];
[self setCycleEnd: @"cycle_end_never"];
}
/* helpers */
@@ -517,13 +559,13 @@
uri = [[[self context] request] uri];
/* first: identify query parameters */
r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
r = [uri rangeOfString: @"?" options:NSBackwardsSearch];
if (r.length > 0)
uri = [uri substringToIndex:r.location];
/* next: append trailing slash */
if (![uri hasSuffix:@"/"])
uri = [uri stringByAppendingString:@"/"];
if (![uri hasSuffix: @"/"])
uri = [uri stringByAppendingString: @"/"];
/* next: append method */
uri = [uri stringByAppendingString:_method];
@@ -535,13 +577,7 @@
- (BOOL) isWriteableClientObject
{
return [[self clientObject]
respondsToSelector:@selector(saveContentString:)];
}
- (BOOL) shouldTakeValuesFromRequest: (WORequest *) _rq
inContext: (WOContext*) _c
{
return YES;
respondsToSelector: @selector(saveContentString:)];
}
- (BOOL) containsConflict: (id) _component
@@ -593,81 +629,6 @@
: @"visibility: hidden;");
}
/* subclasses */
- (NSCalendarDate *) newStartDate
{
NSCalendarDate *newStartDate, *now;
int hour;
newStartDate = [self selectedDate];
if ([[self queryParameterForKey: @"hm"] length] == 0)
{
now = [NSCalendarDate calendarDate];
[now setTimeZone: [[self clientObject] userTimeZone]];
if ([now isDateOnSameDay: newStartDate])
{
hour = [now hourOfDay];
if (hour < 8)
newStartDate = [now hour: 8 minute: 0];
else if (hour > 18)
newStartDate = [[now tomorrow] hour: 8 minute: 0];
else
newStartDate = now;
}
else
newStartDate = [newStartDate hour: 8 minute: 0];
}
return newStartDate;
}
- (void) loadValuesFromComponent: (iCalRepeatableEntityObject *) component
{
iCalRecurrenceRule *rrule;
NSTimeZone *uTZ;
SOGoObject *co;
co = [self clientObject];
componentOwner = [co ownerInContext: nil];
componentLoaded = YES;
startDate = [component startDate];
// if ((startDate = [component startDate]) == nil)
// startDate = [[NSCalendarDate date] hour:11 minute:0];
uTZ = [co userTimeZone];
if (startDate)
{
[startDate setTimeZone: uTZ];
[startDate retain];
}
title = [[component summary] copy];
location = [[component location] copy];
comment = [[component comment] copy];
url = [[[component url] absoluteString] copy];
privacy = [[component accessClass] copy];
priority = [[component priority] copy];
status = [[component status] copy];
categories = [[[component categories] commaSeparatedValues] retain];
organizer = [[component organizer] retain];
participants = [[component participants] retain];
resources = [[component resources] retain];
/* cycles */
if ([component isRecurrent])
{
rrule = [[component recurrenceRules] objectAtIndex: 0];
[self adjustCycleControlsForRRule: rrule];
}
}
- (NSString *) iCalStringTemplate
{
[self subclassResponsibility: _cmd];
return @"";
}
- (NSString *) iCalParticipantsAndResourcesStringFromQueryParameters
{
NSString *s;
@@ -709,7 +670,7 @@
NSArray *es;
unsigned i, count;
es = [s componentsSeparatedByString:@","];
es = [s componentsSeparatedByString: @","];
count = [es count];
for(i = 0; i < count; i++) {
NSString *email, *cn;
@@ -728,13 +689,6 @@
[self cnForUser], [self emailForUser]];
}
- (NSString *) saveUrl
{
[self subclassResponsibility: _cmd];
return @"";
}
- (NSException *) validateObjectForStatusChange
{
id co;
@@ -751,16 +705,6 @@
/* contact editor compatibility */
- (void) setICalString: (NSString *) _s
{
ASSIGNCOPY(iCalString, _s);
}
- (NSString *) iCalString
{
return iCalString;
}
- (NSArray *) availableCalendars
{
NSEnumerator *rawContacts;
@@ -807,58 +751,58 @@
return classes;
}
- (NSString *) _toolbarForCalObject: (iCalEntityObject *) calObject
- (void) _handleAttendeesEdition
{
NSString *filename, *myEmail;
iCalPerson *person;
NSEnumerator *persons;
iCalPersonPartStat myParticipationStatus;
BOOL found;
NSArray *names, *emails;
NSMutableArray *newAttendees;
unsigned int count, max;
NSString *currentEmail;
iCalPerson *currentAttendee;
myEmail = [[[self context] activeUser] email];
if ([[organizer rfc822Email] isEqualToString: myEmail])
filename = @"SOGoAppointmentObject.toolbar";
else
newAttendees = [NSMutableArray new];
names = [attendeesNames componentsSeparatedByString: @","];
emails = [attendeesEmails componentsSeparatedByString: @","];
max = [emails count];
for (count = 0; count < max; count++)
{
filename = @"";
found = NO;
persons = [participants objectEnumerator];
person = [persons nextObject];
while (person && !found)
if ([[person rfc822Email] isEqualToString: myEmail])
{
found = YES;
myParticipationStatus = [person participationStatus];
if (myParticipationStatus == iCalPersonPartStatAccepted)
filename = @"SOGoAppointmentObjectDecline.toolbar";
else if (myParticipationStatus == iCalPersonPartStatDeclined)
filename = @"SOGoAppointmentObjectAccept.toolbar";
else
filename = @"SOGoAppointmentObjectAcceptOrDecline.toolbar";
}
else
person = [persons nextObject];
currentEmail = [emails objectAtIndex: count];
currentAttendee = [component findParticipantWithEmail: currentEmail];
if (!currentAttendee)
{
currentAttendee = [iCalPerson elementWithTag: @"attendee"];
[currentAttendee setCn: [names objectAtIndex: count]];
[currentAttendee setEmail: currentEmail];
[currentAttendee setRole: @"REQ-PARTICIPANT"];
[currentAttendee
setParticipationStatus: iCalPersonPartStatNeedsAction];
}
[newAttendees addObject: currentAttendee];
}
return filename;
[component setAttendees: newAttendees];
[newAttendees release];
}
- (NSString *) toolbar
- (void) takeValuesFromRequest: (WORequest *) _rq
inContext: (WOContext *) _ctx
{
NSString *filename;
iCalEntityObject *calObject;
SOGoCalendarComponent *co;
NSCalendarDate *now;
if (componentLoaded)
[super takeValuesFromRequest: _rq inContext: _ctx];
now = [NSCalendarDate calendarDate];
[component setSummary: title];
[component setLocation: location];
[component setComment: comment];
[component setUrl: url];
if ([[self clientObject] isNew])
{
co = [self clientObject];
calObject = [co component];
filename = [self _toolbarForCalObject: calObject];
[component setCreated: now];
[component setTimeStampAsDate: now];
[component setPriority: @"0"];
}
else
filename = @"";
return filename;
[component setLastModified: now];
[self _handleAttendeesEdition];
}
@end