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 );
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::v2_1 ) {
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 if ( version != VCard::v4_0 ) {
224 VCardLine mailerLine( QLatin1String(
"MAILER" ), ( *addrIt ).mailer() );
225 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).mailer() ) ) {
226 mailerLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
227 mailerLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
229 card.addLine( mailerLine );
234 name.append( ( *addrIt ).familyName().replace( QLatin1Char(
';' ),
235 QLatin1String(
"\\;" ) ) );
237 name.append( ( *addrIt ).givenName().replace( QLatin1Char(
';' ),
238 QLatin1String(
"\\;" ) ) );
240 name.append( ( *addrIt ).additionalName().replace( QLatin1Char(
';' ),
241 QLatin1String(
"\\;" ) ) );
243 name.append( ( *addrIt ).prefix().replace( QLatin1Char(
';' ),
244 QLatin1String(
"\\;" ) ) );
246 name.append( ( *addrIt ).suffix().replace( QLatin1Char(
';' ),
247 QLatin1String(
"\\;" ) ) );
249 VCardLine nLine( QLatin1String(
"N" ), name.join( QLatin1String(
";" ) ) );
250 if ( version == VCard::v2_1 && needsEncoding( name.join( QLatin1String(
";" ) ) ) ) {
251 nLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
252 nLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
254 if ( version == VCard::v4_0 && !( *addrIt ).sortString().isEmpty() ) {
255 nLine.addParameter( QLatin1String(
"SORT-AS" ), ( *addrIt ).sortString() );
258 card.addLine( nLine );
261 if ( version != VCard::v4_0 ) {
262 VCardLine nameLine( QLatin1String(
"NAME" ), ( *addrIt ).name() );
263 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).name() ) ) {
264 nameLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
265 nameLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
267 card.addLine( nameLine );
271 if ( version != VCard::v2_1 ) {
272 card.addLine( VCardLine( QLatin1String(
"NICKNAME" ), ( *addrIt ).nickName() ) );
276 VCardLine noteLine( QLatin1String(
"NOTE" ), ( *addrIt ).note() );
277 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).note() ) ) {
278 noteLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
279 noteLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
281 card.addLine( noteLine );
284 QStringList organization;
285 organization.append( ( *addrIt ).organization().replace( QLatin1Char(
';' ),
286 QLatin1String(
"\\;" ) ) );
287 if ( !( *addrIt ).department().isEmpty() ) {
288 organization.append( ( *addrIt ).department().replace( QLatin1Char(
';' ),
289 QLatin1String(
"\\;" ) ) );
291 VCardLine orgLine( QLatin1String(
"ORG" ), organization.join( QLatin1String(
";" ) ) );
292 if ( version == VCard::v2_1 && needsEncoding( organization.join( QLatin1String(
";" ) ) ) ) {
293 orgLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
294 orgLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
296 card.addLine( orgLine );
299 card.addLine( createPicture( QLatin1String(
"PHOTO" ), ( *addrIt ).photo() ) );
302 if ( version != VCard::v2_1 ) {
303 card.addLine( VCardLine( QLatin1String(
"PRODID" ), ( *addrIt ).productId() ) );
307 card.addLine( VCardLine( QLatin1String(
"REV" ), createDateTime( ( *addrIt ).revision() ) ) );
310 VCardLine roleLine( QLatin1String(
"ROLE" ), ( *addrIt ).role() );
311 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).role() ) ) {
312 roleLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
313 roleLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
315 card.addLine( roleLine );
318 if ( version == VCard::v3_0 ) {
319 card.addLine( VCardLine( QLatin1String(
"SORT-STRING" ), ( *addrIt ).sortString() ) );
323 card.addLine( createSound( ( *addrIt ).sound() ) );
327 PhoneNumber::List::ConstIterator phoneIt;
328 PhoneNumber::List::ConstIterator phoneEnd( phoneNumbers.end() );
329 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneEnd; ++phoneIt ) {
330 VCardLine line( QLatin1String(
"TEL" ), ( *phoneIt ).number() );
332 QMap<QString, PhoneNumber::TypeFlag>::ConstIterator typeIt;
333 QMap<QString, PhoneNumber::TypeFlag>::ConstIterator typeEnd( mPhoneTypeMap.constEnd() );
334 for ( typeIt = mPhoneTypeMap.constBegin(); typeIt != typeEnd; ++typeIt ) {
335 if ( typeIt.value() & ( *phoneIt ).type() ) {
336 line.addParameter( QLatin1String(
"TYPE" ), typeIt.key() );
340 card.addLine( line );
344 VCardLine titleLine( QLatin1String(
"TITLE" ), ( *addrIt ).title() );
345 if ( version == VCard::v2_1 && needsEncoding( ( *addrIt ).title() ) ) {
346 titleLine.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
347 titleLine.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
349 card.addLine( titleLine );
352 const TimeZone timeZone = ( *addrIt ).timeZone();
357 if ( timeZone.
offset() < 0 ) {
361 str.sprintf(
"%c%02d:%02d", ( timeZone.
offset() >= 0 ?
'+' :
'-' ),
362 ( timeZone.
offset() / 60 ) * neg,
363 ( timeZone.
offset() % 60 ) * neg );
365 card.addLine( VCardLine( QLatin1String(
"TZ" ), str ) );
369 card.addLine( VCardLine( QLatin1String(
"UID" ), ( *addrIt ).uid() ) );
372 card.addLine( VCardLine( QLatin1String(
"URL" ), ( *addrIt ).url().url() ) );
375 if ( version == VCard::v2_1 ) {
376 card.addLine( VCardLine( QLatin1String(
"VERSION" ), QLatin1String(
"2.1" ) ) );
377 }
else if ( version == VCard::v3_0 ) {
378 card.addLine( VCardLine( QLatin1String(
"VERSION" ), QLatin1String(
"3.0" ) ) );
379 }
else if ( version == VCard::v4_0 ) {
380 card.addLine( VCardLine( QLatin1String(
"VERSION" ), QLatin1String(
"4.0" ) ) );
384 const QStringList customs = ( *addrIt ).customs();
385 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) {
386 QString identifier = QLatin1String(
"X-" ) +
387 ( *strIt ).left( ( *strIt ).indexOf( QLatin1Char(
':' ) ) );
388 const QString value = ( *strIt ).mid( ( *strIt ).indexOf( QLatin1Char(
':' ) ) + 1 );
389 if ( value.isEmpty() ) {
394 if ( identifier == QLatin1String(
"X-messaging/aim-All" ) ) {
395 identifier = QLatin1String(
"X-AIM" );
396 }
else if ( identifier == QLatin1String(
"X-messaging/icq-All" ) ) {
397 identifier = QLatin1String(
"X-ICQ" );
398 }
else if ( identifier == QLatin1String(
"X-messaging/xmpp-All" ) ) {
399 identifier = QLatin1String(
"X-JABBER" );
400 }
else if ( identifier == QLatin1String(
"X-messaging/msn-All" ) ) {
401 identifier = QLatin1String(
"X-MSN" );
402 }
else if ( identifier == QLatin1String(
"X-messaging/yahoo-All" ) ) {
403 identifier = QLatin1String(
"X-YAHOO" );
404 }
else if ( identifier == QLatin1String(
"X-messaging/gadu-All" ) ) {
405 identifier = QLatin1String(
"X-GADUGADU" );
406 }
else if ( identifier == QLatin1String(
"X-messaging/skype-All" ) ) {
407 identifier = QLatin1String(
"X-SKYPE" );
408 }
else if ( identifier == QLatin1String(
"X-messaging/groupwise-All" ) ) {
409 identifier = QLatin1String(
"X-GROUPWISE" );
410 }
else if ( identifier == QLatin1String(
"X-messaging/sms-All" ) ) {
411 identifier = QLatin1String(
"X-SMS" );
412 }
else if ( identifier == QLatin1String(
"X-messaging/meanwhile-All" ) ) {
413 identifier = QLatin1String(
"X-MEANWHILE" );
414 }
else if ( identifier == QLatin1String(
"X-messaging/irc-All" ) ) {
415 identifier = QLatin1String(
"X-IRC" );
416 }
else if ( identifier == QLatin1String(
"X-messaging/googletalk-All" ) ) {
418 identifier = QLatin1String(
"X-GOOGLETALK" );
422 VCardLine line( identifier, value );
423 if ( version == VCard::v2_1 && needsEncoding( value ) ) {
424 line.addParameter( QLatin1String(
"charset" ), QLatin1String(
"UTF-8" ) );
425 line.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"QUOTED-PRINTABLE" ) );
427 card.addLine( line );
430 vCardList.append( card );
433 return VCardParser::createVCards( vCardList );
436 Addressee::List VCardTool::parseVCards(
const QByteArray &vcard )
const 438 static const QLatin1Char semicolonSep(
';' );
439 static const QLatin1Char commaSep(
',' );
443 const VCard::List vCardList = VCardParser::parseVCards( vcard );
445 VCard::List::ConstIterator cardIt;
446 VCard::List::ConstIterator listEnd( vCardList.end() );
447 for ( cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt ) {
450 const QStringList idents = ( *cardIt ).identifiers();
451 QStringList::ConstIterator identIt;
452 QStringList::ConstIterator identEnd( idents.end() );
453 for ( identIt = idents.begin(); identIt != identEnd; ++identIt ) {
454 const VCardLine::List lines = ( *cardIt ).lines( ( *identIt ) );
455 VCardLine::List::ConstIterator lineIt;
458 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
459 identifier = ( *lineIt ).identifier().toLower();
461 if ( identifier == QLatin1String(
"adr" ) ) {
463 const QStringList addrParts = splitString( semicolonSep, ( *lineIt ).value().toString() );
464 if ( addrParts.count() > 0 ) {
467 if ( addrParts.count() > 1 ) {
470 if ( addrParts.count() > 2 ) {
473 if ( addrParts.count() > 3 ) {
476 if ( addrParts.count() > 4 ) {
479 if ( addrParts.count() > 5 ) {
482 if ( addrParts.count() > 6 ) {
488 const QStringList types = ( *lineIt ).parameters( QLatin1String(
"type" ) );
489 QStringList::ConstIterator end(types.end());
490 for ( QStringList::ConstIterator it = types.begin(); it != end; ++it ) {
491 type |= mAddressTypeMap[ ( *it ).toLower() ];
495 if ( !( *lineIt ).parameter( QLatin1String(
"label" ) ).isEmpty() ) {
496 address.
setLabel( ( *lineIt ).parameter( QLatin1String(
"label" ) ) );
502 else if ( identifier == QLatin1String(
"bday" ) ) {
503 addr.
setBirthday( parseDateTime( ( *lineIt ).value().toString() ) );
507 else if ( identifier == QLatin1String(
"categories" ) ) {
508 const QStringList categories = splitString( commaSep, ( *lineIt ).value().toString() );
513 else if ( identifier == QLatin1String(
"class" ) ) {
518 else if ( identifier == QLatin1String(
"email" ) ) {
519 const QStringList types = ( *lineIt ).parameters( QLatin1String(
"type" ) );
521 types.contains( QLatin1String(
"PREF" ) ) );
525 else if ( identifier == QLatin1String(
"fn" ) ) {
530 else if ( identifier == QLatin1String(
"geo" ) ) {
533 const QStringList geoParts =
534 ( *lineIt ).value().
toString().split( QLatin1Char(
';' ), QString::KeepEmptyParts );
535 if ( geoParts.size() >= 2 ) {
543 else if ( identifier == QLatin1String(
"key" ) ) {
548 else if ( identifier == QLatin1String(
"label" ) ) {
551 const QStringList types = ( *lineIt ).parameters( QLatin1String(
"type" ) );
552 QStringList::ConstIterator end(types.end());
553 for ( QStringList::ConstIterator it = types.begin(); it != end; ++it ) {
554 type |= mAddressTypeMap[ ( *it ).toLower() ];
557 bool available =
false;
559 for ( KABC::Address::List::Iterator it = addressList.begin();
560 it != addressList.end(); ++it ) {
561 if ( ( *it ).type() == type ) {
562 ( *it ).setLabel( ( *lineIt ).value().toString() );
571 address.
setLabel( ( *lineIt ).value().toString() );
577 else if ( identifier == QLatin1String(
"logo" ) ) {
578 addr.
setLogo( parsePicture( *lineIt ) );
582 else if ( identifier == QLatin1String(
"mailer" ) ) {
583 addr.
setMailer( ( *lineIt ).value().toString() );
587 else if ( identifier == QLatin1String(
"n" ) ) {
588 const QStringList nameParts = splitString( semicolonSep, ( *lineIt ).value().toString() );
589 const int numberOfParts( nameParts.count() );
590 if ( numberOfParts > 0 ) {
593 if ( numberOfParts > 1 ) {
596 if ( numberOfParts > 2 ) {
599 if ( numberOfParts > 3 ) {
602 if ( numberOfParts > 4 ) {
605 if ( !( *lineIt ).parameter( QLatin1String(
"sort-as" ) ).isEmpty() ) {
606 addr.
setSortString( ( *lineIt ).parameter( QLatin1String(
"sort-as" ) ) );
611 else if ( identifier == QLatin1String(
"name" ) ) {
612 addr.
setName( ( *lineIt ).value().toString() );
616 else if ( identifier == QLatin1String(
"nickname" ) ) {
617 addr.
setNickName( ( *lineIt ).value().toString() );
621 else if ( identifier == QLatin1String(
"note" ) ) {
622 addr.
setNote( ( *lineIt ).value().toString() );
626 else if ( identifier == QLatin1String(
"org" ) ) {
627 const QStringList orgParts = splitString( semicolonSep, ( *lineIt ).value().toString() );
628 if ( orgParts.count() > 0 ) {
631 if ( orgParts.count() > 1 ) {
634 if ( !( *lineIt ).parameter( QLatin1String(
"sort-as" ) ).isEmpty() ) {
635 addr.
setSortString( ( *lineIt ).parameter( QLatin1String(
"sort-as" ) ) );
640 else if ( identifier == QLatin1String(
"photo" ) ) {
641 addr.
setPhoto( parsePicture( *lineIt ) );
645 else if ( identifier == QLatin1String(
"prodid" ) ) {
650 else if ( identifier == QLatin1String(
"rev" ) ) {
651 addr.
setRevision( parseDateTime( ( *lineIt ).value().toString() ) );
655 else if ( identifier == QLatin1String(
"role" ) ) {
656 addr.
setRole( ( *lineIt ).value().toString() );
660 else if ( identifier == QLatin1String(
"sort-string" ) ) {
665 else if ( identifier == QLatin1String(
"sound" ) ) {
666 addr.
setSound( parseSound( *lineIt ) );
670 else if ( identifier == QLatin1String(
"tel" ) ) {
672 phone.
setNumber( ( *lineIt ).value().toString() );
674 PhoneNumber::Type type;
676 const QStringList types = ( *lineIt ).parameters( QLatin1String(
"type" ) );
677 QStringList::ConstIterator typeEnd( types.end() );
678 for ( QStringList::ConstIterator it = types.begin(); it != typeEnd; ++it ) {
679 type |= mPhoneTypeMap[( *it ).toUpper()];
688 else if ( identifier == QLatin1String(
"title" ) ) {
689 addr.
setTitle( ( *lineIt ).value().toString() );
693 else if ( identifier == QLatin1String(
"tz" ) ) {
695 const QString date = ( *lineIt ).value().
toString();
697 if ( !date.isEmpty() ) {
698 int hours = date.mid( 1, 2 ).toInt();
699 int minutes = date.mid( 4, 2 ).toInt();
700 int offset = ( hours * 60 ) + minutes;
701 offset = offset * ( date[ 0 ] == QLatin1Char(
'+' ) ? 1 : -1 );
709 else if ( identifier == QLatin1String(
"uid" ) ) {
710 addr.
setUid( ( *lineIt ).value().toString() );
714 else if ( identifier == QLatin1String(
"url" ) ) {
715 addr.
setUrl( KUrl( ( *lineIt ).value().toString() ) );
719 else if ( identifier.startsWith( QLatin1String(
"x-" ) ) ) {
720 QString ident = ( *lineIt ).identifier();
722 if ( identifier == QLatin1String(
"x-evolution-spouse" ) ||
723 identifier == QLatin1String(
"x-spouse" ) ) {
724 ident = QLatin1String(
"X-KADDRESSBOOK-X-SpousesName" );
725 }
else if ( identifier == QLatin1String(
"x-evolution-blog-url" ) ) {
726 ident = QLatin1String(
"X-KADDRESSBOOK-BlogFeed" );
727 }
else if ( identifier == QLatin1String(
"x-evolution-assistant" ) ||
728 identifier == QLatin1String(
"x-assistant" ) ) {
729 ident = QLatin1String(
"X-KADDRESSBOOK-X-AssistantsName" );
730 }
else if ( identifier == QLatin1String(
"x-evolution-anniversary" ) ||
731 identifier == QLatin1String(
"x-anniversary" ) ) {
732 ident = QLatin1String(
"X-KADDRESSBOOK-X-Anniversary" );
733 }
else if ( identifier == QLatin1String(
"x-evolution-manager" ) ||
734 identifier == QLatin1String(
"x-manager" ) ) {
735 ident = QLatin1String(
"X-KADDRESSBOOK-X-ManagersName" );
736 }
else if ( identifier == QLatin1String(
"x-aim" ) ) {
737 ident = QLatin1String(
"X-messaging/aim-All" );
738 }
else if ( identifier == QLatin1String(
"x-icq" ) ) {
739 ident = QLatin1String(
"X-messaging/icq-All" );
740 }
else if ( identifier == QLatin1String(
"x-jabber" ) ) {
741 ident = QLatin1String(
"X-messaging/xmpp-All" );
742 }
else if ( identifier == QLatin1String(
"x-jabber" ) ) {
743 ident = QLatin1String(
"X-messaging/xmpp-All" );
744 }
else if ( identifier == QLatin1String(
"x-msn" ) ) {
745 ident = QLatin1String(
"X-messaging/msn-All" );
746 }
else if ( identifier == QLatin1String(
"x-yahoo" ) ) {
747 ident = QLatin1String(
"X-messaging/yahoo-All" );
748 }
else if ( identifier == QLatin1String(
"x-gadugadu" ) ) {
749 ident = QLatin1String(
"X-messaging/gadu-All" );
750 }
else if ( identifier == QLatin1String(
"x-skype" ) ) {
751 ident = QLatin1String(
"X-messaging/skype-All" );
752 }
else if ( identifier == QLatin1String(
"x-groupwise" ) ) {
753 ident = QLatin1String(
"X-messaging/groupwise-All" );
754 }
else if ( identifier == QLatin1String(
"x-sms" ) ) {
755 ident = QLatin1String(
"X-messaging/sms-All" );
756 }
else if ( identifier == QLatin1String(
"x-meanwhile" ) ) {
757 ident = QLatin1String(
"X-messaging/meanwhile-All" );
758 }
else if ( identifier == QLatin1String(
"x-irc" ) ) {
759 ident = QLatin1String(
"X-messaging/irc-All" );
760 }
else if ( identifier == QLatin1String(
"x-googletalk" ) ) {
761 ident = QLatin1String(
"X-messaging/googletalk-All" );
764 const QString key = ident.mid( 2 );
765 const int dash = key.indexOf( QLatin1Char(
'-' ) );
766 addr.
insertCustom( key.left( dash ), key.mid( dash + 1 ),
767 ( *lineIt ).value().toString() );
772 addrList.append( addr );
778 QDateTime VCardTool::parseDateTime(
const QString &str )
const 783 if ( str.indexOf( QLatin1Char(
'-' ) ) == -1 ) {
784 date = QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
785 str.mid( 6, 2 ).toInt() );
787 date = QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
788 str.mid( 8, 2 ).toInt() );
792 int timeStart = str.indexOf( QLatin1Char(
'T' ) );
793 if ( timeStart >= 0 ) {
794 int hour = 0, minute = 0, second = 0;
796 hour = str.mid( timeStart + 1, 2 ).toInt();
798 if ( str.indexOf( QLatin1Char(
':' ), timeStart + 1 ) > 0 ) {
799 if ( str.length() >= ( timeStart + 5 ) ) {
800 minute = str.mid( timeStart + 4, 2 ).toInt();
801 if ( str.length() >= ( timeStart + 8 ) ) {
802 second = str.mid( timeStart + 7, 2 ).toInt();
806 if ( str.length() >= ( timeStart + 4 ) ) {
807 minute = str.mid( timeStart + 3, 2 ).toInt();
808 if ( str.length() >= ( timeStart + 6 ) ) {
809 second = str.mid( timeStart + 5, 2 ).toInt();
814 time = QTime( hour, minute, second );
817 Qt::TimeSpec spec = ( str.right( 1 ) == QLatin1String(
"Z" ) ) ? Qt::UTC : Qt::LocalTime;
819 QDateTime dateTime( date );
827 dateTime.setTime( time );
829 dateTime.setTimeSpec( spec );
833 QString VCardTool::createDateTime(
const QDateTime &dateTime )
const 837 if ( dateTime.date().isValid() ) {
838 str.sprintf(
"%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
839 dateTime.date().day() );
840 if ( dateTime.time().isValid() ) {
842 tmp.sprintf(
"T%02d:%02d:%02d", dateTime.time().hour(), dateTime.time().minute(),
843 dateTime.time().second() );
846 if ( dateTime.timeSpec() == Qt::UTC ) {
847 str += QLatin1Char(
'Z' );
855 Picture VCardTool::parsePicture(
const VCardLine &line )
const 859 const QStringList params = line.parameterList();
861 if ( params.contains( QLatin1String(
"type" ) ) ) {
862 type = line.parameter( QLatin1String(
"type" ) );
864 if ( params.contains( QLatin1String(
"encoding" ) ) ) {
865 pic.
setRawData( line.value().toByteArray(), type );
866 }
else if ( params.contains( QLatin1String(
"value" ) ) ) {
867 if ( line.parameter( QLatin1String(
"value" ) ).toLower() == QLatin1String(
"uri" ) ) {
868 pic.
setUrl( line.value().toString() );
875 VCardLine VCardTool::createPicture(
const QString &identifier,
const Picture &pic )
const 877 VCardLine line( identifier );
884 line.setValue( pic.
rawData() );
885 line.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"b" ) );
886 line.addParameter( QLatin1String(
"type" ), pic.
type() );
888 line.setValue( pic.
url() );
889 line.addParameter( QLatin1String(
"value" ), QLatin1String(
"URI" ) );
895 Sound VCardTool::parseSound(
const VCardLine &line )
const 899 const QStringList params = line.parameterList();
900 if ( params.contains( QLatin1String(
"encoding" ) ) ) {
901 snd.
setData( line.value().toByteArray() );
902 }
else if ( params.contains( QLatin1String(
"value" ) ) ) {
903 if ( line.parameter( QLatin1String(
"value" ) ).toLower() == QLatin1String(
"uri" ) ) {
904 snd.
setUrl( line.value().toString() );
916 VCardLine VCardTool::createSound(
const Sound &snd )
const 918 VCardLine line( QLatin1String(
"SOUND" ) );
921 if ( !snd.
data().isEmpty() ) {
922 line.setValue( snd.
data() );
923 line.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"b" ) );
926 }
else if ( !snd.
url().isEmpty() ) {
927 line.setValue( snd.
url() );
928 line.addParameter( QLatin1String(
"value" ), QLatin1String(
"URI" ) );
934 Key VCardTool::parseKey(
const VCardLine &line )
const 938 const QStringList params = line.parameterList();
939 if ( params.contains( QLatin1String(
"encoding" ) ) ) {
945 if ( params.contains( QLatin1String(
"type" ) ) ) {
946 if ( line.parameter( QLatin1String(
"type" ) ).toLower() == QLatin1String(
"x509" ) ) {
948 }
else if ( line.parameter( QLatin1String(
"type" ) ).toLower() == QLatin1String(
"pgp" ) ) {
959 VCardLine VCardTool::createKey(
const Key &key )
const 961 VCardLine line( QLatin1String(
"KEY" ) );
966 line.addParameter( QLatin1String(
"encoding" ), QLatin1String(
"b" ) );
968 }
else if ( !key.
textData().isEmpty() ) {
973 line.addParameter( QLatin1String(
"type" ), QLatin1String(
"X509" ) );
975 line.addParameter( QLatin1String(
"type" ), QLatin1String(
"PGP" ) );
983 Secrecy VCardTool::parseSecrecy(
const VCardLine &line )
const 987 const QString value = line.value().toString().toLower();
988 if ( value == QLatin1String(
"public" ) ) {
989 secrecy.setType( Secrecy::Public );
990 }
else if ( value == QLatin1String(
"private" ) ) {
991 secrecy.setType( Secrecy::Private );
992 }
else if ( value == QLatin1String(
"confidential" ) ) {
993 secrecy.setType( Secrecy::Confidential );
999 VCardLine VCardTool::createSecrecy(
const Secrecy &secrecy )
const 1001 VCardLine line( QLatin1String(
"CLASS" ) );
1003 int type = secrecy.type();
1005 if ( type == Secrecy::Public ) {
1006 line.setValue( QLatin1String(
"PUBLIC" ) );
1007 }
else if ( type == Secrecy::Private ) {
1008 line.setValue( QLatin1String(
"PRIVATE" ) );
1009 }
else if ( type == Secrecy::Confidential ) {
1010 line.setValue( QLatin1String(
"CONFIDENTIAL" ) );
1016 QStringList VCardTool::splitString(
const QChar &sep,
const QString &str )
const 1019 QString value( str );
1022 int pos = value.indexOf( sep, start );
1024 while ( pos != -1 ) {
1025 if ( pos == 0 || value[ pos - 1 ] != QLatin1Char(
'\\' ) ) {
1026 if ( pos > start && pos <= (
int)value.length() ) {
1027 list << value.mid( start, pos - start );
1033 pos = value.indexOf( sep, start );
1035 value.replace( pos - 1, 2, sep );
1036 pos = value.indexOf( sep, pos );
1040 int l = value.length() - 1;
1041 if ( value.mid( start, l - start + 1 ).length() > 0 ) {
1042 list << value.mid( start, l - start + 1 );
QString type() const
Returns the type of this picture.
Class that holds a Sound clip for a contact.
Personal Communication Service.
QList< Key > List
List of keys.
void setType(Type type)
Sets the type of address.
Postal address information.
void setNickName(const QString &nickName)
Set nick name.
void setBinaryData(const QByteArray &data)
Sets binary data.
void setData(const QByteArray &data)
Sets the raw data of the sound.
bool isIntern() const
Returns whether the picture is described by a URL (extern) or by the raw data (intern).
A class to store a picture of an addressee.
void insertEmail(const QString &email, bool preferred=false)
Insert an email address.
void setUrl(const QString &url)
Sets a URL for the location of the sound file.
void setMailer(const QString &mailer)
Set mail client.
void insertPhoneNumber(const PhoneNumber &phoneNumber)
Insert a phone number.
void setLongitude(float longitude)
Sets the longitude.
a QValueList of Addressee, with sorting functionality
QByteArray rawData() const
Returns the raw data of this picture.
void setSuffix(const QString &suffix)
Set honorific suffixes.
void setPhoto(const Picture &photo)
Set photo.
void setFormattedName(const QString &formattedName)
Set formatted name.
void setTextData(const QString &data)
Sets text data.
QByteArray binaryData() const
Returns the binary data.
A class to store an encryption key.
void setRole(const QString &role)
Set role.
void setOffset(int offset)
Set time zone offset relative to UTC.
void setLatitude(float latitude)
Sets the latitude.
void setCategories(const QStringList &)
Set categories to given value.
bool isIntern() const
Returns whether the sound is described by a URL (extern) or by the raw data (intern).
void setGivenName(const QString &givenName)
Set given name.
void setStreet(const QString &street)
Sets the street (including house number).
void setSortString(const QString &sortString)
Set sort string.
void setAdditionalName(const QString &additionalName)
Set additional names.
void setLogo(const Picture &logo)
Set logo.
void setFamilyName(const QString &familyName)
Set family name.
bool isValid() const
Returns, whether this object contains a valid geographical position.
Custom or IANA conform key.
int offset() const
Return offset in minutes relative to UTC.
void setPrefix(const QString &prefix)
Set honorific prefixes.
void setRawData(const QByteArray &rawData, const QString &type)
Sets the raw data of the picture.
Address::List addresses() const
Return list of all addresses.
QString toString() const
Return string representation of time zone offset.
void setTitle(const QString &title)
Set title.
bool isEmpty() const
Returns true, if the picture is empty.
QString customTypeString() const
Returns the custom type string.
void setType(Type type)
Sets the type.
QString url() const
Returns the location URL of this picture.
void setDepartment(const QString &department)
Set department.
void setNumber(const QString &number)
Sets the phone number.
QList< PhoneNumber > List
List of phone numbers.
void setPostOfficeBox(const QString &postOfficeBox)
Sets the post office box.
void setSound(const Sound &sound)
Set sound.
void setUid(const QString &uid)
Set unique identifier.
void insertKey(const Key &key)
Insert a key.
void setOrganization(const QString &organization)
Set organization.
void setGeo(const Geo &geo)
Set geographic position.
void setUrl(const KUrl &url)
Set homepage.
QList< Address > List
List of addresses.
QString url() const
Returns the location URL of this sound.
void setRegion(const QString ®ion)
Sets the region, e.g.
void setCustomTypeString(const QString &type)
Sets custom type string.
void setName(const QString &name)
Set name.
void setLabel(const QString &label)
Sets the delivery label.
void setNote(const QString ¬e)
Set note.
void insertAddress(const Address &address)
Insert an address.
QString textData() const
Returns the text data.
void insertCustom(const QString &app, const QString &name, const QString &value)
Insert custom entry.
void setType(Type type)
Sets the type.
float latitude() const
Returns the latitude.
void setCountry(const QString &country)
Sets the country.
void setRevision(const QDateTime &revision)
Set revision date.
void setProductId(const QString &productId)
Set product identifier.
void setUrl(const QString &url)
Sets a URL for the location of the picture file.
Type type() const
Returns the type, see Type.
QString toString() const
Returns string representation of geographical position.
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.
void setBirthday(const QDateTime &birthday)
Set birthday.
float longitude() const
Returns the longitude.
void setTimeZone(const TimeZone &timeZone)
Set time zone.
bool isBinary() const
Returns whether the key contains binary or text data.
QByteArray data() const
Returns the raw data of this sound.
void setSecrecy(const Secrecy &secrecy)
Set security class.
bool isValid() const
Return, if this time zone object is valid.