From 676194b020ef3e29acd6f5ddc109218d2a4123ab Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 11 Jun 2010 18:43:46 +0000 Subject: [PATCH] ; Monotone-Parent: fc267c7dc09cc05decc140411d1facce3f441866 Monotone-Revision: c2a5265bbdaf7810309bda5f2f3dd5f2c67b15ed Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-06-11T18:43:46 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 16 ++ .../Appointments/SOGoAppointmentFolders.h | 6 +- .../Appointments/SOGoAppointmentFolders.m | 149 +++++++++++------- .../Appointments/SOGoWebAppointmentFolder.h | 2 +- .../Appointments/SOGoWebAppointmentFolder.m | 18 +-- UI/Scheduler/UIxCalMainActions.h | 3 - UI/Scheduler/UIxCalMainActions.m | 36 +---- UI/Scheduler/UIxCalendarProperties.m | 23 +-- 8 files changed, 130 insertions(+), 123 deletions(-) diff --git a/ChangeLog b/ChangeLog index a837ccaf0..47f457ae2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 2010-06-11 Wolfgang Sourdeau + * UI/Scheduler/UIxCalMainActions.m (-saveUrl:forCalendar:): + removed method since obsoleted by the code below. + + * SoObjects/Appointments/SOGoWebAppointmentFolder.m + (-loadWebCalendar): removed the URL parameter since it's + read-only. + (-delete): simplified method. + + * SoObjects/Appointments/SOGoAppointmentFolders.m + (-newWebCalendarWithName:atURL:): new self-explicit method. + (-reloadWebCalendars): we now make use of the @"WebCalendar" name + as a property key. + (_migrateWebCalendarsSettings): new method that converts + WebCalendar entry keys in a format suitable for use as a property + key. + * UI/Scheduler/UIxCalFilterPanel.m (+initialize): commented out the "All Events" option as this could cause a delay too long in IE when drawing the list. diff --git a/SoObjects/Appointments/SOGoAppointmentFolders.h b/SoObjects/Appointments/SOGoAppointmentFolders.h index 0d392a923..36dff6dc7 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolders.h +++ b/SoObjects/Appointments/SOGoAppointmentFolders.h @@ -27,12 +27,16 @@ @class NSArray; +@class SOGoWebAppointmentFolder; + @interface SOGoAppointmentFolders : SOGoParentFolder { NSMutableArray *folderObjectKeys; } -- (NSArray *) webCalendarIds; +- (SOGoWebAppointmentFolder *) newWebCalendarWithName: (NSString *) folderDisplayName + atURL: (NSString *) url; + - (void) reloadWebCalendars: (BOOL) forceReload; - (BOOL) hasProxyCalendarsWithWriteAccess: (BOOL) write diff --git a/SoObjects/Appointments/SOGoAppointmentFolders.m b/SoObjects/Appointments/SOGoAppointmentFolders.m index c670b6ba0..26082c603 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolders.m +++ b/SoObjects/Appointments/SOGoAppointmentFolders.m @@ -96,6 +96,30 @@ return [self labelForKey: @"Personal Calendar" inContext: context]; } +- (SOGoWebAppointmentFolder *) + newWebCalendarWithName: (NSString *) folderDisplayName + atURL: (NSString *) url +{ + SOGoAppointmentFolder *aptFolder; + SOGoWebAppointmentFolder *webCalendar; + NSString *name; + + if (![self newFolderWithName: folderDisplayName + nameInContainer: &name]) + { + aptFolder = [subFolders objectForKey: name]; + [aptFolder setFolderPropertyValue: url + inCategory: @"WebCalendars"]; + + webCalendar = [SOGoWebAppointmentFolder objectWithName: name + inContainer: self]; + [webCalendar setOCSPath: [aptFolder ocsPath]]; + [subFolders setObject: webCalendar forKey: name]; + } + + return webCalendar; +} + - (NSArray *) toManyRelationshipKeys { NSMutableArray *keys; @@ -348,91 +372,102 @@ return componentSet; } -- (NSArray *) webCalendarIds -{ - SOGoUserSettings *us; - NSDictionary *tmp, *calendars; - NSArray *rc; - - rc = nil; - - us = [[SOGoUser userWithLogin: owner] userSettings]; - tmp = [us objectForKey: @"Calendar"]; - if (tmp) - { - calendars = [tmp objectForKey: @"WebCalendars"]; - if (calendars) - rc = [calendars allKeys]; - } - - if (!rc) - rc = [NSArray array]; - - return rc; -} - - (void) reloadWebCalendars: (BOOL) forceReload { - SOGoUserSettings *settings; - NSMutableDictionary *calendarSettings, *webCalendars; - NSArray *calendarIds; + NSArray *refs; SOGoWebAppointmentFolder *folder; - NSString *name; + SOGoUserSettings *us; + NSDictionary *calSettings; + NSString *ref; int count, max; - settings = [[SOGoUser userWithLogin: owner] userSettings]; - calendarSettings = [settings objectForKey: @"Calendar"]; - webCalendars = [calendarSettings objectForKey: @"WebCalendars"]; - calendarIds = [webCalendars allKeys]; - max = [calendarIds count]; + us = [[SOGoUser userWithLogin: owner] userSettings]; + calSettings = [us objectForKey: @"Calendar"]; + refs = [[calSettings objectForKey: @"WebCalendars"] allKeys]; + max = [refs count]; for (count = 0; count < max; count++) { - name = [calendarIds objectAtIndex: count]; - folder = [self lookupName: name inContext: context acquire: NO]; + ref = [refs objectAtIndex: count]; + folder = [SOGoWebAppointmentFolder + folderWithSubscriptionReference: ref + inContainer: self]; if (folder - && [folder isKindOfClass: [SOGoWebAppointmentFolder class]] && (forceReload || [folder reloadOnLogin])) - [folder loadWebCalendar: [webCalendars objectForKey: name]]; + [folder loadWebCalendar]; } } +- (void) _migrateWebCalendarsSettings +{ + SOGoUserSettings *us; + NSDictionary *module; + NSMutableDictionary *webCalendars; + NSArray *keys; + NSString *oldKey, *prefix, *newKey; + int count, max; + BOOL hasChanged; + + hasChanged = NO; + + us = [[context activeUser] userSettings]; + module = [us objectForKey: @"Calendar"]; + webCalendars = [module objectForKey: @"WebCalendars"]; + keys = [webCalendars allKeys]; + max = [keys count]; + + prefix = [NSString stringWithFormat: @"%@:Calendar/", + [self ownerInContext: context]]; + for (count = 0; count < max; count++) + { + oldKey = [keys objectAtIndex: count]; + if (![oldKey hasPrefix: prefix]) + { + newKey = [prefix stringByAppendingString: oldKey]; + [webCalendars setObject: [webCalendars objectForKey: oldKey] + forKey: newKey]; + [webCalendars removeObjectForKey: oldKey]; + hasChanged = YES; + } + } + if (hasChanged) + [us synchronize]; +} + - (NSException *) _fetchPersonalFolders: (NSString *) sql withChannel: (EOAdaptorChannel *) fc { - int count, max; - NSArray *webCalendarIds; - NSString *name; - SOGoAppointmentFolder *old; - SOGoWebAppointmentFolder *folder; - NSException *error; BOOL isWebRequest; + NSException *error; + NSArray *folders; + int count, max; + SOGoAppointmentFolder *folder; + SOGoWebAppointmentFolder *webFolder; + NSString *name; - isWebRequest = [[context request] handledByDefaultHandler]; error = [super _fetchPersonalFolders: sql withChannel: fc]; if (!error) { - webCalendarIds = [self webCalendarIds]; - max = [webCalendarIds count]; + isWebRequest = [[context request] handledByDefaultHandler]; + folders = [subFolders allValues]; + max = [folders count]; + + [self _migrateWebCalendarsSettings]; for (count = 0; count < max; count++) { - name = [webCalendarIds objectAtIndex: count]; - if (isWebRequest) + folder = [folders objectAtIndex: count]; + if ([folder folderPropertyValueInCategory: @"WebCalendars"]) { - old = [subFolders objectForKey: name]; - if (old) + name = [folder nameInContainer]; + if (isWebRequest) { - folder = [SOGoWebAppointmentFolder objectWithName: name + webFolder = [SOGoWebAppointmentFolder objectWithName: name inContainer: self]; - [folder setOCSPath: [old ocsPath]]; - [subFolders setObject: folder forKey: name]; + [webFolder setOCSPath: [folder ocsPath]]; + [subFolders setObject: webFolder forKey: name]; } else - [self errorWithFormat: @"webcalendar inconsistency: folder with" - @" name '%@' was not found in the database," - @" conversion skipped", name]; + [subFolders removeObjectForKey: name]; } - else - [subFolders removeObjectForKey: name]; } } diff --git a/SoObjects/Appointments/SOGoWebAppointmentFolder.h b/SoObjects/Appointments/SOGoWebAppointmentFolder.h index e237da32a..b20ab1ce1 100644 --- a/SoObjects/Appointments/SOGoWebAppointmentFolder.h +++ b/SoObjects/Appointments/SOGoWebAppointmentFolder.h @@ -27,7 +27,7 @@ @interface SOGoWebAppointmentFolder : SOGoAppointmentFolder -- (int) loadWebCalendar: (NSString *) location; +- (int) loadWebCalendar; - (void) deleteAllContent; - (void) setReloadOnLogin: (BOOL) newReloadOnLogin; diff --git a/SoObjects/Appointments/SOGoWebAppointmentFolder.m b/SoObjects/Appointments/SOGoWebAppointmentFolder.m index e1cf35513..067bfe484 100644 --- a/SoObjects/Appointments/SOGoWebAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoWebAppointmentFolder.m @@ -36,16 +36,16 @@ [[self ocsFolder] deleteAllContent]; } -- (int) loadWebCalendar: (NSString *) location +- (int) loadWebCalendar { NSURL *url; NSData *data; - NSString *contents; + NSString *location, *contents; iCalCalendar *calendar; int imported = 0; + location = [self folderPropertyValueInCategory: @"WebCalendars"]; url = [NSURL URLWithString: location]; - if (url) { data = [url resourceDataUsingCache: NO]; @@ -89,20 +89,10 @@ - (NSException *) delete { NSException *error; - SOGoUserSettings *settings; - NSMutableDictionary *webCalendars; - NSString *name; error = [super delete]; if (!error) - { - settings = [[context activeUser] userSettings]; - webCalendars = [[settings objectForKey: @"Calendar"] - objectForKey: @"WebCalendars"]; - name = [self nameInContainer]; - [webCalendars removeObjectForKey: name]; - [settings synchronize]; - } + [self setFolderPropertyValue: nil inCategory: @"WebCalendars"]; return error; } diff --git a/UI/Scheduler/UIxCalMainActions.h b/UI/Scheduler/UIxCalMainActions.h index ee61f762a..d133e7fdf 100644 --- a/UI/Scheduler/UIxCalMainActions.h +++ b/UI/Scheduler/UIxCalMainActions.h @@ -27,9 +27,6 @@ @interface UIxCalMainActions : WODirectAction -- (void) saveUrl: (NSURL *) calendarURL - forCalendar: (NSString *) calendarName; - @end #endif /* UIXCALMAINACTIONS_H */ diff --git a/UI/Scheduler/UIxCalMainActions.m b/UI/Scheduler/UIxCalMainActions.m index 49dfb95a4..216db791c 100644 --- a/UI/Scheduler/UIxCalMainActions.m +++ b/UI/Scheduler/UIxCalMainActions.m @@ -61,7 +61,7 @@ WOResponse *response; SOGoWebAppointmentFolder *folder; NSURL *url; - NSString *name, *displayName; + NSString *urlString, *displayName; NSMutableDictionary *rc; SOGoAppointmentFolders *folders; int imported = 0; @@ -70,25 +70,21 @@ rc = [NSMutableDictionary dictionary]; // Just a check - url = [NSURL URLWithString: [r formValueForKey: @"url"]]; + urlString = [r formValueForKey: @"url"]; + url = [NSURL URLWithString: urlString]; if (url) { folders = [self clientObject]; displayName = [self displayNameForUrl: [r formValueForKey: @"url"]]; - [folders newFolderWithName: displayName - nameInContainer: &name]; - [self saveUrl: url forCalendar: name]; - folder = [folders lookupName: name - inContext: context - acquire: NO]; + folder = [folders newWebCalendarWithName: displayName + atURL: urlString]; if (folder) { - imported = [folder loadWebCalendar: [r formValueForKey: @"url"]]; - + imported = [folder loadWebCalendar]; if (imported >= 0) { [rc setObject: displayName forKey: @"displayname"]; - [rc setObject: name forKey: @"name"]; + [rc setObject: [folder nameInContainer] forKey: @"name"]; } else { @@ -104,24 +100,6 @@ return response; } -- (void) saveUrl: (NSURL *) calendarURL - forCalendar: (NSString *) calendarName -{ - SOGoUserSettings *settings; - NSMutableDictionary *calSettings, *webCalendars; - - settings = [[context activeUser] userSettings]; - calSettings = [settings objectForKey: @"Calendar"]; - webCalendars = [calSettings objectForKey: @"WebCalendars"]; - if (!webCalendars) - { - webCalendars = [NSMutableDictionary dictionary]; - [calSettings setObject: webCalendars forKey: @"WebCalendars"]; - } - [webCalendars setObject: [calendarURL absoluteString] forKey: calendarName]; - [settings synchronize]; -} - - (WOResponse *) reloadWebCalendarsAction { [[self clientObject] reloadWebCalendars: YES]; diff --git a/UI/Scheduler/UIxCalendarProperties.m b/UI/Scheduler/UIxCalendarProperties.m index 68d4f998d..9633f9f4e 100644 --- a/UI/Scheduler/UIxCalendarProperties.m +++ b/UI/Scheduler/UIxCalendarProperties.m @@ -177,24 +177,6 @@ [calendar setShowCalendarTasks: new]; } -- (NSString *) webCalendarURL -{ - SOGoUserSettings *settings; - NSMutableDictionary *calendarSettings; - NSMutableDictionary *webCalendars; - NSString *rc; - - settings = [[context activeUser] userSettings]; - calendarSettings = [settings objectForKey: @"Calendar"]; - webCalendars = [calendarSettings objectForKey: @"WebCalendars"]; - if (webCalendars) - rc = [webCalendars objectForKey: [calendar nameInContainer]]; - else - rc = nil; - - return rc; -} - - (BOOL) userIsOwner { NSString *userLogin; @@ -209,6 +191,11 @@ return ([calendar isKindOfClass: [SOGoWebAppointmentFolder class]]); } +- (NSString *) webCalendarURL +{ + return [calendar folderPropertyValueInCategory: @"WebCalendars"]; +} + - (void) setReloadOnLogin: (BOOL) newReloadOnLogin { if ([calendar respondsToSelector: @selector (setReloadOnLogin:)])