Monotone-Parent: c29edea33f25c719bad972e23d7441b3851b8164

Monotone-Revision: 9ddb8a8c0200ef2ba32370aff1ace4928f5fad1c

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2006-08-09T21:14:38
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2006-08-09 21:14:38 +00:00
parent fac49e4f69
commit 3c07b3040b
5 changed files with 138 additions and 223 deletions

View File

@ -1,5 +1,8 @@
2006-08-09 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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.

View File

@ -0,0 +1,39 @@
/* SOGoContactGCSEntry.h - this file is part of SOGo
*
* Copyright (C) 2006 Inverse groupe conseil
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* 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 <SOGo/SOGoContentObject.h>
#import "SOGoContactObject.h"
@class NGVCard;
@interface SOGoContactGCSEntry : SOGoContentObject <SOGoContactObject>
{
NGVCard *card;
}
@end
#endif /* SOGOCONTACTGCSENTRY_H */

View File

@ -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 <Foundation/NSArray.h>
#import <Foundation/NSString.h>
#import <NGiCal/NGVCard.h>
#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 */

View File

@ -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 <SOGo/SOGoContentObject.h>
/*
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__ */

View File

@ -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 <NGiCal/NGVCard.h>
#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 */