diff --git a/ChangeLog b/ChangeLog index 011198a0e..c2bffab6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-08-09 Wolfgang Sourdeau + * SoObjects/Contacts/SOGoContactGCSEntry.[hm]: new module name of + "SOGoContactObject". + * SoObjects/Contacts/NGVCard+Contact.m ([NGVCard -asString]): new method that generates a textual representation of the vcard. diff --git a/SoObjects/Contacts/SOGoContactGCSEntry.h b/SoObjects/Contacts/SOGoContactGCSEntry.h new file mode 100644 index 000000000..4ebfeac33 --- /dev/null +++ b/SoObjects/Contacts/SOGoContactGCSEntry.h @@ -0,0 +1,39 @@ +/* SOGoContactGCSEntry.h - this file is part of SOGo + * + * Copyright (C) 2006 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 SOGOCONTACTGCSENTRY_H +#define SOGOCONTACTGCSENTRY_H + +#import + +#import "SOGoContactObject.h" + +@class NGVCard; + +@interface SOGoContactGCSEntry : SOGoContentObject +{ + NGVCard *card; +} + +@end + +#endif /* SOGOCONTACTGCSENTRY_H */ diff --git a/SoObjects/Contacts/SOGoContactGCSEntry.m b/SoObjects/Contacts/SOGoContactGCSEntry.m new file mode 100644 index 000000000..cde28dd90 --- /dev/null +++ b/SoObjects/Contacts/SOGoContactGCSEntry.m @@ -0,0 +1,96 @@ +/* + Copyright (C) 2004-2005 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#import +#import + +#import + +#import "NGVCard+Contact.h" + +#import "SOGoContactGCSEntry.h" + +@implementation SOGoContactGCSEntry + +- (id) init +{ + if ((self = [super init])) + { + card = nil; + } + + return self; +} + +- (void) dealloc +{ + if (card) + [card release]; + [super dealloc]; +} + +/* content */ + +- (NGVCard *) vCard +{ + NSArray *cards; + NSString *contentStr; + + if (!card) + { + contentStr = [self contentAsString]; + if ([contentStr hasPrefix:@"BEGIN:VCARD"]) + { + cards = [NGVCard parseVCardsFromSource: contentStr]; + if ([cards count] > 0) + card = [cards objectAtIndex: 0]; + } + } + + return card; +} + +/* DAV */ + +- (NSString *) davContentType +{ + return @"text/x-vcard"; +} + +/* specialized actions */ + +- (NSException *) save +{ + NGVCard *vcard; + + vcard = [self vCard]; + + return [self saveContentString: [vcard asString]]; +} + +/* message type */ + +- (NSString *) outlookMessageClass +{ + return @"IPM.Contact"; +} + +@end /* SOGoContactGCSEntry */ diff --git a/SoObjects/Contacts/SOGoContactObject.h b/SoObjects/Contacts/SOGoContactObject.h deleted file mode 100644 index 372dfb5e5..000000000 --- a/SoObjects/Contacts/SOGoContactObject.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (C) 2004-2005 SKYRIX Software AG - - This file is part of OpenGroupware.org. - - OGo is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - OGo 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 Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with OGo; see the file COPYING. If not, write to the - Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. -*/ - -#ifndef __Contacts_SOGoContactObject_H__ -#define __Contacts_SOGoContactObject_H__ - -#include - -/* - SOGoContactObject - - Represents a single contact. This SOPE controller object manages all the - attendee storages (that is, it might store into multiple folders for meeting - appointments!). - - Note: SOGoContactObject do not need to exist yet. They can also be "new" - appointments with an externally generated unique key. -*/ - -@class NSDictionary; -@class NGVCard; - -@interface SOGoContactObject : SOGoContentObject -{ - id record; /* either an NSMutableDictionary or a NGVCard */ -} - -/* accessors */ - -- (id)record; -- (BOOL)isVCardRecord; -- (NGVCard *)vCard; - -- (NSException *) saveRecord: (id) _record; - -@end - -#endif /* __Contacts_SOGoContactObject_H__ */ diff --git a/SoObjects/Contacts/SOGoContactObject.m b/SoObjects/Contacts/SOGoContactObject.m deleted file mode 100644 index 124fdfc8d..000000000 --- a/SoObjects/Contacts/SOGoContactObject.m +++ /dev/null @@ -1,167 +0,0 @@ -/* - Copyright (C) 2004-2005 SKYRIX Software AG - - This file is part of OpenGroupware.org. - - OGo is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. - - OGo 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 Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with OGo; see the file COPYING. If not, write to the - Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. -*/ - -#import - -#import "common.h" -#import "SOGoContactObject.h" -#import "NSDictionary+Contact.h" - -@implementation SOGoContactObject - -- (void)dealloc { - [self->record release]; - [super dealloc]; -} - -/* content */ - -- (id) record { - if (self->record == nil) { - NSString *s; - - s = [self contentAsString]; - - if ([s hasPrefix:@"BEGIN:VCARD"]) { - NSArray *v; - - v = [NGVCard parseVCardsFromSource:s]; - if ([v count] == 0) { - [self errorWithFormat:@"Could not parse vCards from content!"]; - return nil; - } - - self->record = [[v objectAtIndex:0] retain]; - } - else - self->record = [[s propertyList] copy]; - - if (self->record == nil) - self->record = [[NSNull null] retain]; - } - return [self->record isNotNull] ? self->record : nil; -} - -- (BOOL)isVCardRecord { - return [[self record] isKindOfClass:[NGVCard class]]; -} - -- (NGVCard *)vCard { - return [[self record] isKindOfClass:[NGVCard class]] - ? [self record] - : nil; -} - -/* key value coding */ - -- (id)valueForKey:(NSString *)_key { - id value; - - if ((value = [[self record] valueForKey:_key]) != nil) - return value; - - return [super valueForKey:_key]; -} - -/* DAV */ - -- (NSString *)davDisplayName { - NSString *n; - - if ((n = [self valueForKey:@"cn"])) - return n; - - return [self nameInContainer]; -} - -/* specialized actions */ - -- (NSException *) saveRecord: (id) _record -{ - if ([_record isKindOfClass:[NGVCard class]]) { - // TODO: implement a vCard generator - return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */ - reason:@"Saving vCards is not supported yet."]; - } - -// return [self saveContentString: [_record description]]; - return - [self saveContentString: [_record vcardContentFromSOGoContactRecord]]; -} - -- (NSException *)patchField:(NSString *)_fname value:(NSString *)_value - inContext:(id)_ctx -{ - NSMutableDictionary *md; - - if ([self isVCardRecord]) { - return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */ - reason:@"Changing vCards is not supported yet."]; - } - - if ([_fname length] == 0) { - return [NSException exceptionWithHTTPStatus:400 /* Bad Request */ - reason:@"missing form field name"]; - } - - if ((md = [[[self record] mutableCopy] autorelease]) == nil) { - return [NSException exceptionWithHTTPStatus:404 /* Not Found */ - reason:@"did not find contact record"]; - } - - [md setObject:[_value isNotNull] ? _value : @"" forKey:_fname]; - - return [self saveRecord:md]; -} - -- (id)patchOneFieldAction:(id)_ctx { - /* - expects: fieldname\nfieldvalue - - TODO: should be extended to properly parse XML. - */ - NSArray *fields; - NSException *error; - - fields = [[[(WOContext *)_ctx request] contentAsString] - componentsSeparatedByString:@"\n"]; - - if ([fields count] < 2) { - return [NSException exceptionWithHTTPStatus:400 /* Bad Request */ - reason:@"missing form fields"]; - } - - error = [self patchField:[fields objectAtIndex:0] - value:[fields objectAtIndex:1] - inContext:_ctx]; - if (error != nil) - return error; - - return [(WOContext *)_ctx response]; -} - -/* message type */ - -- (NSString *)outlookMessageClass { - return @"IPM.Contact"; -} - -@end /* SOGoContactObject */