21 #include "vcardtool.h"
27 #include <QtCore/QString>
28 #include <QtCore/QBuffer>
32 static bool needsEncoding(
const QString &value )
34 uint length = value.length();
35 for ( uint i = 0; i < length; ++i ) {
36 char c = value.at( i ).toLatin1();
37 if ( ( c < 33 || c > 126 ) && c !=
' ' && c !=
'=' ) {
45 VCardTool::VCardTool()
47 mAddressTypeMap.insert( QLatin1String(
"dom" ),
Address::Dom );
48 mAddressTypeMap.insert( QLatin1String(
"intl" ),
Address::Intl );
51 mAddressTypeMap.insert( QLatin1String(
"home" ),
Address::Home );
52 mAddressTypeMap.insert( QLatin1String(
"work" ),
Address::Work );
53 mAddressTypeMap.insert( QLatin1String(
"pref" ),
Address::Pref );
71 VCardTool::~VCardTool()
75 QByteArray VCardTool::exportVCards(
const Addressee::List &list, VCard::Version version )
const
77 return createVCards( list, version,
true );
80 QByteArray VCardTool::createVCards(
const Addressee::List &list, VCard::Version version )
const
82 return createVCards( list, version,
false );
85 QByteArray VCardTool::createVCards(
const Addressee::List &list,
86 VCard::Version version,
bool exportVcard )
const
88 VCard::List vCardList;
90 Addressee::List::ConstIterator addrIt;
91 Addressee::List::ConstIterator listEnd( list.constEnd() );
92 for ( addrIt = list.constBegin(); addrIt != listEnd; ++addrIt ) {
94 QStringList::ConstIterator strIt;
98 for ( Address::List::ConstIterator it = addresses.begin(); it != addresses.end(); ++it ) {
101 const bool isEmpty = ( ( *it ).postOfficeBox().isEmpty() &&
102 ( *it ).extended().isEmpty() &&
103 ( *it ).street().isEmpty() &&
104 ( *it ).locality().isEmpty() &&
105 ( *it ).region().isEmpty() &&
106 ( *it ).postalCode().isEmpty() &&
107 ( *it ).country().isEmpty() );
109 address.append( ( *it ).postOfficeBox().replace( QLatin1Char(
';' ),
110 QLatin1String(
"\\;" ) ) );
112 address.append( ( *it ).extended().replace( QLatin1Char(
';' ),
113 QLatin1String(
"\\;" ) ) );
115 address.append( ( *it ).street().replace( QLatin1Char(
';' ),
116 QLatin1String(
"\\;" ) ) );
118 address.append( ( *it ).locality().replace( QLatin1Char(
';' ),
119 QLatin1String(
"\\;" ) ) );
121 address.append( ( *it ).region().replace( QLatin1Char(
';' ),
122 QLatin1String(
"\\;" ) ) );
124 address.append( ( *it ).postalCode().replace( QLatin1Char(
';' ),
125 QLatin1String(
"\\;" ) ) );
127 address.append( ( *it ).country().replace( QLatin1Char(
';' ),
128 QLatin1String(
"\\;" ) ) );
130 VCardLine adrLine( QLatin1String(
"ADR" ), address.join( QLatin1String(
";" ) ) );
131 if ( version == VCard::v2_1 && needsEncoding( address.join( QLatin1String(
";" ) ) ) ) {
132 adrLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
133 adrLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
136 VCardLine labelLine( QLatin1String(
"LABEL" ), ( *it ).label() );
137 if ( version == VCard::v2_1 && needsEncoding( ( *it ).label() ) ) {
138 labelLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
139 labelLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
142 const bool hasLabel = !( *it ).label().isEmpty();
143 QMap<QString, Address::TypeFlag>::ConstIterator typeIt;
144 for ( typeIt = mAddressTypeMap.constBegin();
145 typeIt != mAddressTypeMap.constEnd(); ++typeIt ) {
146 if ( typeIt.value() & ( *it ).type() ) {
147 adrLine.addParameter( QLatin1String(
"TYPE" ), typeIt.key() );
149 labelLine.addParameter( QLatin1String(
"TYPE" ), typeIt.key() );
155 card.addLine( adrLine );
158 card.addLine( labelLine );
163 card.addLine( VCardLine( QLatin1String(
"BDAY" ), createDateTime( ( *addrIt ).birthday() ) ) );
166 if ( version == VCard::v3_0 ) {
167 QStringList categories = ( *addrIt ).categories();
168 QStringList::Iterator catIt;
169 QStringList::Iterator catEnd( categories.end() );
170 for ( catIt = categories.begin(); catIt != catEnd; ++catIt ) {
171 ( *catIt ).replace( QLatin1Char(
',' ), QLatin1String(
"\\," ) );
174 VCardLine catLine( QLatin1String(
"CATEGORIES" ), categories.join( QLatin1String(
"," ) ) );
175 card.addLine( catLine );
179 if ( version == VCard::v3_0 ) {
180 card.addLine( createSecrecy( ( *addrIt ).secrecy() ) );
184 const QStringList emails = ( *addrIt ).emails();
186 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) {
187 VCardLine line( QLatin1String(
"EMAIL" ), *strIt );
188 if ( pref ==
true && emails.count() > 1 ) {
189 line.addParameter( QLatin1String(
"TYPE" ), QLatin1String(
"PREF" ) );
192 card.addLine( line );
196 VCardLine fnLine( QLatin1String(
"FN" ), ( *addrIt ).formattedName() );
197 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).formattedName() ) ) {
198 fnLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
199 fnLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
201 card.addLine( fnLine );
204 const Geo geo = ( *addrIt ).geo();
208 card.addLine( VCardLine( QLatin1String(
"GEO" ), str ) );
212 const Key::List keys = ( *addrIt ).keys();
213 Key::List::ConstIterator keyIt;
214 Key::List::ConstIterator keyEnd( keys.end() );
215 for ( keyIt = keys.begin(); keyIt != keyEnd; ++keyIt ) {
216 card.addLine( createKey( *keyIt ) );
220 card.addLine( createPicture( QLatin1String(
"LOGO" ), ( *addrIt ).logo() ) );
223 VCardLine mailerLine( QLatin1String(
"MAILER" ), ( *addrIt ).mailer() );
224 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).mailer() ) ) {
225 mailerLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
226 mailerLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
228 card.addLine( mailerLine );
232 name.append( ( *addrIt ).familyName().replace( QLatin1Char(
';' ),
233 QLatin1String(
"\\;" ) ) );
235 name.append( ( *addrIt ).givenName().replace( QLatin1Char(
';' ),
236 QLatin1String(
"\\;" ) ) );
238 name.append( ( *addrIt ).additionalName().replace( QLatin1Char(
';' ),
239 QLatin1String(
"\\;" ) ) );
241 name.append( ( *addrIt ).prefix().replace( QLatin1Char(
';' ),
242 QLatin1String(
"\\;" ) ) );
244 name.append( ( *addrIt ).suffix().replace( QLatin1Char(
';' ),
245 QLatin1String(
"\\;" ) ) );
247 VCardLine nLine( QLatin1String(
"N" ), name.join( QLatin1String(
";" ) ) );
248 if ( version == VCard::v2_1 && needsEncoding( name.join( QLatin1String(
";" ) ) ) ) {
249 nLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
250 nLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
252 card.addLine( nLine );
255 VCardLine nameLine( QLatin1String(
"NAME" ), ( *addrIt ).name() );
256 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).name() ) ) {
257 nameLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
258 nameLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
260 card.addLine( nameLine );
263 if ( version == VCard::v3_0 ) {
264 card.addLine( VCardLine( QLatin1String(
"NICKNAME" ), ( *addrIt ).nickName() ) );
268 VCardLine noteLine( QLatin1String(
"NOTE" ), ( *addrIt ).note() );
269 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).note() ) ) {
270 noteLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
271 noteLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
273 card.addLine( noteLine );
276 QStringList organization;
277 organization.append( ( *addrIt ).organization().replace( QLatin1Char(
';' ),
278 QLatin1String(
"\\;" ) ) );
279 if ( !( *addrIt ).department().isEmpty() ) {
280 organization.append( ( *addrIt ).department().replace( QLatin1Char(
';' ),
281 QLatin1String(
"\\;" ) ) );
283 VCardLine orgLine( QLatin1String(
"ORG" ), organization.join( QLatin1String(
";" ) ) );
284 if ( version == VCard::v2_1 && needsEncoding( organization.join( QLatin1String(
";" ) ) ) ) {
285 orgLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
286 orgLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
288 card.addLine( orgLine );
291 card.addLine( createPicture( QLatin1String(
"PHOTO" ), ( *addrIt ).photo() ) );
294 if ( version == VCard::v3_0 ) {
295 card.addLine( VCardLine( QLatin1String(
"PRODID" ), ( *addrIt ).productId() ) );
299 card.addLine( VCardLine( QLatin1String(
"REV" ), createDateTime( ( *addrIt ).revision() ) ) );
302 VCardLine roleLine( QLatin1String(
"ROLE" ), ( *addrIt ).role() );
303 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).role() ) ) {
304 roleLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
305 roleLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
307 card.addLine( roleLine );
310 if ( version == VCard::v3_0 ) {
311 card.addLine( VCardLine( QLatin1String(
"SORT-STRING" ), ( *addrIt ).sortString() ) );
315 card.addLine( createSound( ( *addrIt ).sound() ) );
319 PhoneNumber::List::ConstIterator phoneIt;
320 PhoneNumber::List::ConstIterator phoneEnd( phoneNumbers.end() );
321 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneEnd; ++phoneIt ) {
322 VCardLine line( QLatin1String(
"TEL" ), ( *phoneIt ).number() );
324 QMap<QString, PhoneNumber::TypeFlag>::ConstIterator typeIt;
325 QMap<QString, PhoneNumber::TypeFlag>::ConstIterator typeEnd( mPhoneTypeMap.constEnd() );
326 for ( typeIt = mPhoneTypeMap.constBegin(); typeIt != typeEnd; ++typeIt ) {
327 if ( typeIt.value() & ( *phoneIt ).type() ) {
328 line.addParameter( QLatin1String(
"TYPE" ), typeIt.key() );
332 card.addLine( line );
336 VCardLine titleLine( QLatin1String(
"TITLE" ), ( *addrIt ).title() );
337 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).title() ) ) {
338 titleLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
339 titleLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
341 card.addLine( titleLine );
344 const TimeZone timeZone = ( *addrIt ).timeZone();
349 if ( timeZone.
offset() < 0 ) {
353 str.sprintf(
"%c%02d:%02d", ( timeZone.
offset() >= 0 ?
'+' :
'-' ),
354 ( timeZone.
offset() / 60 ) * neg,
355 ( timeZone.
offset() % 60 ) * neg );
357 card.addLine( VCardLine( QLatin1String(
"TZ" ), str ) );
361 card.addLine( VCardLine( QLatin1String(
"UID" ), ( *addrIt ).uid() ) );
364 card.addLine( VCardLine( QLatin1String(
"URL" ), ( *addrIt ).url().url() ) );
367 if ( version == VCard::v2_1 ) {
368 card.addLine( VCardLine( QLatin1String(
"VERSION" ), QLatin1String(
"2.1" ) ) );
369 }
else if ( version == VCard::v3_0 ) {
370 card.addLine( VCardLine( QLatin1String(
"VERSION" ), QLatin1String(
"3.0" ) ) );
374 const QStringList customs = ( *addrIt ).customs();
375 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) {
376 QString identifier = QLatin1String(
"X-" ) +
377 ( *strIt ).left( ( *strIt ).indexOf( QLatin1Char(
':' ) ) );
378 const QString value = ( *strIt ).mid( ( *strIt ).indexOf( QLatin1Char(
':' ) ) + 1 );
379 if ( value.isEmpty() ) {
384 if ( identifier == QLatin1String(
"X-messaging/aim-All" ) ) {
385 identifier = QLatin1String(
"X-AIM" );
386 }
else if ( identifier == QLatin1String(
"X-messaging/icq-All" ) ) {
387 identifier = QLatin1String(
"X-ICQ" );
388 }
else if ( identifier == QLatin1String(
"X-messaging/xmpp-All" ) ) {
389 identifier = QLatin1String(
"X-JABBER" );
390 }
else if ( identifier == QLatin1String(
"X-messaging/msn-All" ) ) {
391 identifier = QLatin1String(
"X-MSN" );
392 }
else if ( identifier == QLatin1String(
"X-messaging/yahoo-All" ) ) {
393 identifier = QLatin1String(
"X-YAHOO" );
394 }
else if ( identifier == QLatin1String(
"X-messaging/gadu-All" ) ) {
395 identifier = QLatin1String(
"X-GADUGADU" );
396 }
else if ( identifier == QLatin1String(
"X-messaging/skype-All" ) ) {
397 identifier = QLatin1String(
"X-SKYPE" );
398 }
else if ( identifier == QLatin1String(
"X-messaging/groupwise-All" ) ) {
399 identifier = QLatin1String(
"X-GROUPWISE" );
400 }
else if ( identifier == QLatin1String(
"X-messaging/sms-All" ) ) {
401 identifier = QLatin1String(
"X-SMS" );
402 }
else if ( identifier == QLatin1String(
"X-messaging/meanwhile-All" ) ) {
403 identifier = QLatin1String(
"X-MEANWHILE" );
404 }
else if ( identifier == QLatin1String(
"X-messaging/irc-All" ) ) {
405 identifier = QLatin1String(
"X-IRC" );
406 }
else if ( identifier == QLatin1String(
"X-messaging/googletalk-All" ) ) {
408 identifier = QLatin1String(
"X-GOOGLETALK" );
412 VCardLine line( identifier, value );
413 if ( version == VCard::v2_1 && needsEncoding( value ) ) {
414 line.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
415 line.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
417 card.addLine( line );
420 vCardList.append( card );
423 return VCardParser::createVCards( vCardList );
426 Addressee::List VCardTool::parseVCards(
const QByteArray &vcard )
const
428 static const QLatin1Char semicolonSep(
';' );
429 static const QLatin1Char commaSep(
',' );
432 Addressee::List addrList;
433 const VCard::List vCardList = VCardParser::parseVCards( vcard );
435 VCard::List::ConstIterator cardIt;
436 VCard::List::ConstIterator listEnd( vCardList.end() );
437 for ( cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt ) {
440 const QStringList idents = ( *cardIt ).identifiers();
441 QStringList::ConstIterator identIt;
442 QStringList::ConstIterator identEnd( idents.end() );
443 for ( identIt = idents.begin(); identIt != identEnd; ++identIt ) {
444 const VCardLine::List lines = ( *cardIt ).lines( ( *identIt ) );
445 VCardLine::List::ConstIterator lineIt;
448 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
449 identifier = ( *lineIt ).identifier().toLower();
451 if ( identifier == QLatin1String(
"adr" ) ) {
453 const QStringList addrParts = splitString( semicolonSep, ( *lineIt ).value().toString() );
454 if ( addrParts.count() > 0 ) {
457 if ( addrParts.count() > 1 ) {
460 if ( addrParts.count() > 2 ) {
463 if ( addrParts.count() > 3 ) {
466 if ( addrParts.count() > 4 ) {
469 if ( addrParts.count() > 5 ) {
472 if ( addrParts.count() > 6 ) {
478 const QStringList types = ( *lineIt ).parameters( QLatin1String(
"type" ) );
479 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) {
480 type |= mAddressTypeMap[ ( *it ).toLower() ];
484 addr.insertAddress( address );
488 else if ( identifier == QLatin1String(
"bday" ) ) {
489 addr.setBirthday( parseDateTime( ( *lineIt ).value().toString() ) );
493 else if ( identifier == QLatin1String(
"categories" ) ) {
494 const QStringList categories = splitString( commaSep, ( *lineIt ).value().toString() );
495 addr.setCategories( categories );
499 else if ( identifier == QLatin1String(
"class" ) ) {
500 addr.setSecrecy( parseSecrecy( *lineIt ) );
504 else if ( identifier == QLatin1String(
"email" ) ) {
505 const QStringList types = ( *lineIt ).parameters( QLatin1String(
"type" ) );
506 addr.insertEmail( ( *lineIt ).value().toString().toLower(),
507 types.contains( QLatin1String(
"PREF" ) ) );
511 else if ( identifier == QLatin1String(
"fn" ) ) {
512 addr.setFormattedName( ( *lineIt ).value().toString() );
516 else if ( identifier == QLatin1String(
"geo" ) ) {
519 const QStringList geoParts =
520 ( *lineIt ).value().
toString().split( QLatin1Char(
';' ), QString::KeepEmptyParts );
521 if ( geoParts.size() >= 2 ) {
529 else if ( identifier == QLatin1String(
"key" ) ) {
530 addr.insertKey( parseKey( *lineIt ) );
534 else if ( identifier == QLatin1String(
"label" ) ) {
537 const QStringList types = ( *lineIt ).parameters( QLatin1String(
"type" ) );
538 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) {
539 type |= mAddressTypeMap[ ( *it ).toLower() ];
542 bool available =
false;
544 for ( KABC::Address::List::Iterator it = addressList.begin();
545 it != addressList.end(); ++it ) {
546 if ( ( *it ).type() == type ) {
547 ( *it ).setLabel( ( *lineIt ).value().toString() );
548 addr.insertAddress( *it );
556 address.
setLabel( ( *lineIt ).value().toString() );
557 addr.insertAddress( address );
562 else if ( identifier == QLatin1String(
"logo" ) ) {
563 addr.setLogo( parsePicture( *lineIt ) );
567 else if ( identifier == QLatin1String(
"mailer" ) ) {
568 addr.setMailer( ( *lineIt ).value().toString() );
572 else if ( identifier == QLatin1String(
"n" ) ) {
573 const QStringList nameParts = splitString( semicolonSep, ( *lineIt ).value().toString() );
574 const int numberOfParts( nameParts.count() );
575 if ( numberOfParts > 0 ) {
576 addr.setFamilyName( nameParts[ 0 ] );
578 if ( numberOfParts > 1 ) {
579 addr.setGivenName( nameParts[ 1 ] );
581 if ( numberOfParts > 2 ) {
582 addr.setAdditionalName( nameParts[ 2 ] );
584 if ( numberOfParts > 3 ) {
585 addr.setPrefix( nameParts[ 3 ] );
587 if ( numberOfParts > 4 ) {
588 addr.setSuffix( nameParts[ 4 ] );
593 else if ( identifier == QLatin1String(
"name" ) ) {
594 addr.setName( ( *lineIt ).value().toString() );
598 else if ( identifier == QLatin1String(
"nickname" ) ) {
599 addr.setNickName( ( *lineIt ).value().toString() );
603 else if ( identifier == QLatin1String(
"note" ) ) {
604 addr.setNote( ( *lineIt ).value().toString() );
608 else if ( identifier == QLatin1String(
"org" ) ) {
609 const QStringList orgParts = splitString( semicolonSep, ( *lineIt ).value().toString() );
610 if ( orgParts.count() > 0 ) {
611 addr.setOrganization( orgParts[ 0 ] );
613 if ( orgParts.count() > 1 ) {
614 addr.setDepartment( orgParts[ 1 ] );
619 else if ( identifier == QLatin1String(
"photo" ) ) {
620 addr.setPhoto( parsePicture( *lineIt ) );
624 else if ( identifier == QLatin1String(
"prodid" ) ) {
625 addr.setProductId( ( *lineIt ).value().toString() );
629 else if ( identifier == QLatin1String(
"rev" ) ) {
630 addr.setRevision( parseDateTime( ( *lineIt ).value().toString() ) );
634 else if ( identifier == QLatin1String(
"role" ) ) {
635 addr.setRole( ( *lineIt ).value().toString() );
639 else if ( identifier == QLatin1String(
"sort-string" ) ) {
640 addr.setSortString( ( *lineIt ).value().toString() );
644 else if ( identifier == QLatin1String(
"sound" ) ) {
645 addr.setSound( parseSound( *lineIt ) );
649 else if ( identifier == QLatin1String(
"tel" ) ) {
651 phone.
setNumber( ( *lineIt ).value().toString() );
653 PhoneNumber::Type type;
655 const QStringList types = ( *lineIt ).parameters( QLatin1String(
"type" ) );
656 QStringList::ConstIterator typeEnd( types.end() );
657 for ( QStringList::ConstIterator it = types.begin(); it != typeEnd; ++it ) {
658 type |= mPhoneTypeMap[( *it ).toUpper()];
663 addr.insertPhoneNumber( phone );
667 else if ( identifier == QLatin1String(
"title" ) ) {
668 addr.setTitle( ( *lineIt ).value().toString() );
672 else if ( identifier == QLatin1String(
"tz" ) ) {
674 const QString date = ( *lineIt ).value().
toString();
676 if ( !date.isEmpty() ) {
677 int hours = date.mid( 1, 2 ).toInt();
678 int minutes = date.mid( 4, 2 ).toInt();
679 int offset = ( hours * 60 ) + minutes;
680 offset = offset * ( date[ 0 ] == QLatin1Char(
'+' ) ? 1 : -1 );
683 addr.setTimeZone( tz );
688 else if ( identifier == QLatin1String(
"uid" ) ) {
689 addr.setUid( ( *lineIt ).value().toString() );
693 else if ( identifier == QLatin1String(
"url" ) ) {
694 addr.setUrl( KUrl( ( *lineIt ).value().toString() ) );
698 else if ( identifier.startsWith( QLatin1String(
"x-" ) ) ) {
699 QString ident = ( *lineIt ).identifier();
701 if ( identifier == QLatin1String(
"x-evolution-spouse" ) ||
702 identifier == QLatin1String(
"x-spouse" ) ) {
703 ident = QLatin1String(
"X-KADDRESSBOOK-X-SpousesName" );
704 }
else if ( identifier == QLatin1String(
"x-evolution-blog-url" ) ) {
705 ident = QLatin1String(
"X-KADDRESSBOOK-BlogFeed" );
706 }
else if ( identifier == QLatin1String(
"x-evolution-assistant" ) ||
707 identifier == QLatin1String(
"x-assistant" ) ) {
708 ident = QLatin1String(
"X-KADDRESSBOOK-X-AssistantsName" );
709 }
else if ( identifier == QLatin1String(
"x-evolution-anniversary" ) ||
710 identifier == QLatin1String(
"x-anniversary" ) ) {
711 ident = QLatin1String(
"X-KADDRESSBOOK-X-Anniversary" );
712 }
else if ( identifier == QLatin1String(
"x-evolution-manager" ) ||
713 identifier == QLatin1String(
"x-manager" ) ) {
714 ident = QLatin1String(
"X-KADDRESSBOOK-X-ManagersName" );
715 }
else if ( identifier == QLatin1String(
"x-aim" ) ) {
716 ident = QLatin1String(
"X-messaging/aim-All" );
717 }
else if ( identifier == QLatin1String(
"x-icq" ) ) {
718 ident = QLatin1String(
"X-messaging/icq-All" );
719 }
else if ( identifier == QLatin1String(
"x-jabber" ) ) {
720 ident = QLatin1String(
"X-messaging/xmpp-All" );
721 }
else if ( identifier == QLatin1String(
"x-jabber" ) ) {
722 ident = QLatin1String(
"X-messaging/xmpp-All" );
723 }
else if ( identifier == QLatin1String(
"x-msn" ) ) {
724 ident = QLatin1String(
"X-messaging/msn-All" );
725 }
else if ( identifier == QLatin1String(
"x-yahoo" ) ) {
726 ident = QLatin1String(
"X-messaging/yahoo-All" );
727 }
else if ( identifier == QLatin1String(
"x-gadugadu" ) ) {
728 ident = QLatin1String(
"X-messaging/gadu-All" );
729 }
else if ( identifier == QLatin1String(
"x-skype" ) ) {
730 ident = QLatin1String(
"X-messaging/skype-All" );
731 }
else if ( identifier == QLatin1String(
"x-groupwise" ) ) {
732 ident = QLatin1String(
"X-messaging/groupwise-All" );
733 }
else if ( identifier == QLatin1String(
"x-sms" ) ) {
734 ident = QLatin1String(
"X-messaging/sms-All" );
735 }
else if ( identifier == QLatin1String(
"x-meanwhile" ) ) {
736 ident = QLatin1String(
"X-messaging/meanwhile-All" );
737 }
else if ( identifier == QLatin1String(
"x-irc" ) ) {
738 ident = QLatin1String(
"X-messaging/irc-All" );
739 }
else if ( identifier == QLatin1String(
"x-googletalk" ) ) {
740 ident = QLatin1String(
"X-messaging/googletalk-All" );
743 const QString key = ident.mid( 2 );
744 const int dash = key.indexOf( QLatin1Char(
'-' ) );
745 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ),
746 ( *lineIt ).value().toString() );
751 addrList.append( addr );
757 QDateTime VCardTool::parseDateTime(
const QString &str )
const
762 if ( str.indexOf( QLatin1Char(
'-' ) ) == -1 ) {
763 date = QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
764 str.mid( 6, 2 ).toInt() );
766 date = QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
767 str.mid( 8, 2 ).toInt() );
771 int timeStart = str.indexOf( QLatin1Char(
'T' ) );
772 if ( timeStart >= 0 ) {
773 int hour = 0, minute = 0, second = 0;
775 hour = str.mid( timeStart + 1, 2 ).toInt();
777 if ( str.indexOf( QLatin1Char(
':' ), timeStart + 1 ) > 0 ) {
778 if ( str.length() >= ( timeStart + 5 ) ) {
779 minute = str.mid( timeStart + 4, 2 ).toInt();
780 if ( str.length() >= ( timeStart + 8 ) ) {
781 second = str.mid( timeStart + 7, 2 ).toInt();
785 if ( str.length() >= ( timeStart + 4 ) ) {
786 minute = str.mid( timeStart + 3, 2 ).toInt();
787 if ( str.length() >= ( timeStart + 6 ) ) {
788 second = str.mid( timeStart + 5, 2 ).toInt();
793 time = QTime( hour, minute, second );
796 Qt::TimeSpec spec = ( str.right( 1 ) == QLatin1String(
"Z" ) ) ? Qt::UTC : Qt::LocalTime;
798 QDateTime dateTime( date );
806 dateTime.setTime( time );
808 dateTime.setTimeSpec( spec );
812 QString VCardTool::createDateTime(
const QDateTime &dateTime )
const
816 if ( dateTime.date().isValid() ) {
817 str.sprintf(
"%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
818 dateTime.date().day() );
819 if ( dateTime.time().isValid() ) {
821 tmp.sprintf(
"T%02d:%02d:%02d", dateTime.time().hour(), dateTime.time().minute(),
822 dateTime.time().second() );
825 if ( dateTime.timeSpec() == Qt::UTC ) {
826 str += QLatin1Char(
'Z' );
834 Picture VCardTool::parsePicture(
const VCardLine &line )
const
838 const QStringList params = line.parameterList();
840 if ( params.contains( QLatin1String(
"type" ) ) ) {
841 type = line.parameter( QLatin1String(
"type" ) );
843 if ( params.contains( QLatin1String(
"encoding" ) ) ) {
844 pic.
setRawData( line.value().toByteArray(), type );
845 }
else if ( params.contains( QLatin1String(
"value" ) ) ) {
846 if ( line.parameter( QLatin1String(
"value" ) ).toLower() == QLatin1String(
"uri" ) ) {
847 pic.
setUrl( line.value().toString() );
854 VCardLine VCardTool::createPicture(
const QString &identifier,
const Picture &pic )
const
856 VCardLine line( identifier );
863 line.setValue( pic.
rawData() );
864 line.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"b" ) );
865 line.addParameter( QLatin1String(
"type" ), pic.
type() );
867 line.setValue( pic.
url() );
868 line.addParameter( QLatin1String(
"value" ), QLatin1String(
"URI" ) );
874 Sound VCardTool::parseSound(
const VCardLine &line )
const
878 const QStringList params = line.parameterList();
879 if ( params.contains( QLatin1String(
"encoding" ) ) ) {
880 snd.
setData( line.value().toByteArray() );
881 }
else if ( params.contains( QLatin1String(
"value" ) ) ) {
882 if ( line.parameter( QLatin1String(
"value" ) ).toLower() == QLatin1String(
"uri" ) ) {
883 snd.
setUrl( line.value().toString() );
895 VCardLine VCardTool::createSound(
const Sound &snd )
const
897 VCardLine line( QLatin1String(
"SOUND" ) );
900 if ( !snd.
data().isEmpty() ) {
901 line.setValue( snd.
data() );
902 line.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"b" ) );
905 }
else if ( !snd.
url().isEmpty() ) {
906 line.setValue( snd.
url() );
907 line.addParameter( QLatin1String(
"value" ), QLatin1String(
"URI" ) );
913 Key VCardTool::parseKey(
const VCardLine &line )
const
917 const QStringList params = line.parameterList();
918 if ( params.contains( QLatin1String(
"encoding" ) ) ) {
924 if ( params.contains( QLatin1String(
"type" ) ) ) {
925 if ( line.parameter( QLatin1String(
"type" ) ).toLower() == QLatin1String(
"x509" ) ) {
927 }
else if ( line.parameter( QLatin1String(
"type" ) ).toLower() == QLatin1String(
"pgp" ) ) {
938 VCardLine VCardTool::createKey(
const Key &key )
const
940 VCardLine line( QLatin1String(
"KEY" ) );
945 line.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"b" ) );
947 }
else if ( !key.
textData().isEmpty() ) {
952 line.addParameter( QLatin1String(
"type" ), QLatin1String(
"X509" ) );
954 line.addParameter( QLatin1String(
"type" ), QLatin1String(
"PGP" ) );
962 Secrecy VCardTool::parseSecrecy(
const VCardLine &line )
const
966 const QString value = line.value().toString().toLower();
967 if ( value == QLatin1String(
"public" ) ) {
968 secrecy.setType( Secrecy::Public );
969 }
else if ( value == QLatin1String(
"private" ) ) {
970 secrecy.setType( Secrecy::Private );
971 }
else if ( value == QLatin1String(
"confidential" ) ) {
972 secrecy.setType( Secrecy::Confidential );
978 VCardLine VCardTool::createSecrecy(
const Secrecy &secrecy )
const
980 VCardLine line( QLatin1String(
"CLASS" ) );
982 int type = secrecy.type();
984 if ( type == Secrecy::Public ) {
985 line.setValue( QLatin1String(
"PUBLIC" ) );
986 }
else if ( type == Secrecy::Private ) {
987 line.setValue( QLatin1String(
"PRIVATE" ) );
988 }
else if ( type == Secrecy::Confidential ) {
989 line.setValue( QLatin1String(
"CONFIDENTIAL" ) );
995 QStringList VCardTool::splitString(
const QChar &sep,
const QString &str )
const
998 QString value( str );
1001 int pos = value.indexOf( sep, start );
1003 while ( pos != -1 ) {
1004 if ( pos == 0 || value[ pos - 1 ] != QLatin1Char(
'\\' ) ) {
1005 if ( pos > start && pos <= (
int)value.length() ) {
1006 list << value.mid( start, pos - start );
1012 pos = value.indexOf( sep, start );
1014 value.replace( pos - 1, 2, sep );
1015 pos = value.indexOf( sep, pos );
1019 int l = value.length() - 1;
1020 if ( value.mid( start, l - start + 1 ).length() > 0 ) {
1021 list << value.mid( start, l - start + 1 );
Class that holds a Sound clip for a contact.
Personal Communication Service.
QList< Key > List
List of keys.
QString textData() const
Returns the text data.
void setType(Type type)
Sets the type of address.
Postal address information.
void setBinaryData(const QByteArray &data)
Sets binary data.
void setData(const QByteArray &data)
Sets the raw data of the sound.
A class to store a picture of an addressee.
void setUrl(const QString &url)
Sets a URL for the location of the sound file.
void setLongitude(float longitude)
Sets the longitude.
void setTextData(const QString &data)
Sets text data.
QByteArray binaryData() const
Returns the binary data.
A class to store an encryption key.
void setOffset(int offset)
Set time zone offset relative to UTC.
void setLatitude(float latitude)
Sets the latitude.
float longitude() const
Returns the longitude.
bool isBinary() const
Returns whether the key contains binary or text data.
bool isValid() const
Return, if this time zone object is valid.
void setStreet(const QString &street)
Sets the street (including house number).
QByteArray rawData() const
Returns the raw data of this picture.
Custom or IANA conform key.
void setRawData(const QByteArray &rawData, const QString &type)
Sets the raw data of the picture.
QString url() const
Returns the location URL of this picture.
void setType(Type type)
Sets the type.
void setNumber(const QString &number)
Sets the phone number.
QList< PhoneNumber > List
List of phone numbers.
float latitude() const
Returns the latitude.
void setPostOfficeBox(const QString &postOfficeBox)
Sets the post office box.
int offset() const
Return offset in minutes relative to UTC.
QByteArray data() const
Returns the raw data of this sound.
bool isValid() const
Returns, whether this object contains a valid geographical position.
QList< Address > List
List of addresses.
void setRegion(const QString ®ion)
Sets the region, e.g.
void setCustomTypeString(const QString &type)
Sets custom type string.
void setLabel(const QString &label)
Sets the delivery label.
bool isEmpty() const
Returns true, if the picture is empty.
void setType(Type type)
Sets the type.
void setCountry(const QString &country)
Sets the country.
QString type() const
Returns the type of this picture.
void setUrl(const QString &url)
Sets a URL for the location of the picture file.
QString customTypeString() const
Returns the custom type string.
void setLocality(const QString &locality)
Sets the locality, e.g.
void setPostalCode(const QString &code)
Sets the postal code.
void setExtended(const QString &extended)
Sets the extended address information.
bool isIntern() const
Returns whether the sound is described by a URL (extern) or by the raw data (intern).
Type type() const
Returns the type, see Type.
QString toString() const
Returns string representation of geographical position.
bool isIntern() const
Returns whether the picture is described by a URL (extern) or by the raw data (intern).
QString url() const
Returns the location URL of this sound.
QString toString() const
Return string representation of time zone offset.