// // ABPerson.m // mySTEP // // Created by Dr. H. Nikolaus Schaller on Mon Aug 18 2003. // Copyright (c) 2003 DSITRI. All rights reserved. // #import #import "Private.h" @implementation ABPerson + (void) cancelLoadingImageDataForTag:(int) tag; { } - (id) initWithUniqueId:(id) uid; { self=[super initWithUniqueId:uid]; if(self) { parentgroups=[[NSMutableArray array] retain]; } return self; } - (id) init; { self=[super init]; if(self) { parentgroups=[[NSMutableArray array] retain]; } return self; } - (id) initWithVCardRepresentation:(NSData *) vCardData; { self=[super init]; if(self) { NSString *str=[[[NSString alloc] initWithData:vCardData encoding:NSUTF8StringEncoding] autorelease]; if(![self _decodeWithVCardScanner:[NSScanner scannerWithString:str] firstLine:nil]) { [self release]; return nil; } } return self; } - (void) dealloc; { [parentgroups release]; [super dealloc]; } - (void) _addToParentGroup:(ABGroup *) grp; { [parentgroups addObject:grp]; [self _touch]; } - (void) _removeFromParentGroup:(ABGroup *) grp; { [parentgroups removeObject:grp]; [self _touch]; } - (NSArray *) parentGroups; { return parentgroups; } - (NSString *) _imageFileName; { return [AB_IMAGES stringByAppendingPathComponent:[self uniqueId]]; } - (int) beginLoadingImageDataForClient:(id) client; { return 0; } - (BOOL) setImageData:(NSData *) d; { if(d) return [d writeToFile:[self _imageFileName] atomically:YES]; // remove file if existing return YES; } - (NSData*) imageData; { return [NSData dataWithContentsOfFile:[self _imageFileName]]; } // from ABImageClient protocol - (void) consumeImageData:(NSData*) data forTag:(int) tag; { } #if OLD - (NSString *) _stringForProperty:(NSString *) prop; { // get as printable string id val=[self valueForProperty:prop]; if(!val) return @""; return [val description]; } #endif - (NSString *) _vCardTag; { return @"VCARD"; } - (NSDictionary *) _propertiesToEncode; { // default properties and attributes return [NSDictionary dictionaryWithObjectsAndKeys: kABUIDProperty, @"UID", // @"CREATED", kCALCreatedProperty, // @"LASTMODIFIED", kCALModifiedProperty, // @"X-CALNAME", kCALCalendarNameProperty, kABPhoneProperty, @"TEL", kABEmailProperty, @"EMAIL", kABBirthdayProperty, @"BDAY", kABNoteProperty, @"NOTE", kABHomePageProperty, @"URL", kABTitleProperty, @"TITLE", kABJobTitleProperty, @"ROLE", kABOrganizationProperty, @"ORG", kABNicknameProperty, @"X-NICKNAME", kABMaidenNameProperty, @"X-MAIDENNAME", kABDepartmentProperty, @"X-DEPARTMENT", nil]; } - (void) _encodeVCard:(NSMutableString *) s; { NSEnumerator *e; ABGroup *g; [self _encodeTag:@"VERSION" attributes:nil value:@"3.0" to:s]; [self _encodeTag:@"PRODID" attributes:nil value:@"-//DSITRI, Germany//mySTEP 1.10//EN" to:s]; // hard coded [super _encodeVCard:s]; // FN, N // [self _appendLine:[self _formatTag:vCalProperty attributes:nil value:val] to:dest]; // ADR if([self imageData]) { // encode PHOTO as base64 data } e=[[self parentGroups] objectEnumerator]; while((g=[e nextObject])) [self _encodeTag:@"CATEGORIES" attributes:nil value:[g valueForProperty:kABGroupNameProperty] to:s]; } - (NSData *) vCardRepresentation; { NSMutableString *vc=[NSMutableString string]; [self _encodeTag:@"BEGIN" attributes:nil value:[self _vCardTag] to:vc]; [self _encodeVCard:vc]; [self _encodeTag:@"END" attributes:nil value:[self _vCardTag] to:vc]; return [vc dataUsingEncoding:NSUTF8StringEncoding]; } /* example of a vCard generated by MacOS X: BEGIN:VCARD VERSION:3.0 N:last;first;;; FN:first last EMAIL;type=INTERNET;type=HOME;type=pref:user@host.org TEL;type=CELL:+49123456789 TEL;type=HOME;type=pref:+49987654321 item1.ADR;type=HOME;type=pref:;;street number;city;;ZIP;country item1.X-ABADR:de item2.ADR;type=WORK:;;street number;city;;ZIP; item2.X-ABADR:de URL:www.dsitri.de BDAY;value=date:YYYY-MM-DD PHOTO;BASE64: TU0AKgAAAAgAFAD+AAQAAAABAAAAAAEAAAMAAAABADAAAAEBAAMAAAABADAAAAECAAMAAAADAAAA /gEDAAMAAAABAAEAAAEGAAMAAAABAAIAAAERAAQAAAABAAA9oAEVAAMAAAABAAMAAAEWAAMAAAAB .... //8AA6ABAAMAAAAB//8AAKACAAQAAAABAAAAMKADAAQAAAABAAAAMAAAAAAAAA== CATEGORY:group1,group2 END:VCARD */ #if OLD - (NSString *) _vCardEscape:(NSString *) str; { // escape '\n', ',', ';', '\' properly return str; } - (void) _appendTag:(NSString *) tag withProperty:(NSString *) prop toMutableString:(NSMutableString *) vc; { id val=[self valueForProperty:prop]; if(!val) return; // ignore if([val isKindOfClass:[ABMultiValue class]]) { int i, count=[val count]; for(i=0; i