summaryrefslogtreecommitdiffabout
path: root/kabc
authorulf69 <ulf69>2004-08-20 01:16:22 (UTC)
committer ulf69 <ulf69>2004-08-20 01:16:22 (UTC)
commitf7a401f03c18ef96eb40dc5540b31cd10880e845 (patch) (unidiff)
treef028d7dd67e34d00d44bd9af27b6e2c3dcd93cef /kabc
parentd39b363278224b969d4c2945d32968c980b5d842 (diff)
downloadkdepimpi-f7a401f03c18ef96eb40dc5540b31cd10880e845.zip
kdepimpi-f7a401f03c18ef96eb40dc5540b31cd10880e845.tar.gz
kdepimpi-f7a401f03c18ef96eb40dc5540b31cd10880e845.tar.bz2
bugfix: fixed a memoryleak in vCards while saving contacts
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard/VCardEntity.cpp9
-rw-r--r--kabc/vcardformatimpl.cpp4
2 files changed, 10 insertions, 3 deletions
diff --git a/kabc/vcard/VCardEntity.cpp b/kabc/vcard/VCardEntity.cpp
index 0cd2086..5fca3bc 100644
--- a/kabc/vcard/VCardEntity.cpp
+++ b/kabc/vcard/VCardEntity.cpp
@@ -1,122 +1,129 @@
1/* 1/*
2 libvcard - vCard parsing library for vCard version 3.0 2 libvcard - vCard parsing library for vCard version 3.0
3 3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org 4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy 6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to 7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the 8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is 10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions: 11 furnished to do so, subject to the following conditions:
12 12
13 The above copyright notice and this permission notice shall be included in 13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software. 14 all copies or substantial portions of the Software.
15 15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/ 22*/
23 23
24#include <qregexp.h> 24#include <qregexp.h>
25 25
26#include <VCardDefines.h> 26#include <VCardDefines.h>
27#include <VCardVCardEntity.h> 27#include <VCardVCardEntity.h>
28 28
29using namespace VCARD; 29using namespace VCARD;
30 30
31VCardEntity::VCardEntity() 31VCardEntity::VCardEntity()
32 :Entity() 32 :Entity()
33{ 33{
34 cardList_.setAutoDelete( TRUE ); 34 cardList_.setAutoDelete( TRUE );
35} 35}
36 36
37VCardEntity::VCardEntity(const VCardEntity & x) 37VCardEntity::VCardEntity(const VCardEntity & x)
38 :Entity(x) 38 :Entity(x)
39{ 39{
40 cardList_.setAutoDelete( TRUE ); 40 cardList_.setAutoDelete( TRUE );
41} 41}
42 42
43VCardEntity::VCardEntity(const QCString & s) 43VCardEntity::VCardEntity(const QCString & s)
44 :Entity(s) 44 :Entity(s)
45{ 45{
46 cardList_.setAutoDelete( TRUE ); 46 cardList_.setAutoDelete( TRUE );
47} 47}
48 48
49 VCardEntity & 49 VCardEntity &
50VCardEntity::operator = (VCardEntity & x) 50VCardEntity::operator = (VCardEntity & x)
51{ 51{
52 if (*this == x) return *this; 52 if (*this == x) return *this;
53 53
54 Entity::operator = (x); 54 Entity::operator = (x);
55 return *this; 55 return *this;
56} 56}
57 57
58 VCardEntity & 58 VCardEntity &
59VCardEntity::operator = (const QCString & s) 59VCardEntity::operator = (const QCString & s)
60{ 60{
61 Entity::operator = (s); 61 Entity::operator = (s);
62 return *this; 62 return *this;
63} 63}
64 64
65 bool 65 bool
66VCardEntity::operator == (VCardEntity & x) 66VCardEntity::operator == (VCardEntity & x)
67{ 67{
68 x.parse(); 68 x.parse();
69 return false; 69 return false;
70} 70}
71 71
72VCardEntity::~VCardEntity() 72VCardEntity::~VCardEntity()
73{ 73{
74} 74}
75 75
76 void 76 void
77VCardEntity::_parse() 77VCardEntity::_parse()
78{ 78{
79 vDebug("parse"); 79 vDebug("parse");
80 QCString s(strRep_); 80 QCString s(strRep_);
81 81
82 int i = s.find(QRegExp("BEGIN:VCARD", false)); 82 int i = s.find(QRegExp("BEGIN:VCARD", false));
83 83
84 while (i != -1) { 84 while (i != -1) {
85 85
86 i = s.find(QRegExp("BEGIN:VCARD", false), 11); 86 i = s.find(QRegExp("BEGIN:VCARD", false), 11);
87 87
88 QCString cardStr(s.left(i)); 88 QCString cardStr(s.left(i));
89 89
90 VCard * v = new VCard(cardStr); 90 VCard * v = new VCard(cardStr);
91 91
92 cardList_.append(v); 92 cardList_.append(v);
93 93
94 v->parse(); 94 v->parse();
95 95
96 s.remove(0, i); 96 s.remove(0, i);
97 } 97 }
98} 98}
99 99
100 void 100 void
101VCardEntity::_assemble() 101VCardEntity::_assemble()
102{ 102{
103 VCardListIterator it(cardList_); 103 VCardListIterator it(cardList_);
104 104
105 for (; it.current(); ++it) 105 for (; it.current(); ++it)
106 strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. 106 strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck.
107} 107}
108 108
109 VCardList & 109 VCardList &
110VCardEntity::cardList() 110VCardEntity::cardList()
111{ 111{
112 parse(); 112 parse();
113 return cardList_; 113 return cardList_;
114} 114}
115 115
116 void 116 void
117VCardEntity::setCardList(const VCardList & l) 117VCardEntity::setCardList(const VCardList & l)
118{ 118{
119 parse(); 119 parse();
120 cardList_ = l; 120 //UScardList_ = l;
121 VCardListIterator it(l);
122
123 for (; it.current(); ++it) {
124 VCard* v = new VCard(*it.current());
125 cardList_.append(v);
126 }
127
121} 128}
122 129
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp
index bd9a57b..bffaa64 100644
--- a/kabc/vcardformatimpl.cpp
+++ b/kabc/vcardformatimpl.cpp
@@ -1,1030 +1,1030 @@
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/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (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
41using namespace KABC; 41using namespace KABC;
42using namespace VCARD; 42using namespace VCARD;
43 43
44bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) 44bool VCardFormatImpl::load( Addressee &addressee, QFile *file )
45{ 45{
46 kdDebug(5700) << "VCardFormat::load()" << endl; 46 kdDebug(5700) << "VCardFormat::load()" << endl;
47 47
48 QByteArray fdata = file->readAll(); 48 QByteArray fdata = file->readAll();
49 QCString data(fdata.data(), fdata.size()+1); 49 QCString data(fdata.data(), fdata.size()+1);
50 50
51 VCardEntity e( data ); 51 VCardEntity e( data );
52 52
53 VCardListIterator it( e.cardList() ); 53 VCardListIterator it( e.cardList() );
54 54
55 if ( it.current() ) { 55 if ( it.current() ) {
56//US VCard v(*it.current()); 56//US VCard v(*it.current());
57//US loadAddressee( addressee, v ); 57//US loadAddressee( addressee, v );
58 loadAddressee( addressee, it.current() ); 58 loadAddressee( addressee, it.current() );
59 return true; 59 return true;
60 } 60 }
61 61
62 return false; 62 return false;
63} 63}
64 64
65bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) 65bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
66{ 66{
67 kdDebug(5700) << "VCardFormat::loadAll()" << endl; 67 kdDebug(5700) << "VCardFormat::loadAll()" << endl;
68 68
69 QByteArray fdata = file->readAll(); 69 QByteArray fdata = file->readAll();
70 QCString data(fdata.data(), fdata.size()+1); 70 QCString data(fdata.data(), fdata.size()+1);
71 71
72 VCardEntity e( data ); 72 VCardEntity e( data );
73 73
74 VCardListIterator it( e.cardList() ); 74 VCardListIterator it( e.cardList() );
75 75
76 for (; it.current(); ++it) { 76 for (; it.current(); ++it) {
77//US VCard v(*it.current()); 77//US VCard v(*it.current());
78 Addressee addressee; 78 Addressee addressee;
79//US loadAddressee( addressee, v ); 79//US loadAddressee( addressee, v );
80 loadAddressee( addressee, it.current() ); 80 loadAddressee( addressee, it.current() );
81 addressee.setResource( resource ); 81 addressee.setResource( resource );
82 addressBook->insertAddressee( addressee ); 82 addressBook->insertAddressee( addressee );
83 } 83 }
84 84
85 return true; 85 return true;
86} 86}
87 87
88void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) 88void VCardFormatImpl::save( const Addressee &addressee, QFile *file )
89{ 89{
90 VCardEntity vcards; 90 VCardEntity vcards;
91 VCardList vcardlist; 91 VCardList vcardlist;
92 vcardlist.setAutoDelete( true ); 92 vcardlist.setAutoDelete( true );
93 93
94 VCard *v = new VCard; 94 VCard *v = new VCard;
95 95
96 saveAddressee( addressee, v, false ); 96 saveAddressee( addressee, v, false );
97 97
98 vcardlist.append( v ); 98 vcardlist.append( v );
99 vcards.setCardList( vcardlist ); 99 vcards.setCardList( vcardlist );
100 100
101 QCString vcardData = vcards.asString(); 101 QCString vcardData = vcards.asString();
102 file->writeBlock( (const char*)vcardData, vcardData.length() ); 102 file->writeBlock( (const char*)vcardData, vcardData.length() );
103} 103}
104 104
105void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) 105void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file )
106{ 106{
107 VCardEntity vcards; 107 VCardEntity vcards;
108 VCardList vcardlist; 108 VCardList vcardlist;
109 vcardlist.setAutoDelete( true ); 109 vcardlist.setAutoDelete( true );
110 110
111 AddressBook::Iterator it; 111 AddressBook::Iterator it;
112 for ( it = ab->begin(); it != ab->end(); ++it ) { 112 for ( it = ab->begin(); it != ab->end(); ++it ) {
113 if ( (*it).resource() == resource ) { 113 if ( (*it).resource() == resource ) {
114 VCard *v = new VCard; 114 VCard *v = new VCard;
115 saveAddressee( (*it), v, false ); 115 saveAddressee( (*it), v, false );
116 (*it).setChanged( false ); 116 (*it).setChanged( false );
117 vcardlist.append( v ); 117 vcardlist.append( v );
118 } 118 }
119 } 119 }
120 120
121 vcards.setCardList( vcardlist ); 121 vcards.setCardList( vcardlist );
122 122
123 QCString vcardData = vcards.asString(); 123 QCString vcardData = vcards.asString();
124 file->writeBlock( (const char*)vcardData, vcardData.length() ); 124 file->writeBlock( (const char*)vcardData, vcardData.length() );
125} 125}
126 126
127bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) 127bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
128{ 128{
129 QPtrList<ContentLine> contentLines = v->contentLineList(); 129 QPtrList<ContentLine> contentLines = v->contentLineList();
130 ContentLine *cl; 130 ContentLine *cl;
131 131
132 for( cl = contentLines.first(); cl; cl = contentLines.next() ) { 132 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
133 QCString n = cl->name(); 133 QCString n = cl->name();
134 if ( n.left( 2 ) == "X-" ) { 134 if ( n.left( 2 ) == "X-" ) {
135 n = n.mid( 2 ); 135 n = n.mid( 2 );
136 int posDash = n.find( "-" ); 136 int posDash = n.find( "-" );
137 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), 137 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ),
138 QString::fromUtf8( n.mid( posDash + 1 ) ), 138 QString::fromUtf8( n.mid( posDash + 1 ) ),
139 QString::fromUtf8( cl->value()->asString() ) ); 139 QString::fromUtf8( cl->value()->asString() ) );
140 continue; 140 continue;
141 } 141 }
142 142
143 EntityType type = cl->entityType(); 143 EntityType type = cl->entityType();
144 switch( type ) { 144 switch( type ) {
145 145
146 case EntityUID: 146 case EntityUID:
147 addressee.setUid( readTextValue( cl ) ); 147 addressee.setUid( readTextValue( cl ) );
148 break; 148 break;
149 149
150 case EntityEmail: 150 case EntityEmail:
151 addressee.insertEmail( readTextValue( cl ) ); 151 addressee.insertEmail( readTextValue( cl ) );
152 break; 152 break;
153 153
154 case EntityName: 154 case EntityName:
155 addressee.setName( readTextValue( cl ) ); 155 addressee.setName( readTextValue( cl ) );
156 break; 156 break;
157 157
158 case EntityFullName: 158 case EntityFullName:
159 addressee.setFormattedName( readTextValue( cl ) ); 159 addressee.setFormattedName( readTextValue( cl ) );
160 break; 160 break;
161 161
162 case EntityURL: 162 case EntityURL:
163 addressee.setUrl( KURL( readTextValue( cl ) ) ); 163 addressee.setUrl( KURL( readTextValue( cl ) ) );
164 break; 164 break;
165 165
166 case EntityNickname: 166 case EntityNickname:
167 addressee.setNickName( readTextValue( cl ) ); 167 addressee.setNickName( readTextValue( cl ) );
168 break; 168 break;
169 169
170 case EntityLabel: 170 case EntityLabel:
171 // not yet supported by kabc 171 // not yet supported by kabc
172 break; 172 break;
173 173
174 case EntityMailer: 174 case EntityMailer:
175 addressee.setMailer( readTextValue( cl ) ); 175 addressee.setMailer( readTextValue( cl ) );
176 break; 176 break;
177 177
178 case EntityTitle: 178 case EntityTitle:
179 addressee.setTitle( readTextValue( cl ) ); 179 addressee.setTitle( readTextValue( cl ) );
180 break; 180 break;
181 181
182 case EntityRole: 182 case EntityRole:
183 addressee.setRole( readTextValue( cl ) ); 183 addressee.setRole( readTextValue( cl ) );
184 break; 184 break;
185 185
186 case EntityOrganisation: 186 case EntityOrganisation:
187 addressee.setOrganization( readTextValue( cl ) ); 187 addressee.setOrganization( readTextValue( cl ) );
188 break; 188 break;
189 189
190 case EntityNote: 190 case EntityNote:
191 addressee.setNote( readTextValue( cl ) ); 191 addressee.setNote( readTextValue( cl ) );
192 break; 192 break;
193 193
194 case EntityProductID: 194 case EntityProductID:
195 addressee.setProductId( readTextValue( cl ) ); 195 addressee.setProductId( readTextValue( cl ) );
196 break; 196 break;
197 197
198 case EntitySortString: 198 case EntitySortString:
199 addressee.setSortString( readTextValue( cl ) ); 199 addressee.setSortString( readTextValue( cl ) );
200 break; 200 break;
201 201
202 case EntityN: 202 case EntityN:
203 readNValue( cl, addressee ); 203 readNValue( cl, addressee );
204 break; 204 break;
205 205
206 case EntityAddress: 206 case EntityAddress:
207 addressee.insertAddress( readAddressValue( cl ) ); 207 addressee.insertAddress( readAddressValue( cl ) );
208 break; 208 break;
209 209
210 case EntityTelephone: 210 case EntityTelephone:
211 addressee.insertPhoneNumber( readTelephoneValue( cl ) ); 211 addressee.insertPhoneNumber( readTelephoneValue( cl ) );
212 break; 212 break;
213 213
214 case EntityCategories: 214 case EntityCategories:
215 addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); 215 addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) );
216 break; 216 break;
217 217
218 case EntityBirthday: 218 case EntityBirthday:
219 addressee.setBirthday( readDateValue( cl ) ); 219 addressee.setBirthday( readDateValue( cl ) );
220 break; 220 break;
221 221
222 case EntityRevision: 222 case EntityRevision:
223 addressee.setRevision( readDateTimeValue( cl ) ); 223 addressee.setRevision( readDateTimeValue( cl ) );
224 break; 224 break;
225 225
226 case EntityGeo: 226 case EntityGeo:
227 addressee.setGeo( readGeoValue( cl ) ); 227 addressee.setGeo( readGeoValue( cl ) );
228 break; 228 break;
229 229
230 case EntityTimeZone: 230 case EntityTimeZone:
231 addressee.setTimeZone( readUTCValue( cl ) ); 231 addressee.setTimeZone( readUTCValue( cl ) );
232 break; 232 break;
233 233
234 case EntityVersion: 234 case EntityVersion:
235 break; 235 break;
236 236
237 case EntityClass: 237 case EntityClass:
238 addressee.setSecrecy( readClassValue( cl ) ); 238 addressee.setSecrecy( readClassValue( cl ) );
239 break; 239 break;
240 240
241 case EntityKey: 241 case EntityKey:
242 addressee.insertKey( readKeyValue( cl ) ); 242 addressee.insertKey( readKeyValue( cl ) );
243 break; 243 break;
244 244
245 case EntityPhoto: 245 case EntityPhoto:
246 addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); 246 addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) );
247 break; 247 break;
248 248
249 case EntityLogo: 249 case EntityLogo:
250 addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); 250 addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) );
251 break; 251 break;
252 252
253 case EntityAgent: 253 case EntityAgent:
254 addressee.setAgent( readAgentValue( cl ) ); 254 addressee.setAgent( readAgentValue( cl ) );
255 break; 255 break;
256 256
257 case EntitySound: 257 case EntitySound:
258 addressee.setSound( readSoundValue( cl, addressee ) ); 258 addressee.setSound( readSoundValue( cl, addressee ) );
259 break; 259 break;
260 260
261 default: 261 default:
262 kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " 262 kdDebug(5700) << "VCardFormat::load(): Unsupported entity: "
263 << int( type ) << ": " << cl->asString() << endl; 263 << int( type ) << ": " << cl->asString() << endl;
264 break; 264 break;
265 } 265 }
266 } 266 }
267 267
268 for( cl = contentLines.first(); cl; cl = contentLines.next() ) { 268 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
269 EntityType type = cl->entityType(); 269 EntityType type = cl->entityType();
270 if ( type == EntityLabel ) { 270 if ( type == EntityLabel ) {
271 int type = readAddressParam( cl ); 271 int type = readAddressParam( cl );
272 Address address = addressee.address( type ); 272 Address address = addressee.address( type );
273 if ( address.isEmpty() ) 273 if ( address.isEmpty() )
274 address.setType( type ); 274 address.setType( type );
275 275
276 address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); 276 address.setLabel( QString::fromUtf8( cl->value()->asString() ) );
277 addressee.insertAddress( address ); 277 addressee.insertAddress( address );
278 } 278 }
279 } 279 }
280 280
281 return true; 281 return true;
282} 282}
283 283
284void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) 284void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern )
285{ 285{
286 ContentLine cl; 286//US ContentLine cl;
287 QString value; 287//US QString value;
288 288
289 addTextValue( v, EntityName, addressee.name() ); 289 addTextValue( v, EntityName, addressee.name() );
290 addTextValue( v, EntityUID, addressee.uid() ); 290 addTextValue( v, EntityUID, addressee.uid() );
291 addTextValue( v, EntityFullName, addressee.formattedName() ); 291 addTextValue( v, EntityFullName, addressee.formattedName() );
292 292
293 QStringList emails = addressee.emails(); 293 QStringList emails = addressee.emails();
294 QStringList::ConstIterator it4; 294 QStringList::ConstIterator it4;
295 for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { 295 for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) {
296 addTextValue( v, EntityEmail, *it4 ); 296 addTextValue( v, EntityEmail, *it4 );
297 } 297 }
298 298
299 QStringList customs = addressee.customs(); 299 QStringList customs = addressee.customs();
300 QStringList::ConstIterator it5; 300 QStringList::ConstIterator it5;
301 for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { 301 for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) {
302 addCustomValue( v, *it5 ); 302 addCustomValue( v, *it5 );
303 } 303 }
304 304
305 addTextValue( v, EntityURL, addressee.url().url() ); 305 addTextValue( v, EntityURL, addressee.url().url() );
306 306
307 addNValue( v, addressee ); 307 addNValue( v, addressee );
308 308
309 addTextValue( v, EntityNickname, addressee.nickName() ); 309 addTextValue( v, EntityNickname, addressee.nickName() );
310 addTextValue( v, EntityMailer, addressee.mailer() ); 310 addTextValue( v, EntityMailer, addressee.mailer() );
311 addTextValue( v, EntityTitle, addressee.title() ); 311 addTextValue( v, EntityTitle, addressee.title() );
312 addTextValue( v, EntityRole, addressee.role() ); 312 addTextValue( v, EntityRole, addressee.role() );
313 addTextValue( v, EntityOrganisation, addressee.organization() ); 313 addTextValue( v, EntityOrganisation, addressee.organization() );
314 addTextValue( v, EntityNote, addressee.note() ); 314 addTextValue( v, EntityNote, addressee.note() );
315 addTextValue( v, EntityProductID, addressee.productId() ); 315 addTextValue( v, EntityProductID, addressee.productId() );
316 addTextValue( v, EntitySortString, addressee.sortString() ); 316 addTextValue( v, EntitySortString, addressee.sortString() );
317 317
318 Address::List addresses = addressee.addresses(); 318 Address::List addresses = addressee.addresses();
319 Address::List::ConstIterator it3; 319 Address::List::ConstIterator it3;
320 for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { 320 for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) {
321 addAddressValue( v, *it3 ); 321 addAddressValue( v, *it3 );
322 addLabelValue( v, *it3 ); 322 addLabelValue( v, *it3 );
323 } 323 }
324 324
325 PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); 325 PhoneNumber::List phoneNumbers = addressee.phoneNumbers();
326 PhoneNumber::List::ConstIterator it2; 326 PhoneNumber::List::ConstIterator it2;
327 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { 327 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
328 addTelephoneValue( v, *it2 ); 328 addTelephoneValue( v, *it2 );
329 } 329 }
330 330
331 Key::List keys = addressee.keys(); 331 Key::List keys = addressee.keys();
332 Key::List::ConstIterator it6; 332 Key::List::ConstIterator it6;
333 for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { 333 for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) {
334 addKeyValue( v, *it6 ); 334 addKeyValue( v, *it6 );
335 } 335 }
336 336
337 addTextValue( v, EntityCategories, addressee.categories().join(",") ); 337 addTextValue( v, EntityCategories, addressee.categories().join(",") );
338 338
339 addDateValue( v, EntityBirthday, addressee.birthday().date() ); 339 addDateValue( v, EntityBirthday, addressee.birthday().date() );
340 addDateTimeValue( v, EntityRevision, addressee.revision() ); 340 addDateTimeValue( v, EntityRevision, addressee.revision() );
341 addGeoValue( v, addressee.geo() ); 341 addGeoValue( v, addressee.geo() );
342 addUTCValue( v, addressee.timeZone() ); 342 addUTCValue( v, addressee.timeZone() );
343 343
344 addClassValue( v, addressee.secrecy() ); 344 addClassValue( v, addressee.secrecy() );
345 345
346 addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); 346 addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern );
347 addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); 347 addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern );
348 348
349 addAgentValue( v, addressee.agent() ); 349 addAgentValue( v, addressee.agent() );
350 350
351 addSoundValue( v, addressee.sound(), addressee, intern ); 351 addSoundValue( v, addressee.sound(), addressee, intern );
352} 352}
353 353
354void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) 354void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt )
355{ 355{
356 if ( txt.isEmpty() ) return; 356 if ( txt.isEmpty() ) return;
357 357
358 ContentLine cl; 358 ContentLine cl;
359 cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); 359 cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() );
360 QString value = txt.mid( txt.find( ":" ) + 1 ); 360 QString value = txt.mid( txt.find( ":" ) + 1 );
361 if ( value.isEmpty() ) 361 if ( value.isEmpty() )
362 return; 362 return;
363 cl.setValue( new TextValue( value.utf8() ) ); 363 cl.setValue( new TextValue( value.utf8() ) );
364 v->add(cl); 364 v->add(cl);
365} 365}
366 366
367void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) 367void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt )
368{ 368{
369 if ( txt.isEmpty() ) return; 369 if ( txt.isEmpty() ) return;
370 370
371 ContentLine cl; 371 ContentLine cl;
372 cl.setName( EntityTypeToParamName( type ) ); 372 cl.setName( EntityTypeToParamName( type ) );
373 cl.setValue( new TextValue( txt.utf8() ) ); 373 cl.setValue( new TextValue( txt.utf8() ) );
374 v->add(cl); 374 v->add(cl);
375} 375}
376 376
377void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, 377void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type,
378 const QDate &date ) 378 const QDate &date )
379{ 379{
380 if ( !date.isValid() ) return; 380 if ( !date.isValid() ) return;
381 381
382 ContentLine cl; 382 ContentLine cl;
383 cl.setName( EntityTypeToParamName( type ) ); 383 cl.setName( EntityTypeToParamName( type ) );
384 384
385 DateValue *v = new DateValue( date ); 385 DateValue *v = new DateValue( date );
386 cl.setValue( v ); 386 cl.setValue( v );
387 vcard->add(cl); 387 vcard->add(cl);
388} 388}
389 389
390void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, 390void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type,
391 const QDateTime &dateTime ) 391 const QDateTime &dateTime )
392{ 392{
393 if ( !dateTime.isValid() ) return; 393 if ( !dateTime.isValid() ) return;
394 394
395 ContentLine cl; 395 ContentLine cl;
396 cl.setName( EntityTypeToParamName( type ) ); 396 cl.setName( EntityTypeToParamName( type ) );
397 397
398 DateValue *v = new DateValue( dateTime ); 398 DateValue *v = new DateValue( dateTime );
399 cl.setValue( v ); 399 cl.setValue( v );
400 vcard->add(cl); 400 vcard->add(cl);
401} 401}
402 402
403void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) 403void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a )
404{ 404{
405 if ( a.isEmpty() ) 405 if ( a.isEmpty() )
406 return; 406 return;
407 407
408 ContentLine cl; 408 ContentLine cl;
409 cl.setName( EntityTypeToParamName( EntityAddress ) ); 409 cl.setName( EntityTypeToParamName( EntityAddress ) );
410 410
411 AdrValue *v = new AdrValue; 411 AdrValue *v = new AdrValue;
412 v->setPOBox( a.postOfficeBox().utf8() ); 412 v->setPOBox( a.postOfficeBox().utf8() );
413 v->setExtAddress( a.extended().utf8() ); 413 v->setExtAddress( a.extended().utf8() );
414 v->setStreet( a.street().utf8() ); 414 v->setStreet( a.street().utf8() );
415 v->setLocality( a.locality().utf8() ); 415 v->setLocality( a.locality().utf8() );
416 v->setRegion( a.region().utf8() ); 416 v->setRegion( a.region().utf8() );
417 v->setPostCode( a.postalCode().utf8() ); 417 v->setPostCode( a.postalCode().utf8() );
418 v->setCountryName( a.country().utf8() ); 418 v->setCountryName( a.country().utf8() );
419 cl.setValue( v ); 419 cl.setValue( v );
420 420
421 addAddressParam( &cl, a.type() ); 421 addAddressParam( &cl, a.type() );
422 422
423 vcard->add( cl ); 423 vcard->add( cl );
424} 424}
425 425
426void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) 426void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a )
427{ 427{
428 if ( a.label().isEmpty() ) return; 428 if ( a.label().isEmpty() ) return;
429 429
430 ContentLine cl; 430 ContentLine cl;
431 cl.setName( EntityTypeToParamName( EntityLabel ) ); 431 cl.setName( EntityTypeToParamName( EntityLabel ) );
432 cl.setValue( new TextValue( a.label().utf8() ) ); 432 cl.setValue( new TextValue( a.label().utf8() ) );
433 433
434 addAddressParam( &cl, a.type() ); 434 addAddressParam( &cl, a.type() );
435 435
436 vcard->add( cl ); 436 vcard->add( cl );
437} 437}
438 438
439void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) 439void VCardFormatImpl::addAddressParam( ContentLine *cl, int type )
440{ 440{
441 ParamList params; 441 ParamList params;
442 if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); 442 if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) );
443 if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); 443 if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) );
444 if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); 444 if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) );
445 if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); 445 if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) );
446 if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); 446 if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) );
447 if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); 447 if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) );
448 if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); 448 if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) );
449 cl->setParamList( params ); 449 cl->setParamList( params );
450} 450}
451 451
452void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) 452void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo )
453{ 453{
454 if ( !geo.isValid() ) return; 454 if ( !geo.isValid() ) return;
455 455
456 ContentLine cl; 456 ContentLine cl;
457 cl.setName( EntityTypeToParamName( EntityGeo ) ); 457 cl.setName( EntityTypeToParamName( EntityGeo ) );
458 458
459 GeoValue *v = new GeoValue; 459 GeoValue *v = new GeoValue;
460 v->setLatitude( geo.latitude() ); 460 v->setLatitude( geo.latitude() );
461 v->setLongitude( geo.longitude() ); 461 v->setLongitude( geo.longitude() );
462 462
463 cl.setValue( v ); 463 cl.setValue( v );
464 vcard->add(cl); 464 vcard->add(cl);
465} 465}
466 466
467void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) 467void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz )
468{ 468{
469 if ( !tz.isValid() ) return; 469 if ( !tz.isValid() ) return;
470 470
471 ContentLine cl; 471 ContentLine cl;
472 cl.setName( EntityTypeToParamName( EntityTimeZone ) ); 472 cl.setName( EntityTypeToParamName( EntityTimeZone ) );
473 473
474 UTCValue *v = new UTCValue; 474 UTCValue *v = new UTCValue;
475 475
476 v->setPositive( tz.offset() >= 0 ); 476 v->setPositive( tz.offset() >= 0 );
477 v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); 477 v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
478 v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); 478 v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
479 479
480 cl.setValue( v ); 480 cl.setValue( v );
481 vcard->add(cl); 481 vcard->add(cl);
482} 482}
483 483
484void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) 484void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy )
485{ 485{
486 ContentLine cl; 486 ContentLine cl;
487 cl.setName( EntityTypeToParamName( EntityClass ) ); 487 cl.setName( EntityTypeToParamName( EntityClass ) );
488 488
489 ClassValue *v = new ClassValue; 489 ClassValue *v = new ClassValue;
490 switch ( secrecy.type() ) { 490 switch ( secrecy.type() ) {
491 case Secrecy::Public: 491 case Secrecy::Public:
492 v->setType( (int)ClassValue::Public ); 492 v->setType( (int)ClassValue::Public );
493 break; 493 break;
494 case Secrecy::Private: 494 case Secrecy::Private:
495 v->setType( (int)ClassValue::Private ); 495 v->setType( (int)ClassValue::Private );
496 break; 496 break;
497 case Secrecy::Confidential: 497 case Secrecy::Confidential:
498 v->setType( (int)ClassValue::Confidential ); 498 v->setType( (int)ClassValue::Confidential );
499 break; 499 break;
500 } 500 }
501 501
502 cl.setValue( v ); 502 cl.setValue( v );
503 vcard->add(cl); 503 vcard->add(cl);
504} 504}
505 505
506 506
507Address VCardFormatImpl::readAddressValue( ContentLine *cl ) 507Address VCardFormatImpl::readAddressValue( ContentLine *cl )
508{ 508{
509 Address a; 509 Address a;
510 AdrValue *v = (AdrValue *)cl->value(); 510 AdrValue *v = (AdrValue *)cl->value();
511 a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); 511 a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) );
512 a.setExtended( QString::fromUtf8( v->extAddress() ) ); 512 a.setExtended( QString::fromUtf8( v->extAddress() ) );
513 a.setStreet( QString::fromUtf8( v->street() ) ); 513 a.setStreet( QString::fromUtf8( v->street() ) );
514 a.setLocality( QString::fromUtf8( v->locality() ) ); 514 a.setLocality( QString::fromUtf8( v->locality() ) );
515 a.setRegion( QString::fromUtf8( v->region() ) ); 515 a.setRegion( QString::fromUtf8( v->region() ) );
516 a.setPostalCode( QString::fromUtf8( v->postCode() ) ); 516 a.setPostalCode( QString::fromUtf8( v->postCode() ) );
517 a.setCountry( QString::fromUtf8( v->countryName() ) ); 517 a.setCountry( QString::fromUtf8( v->countryName() ) );
518 518
519 a.setType( readAddressParam( cl ) ); 519 a.setType( readAddressParam( cl ) );
520 520
521 return a; 521 return a;
522} 522}
523 523
524int VCardFormatImpl::readAddressParam( ContentLine *cl ) 524int VCardFormatImpl::readAddressParam( ContentLine *cl )
525{ 525{
526 int type = 0; 526 int type = 0;
527 ParamList params = cl->paramList(); 527 ParamList params = cl->paramList();
528 ParamListIterator it( params ); 528 ParamListIterator it( params );
529 QCString tmpStr; 529 QCString tmpStr;
530 for( ; it.current(); ++it ) { 530 for( ; it.current(); ++it ) {
531 if ( (*it)->name().upper() == "TYPE" ) { 531 if ( (*it)->name().upper() == "TYPE" ) {
532 tmpStr = (*it)->value().lower(); 532 tmpStr = (*it)->value().lower();
533 if ( tmpStr == "dom" ) type |= Address::Dom; 533 if ( tmpStr == "dom" ) type |= Address::Dom;
534 else if ( tmpStr == "intl" ) type |= Address::Intl; 534 else if ( tmpStr == "intl" ) type |= Address::Intl;
535 else if ( tmpStr == "parcel" ) type |= Address::Parcel; 535 else if ( tmpStr == "parcel" ) type |= Address::Parcel;
536 else if ( tmpStr == "postal" ) type |= Address::Postal; 536 else if ( tmpStr == "postal" ) type |= Address::Postal;
537 else if ( tmpStr == "work" ) type |= Address::Work; 537 else if ( tmpStr == "work" ) type |= Address::Work;
538 else if ( tmpStr == "home" ) type |= Address::Home; 538 else if ( tmpStr == "home" ) type |= Address::Home;
539 else if ( tmpStr == "pref" ) type |= Address::Pref; 539 else if ( tmpStr == "pref" ) type |= Address::Pref;
540 } 540 }
541 } 541 }
542 return type; 542 return type;
543} 543}
544 544
545void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) 545void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a )
546{ 546{
547 ContentLine cl; 547 ContentLine cl;
548 cl.setName(EntityTypeToParamName( EntityN ) ); 548 cl.setName(EntityTypeToParamName( EntityN ) );
549 NValue *v = new NValue; 549 NValue *v = new NValue;
550 v->setFamily( a.familyName().utf8() ); 550 v->setFamily( a.familyName().utf8() );
551 v->setGiven( a.givenName().utf8() ); 551 v->setGiven( a.givenName().utf8() );
552 v->setMiddle( a.additionalName().utf8() ); 552 v->setMiddle( a.additionalName().utf8() );
553 v->setPrefix( a.prefix().utf8() ); 553 v->setPrefix( a.prefix().utf8() );
554 v->setSuffix( a.suffix().utf8() ); 554 v->setSuffix( a.suffix().utf8() );
555 555
556 cl.setValue( v ); 556 cl.setValue( v );
557 vcard->add(cl); 557 vcard->add(cl);
558} 558}
559 559
560void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) 560void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a )
561{ 561{
562 NValue *v = (NValue *)cl->value(); 562 NValue *v = (NValue *)cl->value();
563 a.setFamilyName( QString::fromUtf8( v->family() ) ); 563 a.setFamilyName( QString::fromUtf8( v->family() ) );
564 a.setGivenName( QString::fromUtf8( v->given() ) ); 564 a.setGivenName( QString::fromUtf8( v->given() ) );
565 a.setAdditionalName( QString::fromUtf8( v->middle() ) ); 565 a.setAdditionalName( QString::fromUtf8( v->middle() ) );
566 a.setPrefix( QString::fromUtf8( v->prefix() ) ); 566 a.setPrefix( QString::fromUtf8( v->prefix() ) );
567 a.setSuffix( QString::fromUtf8( v->suffix() ) ); 567 a.setSuffix( QString::fromUtf8( v->suffix() ) );
568} 568}
569 569
570void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) 570void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p )
571{ 571{
572 if ( p.number().isEmpty() ) 572 if ( p.number().isEmpty() )
573 return; 573 return;
574 574
575 ContentLine cl; 575 ContentLine cl;
576 cl.setName(EntityTypeToParamName(EntityTelephone)); 576 cl.setName(EntityTypeToParamName(EntityTelephone));
577 cl.setValue(new TelValue( p.number().utf8() )); 577 cl.setValue(new TelValue( p.number().utf8() ));
578 578
579 ParamList params; 579 ParamList params;
580 if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); 580 if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) );
581 if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); 581 if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) );
582 if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); 582 if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) );
583 if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); 583 if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) );
584 if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); 584 if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) );
585 if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); 585 if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) );
586 if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); 586 if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) );
587 if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); 587 if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) );
588 if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); 588 if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) );
589 if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); 589 if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) );
590 if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); 590 if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) );
591 if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); 591 if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) );
592 if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); 592 if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) );
593 if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); 593 if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) );
594 cl.setParamList( params ); 594 cl.setParamList( params );
595 595
596 v->add(cl); 596 v->add(cl);
597} 597}
598 598
599PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) 599PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl )
600{ 600{
601 PhoneNumber p; 601 PhoneNumber p;
602 TelValue *value = (TelValue *)cl->value(); 602 TelValue *value = (TelValue *)cl->value();
603 p.setNumber( QString::fromUtf8( value->asString() ) ); 603 p.setNumber( QString::fromUtf8( value->asString() ) );
604 604
605 int type = 0; 605 int type = 0;
606 ParamList params = cl->paramList(); 606 ParamList params = cl->paramList();
607 ParamListIterator it( params ); 607 ParamListIterator it( params );
608 QCString tmpStr; 608 QCString tmpStr;
609 for( ; it.current(); ++it ) { 609 for( ; it.current(); ++it ) {
610 if ( (*it)->name() == "TYPE" ) { 610 if ( (*it)->name() == "TYPE" ) {
611 tmpStr = (*it)->value().lower(); 611 tmpStr = (*it)->value().lower();
612 if ( tmpStr == "home" ) type |= PhoneNumber::Home; 612 if ( tmpStr == "home" ) type |= PhoneNumber::Home;
613 else if ( tmpStr == "work" ) type |= PhoneNumber::Work; 613 else if ( tmpStr == "work" ) type |= PhoneNumber::Work;
614 else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; 614 else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg;
615 else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; 615 else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref;
616 else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; 616 else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice;
617 else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; 617 else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax;
618 else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; 618 else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell;
619 else if ( tmpStr == "video" ) type |= PhoneNumber::Video; 619 else if ( tmpStr == "video" ) type |= PhoneNumber::Video;
620 else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; 620 else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs;
621 else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; 621 else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem;
622 else if ( tmpStr == "car" ) type |= PhoneNumber::Car; 622 else if ( tmpStr == "car" ) type |= PhoneNumber::Car;
623 else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; 623 else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn;
624 else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; 624 else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs;
625 else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; 625 else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager;
626 } 626 }
627 } 627 }
628 p.setType( type ); 628 p.setType( type );
629 629
630 return p; 630 return p;
631} 631}
632 632
633QString VCardFormatImpl::readTextValue( ContentLine *cl ) 633QString VCardFormatImpl::readTextValue( ContentLine *cl )
634{ 634{
635 VCARD::Value *value = cl->value(); 635 VCARD::Value *value = cl->value();
636 if ( value ) { 636 if ( value ) {
637 return QString::fromUtf8( value->asString() ); 637 return QString::fromUtf8( value->asString() );
638 } else { 638 } else {
639 kdDebug(5700) << "No value: " << cl->asString() << endl; 639 kdDebug(5700) << "No value: " << cl->asString() << endl;
640 return QString::null; 640 return QString::null;
641 } 641 }
642} 642}
643 643
644QDate VCardFormatImpl::readDateValue( ContentLine *cl ) 644QDate VCardFormatImpl::readDateValue( ContentLine *cl )
645{ 645{
646 DateValue *dateValue = (DateValue *)cl->value(); 646 DateValue *dateValue = (DateValue *)cl->value();
647 if ( dateValue ) 647 if ( dateValue )
648 return dateValue->qdate(); 648 return dateValue->qdate();
649 else 649 else
650 return QDate(); 650 return QDate();
651} 651}
652 652
653QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) 653QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl )
654{ 654{
655 DateValue *dateValue = (DateValue *)cl->value(); 655 DateValue *dateValue = (DateValue *)cl->value();
656 if ( dateValue ) 656 if ( dateValue )
657 return dateValue->qdt(); 657 return dateValue->qdt();
658 else 658 else
659 return QDateTime(); 659 return QDateTime();
660} 660}
661 661
662Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) 662Geo VCardFormatImpl::readGeoValue( ContentLine *cl )
663{ 663{
664 GeoValue *geoValue = (GeoValue *)cl->value(); 664 GeoValue *geoValue = (GeoValue *)cl->value();
665 if ( geoValue ) { 665 if ( geoValue ) {
666 Geo geo( geoValue->latitude(), geoValue->longitude() ); 666 Geo geo( geoValue->latitude(), geoValue->longitude() );
667 return geo; 667 return geo;
668 } else 668 } else
669 return Geo(); 669 return Geo();
670} 670}
671 671
672TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) 672TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl )
673{ 673{
674 UTCValue *utcValue = (UTCValue *)cl->value(); 674 UTCValue *utcValue = (UTCValue *)cl->value();
675 if ( utcValue ) { 675 if ( utcValue ) {
676 TimeZone tz; 676 TimeZone tz;
677 tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); 677 tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1));
678 return tz; 678 return tz;
679 } else 679 } else
680 return TimeZone(); 680 return TimeZone();
681} 681}
682 682
683Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) 683Secrecy VCardFormatImpl::readClassValue( ContentLine *cl )
684{ 684{
685 ClassValue *classValue = (ClassValue *)cl->value(); 685 ClassValue *classValue = (ClassValue *)cl->value();
686 if ( classValue ) { 686 if ( classValue ) {
687 Secrecy secrecy; 687 Secrecy secrecy;
688 switch ( classValue->type() ) { 688 switch ( classValue->type() ) {
689 case ClassValue::Public: 689 case ClassValue::Public:
690 secrecy.setType( Secrecy::Public ); 690 secrecy.setType( Secrecy::Public );
691 break; 691 break;
692 case ClassValue::Private: 692 case ClassValue::Private:
693 secrecy.setType( Secrecy::Private ); 693 secrecy.setType( Secrecy::Private );
694 break; 694 break;
695 case ClassValue::Confidential: 695 case ClassValue::Confidential:
696 secrecy.setType( Secrecy::Confidential ); 696 secrecy.setType( Secrecy::Confidential );
697 break; 697 break;
698 } 698 }
699 699
700 return secrecy; 700 return secrecy;
701 } else 701 } else
702 return Secrecy(); 702 return Secrecy();
703} 703}
704 704
705void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) 705void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key )
706{ 706{
707 ContentLine cl; 707 ContentLine cl;
708 cl.setName( EntityTypeToParamName( EntityKey ) ); 708 cl.setName( EntityTypeToParamName( EntityKey ) );
709 709
710 ParamList params; 710 ParamList params;
711 if ( key.isBinary() ) { 711 if ( key.isBinary() ) {
712 cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); 712 cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) );
713 params.append( new Param( "ENCODING", "b" ) ); 713 params.append( new Param( "ENCODING", "b" ) );
714 } else { 714 } else {
715 cl.setValue( new TextValue( key.textData().utf8() ) ); 715 cl.setValue( new TextValue( key.textData().utf8() ) );
716 } 716 }
717 717
718 switch ( key.type() ) { 718 switch ( key.type() ) {
719 case Key::X509: 719 case Key::X509:
720 params.append( new Param( "TYPE", "X509" ) ); 720 params.append( new Param( "TYPE", "X509" ) );
721 break; 721 break;
722 case Key::PGP: 722 case Key::PGP:
723 params.append( new Param( "TYPE", "PGP" ) ); 723 params.append( new Param( "TYPE", "PGP" ) );
724 break; 724 break;
725 case Key::Custom: 725 case Key::Custom:
726 params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); 726 params.append( new Param( "TYPE", key.customTypeString().utf8() ) );
727 break; 727 break;
728 } 728 }
729 729
730 cl.setParamList( params ); 730 cl.setParamList( params );
731 vcard->add( cl ); 731 vcard->add( cl );
732} 732}
733 733
734Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) 734Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl )
735{ 735{
736 Key key; 736 Key key;
737 bool isBinary = false; 737 bool isBinary = false;
738 TextValue *v = (TextValue *)cl->value(); 738 TextValue *v = (TextValue *)cl->value();
739 739
740 ParamList params = cl->paramList(); 740 ParamList params = cl->paramList();
741 ParamListIterator it( params ); 741 ParamListIterator it( params );
742 for( ; it.current(); ++it ) { 742 for( ; it.current(); ++it ) {
743 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) 743 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
744 isBinary = true; 744 isBinary = true;
745 if ( (*it)->name() == "TYPE" ) { 745 if ( (*it)->name() == "TYPE" ) {
746 if ( (*it)->value().isEmpty() ) 746 if ( (*it)->value().isEmpty() )
747 continue; 747 continue;
748 if ( (*it)->value() == "X509" ) 748 if ( (*it)->value() == "X509" )
749 key.setType( Key::X509 ); 749 key.setType( Key::X509 );
750 else if ( (*it)->value() == "PGP" ) 750 else if ( (*it)->value() == "PGP" )
751 key.setType( Key::PGP ); 751 key.setType( Key::PGP );
752 else { 752 else {
753 key.setType( Key::Custom ); 753 key.setType( Key::Custom );
754 key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); 754 key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) );
755 } 755 }
756 } 756 }
757 } 757 }
758 758
759 759
760 if ( isBinary ) { 760 if ( isBinary ) {
761 QByteArray data; 761 QByteArray data;
762 KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); 762 KCodecs::base64Decode( v->asString().stripWhiteSpace(), data );
763 key.setBinaryData( data ); 763 key.setBinaryData( data );
764 } else { 764 } else {
765 key.setTextData( QString::fromUtf8( v->asString() ) ); 765 key.setTextData( QString::fromUtf8( v->asString() ) );
766 } 766 }
767 767
768 return key; 768 return key;
769} 769}
770 770
771 771
772void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) 772void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent )
773{ 773{
774 if ( agent.isIntern() && !agent.addressee() ) 774 if ( agent.isIntern() && !agent.addressee() )
775 return; 775 return;
776 776
777 if ( !agent.isIntern() && agent.url().isEmpty() ) 777 if ( !agent.isIntern() && agent.url().isEmpty() )
778 return; 778 return;
779 779
780 ContentLine cl; 780 ContentLine cl;
781 cl.setName( EntityTypeToParamName( EntityAgent ) ); 781 cl.setName( EntityTypeToParamName( EntityAgent ) );
782 782
783 ParamList params; 783 ParamList params;
784 if ( agent.isIntern() ) { 784 if ( agent.isIntern() ) {
785 QString vstr; 785 QString vstr;
786 Addressee *addr = agent.addressee(); 786 Addressee *addr = agent.addressee();
787 if ( addr ) { 787 if ( addr ) {
788 writeToString( (*addr), vstr ); 788 writeToString( (*addr), vstr );
789 789
790 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); 790 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
791/*US 791/*US
792 vstr.replace( ":", "\\:" ); 792 vstr.replace( ":", "\\:" );
793 vstr.replace( ",", "\\," ); 793 vstr.replace( ",", "\\," );
794 vstr.replace( ";", "\\;" ); 794 vstr.replace( ";", "\\;" );
795 vstr.replace( "\r\n", "\\n" ); 795 vstr.replace( "\r\n", "\\n" );
796*/ 796*/
797 vstr.replace( QRegExp(":"), "\\:" ); 797 vstr.replace( QRegExp(":"), "\\:" );
798 vstr.replace( QRegExp(","), "\\," ); 798 vstr.replace( QRegExp(","), "\\," );
799 vstr.replace( QRegExp(";"), "\\;" ); 799 vstr.replace( QRegExp(";"), "\\;" );
800 vstr.replace( QRegExp("\r\n"), "\\n" ); 800 vstr.replace( QRegExp("\r\n"), "\\n" );
801 801
802 cl.setValue( new TextValue( vstr.utf8() ) ); 802 cl.setValue( new TextValue( vstr.utf8() ) );
803 } else 803 } else
804 return; 804 return;
805 } else { 805 } else {
806 cl.setValue( new TextValue( agent.url().utf8() ) ); 806 cl.setValue( new TextValue( agent.url().utf8() ) );
807 params.append( new Param( "VALUE", "uri" ) ); 807 params.append( new Param( "VALUE", "uri" ) );
808 } 808 }
809 809
810 cl.setParamList( params ); 810 cl.setParamList( params );
811 vcard->add( cl ); 811 vcard->add( cl );
812} 812}
813 813
814Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) 814Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl )
815{ 815{
816 Agent agent; 816 Agent agent;
817 bool isIntern = true; 817 bool isIntern = true;
818 TextValue *v = (TextValue *)cl->value(); 818 TextValue *v = (TextValue *)cl->value();
819 819
820 ParamList params = cl->paramList(); 820 ParamList params = cl->paramList();
821 ParamListIterator it( params ); 821 ParamListIterator it( params );
822 for( ; it.current(); ++it ) { 822 for( ; it.current(); ++it ) {
823 if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) 823 if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" )
824 isIntern = false; 824 isIntern = false;
825 } 825 }
826 826
827 if ( isIntern ) { 827 if ( isIntern ) {
828 QString vstr = QString::fromUtf8( v->asString() ); 828 QString vstr = QString::fromUtf8( v->asString() );
829 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); 829 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
830/*US 830/*US
831 vstr.replace( "\\n", "\r\n" ); 831 vstr.replace( "\\n", "\r\n" );
832 vstr.replace( "\\:", ":" ); 832 vstr.replace( "\\:", ":" );
833 vstr.replace( "\\,", "," ); 833 vstr.replace( "\\,", "," );
834 vstr.replace( "\\;", ";" ); 834 vstr.replace( "\\;", ";" );
835*/ 835*/
836 vstr.replace( QRegExp("\\n"), "\r\n" ); 836 vstr.replace( QRegExp("\\n"), "\r\n" );
837 vstr.replace( QRegExp("\\:"), ":" ); 837 vstr.replace( QRegExp("\\:"), ":" );
838 vstr.replace( QRegExp("\\,"), "," ); 838 vstr.replace( QRegExp("\\,"), "," );
839 vstr.replace( QRegExp("\\;"), ";" ); 839 vstr.replace( QRegExp("\\;"), ";" );
840 840
841 Addressee *addr = new Addressee; 841 Addressee *addr = new Addressee;
842 readFromString( vstr, *addr ); 842 readFromString( vstr, *addr );
843 agent.setAddressee( addr ); 843 agent.setAddressee( addr );
844 } else { 844 } else {
845 agent.setUrl( QString::fromUtf8( v->asString() ) ); 845 agent.setUrl( QString::fromUtf8( v->asString() ) );
846 } 846 }
847 847
848 return agent; 848 return agent;
849} 849}
850 850
851void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) 851void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern )
852{ 852{
853 ContentLine cl; 853 ContentLine cl;
854 cl.setName( EntityTypeToParamName( type ) ); 854 cl.setName( EntityTypeToParamName( type ) );
855 855
856 if ( pic.isIntern() && pic.data().isNull() ) 856 if ( pic.isIntern() && pic.data().isNull() )
857 return; 857 return;
858 858
859 if ( !pic.isIntern() && pic.url().isEmpty() ) 859 if ( !pic.isIntern() && pic.url().isEmpty() )
860 return; 860 return;
861 861
862 ParamList params; 862 ParamList params;
863 if ( pic.isIntern() ) { 863 if ( pic.isIntern() ) {
864 QImage img = pic.data(); 864 QImage img = pic.data();
865 if ( intern ) { // only for vCard export we really write the data inline 865 if ( intern ) { // only for vCard export we really write the data inline
866 QByteArray data; 866 QByteArray data;
867 QDataStream s( data, IO_WriteOnly ); 867 QDataStream s( data, IO_WriteOnly );
868 s.setVersion( 4 ); // to produce valid png files 868 s.setVersion( 4 ); // to produce valid png files
869 s << img; 869 s << img;
870 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); 870 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
871 871
872 } else { // save picture in cache 872 } else { // save picture in cache
873 QString dir; 873 QString dir;
874 if ( type == EntityPhoto ) 874 if ( type == EntityPhoto )
875 dir = "photos"; 875 dir = "photos";
876 if ( type == EntityLogo ) 876 if ( type == EntityLogo )
877 dir = "logos"; 877 dir = "logos";
878 878
879 img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); 879 img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() );
880 cl.setValue( new TextValue( "<dummy>" ) ); 880 cl.setValue( new TextValue( "<dummy>" ) );
881 } 881 }
882 params.append( new Param( "ENCODING", "b" ) ); 882 params.append( new Param( "ENCODING", "b" ) );
883 if ( !pic.type().isEmpty() ) 883 if ( !pic.type().isEmpty() )
884 params.append( new Param( "TYPE", pic.type().utf8() ) ); 884 params.append( new Param( "TYPE", pic.type().utf8() ) );
885 } else { 885 } else {
886 886
887 cl.setValue( new TextValue( pic.url().utf8() ) ); 887 cl.setValue( new TextValue( pic.url().utf8() ) );
888 params.append( new Param( "VALUE", "uri" ) ); 888 params.append( new Param( "VALUE", "uri" ) );
889 } 889 }
890 890
891 cl.setParamList( params ); 891 cl.setParamList( params );
892 vcard->add( cl ); 892 vcard->add( cl );
893} 893}
894 894
895Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr ) 895Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr )
896{ 896{
897 Picture pic; 897 Picture pic;
898 bool isInline = false; 898 bool isInline = false;
899 QString picType; 899 QString picType;
900 TextValue *v = (TextValue *)cl->value(); 900 TextValue *v = (TextValue *)cl->value();
901 901
902 ParamList params = cl->paramList(); 902 ParamList params = cl->paramList();
903 ParamListIterator it( params ); 903 ParamListIterator it( params );
904 for( ; it.current(); ++it ) { 904 for( ; it.current(); ++it ) {
905 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) 905 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
906 isInline = true; 906 isInline = true;
907 if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() ) 907 if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() )
908 picType = QString::fromUtf8( (*it)->value() ); 908 picType = QString::fromUtf8( (*it)->value() );
909 } 909 }
910 910
911 if ( isInline ) { 911 if ( isInline ) {
912 QImage img; 912 QImage img;
913 if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache 913 if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache
914 QString dir; 914 QString dir;
915 if ( type == EntityPhoto ) 915 if ( type == EntityPhoto )
916 dir = "photos"; 916 dir = "photos";
917 if ( type == EntityLogo ) 917 if ( type == EntityLogo )
918 dir = "logos"; 918 dir = "logos";
919 919
920 img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) ); 920 img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) );
921 } else { 921 } else {
922 QByteArray data; 922 QByteArray data;
923 KCodecs::base64Decode( v->asString(), data ); 923 KCodecs::base64Decode( v->asString(), data );
924 img.loadFromData( data ); 924 img.loadFromData( data );
925 } 925 }
926 pic.setData( img ); 926 pic.setData( img );
927 pic.setType( picType ); 927 pic.setType( picType );
928 } else { 928 } else {
929 pic.setUrl( QString::fromUtf8( v->asString() ) ); 929 pic.setUrl( QString::fromUtf8( v->asString() ) );
930 } 930 }
931 931
932 return pic; 932 return pic;
933} 933}
934 934
935void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern ) 935void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern )
936{ 936{
937 ContentLine cl; 937 ContentLine cl;
938 cl.setName( EntityTypeToParamName( EntitySound ) ); 938 cl.setName( EntityTypeToParamName( EntitySound ) );
939 939
940 if ( sound.isIntern() && sound.data().isNull() ) 940 if ( sound.isIntern() && sound.data().isNull() )
941 return; 941 return;
942 942
943 if ( !sound.isIntern() && sound.url().isEmpty() ) 943 if ( !sound.isIntern() && sound.url().isEmpty() )
944 return; 944 return;
945 945
946 ParamList params; 946 ParamList params;
947 if ( sound.isIntern() ) { 947 if ( sound.isIntern() ) {
948 QByteArray data = sound.data(); 948 QByteArray data = sound.data();
949 if ( intern ) { // only for vCard export we really write the data inline 949 if ( intern ) { // only for vCard export we really write the data inline
950 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); 950 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
951 } else { // save sound in cache 951 } else { // save sound in cache
952 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); 952 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
953 if ( file.open( IO_WriteOnly ) ) { 953 if ( file.open( IO_WriteOnly ) ) {
954 file.writeBlock( data ); 954 file.writeBlock( data );
955 } 955 }
956 cl.setValue( new TextValue( "<dummy>" ) ); 956 cl.setValue( new TextValue( "<dummy>" ) );
957 } 957 }
958 params.append( new Param( "ENCODING", "b" ) ); 958 params.append( new Param( "ENCODING", "b" ) );
959 } else { 959 } else {
960 cl.setValue( new TextValue( sound.url().utf8() ) ); 960 cl.setValue( new TextValue( sound.url().utf8() ) );
961 params.append( new Param( "VALUE", "uri" ) ); 961 params.append( new Param( "VALUE", "uri" ) );
962 } 962 }
963 963
964 cl.setParamList( params ); 964 cl.setParamList( params );
965 vcard->add( cl ); 965 vcard->add( cl );
966} 966}
967 967
968Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr ) 968Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr )
969{ 969{
970 Sound sound; 970 Sound sound;
971 bool isInline = false; 971 bool isInline = false;
972 TextValue *v = (TextValue *)cl->value(); 972 TextValue *v = (TextValue *)cl->value();
973 973
974 ParamList params = cl->paramList(); 974 ParamList params = cl->paramList();
975 ParamListIterator it( params ); 975 ParamListIterator it( params );
976 for( ; it.current(); ++it ) { 976 for( ; it.current(); ++it ) {
977 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) 977 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
978 isInline = true; 978 isInline = true;
979 } 979 }
980 980
981 if ( isInline ) { 981 if ( isInline ) {
982 QByteArray data; 982 QByteArray data;
983 if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache 983 if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache
984 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); 984 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
985 if ( file.open( IO_ReadOnly ) ) { 985 if ( file.open( IO_ReadOnly ) ) {
986 data = file.readAll(); 986 data = file.readAll();
987 file.close(); 987 file.close();
988 } 988 }
989 } else { 989 } else {
990 KCodecs::base64Decode( v->asString(), data ); 990 KCodecs::base64Decode( v->asString(), data );
991 } 991 }
992 sound.setData( data ); 992 sound.setData( data );
993 } else { 993 } else {
994 sound.setUrl( QString::fromUtf8( v->asString() ) ); 994 sound.setUrl( QString::fromUtf8( v->asString() ) );
995 } 995 }
996 996
997 return sound; 997 return sound;
998} 998}
999 999
1000bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) 1000bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee )
1001{ 1001{
1002 VCardEntity e( vcard.utf8() ); 1002 VCardEntity e( vcard.utf8() );
1003 VCardListIterator it( e.cardList() ); 1003 VCardListIterator it( e.cardList() );
1004 1004
1005 if ( it.current() ) { 1005 if ( it.current() ) {
1006//US VCard v(*it.current()); 1006//US VCard v(*it.current());
1007//US loadAddressee( addressee, v ); 1007//US loadAddressee( addressee, v );
1008 loadAddressee( addressee, it.current() ); 1008 loadAddressee( addressee, it.current() );
1009 return true; 1009 return true;
1010 } 1010 }
1011 1011
1012 return false; 1012 return false;
1013} 1013}
1014 1014
1015bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard ) 1015bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard )
1016{ 1016{
1017 VCardEntity vcards; 1017 VCardEntity vcards;
1018 VCardList vcardlist; 1018 VCardList vcardlist;
1019 vcardlist.setAutoDelete( true ); 1019 vcardlist.setAutoDelete( true );
1020 1020
1021 VCard *v = new VCard; 1021 VCard *v = new VCard;
1022 1022
1023 saveAddressee( addressee, v, true ); 1023 saveAddressee( addressee, v, true );
1024 1024
1025 vcardlist.append( v ); 1025 vcardlist.append( v );
1026 vcards.setCardList( vcardlist ); 1026 vcards.setCardList( vcardlist );
1027 vcard = QString::fromUtf8( vcards.asString() ); 1027 vcard = QString::fromUtf8( vcards.asString() );
1028 1028
1029 return true; 1029 return true;
1030} 1030}