-rw-r--r-- | kabc/vcardformatimpl.cpp | 11 | ||||
-rw-r--r-- | kabc/vcardformatimpl.h | 5 |
2 files changed, 16 insertions, 0 deletions
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index 1bf2cde..ede5773 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp | |||
@@ -1,850 +1,861 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <qfile.h> | 28 | #include <qfile.h> |
29 | #include <qregexp.h> | 29 | #include <qregexp.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <kmdcodec.h> | 32 | #include <kmdcodec.h> |
33 | #include <kstandarddirs.h> | 33 | #include <kstandarddirs.h> |
34 | #include <ktempfile.h> | 34 | #include <ktempfile.h> |
35 | 35 | ||
36 | #include <VCard.h> | 36 | #include <VCard.h> |
37 | 37 | ||
38 | #include "addressbook.h" | 38 | #include "addressbook.h" |
39 | #include "vcardformatimpl.h" | 39 | #include "vcardformatimpl.h" |
40 | 40 | ||
41 | using namespace KABC; | 41 | using namespace KABC; |
42 | using namespace VCARD; | 42 | using namespace VCARD; |
43 | 43 | ||
44 | int VCardFormatImpl::debug = -1; | ||
45 | |||
46 | VCardFormatImpl::VCardFormatImpl() | ||
47 | { | ||
48 | debug = (getenv("KABC_DEBUG") != 0); | ||
49 | } | ||
50 | |||
44 | bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) | 51 | bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) |
45 | { | 52 | { |
46 | kdDebug(5700) << "VCardFormat::load()" << endl; | 53 | kdDebug(5700) << "VCardFormat::load()" << endl; |
47 | 54 | ||
48 | QByteArray fdata = file->readAll(); | 55 | QByteArray fdata = file->readAll(); |
49 | QCString data(fdata.data(), fdata.size()+1); | 56 | QCString data(fdata.data(), fdata.size()+1); |
50 | 57 | ||
51 | VCardEntity e( data ); | 58 | VCardEntity e( data ); |
52 | 59 | ||
53 | VCardListIterator it( e.cardList() ); | 60 | VCardListIterator it( e.cardList() ); |
54 | 61 | ||
55 | if ( it.current() ) { | 62 | if ( it.current() ) { |
56 | //US VCard v(*it.current()); | 63 | //US VCard v(*it.current()); |
57 | //US loadAddressee( addressee, v ); | 64 | //US loadAddressee( addressee, v ); |
58 | loadAddressee( addressee, it.current() ); | 65 | loadAddressee( addressee, it.current() ); |
59 | return true; | 66 | return true; |
60 | } | 67 | } |
61 | 68 | ||
62 | return false; | 69 | return false; |
63 | } | 70 | } |
64 | 71 | ||
65 | bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) | 72 | bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) |
66 | { | 73 | { |
67 | kdDebug(5700) << "VCardFormat::loadAll()" << endl; | 74 | kdDebug(5700) << "VCardFormat::loadAll()" << endl; |
68 | 75 | ||
69 | QByteArray fdata = file->readAll(); | 76 | QByteArray fdata = file->readAll(); |
70 | QCString data(fdata.data(), fdata.size()+1); | 77 | QCString data(fdata.data(), fdata.size()+1); |
71 | 78 | ||
72 | VCardEntity e( data ); | 79 | VCardEntity e( data ); |
73 | 80 | ||
74 | VCardListIterator it( e.cardList() ); | 81 | VCardListIterator it( e.cardList() ); |
75 | 82 | ||
76 | for (; it.current(); ++it) { | 83 | for (; it.current(); ++it) { |
77 | //US VCard v(*it.current()); | 84 | //US VCard v(*it.current()); |
78 | Addressee addressee; | 85 | Addressee addressee; |
79 | //US loadAddressee( addressee, v ); | 86 | //US loadAddressee( addressee, v ); |
80 | loadAddressee( addressee, it.current() ); | 87 | loadAddressee( addressee, it.current() ); |
81 | addressee.setResource( resource ); | 88 | addressee.setResource( resource ); |
82 | addressBook->insertAddressee( addressee ); | 89 | addressBook->insertAddressee( addressee ); |
90 | if (debug == true) | ||
91 | { | ||
92 | printf("address %s loaded successfully\n", addressee.formattedName().latin1()); | ||
93 | } | ||
83 | } | 94 | } |
84 | 95 | ||
85 | return true; | 96 | return true; |
86 | } | 97 | } |
87 | 98 | ||
88 | void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) | 99 | void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) |
89 | { | 100 | { |
90 | VCardEntity vcards; | 101 | VCardEntity vcards; |
91 | VCardList vcardlist; | 102 | VCardList vcardlist; |
92 | vcardlist.setAutoDelete( true ); | 103 | vcardlist.setAutoDelete( true ); |
93 | 104 | ||
94 | VCard *v = new VCard; | 105 | VCard *v = new VCard; |
95 | 106 | ||
96 | saveAddressee( addressee, v, false ); | 107 | saveAddressee( addressee, v, false ); |
97 | 108 | ||
98 | vcardlist.append( v ); | 109 | vcardlist.append( v ); |
99 | vcards.setCardList( vcardlist ); | 110 | vcards.setCardList( vcardlist ); |
100 | 111 | ||
101 | QCString vcardData = vcards.asString(); | 112 | QCString vcardData = vcards.asString(); |
102 | file->writeBlock( (const char*)vcardData, vcardData.length() ); | 113 | file->writeBlock( (const char*)vcardData, vcardData.length() ); |
103 | } | 114 | } |
104 | 115 | ||
105 | void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) | 116 | void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) |
106 | { | 117 | { |
107 | VCardEntity vcards; | 118 | VCardEntity vcards; |
108 | VCardList vcardlist; | 119 | VCardList vcardlist; |
109 | vcardlist.setAutoDelete( true ); | 120 | vcardlist.setAutoDelete( true ); |
110 | 121 | ||
111 | AddressBook::Iterator it; | 122 | AddressBook::Iterator it; |
112 | for ( it = ab->begin(); it != ab->end(); ++it ) { | 123 | for ( it = ab->begin(); it != ab->end(); ++it ) { |
113 | if ( (*it).resource() == resource ) { | 124 | if ( (*it).resource() == resource ) { |
114 | VCard *v = new VCard; | 125 | VCard *v = new VCard; |
115 | saveAddressee( (*it), v, false ); | 126 | saveAddressee( (*it), v, false ); |
116 | (*it).setChanged( false ); | 127 | (*it).setChanged( false ); |
117 | vcardlist.append( v ); | 128 | vcardlist.append( v ); |
118 | } | 129 | } |
119 | } | 130 | } |
120 | 131 | ||
121 | vcards.setCardList( vcardlist ); | 132 | vcards.setCardList( vcardlist ); |
122 | 133 | ||
123 | QCString vcardData = vcards.asString(); | 134 | QCString vcardData = vcards.asString(); |
124 | file->writeBlock( (const char*)vcardData, vcardData.length() ); | 135 | file->writeBlock( (const char*)vcardData, vcardData.length() ); |
125 | } | 136 | } |
126 | 137 | ||
127 | bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) | 138 | bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) |
128 | { | 139 | { |
129 | QPtrList<ContentLine> contentLines = v->contentLineList(); | 140 | QPtrList<ContentLine> contentLines = v->contentLineList(); |
130 | ContentLine *cl; | 141 | ContentLine *cl; |
131 | 142 | ||
132 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { | 143 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { |
133 | QCString n = cl->name(); | 144 | QCString n = cl->name(); |
134 | if ( n.left( 2 ) == "X-" ) { | 145 | if ( n.left( 2 ) == "X-" ) { |
135 | n = n.mid( 2 ); | 146 | n = n.mid( 2 ); |
136 | int posDash = n.find( "-" ); | 147 | int posDash = n.find( "-" ); |
137 | addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), | 148 | addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), |
138 | QString::fromUtf8( n.mid( posDash + 1 ) ), | 149 | QString::fromUtf8( n.mid( posDash + 1 ) ), |
139 | QString::fromUtf8( cl->value()->asString() ) ); | 150 | QString::fromUtf8( cl->value()->asString() ) ); |
140 | continue; | 151 | continue; |
141 | } | 152 | } |
142 | 153 | ||
143 | EntityType type = cl->entityType(); | 154 | EntityType type = cl->entityType(); |
144 | switch( type ) { | 155 | switch( type ) { |
145 | 156 | ||
146 | case EntityUID: | 157 | case EntityUID: |
147 | addressee.setUid( readTextValue( cl ) ); | 158 | addressee.setUid( readTextValue( cl ) ); |
148 | break; | 159 | break; |
149 | 160 | ||
150 | case EntityEmail: | 161 | case EntityEmail: |
151 | addressee.insertEmail( readTextValue( cl ) ); | 162 | addressee.insertEmail( readTextValue( cl ) ); |
152 | break; | 163 | break; |
153 | 164 | ||
154 | case EntityName: | 165 | case EntityName: |
155 | addressee.setName( readTextValue( cl ) ); | 166 | addressee.setName( readTextValue( cl ) ); |
156 | break; | 167 | break; |
157 | 168 | ||
158 | case EntityFullName: | 169 | case EntityFullName: |
159 | addressee.setFormattedName( readTextValue( cl ) ); | 170 | addressee.setFormattedName( readTextValue( cl ) ); |
160 | break; | 171 | break; |
161 | 172 | ||
162 | case EntityURL: | 173 | case EntityURL: |
163 | addressee.setUrl( KURL( readTextValue( cl ) ) ); | 174 | addressee.setUrl( KURL( readTextValue( cl ) ) ); |
164 | break; | 175 | break; |
165 | 176 | ||
166 | case EntityNickname: | 177 | case EntityNickname: |
167 | addressee.setNickName( readTextValue( cl ) ); | 178 | addressee.setNickName( readTextValue( cl ) ); |
168 | break; | 179 | break; |
169 | 180 | ||
170 | case EntityLabel: | 181 | case EntityLabel: |
171 | // not yet supported by kabc | 182 | // not yet supported by kabc |
172 | break; | 183 | break; |
173 | 184 | ||
174 | case EntityMailer: | 185 | case EntityMailer: |
175 | addressee.setMailer( readTextValue( cl ) ); | 186 | addressee.setMailer( readTextValue( cl ) ); |
176 | break; | 187 | break; |
177 | 188 | ||
178 | case EntityTitle: | 189 | case EntityTitle: |
179 | addressee.setTitle( readTextValue( cl ) ); | 190 | addressee.setTitle( readTextValue( cl ) ); |
180 | break; | 191 | break; |
181 | 192 | ||
182 | case EntityRole: | 193 | case EntityRole: |
183 | addressee.setRole( readTextValue( cl ) ); | 194 | addressee.setRole( readTextValue( cl ) ); |
184 | break; | 195 | break; |
185 | 196 | ||
186 | case EntityOrganisation: | 197 | case EntityOrganisation: |
187 | addressee.setOrganization( readTextValue( cl ) ); | 198 | addressee.setOrganization( readTextValue( cl ) ); |
188 | break; | 199 | break; |
189 | 200 | ||
190 | case EntityNote: | 201 | case EntityNote: |
191 | addressee.setNote( readTextValue( cl ) ); | 202 | addressee.setNote( readTextValue( cl ) ); |
192 | break; | 203 | break; |
193 | 204 | ||
194 | case EntityProductID: | 205 | case EntityProductID: |
195 | addressee.setProductId( readTextValue( cl ) ); | 206 | addressee.setProductId( readTextValue( cl ) ); |
196 | break; | 207 | break; |
197 | 208 | ||
198 | case EntitySortString: | 209 | case EntitySortString: |
199 | addressee.setSortString( readTextValue( cl ) ); | 210 | addressee.setSortString( readTextValue( cl ) ); |
200 | break; | 211 | break; |
201 | 212 | ||
202 | case EntityN: | 213 | case EntityN: |
203 | readNValue( cl, addressee ); | 214 | readNValue( cl, addressee ); |
204 | break; | 215 | break; |
205 | 216 | ||
206 | case EntityAddress: | 217 | case EntityAddress: |
207 | addressee.insertAddress( readAddressValue( cl ) ); | 218 | addressee.insertAddress( readAddressValue( cl ) ); |
208 | break; | 219 | break; |
209 | 220 | ||
210 | case EntityTelephone: | 221 | case EntityTelephone: |
211 | addressee.insertPhoneNumber( readTelephoneValue( cl ) ); | 222 | addressee.insertPhoneNumber( readTelephoneValue( cl ) ); |
212 | break; | 223 | break; |
213 | 224 | ||
214 | case EntityCategories: | 225 | case EntityCategories: |
215 | addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); | 226 | addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); |
216 | break; | 227 | break; |
217 | 228 | ||
218 | case EntityBirthday: | 229 | case EntityBirthday: |
219 | addressee.setBirthday( readDateValue( cl ) ); | 230 | addressee.setBirthday( readDateValue( cl ) ); |
220 | break; | 231 | break; |
221 | 232 | ||
222 | case EntityRevision: | 233 | case EntityRevision: |
223 | addressee.setRevision( readDateTimeValue( cl ) ); | 234 | addressee.setRevision( readDateTimeValue( cl ) ); |
224 | break; | 235 | break; |
225 | 236 | ||
226 | case EntityGeo: | 237 | case EntityGeo: |
227 | addressee.setGeo( readGeoValue( cl ) ); | 238 | addressee.setGeo( readGeoValue( cl ) ); |
228 | break; | 239 | break; |
229 | 240 | ||
230 | case EntityTimeZone: | 241 | case EntityTimeZone: |
231 | addressee.setTimeZone( readUTCValue( cl ) ); | 242 | addressee.setTimeZone( readUTCValue( cl ) ); |
232 | break; | 243 | break; |
233 | 244 | ||
234 | case EntityVersion: | 245 | case EntityVersion: |
235 | break; | 246 | break; |
236 | 247 | ||
237 | case EntityClass: | 248 | case EntityClass: |
238 | addressee.setSecrecy( readClassValue( cl ) ); | 249 | addressee.setSecrecy( readClassValue( cl ) ); |
239 | break; | 250 | break; |
240 | 251 | ||
241 | case EntityKey: | 252 | case EntityKey: |
242 | addressee.insertKey( readKeyValue( cl ) ); | 253 | addressee.insertKey( readKeyValue( cl ) ); |
243 | break; | 254 | break; |
244 | 255 | ||
245 | case EntityPhoto: | 256 | case EntityPhoto: |
246 | addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); | 257 | addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); |
247 | break; | 258 | break; |
248 | 259 | ||
249 | case EntityLogo: | 260 | case EntityLogo: |
250 | addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); | 261 | addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); |
251 | break; | 262 | break; |
252 | 263 | ||
253 | case EntityAgent: | 264 | case EntityAgent: |
254 | addressee.setAgent( readAgentValue( cl ) ); | 265 | addressee.setAgent( readAgentValue( cl ) ); |
255 | break; | 266 | break; |
256 | 267 | ||
257 | case EntitySound: | 268 | case EntitySound: |
258 | addressee.setSound( readSoundValue( cl, addressee ) ); | 269 | addressee.setSound( readSoundValue( cl, addressee ) ); |
259 | break; | 270 | break; |
260 | 271 | ||
261 | default: | 272 | default: |
262 | kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " | 273 | kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " |
263 | << int( type ) << ": " << cl->asString() << endl; | 274 | << int( type ) << ": " << cl->asString() << endl; |
264 | qDebug("VCardFormat::load(): Unsupported entity: %i: %s ", int(type), (const char*)cl->asString()); | 275 | qDebug("VCardFormat::load(): Unsupported entity: %i: %s ", int(type), (const char*)cl->asString()); |
265 | break; | 276 | break; |
266 | } | 277 | } |
267 | } | 278 | } |
268 | 279 | ||
269 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { | 280 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { |
270 | EntityType type = cl->entityType(); | 281 | EntityType type = cl->entityType(); |
271 | if ( type == EntityLabel ) { | 282 | if ( type == EntityLabel ) { |
272 | int type = readAddressParam( cl ); | 283 | int type = readAddressParam( cl ); |
273 | Address address = addressee.address( type ); | 284 | Address address = addressee.address( type ); |
274 | if ( address.isEmpty() ) | 285 | if ( address.isEmpty() ) |
275 | address.setType( type ); | 286 | address.setType( type ); |
276 | 287 | ||
277 | address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); | 288 | address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); |
278 | addressee.insertAddress( address ); | 289 | addressee.insertAddress( address ); |
279 | } | 290 | } |
280 | } | 291 | } |
281 | 292 | ||
282 | return true; | 293 | return true; |
283 | } | 294 | } |
284 | 295 | ||
285 | void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) | 296 | void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) |
286 | { | 297 | { |
287 | //US ContentLine cl; | 298 | //US ContentLine cl; |
288 | //US QString value; | 299 | //US QString value; |
289 | 300 | ||
290 | addTextValue( v, EntityName, addressee.name() ); | 301 | addTextValue( v, EntityName, addressee.name() ); |
291 | addTextValue( v, EntityUID, addressee.uid() ); | 302 | addTextValue( v, EntityUID, addressee.uid() ); |
292 | addTextValue( v, EntityFullName, addressee.formattedName() ); | 303 | addTextValue( v, EntityFullName, addressee.formattedName() ); |
293 | 304 | ||
294 | QStringList emails = addressee.emails(); | 305 | QStringList emails = addressee.emails(); |
295 | QStringList::ConstIterator it4; | 306 | QStringList::ConstIterator it4; |
296 | for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { | 307 | for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { |
297 | addTextValue( v, EntityEmail, *it4 ); | 308 | addTextValue( v, EntityEmail, *it4 ); |
298 | } | 309 | } |
299 | 310 | ||
300 | QStringList customs = addressee.customs(); | 311 | QStringList customs = addressee.customs(); |
301 | QStringList::ConstIterator it5; | 312 | QStringList::ConstIterator it5; |
302 | for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { | 313 | for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { |
303 | addCustomValue( v, *it5 ); | 314 | addCustomValue( v, *it5 ); |
304 | } | 315 | } |
305 | 316 | ||
306 | addTextValue( v, EntityURL, addressee.url().url() ); | 317 | addTextValue( v, EntityURL, addressee.url().url() ); |
307 | 318 | ||
308 | addNValue( v, addressee ); | 319 | addNValue( v, addressee ); |
309 | 320 | ||
310 | addTextValue( v, EntityNickname, addressee.nickName() ); | 321 | addTextValue( v, EntityNickname, addressee.nickName() ); |
311 | addTextValue( v, EntityMailer, addressee.mailer() ); | 322 | addTextValue( v, EntityMailer, addressee.mailer() ); |
312 | addTextValue( v, EntityTitle, addressee.title() ); | 323 | addTextValue( v, EntityTitle, addressee.title() ); |
313 | addTextValue( v, EntityRole, addressee.role() ); | 324 | addTextValue( v, EntityRole, addressee.role() ); |
314 | addTextValue( v, EntityOrganisation, addressee.organization() ); | 325 | addTextValue( v, EntityOrganisation, addressee.organization() ); |
315 | addTextValue( v, EntityNote, addressee.note() ); | 326 | addTextValue( v, EntityNote, addressee.note() ); |
316 | addTextValue( v, EntityProductID, addressee.productId() ); | 327 | addTextValue( v, EntityProductID, addressee.productId() ); |
317 | addTextValue( v, EntitySortString, addressee.sortString() ); | 328 | addTextValue( v, EntitySortString, addressee.sortString() ); |
318 | 329 | ||
319 | Address::List addresses = addressee.addresses(); | 330 | Address::List addresses = addressee.addresses(); |
320 | Address::List::ConstIterator it3; | 331 | Address::List::ConstIterator it3; |
321 | for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { | 332 | for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { |
322 | addAddressValue( v, *it3 ); | 333 | addAddressValue( v, *it3 ); |
323 | addLabelValue( v, *it3 ); | 334 | addLabelValue( v, *it3 ); |
324 | } | 335 | } |
325 | 336 | ||
326 | PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); | 337 | PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); |
327 | PhoneNumber::List::ConstIterator it2; | 338 | PhoneNumber::List::ConstIterator it2; |
328 | for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { | 339 | for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { |
329 | addTelephoneValue( v, *it2 ); | 340 | addTelephoneValue( v, *it2 ); |
330 | } | 341 | } |
331 | 342 | ||
332 | Key::List keys = addressee.keys(); | 343 | Key::List keys = addressee.keys(); |
333 | Key::List::ConstIterator it6; | 344 | Key::List::ConstIterator it6; |
334 | for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { | 345 | for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { |
335 | addKeyValue( v, *it6 ); | 346 | addKeyValue( v, *it6 ); |
336 | } | 347 | } |
337 | 348 | ||
338 | addTextValue( v, EntityCategories, addressee.categories().join(",") ); | 349 | addTextValue( v, EntityCategories, addressee.categories().join(",") ); |
339 | 350 | ||
340 | addDateValue( v, EntityBirthday, addressee.birthday().date() ); | 351 | addDateValue( v, EntityBirthday, addressee.birthday().date() ); |
341 | addDateTimeValue( v, EntityRevision, addressee.revision() ); | 352 | addDateTimeValue( v, EntityRevision, addressee.revision() ); |
342 | addGeoValue( v, addressee.geo() ); | 353 | addGeoValue( v, addressee.geo() ); |
343 | addUTCValue( v, addressee.timeZone() ); | 354 | addUTCValue( v, addressee.timeZone() ); |
344 | 355 | ||
345 | addClassValue( v, addressee.secrecy() ); | 356 | addClassValue( v, addressee.secrecy() ); |
346 | 357 | ||
347 | addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); | 358 | addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); |
348 | addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); | 359 | addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); |
349 | 360 | ||
350 | addAgentValue( v, addressee.agent() ); | 361 | addAgentValue( v, addressee.agent() ); |
351 | 362 | ||
352 | addSoundValue( v, addressee.sound(), addressee, intern ); | 363 | addSoundValue( v, addressee.sound(), addressee, intern ); |
353 | } | 364 | } |
354 | 365 | ||
355 | void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) | 366 | void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) |
356 | { | 367 | { |
357 | if ( txt.isEmpty() ) return; | 368 | if ( txt.isEmpty() ) return; |
358 | 369 | ||
359 | ContentLine cl; | 370 | ContentLine cl; |
360 | cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); | 371 | cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); |
361 | QString value = txt.mid( txt.find( ":" ) + 1 ); | 372 | QString value = txt.mid( txt.find( ":" ) + 1 ); |
362 | if ( value.isEmpty() ) | 373 | if ( value.isEmpty() ) |
363 | return; | 374 | return; |
364 | cl.setValue( new TextValue( value.utf8() ) ); | 375 | cl.setValue( new TextValue( value.utf8() ) ); |
365 | v->add(cl); | 376 | v->add(cl); |
366 | } | 377 | } |
367 | 378 | ||
368 | void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) | 379 | void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) |
369 | { | 380 | { |
370 | if ( txt.isEmpty() ) return; | 381 | if ( txt.isEmpty() ) return; |
371 | 382 | ||
372 | ContentLine cl; | 383 | ContentLine cl; |
373 | cl.setName( EntityTypeToParamName( type ) ); | 384 | cl.setName( EntityTypeToParamName( type ) ); |
374 | cl.setValue( new TextValue( txt.utf8() ) ); | 385 | cl.setValue( new TextValue( txt.utf8() ) ); |
375 | v->add(cl); | 386 | v->add(cl); |
376 | } | 387 | } |
377 | 388 | ||
378 | void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, | 389 | void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, |
379 | const QDate &date ) | 390 | const QDate &date ) |
380 | { | 391 | { |
381 | if ( !date.isValid() ) return; | 392 | if ( !date.isValid() ) return; |
382 | 393 | ||
383 | ContentLine cl; | 394 | ContentLine cl; |
384 | cl.setName( EntityTypeToParamName( type ) ); | 395 | cl.setName( EntityTypeToParamName( type ) ); |
385 | 396 | ||
386 | DateValue *v = new DateValue( date ); | 397 | DateValue *v = new DateValue( date ); |
387 | cl.setValue( v ); | 398 | cl.setValue( v ); |
388 | vcard->add(cl); | 399 | vcard->add(cl); |
389 | } | 400 | } |
390 | 401 | ||
391 | void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, | 402 | void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, |
392 | const QDateTime &dateTime ) | 403 | const QDateTime &dateTime ) |
393 | { | 404 | { |
394 | if ( !dateTime.isValid() ) return; | 405 | if ( !dateTime.isValid() ) return; |
395 | 406 | ||
396 | ContentLine cl; | 407 | ContentLine cl; |
397 | cl.setName( EntityTypeToParamName( type ) ); | 408 | cl.setName( EntityTypeToParamName( type ) ); |
398 | 409 | ||
399 | DateValue *v = new DateValue( dateTime ); | 410 | DateValue *v = new DateValue( dateTime ); |
400 | cl.setValue( v ); | 411 | cl.setValue( v ); |
401 | vcard->add(cl); | 412 | vcard->add(cl); |
402 | } | 413 | } |
403 | 414 | ||
404 | void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) | 415 | void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) |
405 | { | 416 | { |
406 | if ( a.isEmpty() ) | 417 | if ( a.isEmpty() ) |
407 | return; | 418 | return; |
408 | 419 | ||
409 | ContentLine cl; | 420 | ContentLine cl; |
410 | cl.setName( EntityTypeToParamName( EntityAddress ) ); | 421 | cl.setName( EntityTypeToParamName( EntityAddress ) ); |
411 | 422 | ||
412 | AdrValue *v = new AdrValue; | 423 | AdrValue *v = new AdrValue; |
413 | v->setPOBox( a.postOfficeBox().utf8() ); | 424 | v->setPOBox( a.postOfficeBox().utf8() ); |
414 | v->setExtAddress( a.extended().utf8() ); | 425 | v->setExtAddress( a.extended().utf8() ); |
415 | v->setStreet( a.street().utf8() ); | 426 | v->setStreet( a.street().utf8() ); |
416 | v->setLocality( a.locality().utf8() ); | 427 | v->setLocality( a.locality().utf8() ); |
417 | v->setRegion( a.region().utf8() ); | 428 | v->setRegion( a.region().utf8() ); |
418 | v->setPostCode( a.postalCode().utf8() ); | 429 | v->setPostCode( a.postalCode().utf8() ); |
419 | v->setCountryName( a.country().utf8() ); | 430 | v->setCountryName( a.country().utf8() ); |
420 | cl.setValue( v ); | 431 | cl.setValue( v ); |
421 | 432 | ||
422 | addAddressParam( &cl, a.type() ); | 433 | addAddressParam( &cl, a.type() ); |
423 | 434 | ||
424 | vcard->add( cl ); | 435 | vcard->add( cl ); |
425 | } | 436 | } |
426 | 437 | ||
427 | void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) | 438 | void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) |
428 | { | 439 | { |
429 | if ( a.label().isEmpty() ) return; | 440 | if ( a.label().isEmpty() ) return; |
430 | 441 | ||
431 | ContentLine cl; | 442 | ContentLine cl; |
432 | cl.setName( EntityTypeToParamName( EntityLabel ) ); | 443 | cl.setName( EntityTypeToParamName( EntityLabel ) ); |
433 | cl.setValue( new TextValue( a.label().utf8() ) ); | 444 | cl.setValue( new TextValue( a.label().utf8() ) ); |
434 | 445 | ||
435 | addAddressParam( &cl, a.type() ); | 446 | addAddressParam( &cl, a.type() ); |
436 | 447 | ||
437 | vcard->add( cl ); | 448 | vcard->add( cl ); |
438 | } | 449 | } |
439 | 450 | ||
440 | void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) | 451 | void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) |
441 | { | 452 | { |
442 | ParamList params; | 453 | ParamList params; |
443 | if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); | 454 | if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); |
444 | if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); | 455 | if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); |
445 | if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); | 456 | if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); |
446 | if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); | 457 | if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); |
447 | if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); | 458 | if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); |
448 | if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); | 459 | if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); |
449 | if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); | 460 | if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); |
450 | cl->setParamList( params ); | 461 | cl->setParamList( params ); |
451 | } | 462 | } |
452 | 463 | ||
453 | void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) | 464 | void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) |
454 | { | 465 | { |
455 | if ( !geo.isValid() ) return; | 466 | if ( !geo.isValid() ) return; |
456 | 467 | ||
457 | ContentLine cl; | 468 | ContentLine cl; |
458 | cl.setName( EntityTypeToParamName( EntityGeo ) ); | 469 | cl.setName( EntityTypeToParamName( EntityGeo ) ); |
459 | 470 | ||
460 | GeoValue *v = new GeoValue; | 471 | GeoValue *v = new GeoValue; |
461 | v->setLatitude( geo.latitude() ); | 472 | v->setLatitude( geo.latitude() ); |
462 | v->setLongitude( geo.longitude() ); | 473 | v->setLongitude( geo.longitude() ); |
463 | 474 | ||
464 | cl.setValue( v ); | 475 | cl.setValue( v ); |
465 | vcard->add(cl); | 476 | vcard->add(cl); |
466 | } | 477 | } |
467 | 478 | ||
468 | void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) | 479 | void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) |
469 | { | 480 | { |
470 | if ( !tz.isValid() ) return; | 481 | if ( !tz.isValid() ) return; |
471 | 482 | ||
472 | ContentLine cl; | 483 | ContentLine cl; |
473 | cl.setName( EntityTypeToParamName( EntityTimeZone ) ); | 484 | cl.setName( EntityTypeToParamName( EntityTimeZone ) ); |
474 | 485 | ||
475 | UTCValue *v = new UTCValue; | 486 | UTCValue *v = new UTCValue; |
476 | 487 | ||
477 | v->setPositive( tz.offset() >= 0 ); | 488 | v->setPositive( tz.offset() >= 0 ); |
478 | v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); | 489 | v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); |
479 | v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); | 490 | v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); |
480 | 491 | ||
481 | cl.setValue( v ); | 492 | cl.setValue( v ); |
482 | vcard->add(cl); | 493 | vcard->add(cl); |
483 | } | 494 | } |
484 | 495 | ||
485 | void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) | 496 | void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) |
486 | { | 497 | { |
487 | ContentLine cl; | 498 | ContentLine cl; |
488 | cl.setName( EntityTypeToParamName( EntityClass ) ); | 499 | cl.setName( EntityTypeToParamName( EntityClass ) ); |
489 | 500 | ||
490 | ClassValue *v = new ClassValue; | 501 | ClassValue *v = new ClassValue; |
491 | switch ( secrecy.type() ) { | 502 | switch ( secrecy.type() ) { |
492 | case Secrecy::Public: | 503 | case Secrecy::Public: |
493 | v->setType( (int)ClassValue::Public ); | 504 | v->setType( (int)ClassValue::Public ); |
494 | break; | 505 | break; |
495 | case Secrecy::Private: | 506 | case Secrecy::Private: |
496 | v->setType( (int)ClassValue::Private ); | 507 | v->setType( (int)ClassValue::Private ); |
497 | break; | 508 | break; |
498 | case Secrecy::Confidential: | 509 | case Secrecy::Confidential: |
499 | v->setType( (int)ClassValue::Confidential ); | 510 | v->setType( (int)ClassValue::Confidential ); |
500 | break; | 511 | break; |
501 | } | 512 | } |
502 | 513 | ||
503 | cl.setValue( v ); | 514 | cl.setValue( v ); |
504 | vcard->add(cl); | 515 | vcard->add(cl); |
505 | } | 516 | } |
506 | 517 | ||
507 | 518 | ||
508 | Address VCardFormatImpl::readAddressValue( ContentLine *cl ) | 519 | Address VCardFormatImpl::readAddressValue( ContentLine *cl ) |
509 | { | 520 | { |
510 | Address a; | 521 | Address a; |
511 | AdrValue *v = (AdrValue *)cl->value(); | 522 | AdrValue *v = (AdrValue *)cl->value(); |
512 | a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); | 523 | a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); |
513 | a.setExtended( QString::fromUtf8( v->extAddress() ) ); | 524 | a.setExtended( QString::fromUtf8( v->extAddress() ) ); |
514 | a.setStreet( QString::fromUtf8( v->street() ) ); | 525 | a.setStreet( QString::fromUtf8( v->street() ) ); |
515 | a.setLocality( QString::fromUtf8( v->locality() ) ); | 526 | a.setLocality( QString::fromUtf8( v->locality() ) ); |
516 | a.setRegion( QString::fromUtf8( v->region() ) ); | 527 | a.setRegion( QString::fromUtf8( v->region() ) ); |
517 | a.setPostalCode( QString::fromUtf8( v->postCode() ) ); | 528 | a.setPostalCode( QString::fromUtf8( v->postCode() ) ); |
518 | a.setCountry( QString::fromUtf8( v->countryName() ) ); | 529 | a.setCountry( QString::fromUtf8( v->countryName() ) ); |
519 | 530 | ||
520 | a.setType( readAddressParam( cl ) ); | 531 | a.setType( readAddressParam( cl ) ); |
521 | 532 | ||
522 | return a; | 533 | return a; |
523 | } | 534 | } |
524 | 535 | ||
525 | int VCardFormatImpl::readAddressParam( ContentLine *cl ) | 536 | int VCardFormatImpl::readAddressParam( ContentLine *cl ) |
526 | { | 537 | { |
527 | int type = 0; | 538 | int type = 0; |
528 | ParamList params = cl->paramList(); | 539 | ParamList params = cl->paramList(); |
529 | ParamListIterator it( params ); | 540 | ParamListIterator it( params ); |
530 | QCString tmpStr; | 541 | QCString tmpStr; |
531 | for( ; it.current(); ++it ) { | 542 | for( ; it.current(); ++it ) { |
532 | if ( (*it)->name().upper() == "TYPE" ) { | 543 | if ( (*it)->name().upper() == "TYPE" ) { |
533 | tmpStr = (*it)->value().lower(); | 544 | tmpStr = (*it)->value().lower(); |
534 | if ( tmpStr == "dom" ) type |= Address::Dom; | 545 | if ( tmpStr == "dom" ) type |= Address::Dom; |
535 | else if ( tmpStr == "intl" ) type |= Address::Intl; | 546 | else if ( tmpStr == "intl" ) type |= Address::Intl; |
536 | else if ( tmpStr == "parcel" ) type |= Address::Parcel; | 547 | else if ( tmpStr == "parcel" ) type |= Address::Parcel; |
537 | else if ( tmpStr == "postal" ) type |= Address::Postal; | 548 | else if ( tmpStr == "postal" ) type |= Address::Postal; |
538 | else if ( tmpStr == "work" ) type |= Address::Work; | 549 | else if ( tmpStr == "work" ) type |= Address::Work; |
539 | else if ( tmpStr == "home" ) type |= Address::Home; | 550 | else if ( tmpStr == "home" ) type |= Address::Home; |
540 | else if ( tmpStr == "pref" ) type |= Address::Pref; | 551 | else if ( tmpStr == "pref" ) type |= Address::Pref; |
541 | } | 552 | } |
542 | } | 553 | } |
543 | return type; | 554 | return type; |
544 | } | 555 | } |
545 | 556 | ||
546 | void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) | 557 | void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) |
547 | { | 558 | { |
548 | ContentLine cl; | 559 | ContentLine cl; |
549 | cl.setName(EntityTypeToParamName( EntityN ) ); | 560 | cl.setName(EntityTypeToParamName( EntityN ) ); |
550 | NValue *v = new NValue; | 561 | NValue *v = new NValue; |
551 | v->setFamily( a.familyName().utf8() ); | 562 | v->setFamily( a.familyName().utf8() ); |
552 | v->setGiven( a.givenName().utf8() ); | 563 | v->setGiven( a.givenName().utf8() ); |
553 | v->setMiddle( a.additionalName().utf8() ); | 564 | v->setMiddle( a.additionalName().utf8() ); |
554 | v->setPrefix( a.prefix().utf8() ); | 565 | v->setPrefix( a.prefix().utf8() ); |
555 | v->setSuffix( a.suffix().utf8() ); | 566 | v->setSuffix( a.suffix().utf8() ); |
556 | 567 | ||
557 | cl.setValue( v ); | 568 | cl.setValue( v ); |
558 | vcard->add(cl); | 569 | vcard->add(cl); |
559 | } | 570 | } |
560 | 571 | ||
561 | void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) | 572 | void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) |
562 | { | 573 | { |
563 | NValue *v = (NValue *)cl->value(); | 574 | NValue *v = (NValue *)cl->value(); |
564 | a.setFamilyName( QString::fromUtf8( v->family() ) ); | 575 | a.setFamilyName( QString::fromUtf8( v->family() ) ); |
565 | a.setGivenName( QString::fromUtf8( v->given() ) ); | 576 | a.setGivenName( QString::fromUtf8( v->given() ) ); |
566 | a.setAdditionalName( QString::fromUtf8( v->middle() ) ); | 577 | a.setAdditionalName( QString::fromUtf8( v->middle() ) ); |
567 | a.setPrefix( QString::fromUtf8( v->prefix() ) ); | 578 | a.setPrefix( QString::fromUtf8( v->prefix() ) ); |
568 | a.setSuffix( QString::fromUtf8( v->suffix() ) ); | 579 | a.setSuffix( QString::fromUtf8( v->suffix() ) ); |
569 | } | 580 | } |
570 | 581 | ||
571 | void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) | 582 | void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) |
572 | { | 583 | { |
573 | if ( p.number().isEmpty() ) | 584 | if ( p.number().isEmpty() ) |
574 | return; | 585 | return; |
575 | 586 | ||
576 | ContentLine cl; | 587 | ContentLine cl; |
577 | cl.setName(EntityTypeToParamName(EntityTelephone)); | 588 | cl.setName(EntityTypeToParamName(EntityTelephone)); |
578 | cl.setValue(new TelValue( p.number().utf8() )); | 589 | cl.setValue(new TelValue( p.number().utf8() )); |
579 | 590 | ||
580 | ParamList params; | 591 | ParamList params; |
581 | if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); | 592 | if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); |
582 | if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); | 593 | if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); |
583 | if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); | 594 | if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); |
584 | if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); | 595 | if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); |
585 | if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); | 596 | if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); |
586 | if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); | 597 | if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); |
587 | if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); | 598 | if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); |
588 | if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); | 599 | if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); |
589 | if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); | 600 | if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); |
590 | if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); | 601 | if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); |
591 | if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); | 602 | if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); |
592 | if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); | 603 | if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); |
593 | if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); | 604 | if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); |
594 | if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); | 605 | if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); |
595 | if( p.type() & PhoneNumber::Sip ) params.append( new Param( "TYPE", "sip" ) ); | 606 | if( p.type() & PhoneNumber::Sip ) params.append( new Param( "TYPE", "sip" ) ); |
596 | cl.setParamList( params ); | 607 | cl.setParamList( params ); |
597 | 608 | ||
598 | v->add(cl); | 609 | v->add(cl); |
599 | } | 610 | } |
600 | 611 | ||
601 | PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) | 612 | PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) |
602 | { | 613 | { |
603 | PhoneNumber p; | 614 | PhoneNumber p; |
604 | TelValue *value = (TelValue *)cl->value(); | 615 | TelValue *value = (TelValue *)cl->value(); |
605 | p.setNumber( QString::fromUtf8( value->asString() ) ); | 616 | p.setNumber( QString::fromUtf8( value->asString() ) ); |
606 | 617 | ||
607 | int type = 0; | 618 | int type = 0; |
608 | ParamList params = cl->paramList(); | 619 | ParamList params = cl->paramList(); |
609 | ParamListIterator it( params ); | 620 | ParamListIterator it( params ); |
610 | QCString tmpStr; | 621 | QCString tmpStr; |
611 | for( ; it.current(); ++it ) { | 622 | for( ; it.current(); ++it ) { |
612 | if ( (*it)->name() == "TYPE" ) { | 623 | if ( (*it)->name() == "TYPE" ) { |
613 | tmpStr = (*it)->value().lower(); | 624 | tmpStr = (*it)->value().lower(); |
614 | if ( tmpStr == "home" ) type |= PhoneNumber::Home; | 625 | if ( tmpStr == "home" ) type |= PhoneNumber::Home; |
615 | else if ( tmpStr == "work" ) type |= PhoneNumber::Work; | 626 | else if ( tmpStr == "work" ) type |= PhoneNumber::Work; |
616 | else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; | 627 | else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; |
617 | else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; | 628 | else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; |
618 | else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; | 629 | else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; |
619 | else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; | 630 | else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; |
620 | else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; | 631 | else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; |
621 | else if ( tmpStr == "video" ) type |= PhoneNumber::Video; | 632 | else if ( tmpStr == "video" ) type |= PhoneNumber::Video; |
622 | else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; | 633 | else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; |
623 | else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; | 634 | else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; |
624 | else if ( tmpStr == "car" ) type |= PhoneNumber::Car; | 635 | else if ( tmpStr == "car" ) type |= PhoneNumber::Car; |
625 | else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; | 636 | else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; |
626 | else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; | 637 | else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; |
627 | else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; | 638 | else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; |
628 | else if ( tmpStr == "sip" ) type |= PhoneNumber::Sip; | 639 | else if ( tmpStr == "sip" ) type |= PhoneNumber::Sip; |
629 | } | 640 | } |
630 | } | 641 | } |
631 | p.setType( type ); | 642 | p.setType( type ); |
632 | 643 | ||
633 | return p; | 644 | return p; |
634 | } | 645 | } |
635 | 646 | ||
636 | QString VCardFormatImpl::readTextValue( ContentLine *cl ) | 647 | QString VCardFormatImpl::readTextValue( ContentLine *cl ) |
637 | { | 648 | { |
638 | VCARD::Value *value = cl->value(); | 649 | VCARD::Value *value = cl->value(); |
639 | if ( value ) { | 650 | if ( value ) { |
640 | return QString::fromUtf8( value->asString() ); | 651 | return QString::fromUtf8( value->asString() ); |
641 | } else { | 652 | } else { |
642 | kdDebug(5700) << "No value: " << cl->asString() << endl; | 653 | kdDebug(5700) << "No value: " << cl->asString() << endl; |
643 | qDebug("No value: %s", (const char*)(cl->asString())); | 654 | qDebug("No value: %s", (const char*)(cl->asString())); |
644 | return QString::null; | 655 | return QString::null; |
645 | } | 656 | } |
646 | } | 657 | } |
647 | 658 | ||
648 | QDate VCardFormatImpl::readDateValue( ContentLine *cl ) | 659 | QDate VCardFormatImpl::readDateValue( ContentLine *cl ) |
649 | { | 660 | { |
650 | DateValue *dateValue = (DateValue *)cl->value(); | 661 | DateValue *dateValue = (DateValue *)cl->value(); |
651 | if ( dateValue ) | 662 | if ( dateValue ) |
652 | return dateValue->qdate(); | 663 | return dateValue->qdate(); |
653 | else | 664 | else |
654 | return QDate(); | 665 | return QDate(); |
655 | } | 666 | } |
656 | 667 | ||
657 | QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) | 668 | QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) |
658 | { | 669 | { |
659 | DateValue *dateValue = (DateValue *)cl->value(); | 670 | DateValue *dateValue = (DateValue *)cl->value(); |
660 | if ( dateValue ) | 671 | if ( dateValue ) |
661 | return dateValue->qdt(); | 672 | return dateValue->qdt(); |
662 | else | 673 | else |
663 | return QDateTime(); | 674 | return QDateTime(); |
664 | } | 675 | } |
665 | 676 | ||
666 | Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) | 677 | Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) |
667 | { | 678 | { |
668 | GeoValue *geoValue = (GeoValue *)cl->value(); | 679 | GeoValue *geoValue = (GeoValue *)cl->value(); |
669 | if ( geoValue ) { | 680 | if ( geoValue ) { |
670 | Geo geo( geoValue->latitude(), geoValue->longitude() ); | 681 | Geo geo( geoValue->latitude(), geoValue->longitude() ); |
671 | return geo; | 682 | return geo; |
672 | } else | 683 | } else |
673 | return Geo(); | 684 | return Geo(); |
674 | } | 685 | } |
675 | 686 | ||
676 | TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) | 687 | TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) |
677 | { | 688 | { |
678 | UTCValue *utcValue = (UTCValue *)cl->value(); | 689 | UTCValue *utcValue = (UTCValue *)cl->value(); |
679 | if ( utcValue ) { | 690 | if ( utcValue ) { |
680 | TimeZone tz; | 691 | TimeZone tz; |
681 | tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); | 692 | tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); |
682 | return tz; | 693 | return tz; |
683 | } else | 694 | } else |
684 | return TimeZone(); | 695 | return TimeZone(); |
685 | } | 696 | } |
686 | 697 | ||
687 | Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) | 698 | Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) |
688 | { | 699 | { |
689 | ClassValue *classValue = (ClassValue *)cl->value(); | 700 | ClassValue *classValue = (ClassValue *)cl->value(); |
690 | if ( classValue ) { | 701 | if ( classValue ) { |
691 | Secrecy secrecy; | 702 | Secrecy secrecy; |
692 | switch ( classValue->type() ) { | 703 | switch ( classValue->type() ) { |
693 | case ClassValue::Public: | 704 | case ClassValue::Public: |
694 | secrecy.setType( Secrecy::Public ); | 705 | secrecy.setType( Secrecy::Public ); |
695 | break; | 706 | break; |
696 | case ClassValue::Private: | 707 | case ClassValue::Private: |
697 | secrecy.setType( Secrecy::Private ); | 708 | secrecy.setType( Secrecy::Private ); |
698 | break; | 709 | break; |
699 | case ClassValue::Confidential: | 710 | case ClassValue::Confidential: |
700 | secrecy.setType( Secrecy::Confidential ); | 711 | secrecy.setType( Secrecy::Confidential ); |
701 | break; | 712 | break; |
702 | } | 713 | } |
703 | 714 | ||
704 | return secrecy; | 715 | return secrecy; |
705 | } else | 716 | } else |
706 | return Secrecy(); | 717 | return Secrecy(); |
707 | } | 718 | } |
708 | 719 | ||
709 | void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) | 720 | void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) |
710 | { | 721 | { |
711 | ContentLine cl; | 722 | ContentLine cl; |
712 | cl.setName( EntityTypeToParamName( EntityKey ) ); | 723 | cl.setName( EntityTypeToParamName( EntityKey ) ); |
713 | 724 | ||
714 | ParamList params; | 725 | ParamList params; |
715 | if ( key.isBinary() ) { | 726 | if ( key.isBinary() ) { |
716 | cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); | 727 | cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); |
717 | params.append( new Param( "ENCODING", "b" ) ); | 728 | params.append( new Param( "ENCODING", "b" ) ); |
718 | } else { | 729 | } else { |
719 | cl.setValue( new TextValue( key.textData().utf8() ) ); | 730 | cl.setValue( new TextValue( key.textData().utf8() ) ); |
720 | } | 731 | } |
721 | 732 | ||
722 | switch ( key.type() ) { | 733 | switch ( key.type() ) { |
723 | case Key::X509: | 734 | case Key::X509: |
724 | params.append( new Param( "TYPE", "X509" ) ); | 735 | params.append( new Param( "TYPE", "X509" ) ); |
725 | break; | 736 | break; |
726 | case Key::PGP: | 737 | case Key::PGP: |
727 | params.append( new Param( "TYPE", "PGP" ) ); | 738 | params.append( new Param( "TYPE", "PGP" ) ); |
728 | break; | 739 | break; |
729 | case Key::Custom: | 740 | case Key::Custom: |
730 | params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); | 741 | params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); |
731 | break; | 742 | break; |
732 | } | 743 | } |
733 | 744 | ||
734 | cl.setParamList( params ); | 745 | cl.setParamList( params ); |
735 | vcard->add( cl ); | 746 | vcard->add( cl ); |
736 | } | 747 | } |
737 | 748 | ||
738 | Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) | 749 | Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) |
739 | { | 750 | { |
740 | Key key; | 751 | Key key; |
741 | bool isBinary = false; | 752 | bool isBinary = false; |
742 | TextValue *v = (TextValue *)cl->value(); | 753 | TextValue *v = (TextValue *)cl->value(); |
743 | 754 | ||
744 | ParamList params = cl->paramList(); | 755 | ParamList params = cl->paramList(); |
745 | ParamListIterator it( params ); | 756 | ParamListIterator it( params ); |
746 | for( ; it.current(); ++it ) { | 757 | for( ; it.current(); ++it ) { |
747 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) | 758 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) |
748 | isBinary = true; | 759 | isBinary = true; |
749 | if ( (*it)->name() == "TYPE" ) { | 760 | if ( (*it)->name() == "TYPE" ) { |
750 | if ( (*it)->value().isEmpty() ) | 761 | if ( (*it)->value().isEmpty() ) |
751 | continue; | 762 | continue; |
752 | if ( (*it)->value() == "X509" ) | 763 | if ( (*it)->value() == "X509" ) |
753 | key.setType( Key::X509 ); | 764 | key.setType( Key::X509 ); |
754 | else if ( (*it)->value() == "PGP" ) | 765 | else if ( (*it)->value() == "PGP" ) |
755 | key.setType( Key::PGP ); | 766 | key.setType( Key::PGP ); |
756 | else { | 767 | else { |
757 | key.setType( Key::Custom ); | 768 | key.setType( Key::Custom ); |
758 | key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); | 769 | key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); |
759 | } | 770 | } |
760 | } | 771 | } |
761 | } | 772 | } |
762 | 773 | ||
763 | 774 | ||
764 | if ( isBinary ) { | 775 | if ( isBinary ) { |
765 | QByteArray data; | 776 | QByteArray data; |
766 | KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); | 777 | KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); |
767 | key.setBinaryData( data ); | 778 | key.setBinaryData( data ); |
768 | } else { | 779 | } else { |
769 | key.setTextData( QString::fromUtf8( v->asString() ) ); | 780 | key.setTextData( QString::fromUtf8( v->asString() ) ); |
770 | } | 781 | } |
771 | 782 | ||
772 | return key; | 783 | return key; |
773 | } | 784 | } |
774 | 785 | ||
775 | 786 | ||
776 | void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) | 787 | void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) |
777 | { | 788 | { |
778 | if ( agent.isIntern() && !agent.addressee() ) | 789 | if ( agent.isIntern() && !agent.addressee() ) |
779 | return; | 790 | return; |
780 | 791 | ||
781 | if ( !agent.isIntern() && agent.url().isEmpty() ) | 792 | if ( !agent.isIntern() && agent.url().isEmpty() ) |
782 | return; | 793 | return; |
783 | 794 | ||
784 | ContentLine cl; | 795 | ContentLine cl; |
785 | cl.setName( EntityTypeToParamName( EntityAgent ) ); | 796 | cl.setName( EntityTypeToParamName( EntityAgent ) ); |
786 | 797 | ||
787 | ParamList params; | 798 | ParamList params; |
788 | if ( agent.isIntern() ) { | 799 | if ( agent.isIntern() ) { |
789 | QString vstr; | 800 | QString vstr; |
790 | Addressee *addr = agent.addressee(); | 801 | Addressee *addr = agent.addressee(); |
791 | if ( addr ) { | 802 | if ( addr ) { |
792 | writeToString( (*addr), vstr ); | 803 | writeToString( (*addr), vstr ); |
793 | 804 | ||
794 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); | 805 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); |
795 | /*US | 806 | /*US |
796 | vstr.replace( ":", "\\:" ); | 807 | vstr.replace( ":", "\\:" ); |
797 | vstr.replace( ",", "\\," ); | 808 | vstr.replace( ",", "\\," ); |
798 | vstr.replace( ";", "\\;" ); | 809 | vstr.replace( ";", "\\;" ); |
799 | vstr.replace( "\r\n", "\\n" ); | 810 | vstr.replace( "\r\n", "\\n" ); |
800 | */ | 811 | */ |
801 | vstr.replace( QRegExp(":"), "\\:" ); | 812 | vstr.replace( QRegExp(":"), "\\:" ); |
802 | vstr.replace( QRegExp(","), "\\," ); | 813 | vstr.replace( QRegExp(","), "\\," ); |
803 | vstr.replace( QRegExp(";"), "\\;" ); | 814 | vstr.replace( QRegExp(";"), "\\;" ); |
804 | vstr.replace( QRegExp("\r\n"), "\\n" ); | 815 | vstr.replace( QRegExp("\r\n"), "\\n" ); |
805 | 816 | ||
806 | cl.setValue( new TextValue( vstr.utf8() ) ); | 817 | cl.setValue( new TextValue( vstr.utf8() ) ); |
807 | } else | 818 | } else |
808 | return; | 819 | return; |
809 | } else { | 820 | } else { |
810 | cl.setValue( new TextValue( agent.url().utf8() ) ); | 821 | cl.setValue( new TextValue( agent.url().utf8() ) ); |
811 | params.append( new Param( "VALUE", "uri" ) ); | 822 | params.append( new Param( "VALUE", "uri" ) ); |
812 | } | 823 | } |
813 | 824 | ||
814 | cl.setParamList( params ); | 825 | cl.setParamList( params ); |
815 | vcard->add( cl ); | 826 | vcard->add( cl ); |
816 | } | 827 | } |
817 | 828 | ||
818 | Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) | 829 | Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) |
819 | { | 830 | { |
820 | Agent agent; | 831 | Agent agent; |
821 | bool isIntern = true; | 832 | bool isIntern = true; |
822 | TextValue *v = (TextValue *)cl->value(); | 833 | TextValue *v = (TextValue *)cl->value(); |
823 | 834 | ||
824 | ParamList params = cl->paramList(); | 835 | ParamList params = cl->paramList(); |
825 | ParamListIterator it( params ); | 836 | ParamListIterator it( params ); |
826 | for( ; it.current(); ++it ) { | 837 | for( ; it.current(); ++it ) { |
827 | if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) | 838 | if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) |
828 | isIntern = false; | 839 | isIntern = false; |
829 | } | 840 | } |
830 | 841 | ||
831 | if ( isIntern ) { | 842 | if ( isIntern ) { |
832 | QString vstr = QString::fromUtf8( v->asString() ); | 843 | QString vstr = QString::fromUtf8( v->asString() ); |
833 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); | 844 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); |
834 | /*US | 845 | /*US |
835 | vstr.replace( "\\n", "\r\n" ); | 846 | vstr.replace( "\\n", "\r\n" ); |
836 | vstr.replace( "\\:", ":" ); | 847 | vstr.replace( "\\:", ":" ); |
837 | vstr.replace( "\\,", "," ); | 848 | vstr.replace( "\\,", "," ); |
838 | vstr.replace( "\\;", ";" ); | 849 | vstr.replace( "\\;", ";" ); |
839 | */ | 850 | */ |
840 | vstr.replace( QRegExp("\\n"), "\r\n" ); | 851 | vstr.replace( QRegExp("\\n"), "\r\n" ); |
841 | vstr.replace( QRegExp("\\:"), ":" ); | 852 | vstr.replace( QRegExp("\\:"), ":" ); |
842 | vstr.replace( QRegExp("\\,"), "," ); | 853 | vstr.replace( QRegExp("\\,"), "," ); |
843 | vstr.replace( QRegExp("\\;"), ";" ); | 854 | vstr.replace( QRegExp("\\;"), ";" ); |
844 | 855 | ||
845 | Addressee *addr = new Addressee; | 856 | Addressee *addr = new Addressee; |
846 | readFromString( vstr, *addr ); | 857 | readFromString( vstr, *addr ); |
847 | agent.setAddressee( addr ); | 858 | agent.setAddressee( addr ); |
848 | } else { | 859 | } else { |
849 | agent.setUrl( QString::fromUtf8( v->asString() ) ); | 860 | agent.setUrl( QString::fromUtf8( v->asString() ) ); |
850 | } | 861 | } |
diff --git a/kabc/vcardformatimpl.h b/kabc/vcardformatimpl.h index fa3d55f..4821047 100644 --- a/kabc/vcardformatimpl.h +++ b/kabc/vcardformatimpl.h | |||
@@ -1,112 +1,117 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef KABC_VCARDFORMATIMPL_H | 28 | #ifndef KABC_VCARDFORMATIMPL_H |
29 | #define KABC_VCARDFORMATIMPL_H | 29 | #define KABC_VCARDFORMATIMPL_H |
30 | 30 | ||
31 | #include <qstring.h> | 31 | #include <qstring.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | 33 | ||
34 | #include "address.h" | 34 | #include "address.h" |
35 | #include "addressee.h" | 35 | #include "addressee.h" |
36 | 36 | ||
37 | #include <VCard.h> | 37 | #include <VCard.h> |
38 | 38 | ||
39 | namespace KABC { | 39 | namespace KABC { |
40 | 40 | ||
41 | class AddressBook; | 41 | class AddressBook; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | @short Implementation of vCard backend for address book. | 44 | @short Implementation of vCard backend for address book. |
45 | 45 | ||
46 | This class implements reading and writing of address book information using | 46 | This class implements reading and writing of address book information using |
47 | the vCard format. It requires the vCard lib from kdepim. | 47 | the vCard format. It requires the vCard lib from kdepim. |
48 | */ | 48 | */ |
49 | class VCardFormatImpl | 49 | class VCardFormatImpl |
50 | { | 50 | { |
51 | public: | 51 | public: |
52 | VCardFormatImpl(); | ||
53 | |||
52 | bool load( Addressee &, QFile *file ); | 54 | bool load( Addressee &, QFile *file ); |
53 | bool loadAll( AddressBook *, Resource *, QFile *file ); | 55 | bool loadAll( AddressBook *, Resource *, QFile *file ); |
54 | void save( const Addressee &, QFile *file ); | 56 | void save( const Addressee &, QFile *file ); |
55 | void saveAll( AddressBook *, Resource *, QFile *file ); | 57 | void saveAll( AddressBook *, Resource *, QFile *file ); |
56 | 58 | ||
57 | bool readFromString( const QString &vcard, Addressee &addr ); | 59 | bool readFromString( const QString &vcard, Addressee &addr ); |
58 | bool writeToString( const Addressee &addressee, QString &vcard ); | 60 | bool writeToString( const Addressee &addressee, QString &vcard ); |
59 | 61 | ||
60 | protected: | 62 | protected: |
61 | bool loadAddressee( Addressee &, VCARD::VCard * ); | 63 | bool loadAddressee( Addressee &, VCARD::VCard * ); |
62 | void saveAddressee( const Addressee &, VCARD::VCard *, bool intern ); | 64 | void saveAddressee( const Addressee &, VCARD::VCard *, bool intern ); |
63 | 65 | ||
64 | void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & ); | 66 | void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & ); |
65 | QString readTextValue( VCARD::ContentLine * ); | 67 | QString readTextValue( VCARD::ContentLine * ); |
66 | 68 | ||
67 | void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & ); | 69 | void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & ); |
68 | QDate readDateValue( VCARD::ContentLine * ); | 70 | QDate readDateValue( VCARD::ContentLine * ); |
69 | 71 | ||
70 | void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & ); | 72 | void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & ); |
71 | QDateTime readDateTimeValue( VCARD::ContentLine * ); | 73 | QDateTime readDateTimeValue( VCARD::ContentLine * ); |
72 | 74 | ||
73 | void addAddressValue( VCARD::VCard *, const Address & ); | 75 | void addAddressValue( VCARD::VCard *, const Address & ); |
74 | Address readAddressValue( VCARD::ContentLine * ); | 76 | Address readAddressValue( VCARD::ContentLine * ); |
75 | 77 | ||
76 | void addLabelValue( VCARD::VCard *, const Address & ); | 78 | void addLabelValue( VCARD::VCard *, const Address & ); |
77 | 79 | ||
78 | void addTelephoneValue( VCARD::VCard *, const PhoneNumber & ); | 80 | void addTelephoneValue( VCARD::VCard *, const PhoneNumber & ); |
79 | PhoneNumber readTelephoneValue( VCARD::ContentLine * ); | 81 | PhoneNumber readTelephoneValue( VCARD::ContentLine * ); |
80 | 82 | ||
81 | void addNValue( VCARD::VCard *, const Addressee & ); | 83 | void addNValue( VCARD::VCard *, const Addressee & ); |
82 | void readNValue( VCARD::ContentLine *, Addressee & ); | 84 | void readNValue( VCARD::ContentLine *, Addressee & ); |
83 | 85 | ||
84 | void addCustomValue( VCARD::VCard *, const QString & ); | 86 | void addCustomValue( VCARD::VCard *, const QString & ); |
85 | 87 | ||
86 | void addAddressParam( VCARD::ContentLine *, int ); | 88 | void addAddressParam( VCARD::ContentLine *, int ); |
87 | int readAddressParam( VCARD::ContentLine * ); | 89 | int readAddressParam( VCARD::ContentLine * ); |
88 | 90 | ||
89 | void addGeoValue( VCARD::VCard *, const Geo & ); | 91 | void addGeoValue( VCARD::VCard *, const Geo & ); |
90 | Geo readGeoValue( VCARD::ContentLine * ); | 92 | Geo readGeoValue( VCARD::ContentLine * ); |
91 | 93 | ||
92 | void addUTCValue( VCARD::VCard *, const TimeZone & ); | 94 | void addUTCValue( VCARD::VCard *, const TimeZone & ); |
93 | TimeZone readUTCValue( VCARD::ContentLine * ); | 95 | TimeZone readUTCValue( VCARD::ContentLine * ); |
94 | 96 | ||
95 | void addClassValue( VCARD::VCard *, const Secrecy & ); | 97 | void addClassValue( VCARD::VCard *, const Secrecy & ); |
96 | Secrecy readClassValue( VCARD::ContentLine * ); | 98 | Secrecy readClassValue( VCARD::ContentLine * ); |
97 | 99 | ||
98 | void addKeyValue( VCARD::VCard *, const Key & ); | 100 | void addKeyValue( VCARD::VCard *, const Key & ); |
99 | Key readKeyValue( VCARD::ContentLine * ); | 101 | Key readKeyValue( VCARD::ContentLine * ); |
100 | 102 | ||
101 | void addPictureValue( VCARD::VCard *, VCARD::EntityType, const Picture &, const Addressee &, bool ); | 103 | void addPictureValue( VCARD::VCard *, VCARD::EntityType, const Picture &, const Addressee &, bool ); |
102 | Picture readPictureValue( VCARD::ContentLine *, VCARD::EntityType, const Addressee &addr ); | 104 | Picture readPictureValue( VCARD::ContentLine *, VCARD::EntityType, const Addressee &addr ); |
103 | 105 | ||
104 | void addSoundValue( VCARD::VCard *, const Sound &, const Addressee &, bool ); | 106 | void addSoundValue( VCARD::VCard *, const Sound &, const Addressee &, bool ); |
105 | Sound readSoundValue( VCARD::ContentLine *, const Addressee &addr ); | 107 | Sound readSoundValue( VCARD::ContentLine *, const Addressee &addr ); |
106 | 108 | ||
107 | void addAgentValue( VCARD::VCard *, const Agent & ); | 109 | void addAgentValue( VCARD::VCard *, const Agent & ); |
108 | Agent readAgentValue( VCARD::ContentLine * ); | 110 | Agent readAgentValue( VCARD::ContentLine * ); |
111 | |||
112 | private: | ||
113 | static int debug; | ||
109 | }; | 114 | }; |
110 | 115 | ||
111 | } | 116 | } |
112 | #endif | 117 | #endif |