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
27 - (id)initWithPropertyList:(id)_plist group:(NSString *)_group
28 types:(NSArray *)_types arguments:(NSDictionary *)_a
30 if ((self = [super initWithGroup:_group types:_types arguments:_a]) != nil) {
31 self->family = [[_plist objectForKey:@"family"] copy];
32 self->given = [[_plist objectForKey:@"given"] copy];
33 self->other = [[_plist objectForKey:@"other"] copy];
34 self->prefix = [[_plist objectForKey:@"prefix"] copy];
35 self->suffix = [[_plist objectForKey:@"suffix"] copy];
40 - (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
41 arguments:(NSDictionary *)_a
43 return [self initWithPropertyList:nil
44 group:_group types:_types arguments:_a];
47 return [self initWithPropertyList:nil group:nil types:nil arguments:nil];
51 [self->family release];
52 [self->given release];
53 [self->other release];
54 [self->prefix release];
55 [self->suffix release];
61 - (NSString *)family {
70 - (NSString *)prefix {
73 - (NSString *)suffix {
77 /* fake being an array */
79 - (id)objectAtIndex:(unsigned)_idx {
83 case 0: return (s = [self family]) ? s : (NSString *)[NSNull null];
84 case 1: return (s = [self given]) ? s : (NSString *)[NSNull null];
85 case 2: return (s = [self other]) ? s : (NSString *)[NSNull null];
86 case 3: return (s = [self prefix]) ? s : (NSString *)[NSNull null];
87 case 4: return (s = [self suffix]) ? s : (NSString *)[NSNull null];
90 // TODO: throw exception
99 - (NSString *)stringValue {
100 return [self vCardString];
103 - (NSString *)xmlString {
107 ms = [[NSMutableString alloc] initWithCapacity:256];
108 [self appendXMLTag:@"family" value:[self family] to:ms];
109 [self appendXMLTag:@"given" value:[self given] to:ms];
110 [self appendXMLTag:@"other" value:[self other] to:ms];
111 [self appendXMLTag:@"prefix" value:[self prefix] to:ms];
112 [self appendXMLTag:@"suffix" value:[self suffix] to:ms];
113 s = [[ms copy] autorelease];
118 - (NSString *)vCardString {
122 ms = [[NSMutableString alloc] initWithCapacity:256];
123 [self appendVCardValue:[self family] to:ms]; [ms appendString:@";"];
124 [self appendVCardValue:[self given] to:ms]; [ms appendString:@";"];
125 [self appendVCardValue:[self other] to:ms]; [ms appendString:@";"];
126 [self appendVCardValue:[self prefix] to:ms]; [ms appendString:@";"];
127 [self appendVCardValue:[self suffix] to:ms];
128 s = [[ms copy] autorelease];
133 - (NSDictionary *)asDictionary {
134 static NSString *keys[] = {
135 @"family", @"given", @"other", @"prefix", @"suffix", nil
137 id values[[self count] + 1];
140 for (i = 0; i < [self count]; i++)
141 values[i] = [self objectAtIndex:i];
143 return [NSDictionary dictionaryWithObjects:values forKeys:keys
147 - (NSArray *)asArray {
148 id values[[self count] + 1];
151 for (i = 0; i < [self count]; i++)
152 values[i] = [self objectAtIndex:i];
154 return [NSArray arrayWithObjects:values count:[self count]];
158 return [self asDictionary];
163 - (void)encodeWithCoder:(NSCoder *)_coder {
164 [super encodeWithCoder:_coder];
166 [_coder encodeObject:self->family];
167 [_coder encodeObject:self->given];
168 [_coder encodeObject:self->other];
169 [_coder encodeObject:self->prefix];
170 [_coder encodeObject:self->suffix];
172 - (id)initWithCoder:(NSCoder *)_coder {
173 if ((self = [super initWithCoder:_coder]) != nil) {
174 self->family = [[_coder decodeObject] copy];
175 self->given = [[_coder decodeObject] copy];
176 self->other = [[_coder decodeObject] copy];
177 self->prefix = [[_coder decodeObject] copy];
178 self->suffix = [[_coder decodeObject] copy];
185 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
186 [super appendAttributesToDescription:_ms];
187 [_ms appendFormat:@" vcard=%@", [self vCardString]];
190 @end /* NGVCardName */