summaryrefslogtreecommitdiffabout
path: root/kabc/vcard21parser.cpp
Unidiff
Diffstat (limited to 'kabc/vcard21parser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard21parser.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/kabc/vcard21parser.cpp b/kabc/vcard21parser.cpp
index 60d02b8..e24a9dc 100644
--- a/kabc/vcard21parser.cpp
+++ b/kabc/vcard21parser.cpp
@@ -1,607 +1,613 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Mark Westcott <mark@houseoffish.org> 3 Copyright (c) 2001 Mark Westcott <mark@houseoffish.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 <qmap.h> 28#include <qmap.h>
29#include <qregexp.h> 29#include <qregexp.h>
30//Added by qt3to4:
31#include <Q3ValueList>
30#include <kmdcodec.h> 32#include <kmdcodec.h>
31 33
32#include "vcard21parser.h" 34#include "vcard21parser.h"
33#include "vcardconverter.h" 35#include "vcardconverter.h"
34 36
35using namespace KABC; 37using namespace KABC;
36 38
37bool VCardLineX::isValid() const 39bool VCardLineX::isValid() const
38{ 40{
39 // Invalid: if it is "begin:vcard" or "end:vcard" 41 // Invalid: if it is "begin:vcard" or "end:vcard"
40 if ( name == VCARD_BEGIN_N || name == VCARD_END_N ) 42 if ( name == VCARD_BEGIN_N || name == VCARD_END_N )
41 return false; 43 return false;
42 44
43 if ( name[0] == 'x' && name[1] == '-' ) // A custom x- line 45 if ( name[0] == 'x' && name[1] == '-' ) // A custom x- line
44 return true; 46 return true;
45 47
46 // This is long but it makes it a bit faster (and saves me from using 48 // This is long but it makes it a bit faster (and saves me from using
47 // a tree which is probably the ideal situation, but a bit memory heavy) 49 // a tree which is probably the ideal situation, but a bit memory heavy)
48 switch( name[0] ) { 50 switch( name[0].unicode() ) {
49 case 'a': 51 case 'a':
50 if ( name == VCARD_ADR && qualified && 52 if ( name == VCARD_ADR && qualified &&
51 (qualifiers.contains(VCARD_ADR_DOM) || 53 (qualifiers.contains(VCARD_ADR_DOM) ||
52 qualifiers.contains(VCARD_ADR_INTL) || 54 qualifiers.contains(VCARD_ADR_INTL) ||
53 qualifiers.contains(VCARD_ADR_POSTAL) || 55 qualifiers.contains(VCARD_ADR_POSTAL) ||
54 qualifiers.contains(VCARD_ADR_HOME) || 56 qualifiers.contains(VCARD_ADR_HOME) ||
55 qualifiers.contains(VCARD_ADR_WORK) || 57 qualifiers.contains(VCARD_ADR_WORK) ||
56 qualifiers.contains(VCARD_ADR_PREF) 58 qualifiers.contains(VCARD_ADR_PREF)
57 ) ) 59 ) )
58 return true; 60 return true;
59 61
60 if ( name == VCARD_AGENT ) 62 if ( name == VCARD_AGENT )
61 return true; 63 return true;
62 break; 64 break;
63 65
64 case 'b': 66 case 'b':
65 if ( name == VCARD_BDAY ) 67 if ( name == VCARD_BDAY )
66 return true; 68 return true;
67 break; 69 break;
68 70
69 case 'c': 71 case 'c':
70 if ( name == VCARD_CATEGORIES ) 72 if ( name == VCARD_CATEGORIES )
71 return true; 73 return true;
72 if ( name == VCARD_CLASS && qualified && 74 if ( name == VCARD_CLASS && qualified &&
73 (qualifiers.contains(VCARD_CLASS_PUBLIC) || 75 (qualifiers.contains(VCARD_CLASS_PUBLIC) ||
74 qualifiers.contains(VCARD_CLASS_PRIVATE) || 76 qualifiers.contains(VCARD_CLASS_PRIVATE) ||
75 qualifiers.contains(VCARD_CLASS_CONFIDENTIAL) 77 qualifiers.contains(VCARD_CLASS_CONFIDENTIAL)
76 ) ) 78 ) )
77 return true; 79 return true;
78 break; 80 break;
79 81
80 case 'e': 82 case 'e':
81 if ( name == VCARD_EMAIL && qualified && 83 if ( name == VCARD_EMAIL && qualified &&
82 (qualifiers.contains(VCARD_EMAIL_INTERNET) || 84 (qualifiers.contains(VCARD_EMAIL_INTERNET) ||
83 qualifiers.contains(VCARD_EMAIL_PREF) || 85 qualifiers.contains(VCARD_EMAIL_PREF) ||
84 qualifiers.contains(VCARD_EMAIL_X400) 86 qualifiers.contains(VCARD_EMAIL_X400)
85 ) ) 87 ) )
86 return true; 88 return true;
87 break; 89 break;
88 90
89 case 'f': 91 case 'f':
90 if ( name == VCARD_FN ) 92 if ( name == VCARD_FN )
91 return true; 93 return true;
92 break; 94 break;
93 95
94 case 'g': 96 case 'g':
95 if ( name == VCARD_GEO ) 97 if ( name == VCARD_GEO )
96 return true; 98 return true;
97 break; 99 break;
98 100
99 case 'k': 101 case 'k':
100 if ( name == VCARD_KEY && qualified && 102 if ( name == VCARD_KEY && qualified &&
101 (qualifiers.contains(VCARD_KEY_X509) || 103 (qualifiers.contains(VCARD_KEY_X509) ||
102 qualifiers.contains(VCARD_KEY_PGP) 104 qualifiers.contains(VCARD_KEY_PGP)
103 ) ) 105 ) )
104 return true; 106 return true;
105 break; 107 break;
106 108
107 case 'l': 109 case 'l':
108 if ( name == VCARD_LABEL ) 110 if ( name == VCARD_LABEL )
109 return true; 111 return true;
110 if ( name == VCARD_LOGO ) 112 if ( name == VCARD_LOGO )
111 return true; 113 return true;
112 break; 114 break;
113 115
114 case 'm': 116 case 'm':
115 if ( name == VCARD_MAILER ) 117 if ( name == VCARD_MAILER )
116 return true; 118 return true;
117 break; 119 break;
118 120
119 case 'n': 121 case 'n':
120 if ( name == VCARD_N ) 122 if ( name == VCARD_N )
121 return true; 123 return true;
122 if ( name == VCARD_NAME ) 124 if ( name == VCARD_NAME )
123 return true; 125 return true;
124 if ( name == VCARD_NICKNAME ) 126 if ( name == VCARD_NICKNAME )
125 return true; 127 return true;
126 if ( name == VCARD_NOTE ) 128 if ( name == VCARD_NOTE )
127 return true; 129 return true;
128 break; 130 break;
129 131
130 case 'o': 132 case 'o':
131 if ( name == VCARD_ORG ) 133 if ( name == VCARD_ORG )
132 return true; 134 return true;
133 break; 135 break;
134 136
135 case 'p': 137 case 'p':
136 if ( name == VCARD_PHOTO ) 138 if ( name == VCARD_PHOTO )
137 return true; 139 return true;
138 if ( name == VCARD_PROFILE ) 140 if ( name == VCARD_PROFILE )
139 return true; 141 return true;
140 if ( name == VCARD_PRODID ) 142 if ( name == VCARD_PRODID )
141 return true; 143 return true;
142 break; 144 break;
143 145
144 case 'r': 146 case 'r':
145 if ( name == VCARD_ROLE ) 147 if ( name == VCARD_ROLE )
146 return true; 148 return true;
147 if ( name == VCARD_REV ) 149 if ( name == VCARD_REV )
148 return true; 150 return true;
149 break; 151 break;
150 152
151 case 's': 153 case 's':
152 if ( name == VCARD_SOURCE ) 154 if ( name == VCARD_SOURCE )
153 return true; 155 return true;
154 if ( name == VCARD_SOUND ) 156 if ( name == VCARD_SOUND )
155 return true; 157 return true;
156 break; 158 break;
157 159
158 case 't': 160 case 't':
159 if ( name == VCARD_TEL && qualified && 161 if ( name == VCARD_TEL && qualified &&
160 (qualifiers.contains(VCARD_TEL_HOME) || 162 (qualifiers.contains(VCARD_TEL_HOME) ||
161 qualifiers.contains(VCARD_TEL_WORK) || 163 qualifiers.contains(VCARD_TEL_WORK) ||
162 qualifiers.contains(VCARD_TEL_PREF) || 164 qualifiers.contains(VCARD_TEL_PREF) ||
163 qualifiers.contains(VCARD_TEL_VOICE) || 165 qualifiers.contains(VCARD_TEL_VOICE) ||
164 qualifiers.contains(VCARD_TEL_FAX) || 166 qualifiers.contains(VCARD_TEL_FAX) ||
165 qualifiers.contains(VCARD_TEL_MSG) || 167 qualifiers.contains(VCARD_TEL_MSG) ||
166 qualifiers.contains(VCARD_TEL_CELL) || 168 qualifiers.contains(VCARD_TEL_CELL) ||
167 qualifiers.contains(VCARD_TEL_PAGER) || 169 qualifiers.contains(VCARD_TEL_PAGER) ||
168 qualifiers.contains(VCARD_TEL_BBS) || 170 qualifiers.contains(VCARD_TEL_BBS) ||
169 qualifiers.contains(VCARD_TEL_MODEM) || 171 qualifiers.contains(VCARD_TEL_MODEM) ||
170 qualifiers.contains(VCARD_TEL_CAR) || 172 qualifiers.contains(VCARD_TEL_CAR) ||
171 qualifiers.contains(VCARD_TEL_ISDN) || 173 qualifiers.contains(VCARD_TEL_ISDN) ||
172 qualifiers.contains(VCARD_TEL_VIDEO) || 174 qualifiers.contains(VCARD_TEL_VIDEO) ||
173 qualifiers.contains(VCARD_TEL_PCS) 175 qualifiers.contains(VCARD_TEL_PCS)
174 ) ) 176 ) )
175 return true; 177 return true;
176 if ( name == VCARD_TZ ) 178 if ( name == VCARD_TZ )
177 return true; 179 return true;
178 if ( name == VCARD_TITLE ) 180 if ( name == VCARD_TITLE )
179 return true; 181 return true;
180 break; 182 break;
181 183
182 case 'u': 184 case 'u':
183 if ( name == VCARD_URL ) 185 if ( name == VCARD_URL )
184 return true; 186 return true;
185 if ( name == VCARD_UID ) 187 if ( name == VCARD_UID )
186 return true; 188 return true;
187 break; 189 break;
188 190
189 case 'v': 191 case 'v':
190 if ( name == VCARD_VERSION ) 192 if ( name == VCARD_VERSION )
191 return true; 193 return true;
192 break; 194 break;
193 default: 195 default:
194 break; 196 break;
195 } 197 }
196 198
197 return false; 199 return false;
198} 200}
199 201
200 202
201VCard21Parser::VCard21Parser() 203VCard21Parser::VCard21Parser()
202{ 204{
203} 205}
204 206
205VCard21Parser::~VCard21Parser() 207VCard21Parser::~VCard21Parser()
206{ 208{
207} 209}
208 210
209void VCard21Parser::readFromString(KABC::AddressBook *addressbook, const QString &data) 211void VCard21Parser::readFromString(KABC::AddressBook *addressbook, const QString &data)
210{ 212{
211 KABC::Addressee mAddressee = readFromString(data); 213 KABC::Addressee mAddressee = readFromString(data);
212 addressbook->insertAddressee(mAddressee); 214 addressbook->insertAddressee(mAddressee);
213} 215}
214 216
215KABC::Addressee VCard21Parser::readFromString( const QString &data) 217KABC::Addressee VCard21Parser::readFromString( const QString &data)
216{ 218{
217 KABC::Addressee addressee; 219 KABC::Addressee addressee;
218 VCard21ParserImpl *mVCard = VCard21ParserImpl::parseVCard(data); 220 VCard21ParserImpl *mVCard = VCard21ParserImpl::parseVCard(data);
219 QString tmpStr; 221 QString tmpStr;
220 222
221 // Check if parsing failed 223 // Check if parsing failed
222 if (mVCard == 0) 224 if (mVCard == 0)
223 { 225 {
224 kdDebug() << "Parsing failed" << endl; 226 kdDebug() << "Parsing failed" << endl;
225 return addressee; 227 return addressee;
226 } 228 }
227 //set the addressees name and formated name 229 //set the addressees name and formated name
228 QStringList tmpList = mVCard->getValues(VCARD_N); 230 QStringList tmpList = mVCard->getValues(VCARD_N);
229 QString formattedName = ""; 231 QString formattedName = "";
230 if (tmpList.count() > 0) 232 if (tmpList.count() > 0)
231 addressee.setFamilyName(tmpList[0]); 233 addressee.setFamilyName(tmpList[0]);
232 if (tmpList.count() > 1) 234 if (tmpList.count() > 1)
233 addressee.setGivenName(tmpList[1]); 235 addressee.setGivenName(tmpList[1]);
234 if (tmpList.count() > 2) 236 if (tmpList.count() > 2)
235 addressee.setAdditionalName(tmpList[2]); 237 addressee.setAdditionalName(tmpList[2]);
236 if (tmpList.count() > 3) 238 if (tmpList.count() > 3)
237 addressee.setPrefix(tmpList[3]); 239 addressee.setPrefix(tmpList[3]);
238 if (tmpList.count() > 4) 240 if (tmpList.count() > 4)
239 addressee.setSuffix(tmpList[4]); 241 addressee.setSuffix(tmpList[4]);
240 242
241 tmpStr = (mVCard->getValue(VCARD_FN)); 243 tmpStr = (mVCard->getValue(VCARD_FN));
242 if (!tmpStr.isEmpty()) 244 if (!tmpStr.isEmpty())
243 addressee.setFormattedName(tmpStr); 245 addressee.setFormattedName(tmpStr);
244 246
245 //set the addressee's nick name 247 //set the addressee's nick name
246 tmpStr = mVCard->getValue(VCARD_NICKNAME); 248 tmpStr = mVCard->getValue(VCARD_NICKNAME);
247 addressee.setNickName(tmpStr); 249 addressee.setNickName(tmpStr);
248 //set the addressee's organisation 250 //set the addressee's organisation
249 tmpStr = mVCard->getValue(VCARD_ORG); 251 tmpStr = mVCard->getValue(VCARD_ORG);
250 addressee.setOrganization(tmpStr); 252 addressee.setOrganization(tmpStr);
251 //set the addressee's title 253 //set the addressee's title
252 tmpStr = mVCard->getValue(VCARD_TITLE); 254 tmpStr = mVCard->getValue(VCARD_TITLE);
253 addressee.setTitle(tmpStr); 255 addressee.setTitle(tmpStr);
254 //set the addressee's email - we can only deal with two. The preferenced one and one other. 256 //set the addressee's email - we can only deal with two. The preferenced one and one other.
255 tmpStr = mVCard->getValue(VCARD_EMAIL, VCARD_EMAIL_INTERNET); 257 tmpStr = mVCard->getValue(VCARD_EMAIL, VCARD_EMAIL_INTERNET);
256 addressee.insertEmail(tmpStr, false); 258 addressee.insertEmail(tmpStr, false);
257 tmpStr = mVCard->getValue(VCARD_EMAIL,VCARD_EMAIL_PREF); 259 tmpStr = mVCard->getValue(VCARD_EMAIL,VCARD_EMAIL_PREF);
258 addressee.insertEmail(tmpStr, true); 260 addressee.insertEmail(tmpStr, true);
259 //set the addressee's url 261 //set the addressee's url
260 tmpStr = mVCard->getValue(VCARD_URL); 262 tmpStr = mVCard->getValue(VCARD_URL);
261 if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_WORK); 263 if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_WORK);
262 if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_HOME); 264 if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_HOME);
263 if (!tmpStr.isEmpty()) { 265 if (!tmpStr.isEmpty()) {
264 addressee.setUrl(KURL(tmpStr)); 266 addressee.setUrl(KURL(tmpStr));
265 } 267 }
266 268
267 //set the addressee's birthday 269 //set the addressee's birthday
268 tmpStr = mVCard->getValue(VCARD_BDAY); 270 tmpStr = mVCard->getValue(VCARD_BDAY);
269 addressee.setBirthday(VCardStringToDate(tmpStr)); 271 addressee.setBirthday(VCardStringToDate(tmpStr));
270 272
271 //set the addressee's phone numbers 273 //set the addressee's phone numbers
272 for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) { 274 for ( Q3ValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) {
273 if ( (*i).name == VCARD_TEL ) { 275 if ( (*i).name == VCARD_TEL ) {
274 int type = 0; 276 int type = 0;
275 if ( (*i).qualified ) { 277 if ( (*i).qualified ) {
276 if ( (*i).qualifiers.contains( VCARD_TEL_HOME ) ) 278 if ( (*i).qualifiers.contains( VCARD_TEL_HOME ) )
277 type |= PhoneNumber::Home; 279 type |= PhoneNumber::Home;
278 if ( (*i).qualifiers.contains( VCARD_TEL_WORK ) ) 280 if ( (*i).qualifiers.contains( VCARD_TEL_WORK ) )
279 type |= PhoneNumber::Work; 281 type |= PhoneNumber::Work;
280 if ( (*i).qualifiers.contains( VCARD_TEL_PREF ) ) 282 if ( (*i).qualifiers.contains( VCARD_TEL_PREF ) )
281 type |= PhoneNumber::Pref; 283 type |= PhoneNumber::Pref;
282 if ( (*i).qualifiers.contains( VCARD_TEL_VOICE ) ) 284 if ( (*i).qualifiers.contains( VCARD_TEL_VOICE ) )
283 type |= PhoneNumber::Voice; 285 type |= PhoneNumber::Voice;
284 if ( (*i).qualifiers.contains( VCARD_TEL_FAX ) ) 286 if ( (*i).qualifiers.contains( VCARD_TEL_FAX ) )
285 type |= PhoneNumber::Fax; 287 type |= PhoneNumber::Fax;
286 if ( (*i).qualifiers.contains( VCARD_TEL_MSG ) ) 288 if ( (*i).qualifiers.contains( VCARD_TEL_MSG ) )
287 type |= PhoneNumber::Msg; 289 type |= PhoneNumber::Msg;
288 if ( (*i).qualifiers.contains( VCARD_TEL_CELL ) ) 290 if ( (*i).qualifiers.contains( VCARD_TEL_CELL ) )
289 type |= PhoneNumber::Cell; 291 type |= PhoneNumber::Cell;
290 if ( (*i).qualifiers.contains( VCARD_TEL_PAGER ) ) 292 if ( (*i).qualifiers.contains( VCARD_TEL_PAGER ) )
291 type |= PhoneNumber::Pager; 293 type |= PhoneNumber::Pager;
292 if ( (*i).qualifiers.contains( VCARD_TEL_BBS ) ) 294 if ( (*i).qualifiers.contains( VCARD_TEL_BBS ) )
293 type |= PhoneNumber::Bbs; 295 type |= PhoneNumber::Bbs;
294 if ( (*i).qualifiers.contains( VCARD_TEL_MODEM ) ) 296 if ( (*i).qualifiers.contains( VCARD_TEL_MODEM ) )
295 type |= PhoneNumber::Modem; 297 type |= PhoneNumber::Modem;
296 if ( (*i).qualifiers.contains( VCARD_TEL_CAR ) ) 298 if ( (*i).qualifiers.contains( VCARD_TEL_CAR ) )
297 type |= PhoneNumber::Car; 299 type |= PhoneNumber::Car;
298 if ( (*i).qualifiers.contains( VCARD_TEL_ISDN ) ) 300 if ( (*i).qualifiers.contains( VCARD_TEL_ISDN ) )
299 type |= PhoneNumber::Isdn; 301 type |= PhoneNumber::Isdn;
300 if ( (*i).qualifiers.contains( VCARD_TEL_VIDEO ) ) 302 if ( (*i).qualifiers.contains( VCARD_TEL_VIDEO ) )
301 type |= PhoneNumber::Video; 303 type |= PhoneNumber::Video;
302 if ( (*i).qualifiers.contains( VCARD_TEL_PCS ) ) 304 if ( (*i).qualifiers.contains( VCARD_TEL_PCS ) )
303 type |= PhoneNumber::Pcs; 305 type |= PhoneNumber::Pcs;
304 306
305 } 307 }
306 addressee.insertPhoneNumber( PhoneNumber( (*i).parameters[ 0 ], type ) ); 308 addressee.insertPhoneNumber( PhoneNumber( (*i).parameters[ 0 ], type ) );
307 } 309 }
308 } 310 }
309 addressee.makePhoneNumbersOLcompatible(); 311 addressee.makePhoneNumbersOLcompatible();
310 //set the addressee's addresses 312 //set the addressee's addresses
311 for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) { 313 for ( Q3ValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) {
312 if ( (*i).name == VCARD_ADR ) { 314 if ( (*i).name == VCARD_ADR ) {
313 int type = 0; 315 int type = 0;
314 if ( (*i).qualified ) { 316 if ( (*i).qualified ) {
315 if ( (*i).qualifiers.contains( VCARD_ADR_DOM ) ) 317 if ( (*i).qualifiers.contains( VCARD_ADR_DOM ) )
316 type |= Address::Dom; 318 type |= Address::Dom;
317 if ( (*i).qualifiers.contains( VCARD_ADR_INTL ) ) 319 if ( (*i).qualifiers.contains( VCARD_ADR_INTL ) )
318 type |= Address::Intl; 320 type |= Address::Intl;
319 if ( (*i).qualifiers.contains( VCARD_ADR_POSTAL ) ) 321 if ( (*i).qualifiers.contains( VCARD_ADR_POSTAL ) )
320 type |= Address::Postal; 322 type |= Address::Postal;
321 if ( (*i).qualifiers.contains( VCARD_ADR_PARCEL ) ) 323 if ( (*i).qualifiers.contains( VCARD_ADR_PARCEL ) )
322 type |= Address::Parcel; 324 type |= Address::Parcel;
323 if ( (*i).qualifiers.contains( VCARD_ADR_HOME ) ) 325 if ( (*i).qualifiers.contains( VCARD_ADR_HOME ) )
324 type |= Address::Home; 326 type |= Address::Home;
325 if ( (*i).qualifiers.contains( VCARD_ADR_WORK ) ) 327 if ( (*i).qualifiers.contains( VCARD_ADR_WORK ) )
326 type |= Address::Work; 328 type |= Address::Work;
327 if ( (*i).qualifiers.contains( VCARD_ADR_PREF ) ) 329 if ( (*i).qualifiers.contains( VCARD_ADR_PREF ) )
328 type |= Address::Pref; 330 type |= Address::Pref;
329 } 331 }
330 addressee.insertAddress( readAddressFromQStringList( (*i).parameters, type ) ); 332 QStringList tmp;
333 for(Q3ValueList<QString>::const_iterator ii=(*i).parameters.begin();ii!=(*i).parameters.end();++ii)
334 tmp.push_back(*ii);
335 addressee.insertAddress( readAddressFromQStringList( tmp, type ) );
331 } 336 }
332 } 337 }
333 338
334 //set the addressee's delivery label 339 //set the addressee's delivery label
335 tmpStr = mVCard->getValue(VCARD_LABEL); 340 tmpStr = mVCard->getValue(VCARD_LABEL);
336 if (!tmpStr.isEmpty()) { 341 if (!tmpStr.isEmpty()) {
337qDebug("VCard21Parser::readFromString please verify if replace is correct"); 342qDebug("VCard21Parser::readFromString please verify if replace is correct");
338//US tmpStr.replace("\r\n","\n"); 343//US tmpStr.replace("\r\n","\n");
339 tmpStr.replace( QRegExp("\r\n"), "\n" ); 344 tmpStr.replace( QRegExp("\r\n"), "\n" );
340 Address tmpAddress; 345 Address tmpAddress;
341 tmpAddress.setLabel(tmpStr); 346 tmpAddress.setLabel(tmpStr);
342 addressee.insertAddress(tmpAddress); 347 addressee.insertAddress(tmpAddress);
343 } 348 }
344 349
345 //set the addressee's notes 350 //set the addressee's notes
346 tmpStr = mVCard->getValue(VCARD_NOTE); 351 tmpStr = mVCard->getValue(VCARD_NOTE);
347qDebug("VCard21Parser::readFromString please verify if correct"); 352qDebug("VCard21Parser::readFromString please verify if correct");
348//US tmpStr.replace("\r\n","\n"); 353//US tmpStr.replace("\r\n","\n");
349 tmpStr.replace( QRegExp("\r\n"), "\n" ); 354 tmpStr.replace( QRegExp("\r\n"), "\n" );
350 addressee.setNote(tmpStr); 355 addressee.setNote(tmpStr);
351 356
352 //set the addressee's timezone 357 //set the addressee's timezone
353 tmpStr = mVCard->getValue(VCARD_TZ); 358 tmpStr = mVCard->getValue(VCARD_TZ);
354 TimeZone tmpZone(tmpStr.toInt()); 359 TimeZone tmpZone(tmpStr.toInt());
355 addressee.setTimeZone(tmpZone); 360 addressee.setTimeZone(tmpZone);
356 361
357 //set the addressee's geographical position 362 //set the addressee's geographical position
358 tmpList = mVCard->getValues(VCARD_GEO); 363 tmpList = mVCard->getValues(VCARD_GEO);
359 if (tmpList.count()==2) 364 if (tmpList.count()==2)
360 { 365 {
361 tmpStr = tmpList[0]; 366 tmpStr = tmpList[0];
362 float glat = tmpStr.toFloat(); 367 float glat = tmpStr.toFloat();
363 tmpStr = tmpList[1]; 368 tmpStr = tmpList[1];
364 float glong = tmpStr.toFloat(); 369 float glong = tmpStr.toFloat();
365 Geo tmpGeo(glat,glong); 370 Geo tmpGeo(glat,glong);
366 addressee.setGeo(tmpGeo); 371 addressee.setGeo(tmpGeo);
367 } 372 }
368 373
369 //set the last revision date 374 //set the last revision date
370 tmpStr = mVCard->getValue(VCARD_REV); 375 tmpStr = mVCard->getValue(VCARD_REV);
371 addressee.setRevision(VCardStringToDate(tmpStr)); 376 addressee.setRevision(VCardStringToDate(tmpStr));
372 377
373 //set the role of the addressee 378 //set the role of the addressee
374 tmpStr = mVCard->getValue(VCARD_ROLE); 379 tmpStr = mVCard->getValue(VCARD_ROLE);
375 addressee.setRole(tmpStr); 380 addressee.setRole(tmpStr);
376 381
377 return addressee; 382 return addressee;
378} 383}
379 384
380 385
381 386
382KABC::Address VCard21Parser::readAddressFromQStringList ( const QStringList &data, const int type ) 387KABC::Address VCard21Parser::readAddressFromQStringList ( const QStringList &data, const int type )
383{ 388{
384 KABC::Address mAddress; 389 KABC::Address mAddress;
385 mAddress.setType( type ); 390 mAddress.setType( type );
386 391
387 if ( data.count() > 0 ) 392 if ( data.count() > 0 )
388 mAddress.setPostOfficeBox( data[0] ); 393 mAddress.setPostOfficeBox( data[0] );
389 if ( data.count() > 1 ) 394 if ( data.count() > 1 )
390 mAddress.setExtended( data[1] ); 395 mAddress.setExtended( data[1] );
391 if ( data.count() > 2 ) 396 if ( data.count() > 2 )
392 mAddress.setStreet( data[2] ); 397 mAddress.setStreet( data[2] );
393 if ( data.count() > 3 ) 398 if ( data.count() > 3 )
394 mAddress.setLocality( data[3] ); 399 mAddress.setLocality( data[3] );
395 if ( data.count() > 4 ) 400 if ( data.count() > 4 )
396 mAddress.setRegion( data[4] ); 401 mAddress.setRegion( data[4] );
397 if ( data.count() > 5 ) 402 if ( data.count() > 5 )
398 mAddress.setPostalCode( data[5] ); 403 mAddress.setPostalCode( data[5] );
399 if ( data.count() > 6 ) 404 if ( data.count() > 6 )
400 mAddress.setCountry( data[6] ); 405 mAddress.setCountry( data[6] );
401 406
402 return mAddress; 407 return mAddress;
403} 408}
404 409
405 410
406VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err ) 411VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err )
407{ 412{
408 int _err = 0; 413 int _err = 0;
409 int _state = VC_STATE_BEGIN; 414 int _state = VC_STATE_BEGIN;
410 415
411 QValueList<VCardLineX> *_vcdata; 416 Q3ValueList<VCardLineX> *_vcdata;
412 QValueList<QString> lines; 417 QStringList lines;
413 418
414 _vcdata = new QValueList<VCardLineX>; 419 _vcdata = new Q3ValueList<VCardLineX>;
415 420
416 lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), vc ); 421 lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), vc );
417 422
418 // for each line in the vCard 423 // for each line in the vCard
419 for ( QStringList::Iterator j = lines.begin(); j != lines.end(); ++j ) { 424 for ( QStringList::Iterator j = lines.begin(); j != lines.end(); ++j ) {
420 VCardLineX _vcl; 425 VCardLineX _vcl;
421 426
422 // take spaces off the end - ugly but necessary hack 427 // take spaces off the end - ugly but necessary hack
423 for ( int g = (*j).length()-1; g > 0 && (*j)[g].isSpace(); --g ) 428 for ( int g = (*j).length()-1; g > 0 && (*j)[g].isSpace(); --g )
424 (*j)[g] = 0; 429 (*j)[g] = 0;
425 430
426 // first token: 431 // first token:
427 // verify state, update if necessary 432 // verify state, update if necessary
428 if ( _state & VC_STATE_BEGIN) { 433 if ( _state & VC_STATE_BEGIN) {
429 if ( !qstricmp( (*j).latin1(), VCARD_BEGIN ) ) { 434 if ( !qstricmp( (*j).latin1(), VCARD_BEGIN ) ) {
430 _state = VC_STATE_BODY; 435 _state = VC_STATE_BODY;
431 continue; 436 continue;
432 } else { 437 } else {
433 _err = VC_ERR_NO_BEGIN; 438 _err = VC_ERR_NO_BEGIN;
434 break; 439 break;
435 } 440 }
436 } else if ( _state & VC_STATE_BODY ) { 441 } else if ( _state & VC_STATE_BODY ) {
437 if ( !qstricmp( (*j).latin1(), VCARD_END ) ) { 442 if ( !qstricmp( (*j).latin1(), VCARD_END ) ) {
438 _state |= VC_STATE_END; 443 _state |= VC_STATE_END;
439 break; 444 break;
440 } 445 }
441 446
442 // split into two tokens 447 // split into two tokens
443 int colon = (*j).find( ':' ); 448 int colon = (*j).find( ':' );
444 if ( colon < 0 ) { 449 if ( colon < 0 ) {
445 _err = VC_ERR_INVALID_LINE; 450 _err = VC_ERR_INVALID_LINE;
446 break; 451 break;
447 } 452 }
448 453
449 QString key = (*j).left( colon ); 454 QString key = (*j).left( colon );
450 QString value = (*j).mid( colon + 1 ); 455 QString value = (*j).mid( colon + 1 );
451 456
452 // check for qualifiers and 457 // check for qualifiers and
453 // set name, qualified, qualifier(s) 458 // set name, qualified, qualifier(s)
454 QStringList keyTokens = QStringList::split( ';', key ); 459 QStringList keyTokens = QStringList::split( ';', key );
455 bool qp = false, first_pass = true; 460 bool qp = false, first_pass = true;
456 bool b64 = false; 461 bool b64 = false;
457 462
458 if ( keyTokens.count() > 0 ) { 463 if ( keyTokens.count() > 0 ) {
459 _vcl.qualified = false; 464 _vcl.qualified = false;
460 _vcl.name = keyTokens[ 0 ].lower(); 465 _vcl.name = keyTokens[ 0 ].lower();
461 466
462 for ( QStringList::Iterator z = keyTokens.begin(); z != keyTokens.end(); ++z ) { 467 for ( QStringList::Iterator z = keyTokens.begin(); z != keyTokens.end(); ++z ) {
463 QString zz = (*z).lower(); 468 QString zz = (*z).lower();
464 if ( zz == VCARD_QUOTED_PRINTABLE || zz == VCARD_ENCODING_QUOTED_PRINTABLE ) { 469 if ( zz == VCARD_QUOTED_PRINTABLE || zz == VCARD_ENCODING_QUOTED_PRINTABLE ) {
465 qp = true; 470 qp = true;
466 } else if ( zz == VCARD_BASE64 ) { 471 } else if ( zz == VCARD_BASE64 ) {
467 b64 = true; 472 b64 = true;
468 } else if ( !first_pass ) { 473 } else if ( !first_pass ) {
469 _vcl.qualified = true; 474 _vcl.qualified = true;
470 _vcl.qualifiers.append( zz ); 475 _vcl.qualifiers.append( zz );
471 } 476 }
472 first_pass = false; 477 first_pass = false;
473 } 478 }
474 } else { 479 } else {
475 _err = VC_ERR_INVALID_LINE; 480 _err = VC_ERR_INVALID_LINE;
476 } 481 }
477 482
478 if ( _err != 0 ) 483 if ( _err != 0 )
479 break; 484 break;
480 485
481 if ( _vcl.name == VCARD_VERSION ) 486 if ( _vcl.name == VCARD_VERSION )
482 _state |= VC_STATE_HAVE_VERSION; 487 _state |= VC_STATE_HAVE_VERSION;
483 488
484 if ( _vcl.name == VCARD_N || _vcl.name == VCARD_FN ) 489 if ( _vcl.name == VCARD_N || _vcl.name == VCARD_FN )
485 _state |= VC_STATE_HAVE_N; 490 _state |= VC_STATE_HAVE_N;
486 491
487 // second token: 492 // second token:
488 // split into tokens by ; 493 // split into tokens by ;
489 // add to parameters vector 494 // add to parameters vector
490 if ( b64 ) { 495 if ( b64 ) {
491 if ( value.at( value.length() - 1 ) != '=' ) 496 if ( value.at( value.length() - 1 ) != '=' )
492 do { 497 do {
493 value += *( ++j ); 498 value += *( ++j );
494 } while ( (*j).at( (*j).length() - 1 ) != '=' ); 499 } while ( (*j).at( (*j).length() - 1 ) != '=' );
495 } else { 500 } else {
496 if ( qp ) { // join any split lines 501 if ( qp ) { // join any split lines
497 while ( value.at( value.length() - 1 ) == '=' ) { 502 while ( value.at( value.length() - 1 ) == '=' ) {
498 value.remove( value.length() - 1, 1 ); 503 value.remove( value.length() - 1, 1 );
499 value.append(*( ++j )); 504 value.append(*( ++j ));
500 } 505 }
501 } 506 }
502 _vcl.parameters = QStringList::split( ';', value, true ); 507 _vcl.parameters = QStringList::split( ';', value, true );
503 if ( qp ) { // decode the quoted printable 508 if ( qp ) { // decode the quoted printable
504 for ( QStringList::Iterator z = _vcl.parameters.begin(); z != _vcl.parameters.end(); ++z ) 509 for ( QLinkedList<QString>::Iterator z = _vcl.parameters.begin(); z != _vcl.parameters.end(); ++z )
505 *z = KCodecs::quotedPrintableDecode( (*z).latin1() ); 510 *z = KCodecs::quotedPrintableDecode( (Q3CString)(*z).latin1() );
506 } 511 }
507 } 512 }
508 } else { 513 } else {
509 _err = VC_ERR_INTERNAL; 514 _err = VC_ERR_INTERNAL;
510 break; 515 break;
511 } 516 }
512 517
513 // validate VCardLineX 518 // validate VCardLineX
514 if ( !_vcl.isValid() ) { 519 if ( !_vcl.isValid() ) {
515 _err = VC_ERR_INVALID_LINE; 520 _err = VC_ERR_INVALID_LINE;
516 break; 521 break;
517 } 522 }
518 523
519 // add to vector 524 // add to vector
520 _vcdata->append( _vcl ); 525 _vcdata->append( _vcl );
521 } 526 }
522 527
523 // errors to check at the last minute (exit state related) 528 // errors to check at the last minute (exit state related)
524 if ( _err == 0 ) { 529 if ( _err == 0 ) {
525 if ( !( _state & VC_STATE_END ) ) // we have to have an end!! 530 if ( !( _state & VC_STATE_END ) ) // we have to have an end!!
526 _err = VC_ERR_NO_END; 531 _err = VC_ERR_NO_END;
527 532
528 if ( !( _state & VC_STATE_HAVE_N ) || // we have to have the mandatories! 533 if ( !( _state & VC_STATE_HAVE_N ) || // we have to have the mandatories!
529 !( _state & VC_STATE_HAVE_VERSION ) ) 534 !( _state & VC_STATE_HAVE_VERSION ) )
530 _err = VC_ERR_MISSING_MANDATORY; 535 _err = VC_ERR_MISSING_MANDATORY;
531 } 536 }
532 537
533 // set the error message if we can, and only return an object 538 // set the error message if we can, and only return an object
534 // if the vCard was valid. 539 // if the vCard was valid.
535 if ( err ) 540 if ( err )
536 *err = _err; 541 *err = _err;
537 542
538 if ( _err != 0 ) { 543 if ( _err != 0 ) {
539 delete _vcdata; 544 delete _vcdata;
540 return 0; 545 return 0;
541 } 546 }
542 547
543 return new VCard21ParserImpl( _vcdata ); 548 return new VCard21ParserImpl( _vcdata );
544} 549}
545 550
546VCard21ParserImpl::VCard21ParserImpl(QValueList<VCardLineX> *_vcd) : _vcdata(_vcd) 551VCard21ParserImpl::VCard21ParserImpl(Q3ValueList<VCardLineX> *_vcd) : _vcdata(_vcd)
547{ 552{
548} 553}
549 554
550 555
551QString VCard21ParserImpl::getValue(const QString& name, const QString& qualifier) 556QString VCard21ParserImpl::getValue(const QString& name, const QString& qualifier)
552{ 557{
553 QString failed; 558 QString failed;
554 const QString lowname = name.lower(); 559 const QString lowname = name.lower();
555 const QString lowqualifier = qualifier.lower(); 560 const QString lowqualifier = qualifier.lower();
556 561
557 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { 562 for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
558 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) { 563 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) {
559 if ((*i).parameters.count() > 0) 564 if ((*i).parameters.count() > 0)
560 return (*i).parameters[0]; 565 return (*i).parameters[0];
561 else return failed; 566 else return failed;
562 } 567 }
563 } 568 }
564 return failed; 569 return failed;
565} 570}
566 571
567 572
568QString VCard21ParserImpl::getValue(const QString& name) 573QString VCard21ParserImpl::getValue(const QString& name)
569{ 574{
570 QString failed; 575 QString failed;
571 const QString lowname = name.lower(); 576 const QString lowname = name.lower();
572 577
573 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { 578 for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
574 if ((*i).name == lowname && !(*i).qualified) { 579 if ((*i).name == lowname && !(*i).qualified) {
575 if ((*i).parameters.count() > 0) 580 if ((*i).parameters.count() > 0)
576 return (*i).parameters[0]; 581 return (*i).parameters[0];
577 else return failed; 582 else return failed;
578 } 583 }
579 } 584 }
580 return failed; 585 return failed;
581} 586}
582 587
583 588
584QStringList VCard21ParserImpl::getValues(const QString& name) 589QStringList VCard21ParserImpl::getValues(const QString& name)
585{ 590{
586 const QString lowname = name.lower(); 591 const QString lowname = name.lower();
587 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { 592 for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
588 if ((*i).name == lowname && !(*i).qualified) 593 if ((*i).name == lowname && !(*i).qualified) {
589 return (*i).parameters; 594 return QStringList( (*i).parameters );
595 }
590 } 596 }
591 // failed. 597 // failed.
592 return QStringList(); 598 return QStringList();
593} 599}
594 600
595QStringList VCard21ParserImpl::getValues(const QString& name, const QString& qualifier) 601QStringList VCard21ParserImpl::getValues(const QString& name, const QString& qualifier)
596{ 602{
597 const QString lowname = name.lower(); 603 const QString lowname = name.lower();
598 const QString lowqualifier = qualifier.lower(); 604 const QString lowqualifier = qualifier.lower();
599 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { 605 for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
600 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) 606 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier))
601 return (*i).parameters; 607 return QStringList( (*i).parameters );
602 } 608 }
603 // failed. 609 // failed.
604 return QStringList(); 610 return QStringList();
605} 611}
606 612
607 613