/* Copyright (C) 2000-2004 Max Berger This file is part of OGo 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. */ // $Id$ #include "common.h" #include "OGoVCard.h" @interface OGoVCardTel : NSObject { NSString *content; NSString *type; } @end @implementation OGoVCardTel - (void)dealloc { [content release]; [type release]; [super dealloc]; } @end @implementation OGoVCard - (id)init { if ((self = [super init])) { self->contents = [[NSMutableDictionary alloc]init]; } return self; } - (void)dealloc { [contents release]; [super dealloc]; } - (void)_setContentValue:(id)value forKey:(NSString *)key { if ([value length]>0) [self->contents setObject:value forKey:key]; } - (void)_mapType:(NSString *)type andValue:(NSString *)value intoTelDict:(NSMutableDictionary *)dict { NSEnumerator *typeEnum = [[[type lowercaseString] componentsSeparatedByString:@" "]objectEnumerator]; id typeStr; BOOL voice = YES; BOOL home = YES; BOOL cell = NO; BOOL pref = NO; NSString *primary = @"02_tel"; NSString *secondary = @"01_tel"; NSString *use; while ((typeStr = [typeEnum nextObject])) { if ([typeStr isEqual:@"voice"]) voice = YES; else if ([typeStr isEqual:@"fax"]) voice = NO; else if ([typeStr isEqual:@"pref"]) pref = YES; else if ([typeStr isEqual:@"home"]) home = YES; else if ([typeStr isEqual:@"work"]) home = NO; else if ([typeStr isEqual:@"cell"]) cell = YES; } if (voice) { if (cell) { primary = @"03_tel_funk"; secondary = @"02_tel"; } else { if (home) { primary = @"05_tel_private"; secondary = @"02_tel"; } else { primary = @"01_tel"; secondary = @"02_tel"; } } } else { if (home) { primary = @"15_fax_private"; secondary = @"10_fax"; } else { primary = @"10_fax"; secondary = @"15_fax_private"; } } use = primary; if ([dict objectForKey:primary]) use = secondary; if ([dict objectForKey:secondary]) { //FIXME NSLog(@"to many phone numbers!"); } [dict setObject:value forKey:use]; } - (void)setValue:(id)value forKey:(NSString *)key { if ([key isEqual:@"n"]) { [self _setContentValue:[value objectForKey:@"family"] forKey:@"name"]; [self _setContentValue:[value objectForKey:@"given"] forKey:@"givenName"]; [self _setContentValue:[value objectForKey:@"other"] forKey:@"middleName"]; //[self _setContentValue:[value objectForKey:@"prefix"] forKey:@"FIXME"]; //[self _setContentValue:[value objectForKey:@"suffix"] forKey:@"FIXME"]; } else if ([key isEqual:@"nickname"]) [self _setContentValue:value forKey:@"nickname"]; else if ([key isEqual:@"url"]) [self _setContentValue:value forKey:@"url"]; else if ([key isEqual:@"tel"]) { NSMutableDictionary *phoneNumbers = [self->contents objectForKey:@"phoneNumbers"]; if (phoneNumbers == nil) { phoneNumbers = [[[NSMutableDictionary alloc]init]autorelease]; [self->contents setObject:phoneNumbers forKey:@"phoneNumbers"]; } [self _mapType:[value valueForKey:@"type"] andValue:[value valueForKey:@"content"] intoTelDict:phoneNumbers]; } } - (void)takeValue:(id)value forKey:(NSString *)key { [self setValue:value forKey:key]; } - (id)valueForKey:(NSString *)key { return nil; } - (NSDictionary *)info { return contents; } @end;