22 #include <tqdatastream.h>
31 #include "vcardtool.h"
35 static bool needsEncoding(
const TQString &value )
37 uint length = value.length();
38 for ( uint i = 0; i < length; ++i ) {
39 char c = value.at( i ).latin1();
40 if ( (c < 33 || c > 126) && c !=
' ' && c !=
'=' )
47 VCardTool::VCardTool()
49 mAddressTypeMap.insert(
"dom", Address::Dom );
50 mAddressTypeMap.insert(
"intl", Address::Intl );
51 mAddressTypeMap.insert(
"postal", Address::Postal );
52 mAddressTypeMap.insert(
"parcel", Address::Parcel );
53 mAddressTypeMap.insert(
"home", Address::Home );
54 mAddressTypeMap.insert(
"work", Address::Work );
55 mAddressTypeMap.insert(
"pref", Address::Pref );
57 mPhoneTypeMap.insert(
"HOME", PhoneNumber::Home );
58 mPhoneTypeMap.insert(
"WORK", PhoneNumber::Work );
59 mPhoneTypeMap.insert(
"MSG", PhoneNumber::Msg );
60 mPhoneTypeMap.insert(
"PREF", PhoneNumber::Pref );
61 mPhoneTypeMap.insert(
"VOICE", PhoneNumber::Voice );
62 mPhoneTypeMap.insert(
"FAX", PhoneNumber::Fax );
63 mPhoneTypeMap.insert(
"CELL", PhoneNumber::Cell );
64 mPhoneTypeMap.insert(
"VIDEO", PhoneNumber::Video );
65 mPhoneTypeMap.insert(
"BBS", PhoneNumber::Bbs );
66 mPhoneTypeMap.insert(
"MODEM", PhoneNumber::Modem );
67 mPhoneTypeMap.insert(
"CAR", PhoneNumber::Car );
68 mPhoneTypeMap.insert(
"ISDN", PhoneNumber::Isdn );
69 mPhoneTypeMap.insert(
"PCS", PhoneNumber::Pcs );
70 mPhoneTypeMap.insert(
"PAGER", PhoneNumber::Pager );
73 VCardTool::~VCardTool()
78 TQString VCardTool::createVCards( Addressee::List list, VCard::Version version )
80 VCard::List vCardList;
82 Addressee::List::ConstIterator addrIt;
83 Addressee::List::ConstIterator listEnd( list.constEnd() );
84 for ( addrIt = list.constBegin(); addrIt != listEnd; ++addrIt ) {
86 TQStringList::ConstIterator strIt;
90 for ( Address::List::ConstIterator it = addresses.begin(); it != addresses.end(); ++it ) {
93 bool isEmpty = ( (*it).postOfficeBox().isEmpty() &&
94 (*it).extended().isEmpty() &&
95 (*it).street().isEmpty() &&
96 (*it).locality().isEmpty() &&
97 (*it).region().isEmpty() &&
98 (*it).postalCode().isEmpty() &&
99 (*it).country().isEmpty() );
101 address.append( (*it).postOfficeBox().replace(
';',
"\\;" ) );
102 address.append( (*it).extended().replace(
';',
"\\;" ) );
103 address.append( (*it).street().replace(
';',
"\\;" ) );
104 address.append( (*it).locality().replace(
';',
"\\;" ) );
105 address.append( (*it).region().replace(
';',
"\\;" ) );
106 address.append( (*it).postalCode().replace(
';',
"\\;" ) );
107 address.append( (*it).country().replace(
';',
"\\;" ) );
109 VCardLine adrLine(
"ADR", address.join(
";" ) );
110 if ( version == VCard::v2_1 && needsEncoding( address.join(
";" ) ) ) {
111 adrLine.addParameter(
"charset",
"UTF-8" );
112 adrLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
115 VCardLine labelLine(
"LABEL", (*it).label() );
116 if ( version == VCard::v2_1 && needsEncoding( (*it).label() ) ) {
117 labelLine.addParameter(
"charset",
"UTF-8" );
118 labelLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
121 bool hasLabel = !(*it).label().isEmpty();
122 TQMap<TQString, int>::ConstIterator typeIt;
123 for ( typeIt = mAddressTypeMap.constBegin(); typeIt != mAddressTypeMap.constEnd(); ++typeIt ) {
124 if ( typeIt.data() & (*it).type() ) {
125 adrLine.addParameter(
"TYPE", typeIt.key() );
127 labelLine.addParameter(
"TYPE", typeIt.key() );
132 card.addLine( adrLine );
134 card.addLine( labelLine );
138 card.addLine( createAgent( version, (*addrIt).agent() ) );
141 card.addLine( VCardLine(
"BDAY", createDateTime( TQT_TQDATETIME_OBJECT((*addrIt).birthday()) ) ) );
144 if ( version == VCard::v3_0 ) {
145 TQStringList categories = (*addrIt).categories();
146 TQStringList::Iterator catIt;
147 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt )
148 (*catIt).replace(
',',
"\\," );
150 VCardLine catLine(
"CATEGORIES", categories.join(
"," ) );
151 if ( version == VCard::v2_1 && needsEncoding( categories.join(
"," ) ) ) {
152 catLine.addParameter(
"charset",
"UTF-8" );
153 catLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
156 card.addLine( catLine );
160 if ( version == VCard::v3_0 ) {
161 card.addLine( createSecrecy( (*addrIt).secrecy() ) );
165 const TQStringList emails = (*addrIt).emails();
167 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) {
168 VCardLine line(
"EMAIL", *strIt );
169 if ( pref ==
true && emails.count() > 1 ) {
170 line.addParameter(
"TYPE",
"PREF" );
173 card.addLine( line );
177 VCardLine fnLine(
"FN", TQString((*addrIt).formattedName()) );
178 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).formattedName() ) ) {
179 fnLine.addParameter(
"charset",
"UTF-8" );
180 fnLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
182 card.addLine( fnLine );
185 Geo geo = (*addrIt).geo();
189 card.addLine( VCardLine(
"GEO", str ) );
193 const Key::List keys = (*addrIt).keys();
194 Key::List::ConstIterator keyIt;
195 for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt )
196 card.addLine( createKey( *keyIt ) );
199 card.addLine( createPicture(
"LOGO", (*addrIt).logo() ) );
202 VCardLine mailerLine(
"MAILER", TQString((*addrIt).mailer()) );
203 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).mailer() ) ) {
204 mailerLine.addParameter(
"charset",
"UTF-8" );
205 mailerLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
207 card.addLine( mailerLine );
211 name.append( (*addrIt).familyName().replace(
';',
"\\;" ) );
212 name.append( (*addrIt).givenName().replace(
';',
"\\;" ) );
213 name.append( (*addrIt).additionalName().replace(
';',
"\\;" ) );
214 name.append( (*addrIt).prefix().replace(
';',
"\\;" ) );
215 name.append( (*addrIt).suffix().replace(
';',
"\\;" ) );
217 VCardLine nLine(
"N", name.join(
";" ) );
218 if ( version == VCard::v2_1 && needsEncoding( name.join(
";" ) ) ) {
219 nLine.addParameter(
"charset",
"UTF-8" );
220 nLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
222 card.addLine( nLine );
225 VCardLine nameLine(
"NAME", TQString((*addrIt).name()) );
226 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).name() ) ) {
227 nameLine.addParameter(
"charset",
"UTF-8" );
228 nameLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
230 card.addLine( nameLine );
233 if ( version == VCard::v3_0 )
234 card.addLine( VCardLine(
"NICKNAME", TQString((*addrIt).nickName()) ) );
237 VCardLine noteLine(
"NOTE", TQString((*addrIt).note()) );
238 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).note() ) ) {
239 noteLine.addParameter(
"charset",
"UTF-8" );
240 noteLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
242 card.addLine( noteLine );
245 TQStringList organization;
246 organization.append( ( *addrIt ).organization().replace(
';',
"\\;" ) );
247 if ( !( *addrIt ).department().isEmpty() )
248 organization.append( ( *addrIt ).department().replace(
';',
"\\;" ) );
249 VCardLine orgLine(
"ORG", organization.join(
";" ) );
250 if ( version == VCard::v2_1 && needsEncoding( organization.join(
";" ) ) ) {
251 orgLine.addParameter(
"charset",
"UTF-8" );
252 orgLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
254 card.addLine( orgLine );
257 card.addLine( createPicture(
"PHOTO", (*addrIt).photo() ) );
260 if ( version == VCard::v3_0 )
261 card.addLine( VCardLine(
"PRODID", TQString((*addrIt).productId()) ) );
264 card.addLine( VCardLine(
"REV", createDateTime( TQT_TQDATETIME_OBJECT((*addrIt).revision()) ) ) );
267 VCardLine roleLine(
"ROLE", TQString((*addrIt).role()) );
268 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).role() ) ) {
269 roleLine.addParameter(
"charset",
"UTF-8" );
270 roleLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
272 card.addLine( roleLine );
275 if ( version == VCard::v3_0 )
276 card.addLine( VCardLine(
"SORT-STRING", TQString((*addrIt).sortString()) ) );
279 card.addLine( createSound( (*addrIt).sound() ) );
282 const PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers();
283 PhoneNumber::List::ConstIterator phoneIt;
284 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
285 VCardLine line(
"TEL", (*phoneIt).number() );
287 TQMap<TQString, int>::ConstIterator typeIt;
288 for ( typeIt = mPhoneTypeMap.constBegin(); typeIt != mPhoneTypeMap.constEnd(); ++typeIt ) {
289 if ( typeIt.data() & (*phoneIt).type() )
290 line.addParameter(
"TYPE", typeIt.key() );
293 card.addLine( line );
297 VCardLine titleLine(
"TITLE", TQString((*addrIt).title()) );
298 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).title() ) ) {
299 titleLine.addParameter(
"charset",
"UTF-8" );
300 titleLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
302 card.addLine( titleLine );
305 TimeZone timeZone = (*addrIt).timeZone();
310 if ( timeZone.
offset() < 0 )
313 str.sprintf(
"%c%02d:%02d", ( timeZone.
offset() >= 0 ?
'+' :
'-' ),
314 ( timeZone.
offset() / 60 ) * neg,
315 ( timeZone.
offset() % 60 ) * neg );
317 card.addLine( VCardLine(
"TZ", str ) );
321 card.addLine( VCardLine(
"UID", (*addrIt).uid() ) );
324 card.addLine( VCardLine(
"URI", (*addrIt).uri() ) );
327 card.addLine( VCardLine(
"URL", (*addrIt).url().url() ) );
330 if ( version == VCard::v2_1 )
331 card.addLine( VCardLine(
"VERSION",
"2.1" ) );
332 if ( version == VCard::v3_0 )
333 card.addLine( VCardLine(
"VERSION",
"3.0" ) );
336 const TQStringList customs = (*addrIt).customs();
337 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) {
338 TQString identifier =
"X-" + (*strIt).left( (*strIt).find(
":" ) );
339 TQString value = (*strIt).mid( (*strIt).find(
":" ) + 1 );
340 if ( value.isEmpty() )
343 VCardLine line( identifier, value );
344 if ( version == VCard::v2_1 && needsEncoding( value ) ) {
345 line.addParameter(
"charset",
"UTF-8" );
346 line.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
348 card.addLine( line );
351 vCardList.append( card );
354 return VCardParser::createVCards( vCardList );
357 Addressee::List VCardTool::parseVCards(
const TQString& vcard )
359 static const TQChar semicolonSep(
';' );
360 static const TQChar commaSep(
',' );
363 Addressee::List addrList;
364 const VCard::List vCardList = VCardParser::parseVCards( vcard );
366 VCard::List::ConstIterator cardIt;
367 VCard::List::ConstIterator listEnd( vCardList.end() );
368 for ( cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt ) {
371 const TQStringList idents = (*cardIt).identifiers();
372 TQStringList::ConstIterator identIt;
373 TQStringList::ConstIterator identEnd( idents.end() );
374 for ( identIt = idents.begin(); identIt != identEnd; ++identIt ) {
375 const VCardLine::List lines = (*cardIt).lines( (*identIt) );
376 VCardLine::List::ConstIterator lineIt;
379 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
380 identifier = (*lineIt).identifier().lower();
382 if ( identifier ==
"adr" ) {
384 const TQStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
385 if ( addrParts.count() > 0 )
387 if ( addrParts.count() > 1 )
389 if ( addrParts.count() > 2 )
391 if ( addrParts.count() > 3 )
393 if ( addrParts.count() > 4 )
395 if ( addrParts.count() > 5 )
397 if ( addrParts.count() > 6 )
402 const TQStringList types = (*lineIt).parameters(
"type" );
403 for ( TQStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
404 type += mAddressTypeMap[ (*it).lower() ];
411 else if ( identifier ==
"agent" )
412 addr.setAgent( parseAgent( *lineIt ) );
415 else if ( identifier ==
"bday" )
416 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) );
419 else if ( identifier ==
"categories" ) {
420 const TQStringList categories = splitString( commaSep, (*lineIt).value().asString() );
425 else if ( identifier ==
"class" )
426 addr.setSecrecy( parseSecrecy( *lineIt ) );
429 else if ( identifier ==
"email" ) {
430 const TQStringList types = (*lineIt).parameters(
"type" );
431 addr.
insertEmail( (*lineIt).value().asString(), types.findIndex(
"PREF" ) != -1 );
435 else if ( identifier ==
"fn" )
436 addr.setFormattedName( (*lineIt).value().asString() );
439 else if ( identifier ==
"geo" ) {
442 const TQStringList geoParts = TQStringList::split(
';', (*lineIt).value().asString(), true );
450 else if ( identifier ==
"key" )
454 else if ( identifier ==
"label" ) {
457 const TQStringList types = (*lineIt).parameters(
"type" );
458 for ( TQStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
459 type += mAddressTypeMap[ (*it).lower() ];
461 bool available =
false;
463 KABC::Address::List::Iterator it;
464 for ( it = addressList.begin(); it != addressList.end(); ++it ) {
465 if ( (*it).type() == type ) {
466 (*it).setLabel( (*lineIt).value().asString() );
475 address.
setLabel( (*lineIt).value().asString() );
481 else if ( identifier ==
"logo" )
482 addr.setLogo( parsePicture( *lineIt ) );
485 else if ( identifier ==
"mailer" )
486 addr.setMailer( (*lineIt).value().asString() );
489 else if ( identifier ==
"n" ) {
490 const TQStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() );
491 if ( nameParts.count() > 0 )
492 addr.setFamilyName( nameParts[ 0 ] );
493 if ( nameParts.count() > 1 )
494 addr.setGivenName( nameParts[ 1 ] );
495 if ( nameParts.count() > 2 )
496 addr.setAdditionalName( nameParts[ 2 ] );
497 if ( nameParts.count() > 3 )
498 addr.setPrefix( nameParts[ 3 ] );
499 if ( nameParts.count() > 4 )
500 addr.setSuffix( nameParts[ 4 ] );
504 else if ( identifier ==
"name" )
505 addr.setName( (*lineIt).value().asString() );
508 else if ( identifier ==
"nickname" )
509 addr.setNickName( (*lineIt).value().asString() );
512 else if ( identifier ==
"note" )
513 addr.setNote( (*lineIt).value().asString() );
516 else if ( identifier ==
"org" ) {
517 const TQStringList orgParts = splitString( semicolonSep, (*lineIt).value().asString() );
518 if ( orgParts.count() > 0 )
519 addr.setOrganization( orgParts[ 0 ] );
520 if ( orgParts.count() > 1 )
521 addr.setDepartment( orgParts[ 1 ] );
525 else if ( identifier ==
"photo" )
526 addr.setPhoto( parsePicture( *lineIt ) );
529 else if ( identifier ==
"prodid" )
530 addr.setProductId( (*lineIt).value().asString() );
533 else if ( identifier ==
"rev" )
534 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) );
537 else if ( identifier ==
"role" )
538 addr.setRole( (*lineIt).value().asString() );
541 else if ( identifier ==
"sort-string" )
542 addr.setSortString( (*lineIt).value().asString() );
545 else if ( identifier ==
"sound" )
546 addr.setSound( parseSound( *lineIt ) );
549 else if ( identifier ==
"tel" ) {
551 phone.
setNumber( (*lineIt).value().asString() );
555 const TQStringList types = (*lineIt).parameters(
"type" );
556 for ( TQStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
557 type += mPhoneTypeMap[(*it).upper()];
565 else if ( identifier ==
"title" )
566 addr.setTitle( (*lineIt).value().asString() );
569 else if ( identifier ==
"tz" ) {
571 const TQString date = (*lineIt).value().
asString();
573 int hours = date.mid( 1, 2).toInt();
574 int minutes = date.mid( 4, 2 ).toInt();
575 int offset = ( hours * 60 ) + minutes;
576 offset = offset * ( date[ 0 ] ==
'+' ? 1 : -1 );
579 addr.setTimeZone( tz );
583 else if ( identifier ==
"uid" )
584 addr.
setUid( (*lineIt).value().asString() );
587 else if ( identifier ==
"uri" )
588 addr.
setUri( (*lineIt).value().asString() );
591 else if ( identifier ==
"url" )
592 addr.setUrl(
KURL( (*lineIt).value().asString() ) );
595 else if ( identifier.startsWith(
"x-" ) ) {
596 const TQString
key = (*lineIt).identifier().mid( 2 );
597 int dash = key.find(
"-" );
598 addr.
insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() );
603 addrList.append( addr );
609 TQDateTime VCardTool::parseDateTime(
const TQString &str )
613 if ( str.find(
'-' ) == -1 ) {
614 dateTime.setDate( TQDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
615 str.mid( 6, 2 ).toInt() ) );
617 if ( str.find(
'T' ) )
618 dateTime.setTime( TQTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
619 str.mid( 17, 2 ).toInt() ) );
622 dateTime.setDate( TQDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
623 str.mid( 8, 2 ).toInt() ) );
625 if ( str.find(
'T' ) )
626 dateTime.setTime( TQTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
627 str.mid( 17, 2 ).toInt() ) );
633 TQString VCardTool::createDateTime(
const TQDateTime &dateTime )
637 if ( dateTime.date().isValid() ) {
638 str.sprintf(
"%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
639 dateTime.date().day() );
640 if ( dateTime.time().isValid() ) {
642 tmp.sprintf(
"T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(),
643 dateTime.time().second() );
651 Picture VCardTool::parsePicture(
const VCardLine &line )
655 const TQStringList params = line.parameterList();
656 if ( params.findIndex(
"encoding" ) != -1 ) {
658 img.loadFromData( line.value().asByteArray() );
660 }
else if ( params.findIndex(
"value" ) != -1 ) {
661 if ( line.parameter(
"value" ).lower() ==
"uri" )
662 pic.setUrl( line.value().asString() );
665 if ( params.findIndex(
"type" ) != -1 )
666 pic.setType( line.parameter(
"type" ) );
671 VCardLine VCardTool::createPicture(
const TQString &identifier,
const Picture &pic )
673 VCardLine line( identifier );
675 if ( pic.isIntern() ) {
676 if ( !pic.data().isNull() ) {
678 TQBuffer buffer( input );
679 buffer.open( IO_WriteOnly );
681 TQImageIO iio( &buffer,
"JPEG" );
682 iio.setImage( pic.data() );
683 iio.setQuality( 100 );
686 line.setValue( input );
687 line.addParameter(
"encoding",
"b" );
688 line.addParameter(
"type",
"image/jpeg" );
690 }
else if ( !pic.url().isEmpty() ) {
691 line.setValue( pic.url() );
692 line.addParameter(
"value",
"URI" );
698 Sound VCardTool::parseSound(
const VCardLine &line )
702 const TQStringList params = line.parameterList();
703 if ( params.findIndex(
"encoding" ) != -1 )
704 snd.
setData( line.value().asByteArray() );
705 else if ( params.findIndex(
"value" ) != -1 ) {
706 if ( line.parameter(
"value" ).lower() ==
"uri" )
707 snd.
setUrl( line.value().asString() );
718 VCardLine VCardTool::createSound(
const Sound &snd )
720 VCardLine line(
"SOUND" );
723 if ( !snd.
data().isEmpty() ) {
724 line.setValue( snd.
data() );
725 line.addParameter(
"encoding",
"b" );
728 }
else if ( !snd.
url().isEmpty() ) {
729 line.setValue( snd.
url() );
730 line.addParameter(
"value",
"URI" );
736 Key VCardTool::parseKey(
const VCardLine &line )
740 const TQStringList params = line.parameterList();
741 if ( params.findIndex(
"encoding" ) != -1 )
746 if ( params.findIndex(
"type" ) != -1 ) {
747 if ( line.parameter(
"type" ).lower() ==
"x509" )
749 else if ( line.parameter(
"type" ).lower() ==
"pgp" )
760 VCardLine VCardTool::createKey(
const Key &key )
762 VCardLine line(
"KEY" );
767 line.addParameter(
"encoding",
"b" );
769 }
else if ( !key.
textData().isEmpty() )
772 if ( key.
type() == Key::X509 )
773 line.addParameter(
"type",
"X509" );
774 else if ( key.
type() == Key::PGP )
775 line.addParameter(
"type",
"PGP" );
776 else if ( key.
type() == Key::Custom )
782 Secrecy VCardTool::parseSecrecy(
const VCardLine &line )
786 if ( line.value().asString().lower() ==
"public" )
787 secrecy.setType( Secrecy::Public );
788 if ( line.value().asString().lower() ==
"private" )
789 secrecy.setType( Secrecy::Private );
790 if ( line.value().asString().lower() ==
"confidential" )
791 secrecy.setType( Secrecy::Confidential );
796 VCardLine VCardTool::createSecrecy(
const Secrecy &secrecy )
798 VCardLine line(
"CLASS" );
800 int type = secrecy.type();
802 if ( type == Secrecy::Public )
803 line.setValue(
"PUBLIC" );
804 else if ( type == Secrecy::Private )
805 line.setValue(
"PRIVATE" );
806 else if ( type == Secrecy::Confidential )
807 line.setValue(
"CONFIDENTIAL" );
812 Agent VCardTool::parseAgent(
const VCardLine &line )
816 const TQStringList params = line.parameterList();
817 if ( params.findIndex(
"value" ) != -1 ) {
818 if ( line.parameter(
"value" ).lower() ==
"uri" )
819 agent.
setUrl( line.value().asString() );
821 TQString str = line.value().asString();
822 str.replace(
"\\n",
"\r\n" );
823 str.replace(
"\\N",
"\r\n" );
824 str.replace(
"\\;",
";" );
825 str.replace(
"\\:",
":" );
826 str.replace(
"\\,",
"," );
828 const Addressee::List list = parseVCards( str );
829 if ( list.count() > 0 ) {
839 VCardLine VCardTool::createAgent( VCard::Version version,
const Agent &agent )
841 VCardLine line(
"AGENT" );
845 Addressee::List list;
848 TQString str = createVCards( list, version );
849 str.replace(
"\r\n",
"\\n" );
850 str.replace(
";",
"\\;" );
851 str.replace(
":",
"\\:" );
852 str.replace(
",",
"\\," );
853 line.setValue( str );
855 }
else if ( !agent.
url().isEmpty() ) {
856 line.setValue( agent.
url() );
857 line.addParameter(
"value",
"URI" );
863 TQStringList VCardTool::splitString(
const TQChar &sep,
const TQString &str )
866 TQString value( str );
869 int pos = value.find( sep, start );
871 while ( pos != -1 ) {
872 if ( value[ pos - 1 ] !=
'\\' ) {
873 if ( pos > start && pos <= (
int)value.length() )
874 list << value.mid( start, pos - start );
876 list << TQString::null;
879 pos = value.find( sep, start );
882 value.replace( pos - 1, 2, sep );
883 pos = value.find( sep, pos );
885 pos = value.find( sep, pos + 1 );
889 int l = value.length() - 1;
890 if ( value.mid( start, l - start + 1 ).length() > 0 )
891 list << value.mid( start, l - start + 1 );
893 list << TQString::null;