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 "NGVCardAddress.h"
25 @implementation NGVCardAddress
27 - (id)initWithDictionary:(NSDictionary *)_plist group:(NSString *)_group
28 types:(NSArray *)_types arguments:(NSDictionary *)_a
30 if ((self = [super initWithGroup:_group types:_types arguments:_a]) != nil) {
31 self->pobox = [[_plist objectForKey:@"pobox"] copy];
32 self->extadd = [[_plist objectForKey:@"extadd"] copy];
33 self->street = [[_plist objectForKey:@"street"] copy];
34 self->locality = [[_plist objectForKey:@"locality"] copy];
35 self->region = [[_plist objectForKey:@"region"] copy];
36 self->pcode = [[_plist objectForKey:@"pcode"] copy];
37 self->country = [[_plist objectForKey:@"country"] copy];
41 - (id)initWithPropertyList:(id)_plist group:(NSString *)_group
42 types:(NSArray *)_types arguments:(NSDictionary *)_a
44 return [self initWithDictionary:_plist
45 group:_group types:_types arguments:_a];
48 - (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
49 arguments:(NSDictionary *)_a
51 return [self initWithPropertyList:nil
52 group:_group types:_types arguments:_a];
55 return [self initWithPropertyList:nil group:nil types:nil arguments:nil];
59 [self->pobox release];
60 [self->extadd release];
61 [self->street release];
62 [self->locality release];
63 [self->region release];
64 [self->pcode release];
65 [self->country release];
74 - (NSString *)extadd {
77 - (NSString *)street {
80 - (NSString *)locality {
81 return self->locality;
83 - (NSString *)region {
89 - (NSString *)country {
93 /* fake being an array */
95 - (id)objectAtIndex:(unsigned)_idx {
99 case 0: return (s = [self pobox]) ? s : (NSString *)[NSNull null];
100 case 1: return (s = [self extadd]) ? s : (NSString *)[NSNull null];
101 case 2: return (s = [self street]) ? s : (NSString *)[NSNull null];
102 case 3: return (s = [self locality]) ? s : (NSString *)[NSNull null];
103 case 4: return (s = [self region]) ? s : (NSString *)[NSNull null];
104 case 5: return (s = [self pcode]) ? s : (NSString *)[NSNull null];
105 case 6: return (s = [self country]) ? s : (NSString *)[NSNull null];
108 // TODO: throw exception
117 - (NSString *)stringValue {
118 return [self vCardString];
121 - (NSString *)xmlString {
125 ms = [[NSMutableString alloc] initWithCapacity:256];
126 [self appendXMLTag:@"pobox" value:[self pobox] to:ms];
127 [self appendXMLTag:@"extadd" value:[self extadd] to:ms];
128 [self appendXMLTag:@"street" value:[self street] to:ms];
129 [self appendXMLTag:@"locality" value:[self locality] to:ms];
130 [self appendXMLTag:@"region" value:[self region] to:ms];
131 [self appendXMLTag:@"pcode" value:[self pcode] to:ms];
132 [self appendXMLTag:@"country" value:[self country] to:ms];
133 s = [[ms copy] autorelease];
138 - (NSString *)vCardString {
142 ms = [[NSMutableString alloc] initWithCapacity:256];
143 [self appendVCardValue:[self pobox] to:ms]; [ms appendString:@";"];
144 [self appendVCardValue:[self extadd] to:ms]; [ms appendString:@";"];
145 [self appendVCardValue:[self street] to:ms]; [ms appendString:@";"];
146 [self appendVCardValue:[self locality] to:ms]; [ms appendString:@";"];
147 [self appendVCardValue:[self region] to:ms]; [ms appendString:@";"];
148 [self appendVCardValue:[self pcode] to:ms]; [ms appendString:@";"];
149 [self appendVCardValue:[self country] to:ms];
150 s = [[ms copy] autorelease];
155 - (NSDictionary *)asDictionary {
156 static NSString *keys[] = {
157 @"pobox", @"extadd", @"street", @"locality", @"region", @"pcode",
163 for (i = 0; i < [self count]; i++)
164 values[i] = [self objectAtIndex:i];
166 return [NSDictionary dictionaryWithObjects:values forKeys:keys
170 - (NSArray *)asArray {
171 id values[[self count] + 1];
174 for (i = 0; i < [self count]; i++)
175 values[i] = [self objectAtIndex:i];
177 return [NSArray arrayWithObjects:values count:[self count]];
182 - (void)encodeWithCoder:(NSCoder *)_coder {
183 [super encodeWithCoder:_coder];
185 [_coder encodeObject:self->pobox];
186 [_coder encodeObject:self->extadd];
187 [_coder encodeObject:self->street];
188 [_coder encodeObject:self->locality];
189 [_coder encodeObject:self->region];
190 [_coder encodeObject:self->pcode];
191 [_coder encodeObject:self->country];
193 - (id)initWithCoder:(NSCoder *)_coder {
194 if ((self = [super initWithCoder:_coder]) != nil) {
195 self->pobox = [[_coder decodeObject] copy];
196 self->extadd = [[_coder decodeObject] copy];
197 self->street = [[_coder decodeObject] copy];
198 self->locality = [[_coder decodeObject] copy];
199 self->region = [[_coder decodeObject] copy];
200 self->pcode = [[_coder decodeObject] copy];
201 self->country = [[_coder decodeObject] copy];
208 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
209 [super appendAttributesToDescription:_ms];
210 [_ms appendFormat:@" vcard=%@", [self vCardString]];
213 @end /* NGVCardAddress */