From bf6f65b35a105355b7f94a04e4b7af795d4f8680 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 11 Sep 2007 20:14:18 +0000 Subject: [PATCH] Monotone-Parent: c5a12fa92d4b395d0d89e97ca85e5ad92a5b087f Monotone-Revision: 530d53ab46bac6f4062942cdd798d31ee1fead30 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-09-11T20:14:18 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 + SoObjects/SOGo/SOGoParentFolder.h | 50 +++++++ SoObjects/SOGo/SOGoParentFolder.m | 240 ++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+) create mode 100644 SoObjects/SOGo/SOGoParentFolder.h create mode 100644 SoObjects/SOGo/SOGoParentFolder.m diff --git a/ChangeLog b/ChangeLog index e960e5f61..4ad4b4474 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-09-11 Wolfgang Sourdeau + * SoObjects/SOGo/SOGoParentFolder.[hm]: new class module derived + from SOGoContactFolders and modified to be more content-independent. + * UI/MailerUI/UIxMailActions.m ([UIxMailActions -markMessageUnreadAction]) ([UIxMailActions -markMessageReadAction]): new methods moved from UIxMailListView and adapted to invoke the client object directly, diff --git a/SoObjects/SOGo/SOGoParentFolder.h b/SoObjects/SOGo/SOGoParentFolder.h new file mode 100644 index 000000000..5bbde0bc6 --- /dev/null +++ b/SoObjects/SOGo/SOGoParentFolder.h @@ -0,0 +1,50 @@ +/* SOGoParentFolder.h - this file is part of SOGo + * + * Copyright (C) 2006, 2007 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef SOGOPARENTFOLDERS_H +#define SOGOPARENTFOLDERS_H + +#import "SOGoObject.h" + +@class NSMutableDictionary; +@class NSString; +@class WOResponse; + +@interface SOGoParentFolder : SOGoObject +{ + NSMutableDictionary *subFolders; + NSString *OCSPath; + Class subFolderClass; +} + ++ (NSString *) gcsFolderType; ++ (Class) subFolderClass; + +- (void) setBaseOCSPath: (NSString *) newOCSPath; + +- (NSArray *) subFolders; + +- (NSException *) newFolderWithName: (NSString *) name; + +@end + +#endif /* SOGOPARENTFOLDERS_H */ diff --git a/SoObjects/SOGo/SOGoParentFolder.m b/SoObjects/SOGo/SOGoParentFolder.m new file mode 100644 index 000000000..2bd1f6963 --- /dev/null +++ b/SoObjects/SOGo/SOGoParentFolder.m @@ -0,0 +1,240 @@ +/* SOGoParentFolder.m - this file is part of SOGo + * + * Copyright (C) 2006, 2007 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import + +#import +#import +#import +#import +#import + +#import "SOGoFolder.h" + +#import "SOGoParentFolder.h" + +@implementation SOGoParentFolder + +- (id) init +{ + if ((self = [super init])) + { + subFolders = nil; + OCSPath = nil; + subFolderClass = Nil; + } + + return self; +} + +- (void) dealloc +{ + [subFolders release]; + [OCSPath release]; + [super dealloc]; +} + ++ (Class) subFolderClass +{ + [self subclassResponsibility: _cmd]; + + return Nil; +} + ++ (NSString *) gcsFolderType +{ + [self subclassResponsibility: _cmd]; + + return nil; +} + +- (void) setBaseOCSPath: (NSString *) newOCSPath +{ + ASSIGN (OCSPath, newOCSPath); +} + +- (void) _fetchPersonalFolders: (NSString *) sql + withChannel: (EOAdaptorChannel *) fc +{ + NSArray *attrs; + NSDictionary *row; + SOGoFolder *folder; + BOOL hasPersonal; + NSString *key, *path; + + if (!subFolderClass) + subFolderClass = [[self class] subFolderClass]; + + hasPersonal = NO; + [fc evaluateExpressionX: sql]; + attrs = [fc describeResults: NO]; + row = [fc fetchAttributes: attrs withZone: NULL]; + while (row) + { + folder + = [subFolderClass folderWithName: [row objectForKey: @"c_path4"] + andDisplayName: [row objectForKey: @"c_foldername"] + inContainer: self]; + key = [row objectForKey: @"c_path4"]; + hasPersonal = (hasPersonal || [key isEqualToString: @"personal"]); + [folder setOCSPath: [NSString stringWithFormat: @"%@/%@", + OCSPath, key]]; + [subFolders setObject: folder forKey: key]; + row = [fc fetchAttributes: attrs withZone: NULL]; + } + + if (!hasPersonal) + { + folder = [subFolderClass folderWithName: @"personal" + andDisplayName: @"personal" + inContainer: self]; + path = [NSString stringWithFormat: @"/Users/%@/%@/personal", + [self ownerInContext: context], + nameInContainer]; + [folder setOCSPath: path]; + [subFolders setObject: folder forKey: @"personal"]; + } +} + +- (void) appendPersonalSources +{ + GCSChannelManager *cm; + EOAdaptorChannel *fc; + NSURL *folderLocation; + NSString *sql, *gcsFolderType; + + cm = [GCSChannelManager defaultChannelManager]; + folderLocation + = [[GCSFolderManager defaultFolderManager] folderInfoLocation]; + fc = [cm acquireOpenChannelForURL: folderLocation]; + if (fc) + { + gcsFolderType = [[self class] gcsFolderType]; + + sql + = [NSString stringWithFormat: (@"SELECT c_path4, c_foldername FROM %@" + @" WHERE c_path2 = '%@'" + @" AND c_folder_type = '%@'"), + [folderLocation gcsTableName], + [self ownerInContext: context], + gcsFolderType]; + [self _fetchPersonalFolders: sql withChannel: fc]; + [cm releaseChannel: fc]; +// sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'", +// uidColumnName, [self uid]]; + } +} + +- (void) appendSystemSources +{ +} + +- (NSException *) newFolderWithName: (NSString *) name +{ + SOGoFolder *newFolder; + NSException *error; + + if (!subFolderClass) + subFolderClass = [[self class] subFolderClass]; + + newFolder = [subFolderClass folderWithName: name + andDisplayName: name + inContainer: self]; + if ([newFolder isKindOfClass: [NSException class]]) + error = (NSException *) newFolder; + else + { + [newFolder setOCSPath: [NSString stringWithFormat: @"%@/%@", + OCSPath, name]]; + if ([newFolder create]) + error = nil; + else + error = [NSException exceptionWithHTTPStatus: 400 + reason: @"The new folder could not be created"]; + } + + return error; +} + +- (void) initSubFolders +{ + if (!subFolders) + { + subFolders = [NSMutableDictionary new]; + [self appendPersonalSources]; + [self appendSystemSources]; + } +} + +- (id) lookupName: (NSString *) name + inContext: (WOContext *) lookupContext + acquire: (BOOL) acquire +{ + id obj; + + /* first check attributes directly bound to the application */ + obj = [super lookupName: name inContext: lookupContext acquire: NO]; + if (!obj) + { + if (!subFolders) + [self initSubFolders]; + + obj = [subFolders objectForKey: name]; + } + + return obj; +} + +- (NSArray *) toManyRelationshipKeys +{ + if (!subFolders) + [self initSubFolders]; + + return [subFolders allKeys]; +} + +- (NSArray *) subFolders +{ + if (!subFolders) + [self initSubFolders]; + + return [subFolders allValues]; +} + +/* acls */ +- (NSArray *) aclsForUser: (NSString *) uid +{ + return nil; +} + +- (BOOL) davIsCollection +{ + return YES; +} + +- (NSString *) davContentType +{ + return @"httpd/unix-directory"; +} + +@end