From 3c69a1b0a483aef8103f74034b05afafb67c1fa1 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 9 Feb 2007 21:18:28 +0000 Subject: [PATCH] Monotone-Parent: ff18846f2110faddb36e8f63098fe42762b93818 Monotone-Revision: b6904285a3ff5bf86b7f88d154e2996c86c0124e Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-02-09T21:18:28 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 ++ SoObjects/Contacts/SOGoContactFolders.m | 73 +++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index b49ad551f..796124ba8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-02-09 Wolfgang Sourdeau + * SoObjects/Contacts/SOGoContactFolders.m ([SOGoContactFolders + -appendPersonalSourcesInContext:context]): we now fetch all + folders with type "Contact" that belong to the current user. + ([SOGoContactFolders -newFolderWithName:name]): new method to + create a new contact folder. + * UI/SOGoUI/UIxComponent.m ([UIxComponent -userFolderPath]): treat resulting url with [NSString+Utilities hostlessURL] instead of using NSURL. This is because the url in question sometimes has a diff --git a/SoObjects/Contacts/SOGoContactFolders.m b/SoObjects/Contacts/SOGoContactFolders.m index e47adecb1..1ac25ca1c 100644 --- a/SoObjects/Contacts/SOGoContactFolders.m +++ b/SoObjects/Contacts/SOGoContactFolders.m @@ -36,6 +36,11 @@ #import #import +#import +#import +#import +#import + #import #import "common.h" @@ -69,13 +74,69 @@ - (void) appendPersonalSourcesInContext: (WOContext *) context; { SOGoContactGCSFolder *ab; + GCSChannelManager *cm; + EOAdaptorChannel *fc; + NSURL *folderLocation; + NSString *sql; + NSArray *attrs; + NSDictionary *row; - ab = [SOGoContactGCSFolder contactFolderWithName: @"personal" - andDisplayName: @"Personal Addressbook" - inContainer: self]; - [ab setOCSPath: [NSString stringWithFormat: @"%@/%@", - OCSPath, @"personal"]]; - [contactFolders setObject: ab forKey: @"personal"]; + cm = [GCSChannelManager defaultChannelManager]; + folderLocation + = [[GCSFolderManager defaultFolderManager] folderInfoLocation]; + fc = [cm acquireOpenChannelForURL: folderLocation]; + if (fc) + { + sql + = [NSString stringWithFormat: @"SELECT c_path4, c_foldername FROM %@" + @" WHERE c_path2 = '%@' AND c_folder_type = 'Contact'", + [folderLocation gcsTableName], + [self ownerInContext: nil]]; + [fc evaluateExpressionX: sql]; + attrs = [fc describeResults: NO]; + row = [fc fetchAttributes: attrs withZone: NULL]; + while (row) + { + ab = [SOGoContactGCSFolder contactFolderWithName: [row objectForKey: @"c_path4"] + andDisplayName: [row objectForKey: @"c_foldername"] + inContainer: self]; + [ab setOCSPath: [NSString stringWithFormat: @"%@/%@", + OCSPath, [row objectForKey: @"c_path4"]]]; + [contactFolders setObject: ab forKey: [row objectForKey: @"c_path4"]]; + row = [fc fetchAttributes: attrs withZone: NULL]; + } + +// sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'", +// uidColumnName, [self uid]]; + } +} + +- (WOResponse *) newFolderWithName: (NSString *) name +{ + SOGoContactGCSFolder *newFolder; + WOResponse *response; + + newFolder = [SOGoContactGCSFolder contactFolderWithName: name + andDisplayName: name + inContainer: [self clientObject]]; + if ([newFolder isKindOfClass: [NSException class]]) + response = (WOResponse *) newFolder; + else + { + [newFolder setOCSPath: [NSString stringWithFormat: @"%@/%@", + OCSPath, name]]; + if ([newFolder create]) + { + response = [WOResponse new]; + [response setStatus: 201]; + [response autorelease]; + } + else + response = [NSException exceptionWithHTTPStatus: 400 + reason: @"The new folder could not be created"]; + } + + return response; } - (void) appendSystemSourcesInContext: (WOContext *) context;