]> err.no Git - sope/blob - sope-ical/NGiCal/NGVCardOrg.m
e76e56b58502b7537b895b17f81ab57feba480bc
[sope] / sope-ical / NGiCal / NGVCardOrg.m
1 /*
2   Copyright (C) 2005 Helge Hess
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "NGVCardOrg.h"
23 #include "common.h"
24
25 @implementation NGVCardOrg
26
27 - (void)dealloc {
28   [self->orgnam   release];
29   [self->orgunits release];
30   [super dealloc];
31 }
32
33 /* accessors */
34
35 - (NSString *)orgnam {
36   return self->orgnam;
37 }
38 - (NSArray *)orgunits {
39   return self->orgunits;
40 }
41
42 /* fake being an array */
43
44 - (id)objectAtIndex:(unsigned)_idx {
45   NSString *s;
46
47   if (_idx == 0)
48     return (s = [self orgnam]) ? s : (NSString *)[NSNull null];
49   
50   return [self->orgunits objectAtIndex:(_idx - 1)];
51 }
52 - (unsigned)count {
53   return 1 + [self->orgunits count];
54 }
55
56 /* values */
57
58 - (NSString *)stringValue {
59   return [self vCardString];
60 }
61
62 - (NSString *)xmlString {
63   NSMutableString *ms;
64   NSString *s;
65   unsigned i;
66   
67   ms = [[NSMutableString alloc] initWithCapacity:256];
68   [self appendXMLTag:@"orgnam" value:[self orgnam] to:ms];
69   
70   for (i = 0; i < [self->orgunits count]; i++) {
71     [self appendXMLTag:@"orgunit" value:[self->orgunits objectAtIndex:i]
72           to:ms];
73   }
74   s = [[ms copy] autorelease];
75   [ms release];
76   return s;
77 }
78
79 - (NSString *)vCardString {
80   NSMutableString *ms;
81   NSString *s;
82   unsigned i;
83   
84   ms = [[NSMutableString alloc] initWithCapacity:64];
85   [self appendVCardValue:[self orgnam] to:ms];
86   for (i = 0; i < [self->orgunits count]; i++) {
87     [ms appendString:@";"];
88     [self appendVCardValue:[self->orgunits objectAtIndex:i] to:ms];
89   }
90   s = [[ms copy] autorelease];
91   [ms release];
92   return s;
93 }
94
95 - (NSDictionary *)asDictionary {
96   static NSString *keys[2] = { @"orgnam", @"orgunits" };
97   id values[2];
98   
99   values[0] = [self orgnam];
100   values[1] = [self orgunits];
101   
102   return [NSDictionary dictionaryWithObjects:values forKeys:keys 
103                        count:[self count]];
104 }
105
106 - (NSArray *)asArray {
107   id values[[self count] + 1];
108   unsigned i;
109
110   for (i = 0; i < [self count]; i++)
111     values[i] = [self objectAtIndex:i];
112   
113   return [NSArray arrayWithObjects:values count:[self count]];
114 }
115
116 /* NSCoding */
117
118 - (void)encodeWithCoder:(NSCoder *)_coder {
119   [super encodeWithCoder:_coder];
120   
121   [_coder encodeObject:self->orgnam];
122   [_coder encodeObject:self->orgunits];
123 }
124 - (id)initWithCoder:(NSCoder *)_coder {
125   if ((self = [super initWithCoder:_coder]) != nil) {
126     self->orgnam   = [[_coder decodeObject] copy];
127     self->orgunits = [[_coder decodeObject] copy];
128   }
129   return self;
130 }
131
132 /* description */
133
134 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
135   [super appendAttributesToDescription:_ms];
136 }
137
138 @end /* NGVCardOrg */