2 Copyright (C) 2005 Helge Hess
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "NGVCardName.h"
25 @implementation NGVCardName
28 return [super version] + 0 /* v0 */;
31 NSAssert2([super version] == 0,
32 @"invalid superclass (%@) version %i !",
33 NSStringFromClass([self superclass]), [super version]);
36 - (id)initWithPropertyList:(id)_plist group:(NSString *)_group
37 types:(NSArray *)_types arguments:(NSDictionary *)_a
39 if ((self = [super initWithGroup:_group types:_types arguments:_a]) != nil) {
40 self->family = [[_plist objectForKey:@"family"] copy];
41 self->given = [[_plist objectForKey:@"given"] copy];
42 self->other = [[_plist objectForKey:@"other"] copy];
43 self->prefix = [[_plist objectForKey:@"prefix"] copy];
44 self->suffix = [[_plist objectForKey:@"suffix"] copy];
49 - (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
50 arguments:(NSDictionary *)_a
52 return [self initWithPropertyList:nil
53 group:_group types:_types arguments:_a];
56 return [self initWithPropertyList:nil group:nil types:nil arguments:nil];
60 [self->family release];
61 [self->given release];
62 [self->other release];
63 [self->prefix release];
64 [self->suffix release];
70 - (NSString *)family {
79 - (NSString *)prefix {
82 - (NSString *)suffix {
86 /* fake being an array */
88 - (id)objectAtIndex:(unsigned)_idx {
92 case 0: return (s = [self family]) ? s : (NSString *)[NSNull null];
93 case 1: return (s = [self given]) ? s : (NSString *)[NSNull null];
94 case 2: return (s = [self other]) ? s : (NSString *)[NSNull null];
95 case 3: return (s = [self prefix]) ? s : (NSString *)[NSNull null];
96 case 4: return (s = [self suffix]) ? s : (NSString *)[NSNull null];
99 // TODO: throw exception
108 - (NSString *)stringValue {
109 return [self vCardString];
112 - (NSString *)xmlString {
116 ms = [[NSMutableString alloc] initWithCapacity:256];
117 [self appendXMLTag:@"family" value:[self family] to:ms];
118 [self appendXMLTag:@"given" value:[self given] to:ms];
119 [self appendXMLTag:@"other" value:[self other] to:ms];
120 [self appendXMLTag:@"prefix" value:[self prefix] to:ms];
121 [self appendXMLTag:@"suffix" value:[self suffix] to:ms];
122 s = [[ms copy] autorelease];
127 - (NSString *)vCardString {
131 ms = [[NSMutableString alloc] initWithCapacity:256];
132 [self appendVCardValue:[self family] to:ms]; [ms appendString:@";"];
133 [self appendVCardValue:[self given] to:ms]; [ms appendString:@";"];
134 [self appendVCardValue:[self other] to:ms]; [ms appendString:@";"];
135 [self appendVCardValue:[self prefix] to:ms]; [ms appendString:@";"];
136 [self appendVCardValue:[self suffix] to:ms];
137 s = [[ms copy] autorelease];
142 - (NSDictionary *)asDictionary {
143 static NSString *keys[] = {
144 @"family", @"given", @"other", @"prefix", @"suffix", nil
146 id values[[self count] + 1];
149 for (i = 0; i < [self count]; i++)
150 values[i] = [self objectAtIndex:i];
152 return [NSDictionary dictionaryWithObjects:values forKeys:keys
156 - (NSArray *)asArray {
157 id values[[self count] + 1];
160 for (i = 0; i < [self count]; i++)
161 values[i] = [self objectAtIndex:i];
163 return [NSArray arrayWithObjects:values count:[self count]];
167 return [self asDictionary];
172 - (void)encodeWithCoder:(NSCoder *)_coder {
173 [super encodeWithCoder:_coder];
175 [_coder encodeObject:self->family];
176 [_coder encodeObject:self->given];
177 [_coder encodeObject:self->other];
178 [_coder encodeObject:self->prefix];
179 [_coder encodeObject:self->suffix];
181 - (id)initWithCoder:(NSCoder *)_coder {
182 if ((self = [super initWithCoder:_coder]) != nil) {
183 self->family = [[_coder decodeObject] copy];
184 self->given = [[_coder decodeObject] copy];
185 self->other = [[_coder decodeObject] copy];
186 self->prefix = [[_coder decodeObject] copy];
187 self->suffix = [[_coder decodeObject] copy];
194 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
195 [super appendAttributesToDescription:_ms];
196 [_ms appendFormat:@" vcard=%@", [self vCardString]];
199 @end /* NGVCardName */