Monotone-Parent: fc267c7dc09cc05decc140411d1facce3f441866
Monotone-Revision: c2a5265bbdaf7810309bda5f2f3dd5f2c67b15ed

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2010-06-11T18:43:46
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2010-06-11 18:43:46 +00:00
parent bfcaea41c0
commit 676194b020
8 changed files with 130 additions and 123 deletions

View File

@ -1,5 +1,21 @@
2010-06-11 Wolfgang Sourdeau <wsourdeau@inverse.ca> 2010-06-11 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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 * UI/Scheduler/UIxCalFilterPanel.m (+initialize): commented out
the "All Events" option as this could cause a delay too long in IE the "All Events" option as this could cause a delay too long in IE
when drawing the list. when drawing the list.

View File

@ -27,12 +27,16 @@
@class NSArray; @class NSArray;
@class SOGoWebAppointmentFolder;
@interface SOGoAppointmentFolders : SOGoParentFolder @interface SOGoAppointmentFolders : SOGoParentFolder
{ {
NSMutableArray *folderObjectKeys; NSMutableArray *folderObjectKeys;
} }
- (NSArray *) webCalendarIds; - (SOGoWebAppointmentFolder *) newWebCalendarWithName: (NSString *) folderDisplayName
atURL: (NSString *) url;
- (void) reloadWebCalendars: (BOOL) forceReload; - (void) reloadWebCalendars: (BOOL) forceReload;
- (BOOL) hasProxyCalendarsWithWriteAccess: (BOOL) write - (BOOL) hasProxyCalendarsWithWriteAccess: (BOOL) write

View File

@ -96,6 +96,30 @@
return [self labelForKey: @"Personal Calendar" inContext: context]; 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 - (NSArray *) toManyRelationshipKeys
{ {
NSMutableArray *keys; NSMutableArray *keys;
@ -348,91 +372,102 @@
return componentSet; 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 - (void) reloadWebCalendars: (BOOL) forceReload
{ {
SOGoUserSettings *settings; NSArray *refs;
NSMutableDictionary *calendarSettings, *webCalendars;
NSArray *calendarIds;
SOGoWebAppointmentFolder *folder; SOGoWebAppointmentFolder *folder;
NSString *name; SOGoUserSettings *us;
NSDictionary *calSettings;
NSString *ref;
int count, max; int count, max;
settings = [[SOGoUser userWithLogin: owner] userSettings]; us = [[SOGoUser userWithLogin: owner] userSettings];
calendarSettings = [settings objectForKey: @"Calendar"]; calSettings = [us objectForKey: @"Calendar"];
webCalendars = [calendarSettings objectForKey: @"WebCalendars"]; refs = [[calSettings objectForKey: @"WebCalendars"] allKeys];
calendarIds = [webCalendars allKeys]; max = [refs count];
max = [calendarIds count];
for (count = 0; count < max; count++) for (count = 0; count < max; count++)
{ {
name = [calendarIds objectAtIndex: count]; ref = [refs objectAtIndex: count];
folder = [self lookupName: name inContext: context acquire: NO]; folder = [SOGoWebAppointmentFolder
folderWithSubscriptionReference: ref
inContainer: self];
if (folder if (folder
&& [folder isKindOfClass: [SOGoWebAppointmentFolder class]]
&& (forceReload || [folder reloadOnLogin])) && (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 - (NSException *) _fetchPersonalFolders: (NSString *) sql
withChannel: (EOAdaptorChannel *) fc withChannel: (EOAdaptorChannel *) fc
{ {
int count, max;
NSArray *webCalendarIds;
NSString *name;
SOGoAppointmentFolder *old;
SOGoWebAppointmentFolder *folder;
NSException *error;
BOOL isWebRequest; 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]; error = [super _fetchPersonalFolders: sql withChannel: fc];
if (!error) if (!error)
{ {
webCalendarIds = [self webCalendarIds]; isWebRequest = [[context request] handledByDefaultHandler];
max = [webCalendarIds count]; folders = [subFolders allValues];
max = [folders count];
[self _migrateWebCalendarsSettings];
for (count = 0; count < max; count++) for (count = 0; count < max; count++)
{ {
name = [webCalendarIds objectAtIndex: count]; folder = [folders objectAtIndex: count];
if (isWebRequest) if ([folder folderPropertyValueInCategory: @"WebCalendars"])
{ {
old = [subFolders objectForKey: name]; name = [folder nameInContainer];
if (old) if (isWebRequest)
{ {
folder = [SOGoWebAppointmentFolder objectWithName: name webFolder = [SOGoWebAppointmentFolder objectWithName: name
inContainer: self]; inContainer: self];
[folder setOCSPath: [old ocsPath]]; [webFolder setOCSPath: [folder ocsPath]];
[subFolders setObject: folder forKey: name]; [subFolders setObject: webFolder forKey: name];
} }
else else
[self errorWithFormat: @"webcalendar inconsistency: folder with" [subFolders removeObjectForKey: name];
@" name '%@' was not found in the database,"
@" conversion skipped", name];
} }
else
[subFolders removeObjectForKey: name];
} }
} }

View File

@ -27,7 +27,7 @@
@interface SOGoWebAppointmentFolder : SOGoAppointmentFolder @interface SOGoWebAppointmentFolder : SOGoAppointmentFolder
- (int) loadWebCalendar: (NSString *) location; - (int) loadWebCalendar;
- (void) deleteAllContent; - (void) deleteAllContent;
- (void) setReloadOnLogin: (BOOL) newReloadOnLogin; - (void) setReloadOnLogin: (BOOL) newReloadOnLogin;

View File

@ -36,16 +36,16 @@
[[self ocsFolder] deleteAllContent]; [[self ocsFolder] deleteAllContent];
} }
- (int) loadWebCalendar: (NSString *) location - (int) loadWebCalendar
{ {
NSURL *url; NSURL *url;
NSData *data; NSData *data;
NSString *contents; NSString *location, *contents;
iCalCalendar *calendar; iCalCalendar *calendar;
int imported = 0; int imported = 0;
location = [self folderPropertyValueInCategory: @"WebCalendars"];
url = [NSURL URLWithString: location]; url = [NSURL URLWithString: location];
if (url) if (url)
{ {
data = [url resourceDataUsingCache: NO]; data = [url resourceDataUsingCache: NO];
@ -89,20 +89,10 @@
- (NSException *) delete - (NSException *) delete
{ {
NSException *error; NSException *error;
SOGoUserSettings *settings;
NSMutableDictionary *webCalendars;
NSString *name;
error = [super delete]; error = [super delete];
if (!error) if (!error)
{ [self setFolderPropertyValue: nil inCategory: @"WebCalendars"];
settings = [[context activeUser] userSettings];
webCalendars = [[settings objectForKey: @"Calendar"]
objectForKey: @"WebCalendars"];
name = [self nameInContainer];
[webCalendars removeObjectForKey: name];
[settings synchronize];
}
return error; return error;
} }

View File

@ -27,9 +27,6 @@
@interface UIxCalMainActions : WODirectAction @interface UIxCalMainActions : WODirectAction
- (void) saveUrl: (NSURL *) calendarURL
forCalendar: (NSString *) calendarName;
@end @end
#endif /* UIXCALMAINACTIONS_H */ #endif /* UIXCALMAINACTIONS_H */

View File

@ -61,7 +61,7 @@
WOResponse *response; WOResponse *response;
SOGoWebAppointmentFolder *folder; SOGoWebAppointmentFolder *folder;
NSURL *url; NSURL *url;
NSString *name, *displayName; NSString *urlString, *displayName;
NSMutableDictionary *rc; NSMutableDictionary *rc;
SOGoAppointmentFolders *folders; SOGoAppointmentFolders *folders;
int imported = 0; int imported = 0;
@ -70,25 +70,21 @@
rc = [NSMutableDictionary dictionary]; rc = [NSMutableDictionary dictionary];
// Just a check // Just a check
url = [NSURL URLWithString: [r formValueForKey: @"url"]]; urlString = [r formValueForKey: @"url"];
url = [NSURL URLWithString: urlString];
if (url) if (url)
{ {
folders = [self clientObject]; folders = [self clientObject];
displayName = [self displayNameForUrl: [r formValueForKey: @"url"]]; displayName = [self displayNameForUrl: [r formValueForKey: @"url"]];
[folders newFolderWithName: displayName folder = [folders newWebCalendarWithName: displayName
nameInContainer: &name]; atURL: urlString];
[self saveUrl: url forCalendar: name];
folder = [folders lookupName: name
inContext: context
acquire: NO];
if (folder) if (folder)
{ {
imported = [folder loadWebCalendar: [r formValueForKey: @"url"]]; imported = [folder loadWebCalendar];
if (imported >= 0) if (imported >= 0)
{ {
[rc setObject: displayName forKey: @"displayname"]; [rc setObject: displayName forKey: @"displayname"];
[rc setObject: name forKey: @"name"]; [rc setObject: [folder nameInContainer] forKey: @"name"];
} }
else else
{ {
@ -104,24 +100,6 @@
return response; 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 - (WOResponse *) reloadWebCalendarsAction
{ {
[[self clientObject] reloadWebCalendars: YES]; [[self clientObject] reloadWebCalendars: YES];

View File

@ -177,24 +177,6 @@
[calendar setShowCalendarTasks: new]; [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 - (BOOL) userIsOwner
{ {
NSString *userLogin; NSString *userLogin;
@ -209,6 +191,11 @@
return ([calendar isKindOfClass: [SOGoWebAppointmentFolder class]]); return ([calendar isKindOfClass: [SOGoWebAppointmentFolder class]]);
} }
- (NSString *) webCalendarURL
{
return [calendar folderPropertyValueInCategory: @"WebCalendars"];
}
- (void) setReloadOnLogin: (BOOL) newReloadOnLogin - (void) setReloadOnLogin: (BOOL) newReloadOnLogin
{ {
if ([calendar respondsToSelector: @selector (setReloadOnLogin:)]) if ([calendar respondsToSelector: @selector (setReloadOnLogin:)])