From c0369494d1be4448ddeea55a800d67893d97ae46 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 29 Mar 2007 17:12:44 +0000 Subject: [PATCH] Monotone-Parent: ce3c09cbf962262c8c3d04cf4422dbd4ded3a5c9 Monotone-Revision: 76a1bb772c883ebc00f5cdb177c280f729babb70 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-03-29T17:12:44 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 11 ++ UI/Contacts/UIxContactFoldersView.m | 250 +++++++++++++++++++--------- UI/Scheduler/UIxCalMainView.m | 16 -- 3 files changed, 183 insertions(+), 94 deletions(-) diff --git a/ChangeLog b/ChangeLog index d0aae3cc5..dc5eafdf5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-03-29 Wolfgang Sourdeau + + * UI/Contacts/UIxContactFoldersView.m ([UIxContactFoldersView + -checkRightsAction]): removed method. + + * UI/Contacts/UIxContactFoldersView.m ([UIxContactFoldersView + -updateAdditionalAddressBooksAction]): removed method. + + * UI/Scheduler/UIxCalMainView.m ([UIxCalMainView + -updateCalendarsAction]): removed method. + 2007-03-28 Wolfgang Sourdeau * UI/Scheduler/UIxCalMainView.m ([UIxCalMainView diff --git a/UI/Contacts/UIxContactFoldersView.m b/UI/Contacts/UIxContactFoldersView.m index 88534001d..c8bad5f96 100644 --- a/UI/Contacts/UIxContactFoldersView.m +++ b/UI/Contacts/UIxContactFoldersView.m @@ -27,11 +27,15 @@ #import #import +#import +#import + #import #import #import #import #import +#import #import "common.h" @@ -84,32 +88,13 @@ return response; } -- (id) selectForSchedulerAction -{ - return [self _selectActionForApplication: @"scheduler-contacts"]; -} - -- (id) selectForMailerAction -{ - return [self _selectActionForApplication: @"mailer-contacts"]; -} - -- (id) selectForCalendarsAction -{ - return [self _selectActionForApplication: @"calendars-contacts"]; -} - -- (id) selectForAddressBooksAction -{ - return [self _selectActionForApplication: @"addressbooks-contacts"]; -} - - (id) selectForAclsAction { return [self _selectActionForApplication: @"acls-contacts"]; } - (NSArray *) _searchResults: (NSString *) contact + ldapFoldersOnly: (BOOL) ldapFoldersOnly { NSMutableArray *results; SOGoContactFolders *topFolder; @@ -124,10 +109,12 @@ currentFolder = [sogoContactFolders nextObject]; while (currentFolder) { - [results addObjectsFromArray: [currentFolder - lookupContactsWithFilter: contact - sortBy: @"cn" - ordering: NSOrderedAscending]]; + if (!ldapFoldersOnly + || [currentFolder isKindOfClass: [SOGoContactLDAPFolder class]]) + [results addObjectsFromArray: [currentFolder + lookupContactsWithFilter: contact + sortBy: @"cn" + ordering: NSOrderedAscending]]; currentFolder = [sogoContactFolders nextObject]; } [topFolder release]; @@ -202,10 +189,169 @@ { NSString *contact; id result; + BOOL ldapFoldersOnly; contact = [self queryParameterForKey: @"search"]; - if ([contact length]) - result = [self _responseForResults: [self _searchResults: contact]]; + ldapFoldersOnly = [[self queryParameterForKey: @"ldap-only"] boolValue]; + if ([contact length] > 0) + result + = [self _responseForResults: [self _searchResults: contact + ldapFoldersOnly: ldapFoldersOnly]]; + else + result = [NSException exceptionWithHTTPStatus: 400 + reason: @"missing 'search' parameter"]; + + return result; +} + +- (NSArray *) _gcsFoldersFromFolder: (SOGoContactFolders *) contactFolders +{ + NSMutableArray *gcsFolders; + NSEnumerator *contactSubfolders; + SOGoContactGCSFolder *currentContactFolder; + NSString *folderName, *displayName; + NSMutableDictionary *currentDictionary; + + gcsFolders = [NSMutableArray new]; + [gcsFolders autorelease]; + + contactSubfolders = [[contactFolders contactFolders] objectEnumerator]; + currentContactFolder = [contactSubfolders nextObject]; + while (currentContactFolder) + { + if ([currentContactFolder + isKindOfClass: [SOGoContactGCSFolder class]]) + { + folderName = [NSString stringWithFormat: @"/Contacts/%@", + [currentContactFolder nameInContainer]]; + currentDictionary = [NSMutableDictionary new]; + [currentDictionary autorelease]; + displayName = [[currentContactFolder ocsFolder] folderName]; + [currentDictionary setObject: displayName forKey: @"displayName"]; + [currentDictionary setObject: folderName forKey: @"name"]; + [currentDictionary setObject: @"contact" forKey: @"type"]; + [gcsFolders addObject: currentDictionary]; + } + currentContactFolder = [contactSubfolders nextObject]; + } + + return gcsFolders; +} + +- (NSArray *) _foldersForUID: (NSString *) uid + ofType: (NSString *) folderType +{ + NSObject *topFolder, *userFolder; + SOGoContactFolders *contactFolders; + NSMutableArray *folders; + NSMutableDictionary *currentDictionary; + + folders = [NSMutableArray new]; + [folders autorelease]; + + topFolder = [[[self clientObject] container] container]; + userFolder = [topFolder lookupName: uid inContext: context acquire: NO]; + + /* FIXME: should be moved in the SOGo* classes. Maybe by having a SOGoFolderManager. */ +#warning this might need adjustments whenever we permit multiple calendar folders per-user + if ([folderType length] == 0 || [folderType isEqualToString: @"calendar"]) + { + currentDictionary = [NSMutableDictionary new]; + [currentDictionary autorelease]; + [currentDictionary setObject: [self labelForKey: @"Calendar"] + forKey: @"displayName"]; + [currentDictionary setObject: @"/Calendar" forKey: @"name"]; + [currentDictionary setObject: @"calendar" forKey: @"type"]; + [folders addObject: currentDictionary]; + } + if ([folderType length] == 0 || [folderType isEqualToString: @"contact"]) + { + contactFolders = [userFolder lookupName: @"Contacts" + inContext: context acquire: NO]; + [folders + addObjectsFromArray: [self _gcsFoldersFromFolder: contactFolders]]; + } + + return folders; +} + +- (NSString *) _foldersStringForFolders: (NSEnumerator *) folders +{ + NSMutableString *foldersString; + NSDictionary *currentFolder; + + foldersString = [NSMutableString new]; + [foldersString autorelease]; + + currentFolder = [folders nextObject]; + while (currentFolder) + { + [foldersString appendFormat: @";%@:%@:%@", + [currentFolder objectForKey: @"displayName"], + [currentFolder objectForKey: @"name"], + [currentFolder objectForKey: @"type"]]; + currentFolder = [folders nextObject]; + } + + return foldersString; +} + +- (WOResponse *) _foldersResponseForResults: (NSArray *) results + withType: (NSString *) folderType +{ + WOResponse *response; + NSString *uid, *foldersString; + NSMutableString *responseString; + NSDictionary *result; + NSEnumerator *resultsEnum; + NSArray *folders; + + response = [context response]; + + if ([results count]) + { + [response setStatus: 200]; + [response setHeader: @"text/plain; charset=iso-8859-1" + forKey: @"Content-Type"]; + + responseString = [NSMutableString new]; + resultsEnum = [results objectEnumerator]; + result = [resultsEnum nextObject]; + while (result) + { + uid = [result objectForKey: @"c_uid"]; + folders = [self _foldersForUID: uid ofType: folderType]; + foldersString + = [self _foldersStringForFolders: [folders objectEnumerator]]; + [responseString appendFormat: @"%@:%@%@\n", + uid, [self _emailForResult: result], foldersString]; + result = [resultsEnum nextObject]; + } + [response appendContentString: responseString]; + [responseString release]; + } + else + [response setStatus: 404]; + + return response; +} + +- (id ) foldersSearchAction +{ + NSString *contact, *folderType; + id result; + BOOL ldapOnly; + + contact = [self queryParameterForKey: @"search"]; + if ([contact length] > 0) + { + ldapOnly = [[self queryParameterForKey: @"ldap-only"] boolValue]; + folderType = [self queryParameterForKey: @"type"]; + result = [self _foldersResponseForResults: + [self _searchResults: contact + ldapFoldersOnly: ldapOnly] + withType: folderType]; + } else result = [NSException exceptionWithHTTPStatus: 400 reason: @"missing 'search' parameter"]; @@ -213,22 +359,6 @@ return result; } -- (id ) updateAdditionalAddressBooksAction -{ - WOResponse *response; - NSUserDefaults *ud; - - ud = [[context activeUser] userDefaults]; - [ud setObject: [self queryParameterForKey: @"ids"] - forKey: @"additionaladdressbooks"]; - [ud synchronize]; - response = [context response]; - [response setStatus: 200]; - [response setHeader: @"text/html; charset=\"utf-8\"" forKey: @"content-type"]; - - return response; -} - - (SOGoContactGCSFolder *) contactFolderForUID: (NSString *) uid { SOGoFolder *upperContainer; @@ -256,40 +386,4 @@ ? contactFolder : nil); } -- (id ) checkRightsAction -{ - WOResponse *response; - NSUserDefaults *ud; - NSString *uids; - NSMutableString *rights; - NSArray *ids; - unsigned int count, max; - BOOL result; - - ud = [[context activeUser] userDefaults]; - uids = [ud objectForKey: @"additionaladdressbooks"]; - - response = [context response]; - [response setStatus: 200]; - [response setHeader: @"text/plain; charset=\"utf-8\"" - forKey: @"content-type"]; - rights = [NSMutableString string]; - if ([uids length] > 0) - { - ids = [uids componentsSeparatedByString: @","]; - max = [ids count]; - for (count = 0; count < max; count++) - { - result = ([self contactFolderForUID: [ids objectAtIndex: count]] != nil); - if (count == 0) - [rights appendFormat: @"%d", result]; - else - [rights appendFormat: @",%d", result]; - } - } - [response appendContentString: rights]; - - return response; -} - @end diff --git a/UI/Scheduler/UIxCalMainView.m b/UI/Scheduler/UIxCalMainView.m index 642f34714..80b66f66d 100644 --- a/UI/Scheduler/UIxCalMainView.m +++ b/UI/Scheduler/UIxCalMainView.m @@ -114,20 +114,4 @@ static NSMutableArray *yearMenuItems = nil; return self; } -- (id ) updateCalendarsAction -{ - WOResponse *response; - NSUserDefaults *ud; - - ud = [[context activeUser] userDefaults]; - [ud setObject: [self queryParameterForKey: @"ids"] - forKey: @"calendaruids"]; - [ud synchronize]; - response = [context response]; - [response setStatus: 200]; - [response setHeader: @"text/html; charset=\"utf-8\"" forKey: @"content-type"]; - - return response; -} - @end