22 #include <tqdatastream.h>
32 #include "vcardtool.h"
34 using namespace TDEABC;
36 static bool needsEncoding(
const TQString &value )
38 uint length = value.length();
39 for ( uint i = 0; i < length; ++i ) {
40 char c = value.at( i ).latin1();
41 if ( (c < 33 || c > 126) && c !=
' ' && c !=
'=' )
48 VCardTool::VCardTool()
50 mAddressTypeMap.insert(
"dom", Address::Dom );
51 mAddressTypeMap.insert(
"intl", Address::Intl );
52 mAddressTypeMap.insert(
"postal", Address::Postal );
53 mAddressTypeMap.insert(
"parcel", Address::Parcel );
54 mAddressTypeMap.insert(
"home", Address::Home );
55 mAddressTypeMap.insert(
"work", Address::Work );
56 mAddressTypeMap.insert(
"pref", Address::Pref );
58 mPhoneTypeMap.insert(
"HOME", PhoneNumber::Home );
59 mPhoneTypeMap.insert(
"WORK", PhoneNumber::Work );
60 mPhoneTypeMap.insert(
"MSG", PhoneNumber::Msg );
61 mPhoneTypeMap.insert(
"PREF", PhoneNumber::Pref );
62 mPhoneTypeMap.insert(
"VOICE", PhoneNumber::Voice );
63 mPhoneTypeMap.insert(
"FAX", PhoneNumber::Fax );
64 mPhoneTypeMap.insert(
"CELL", PhoneNumber::Cell );
65 mPhoneTypeMap.insert(
"VIDEO", PhoneNumber::Video );
66 mPhoneTypeMap.insert(
"BBS", PhoneNumber::Bbs );
67 mPhoneTypeMap.insert(
"MODEM", PhoneNumber::Modem );
68 mPhoneTypeMap.insert(
"CAR", PhoneNumber::Car );
69 mPhoneTypeMap.insert(
"ISDN", PhoneNumber::Isdn );
70 mPhoneTypeMap.insert(
"PCS", PhoneNumber::Pcs );
71 mPhoneTypeMap.insert(
"PAGER", PhoneNumber::Pager );
74 VCardTool::~VCardTool()
79 TQString VCardTool::createVCards( Addressee::List list, VCard::Version version )
81 VCard::List vCardList;
83 Addressee::List::ConstIterator addrIt;
84 Addressee::List::ConstIterator listEnd( list.constEnd() );
85 for ( addrIt = list.constBegin(); addrIt != listEnd; ++addrIt ) {
87 TQStringList::ConstIterator strIt;
91 for ( Address::List::ConstIterator it = addresses.begin(); it != addresses.end(); ++it ) {
94 bool isEmpty = ( (*it).postOfficeBox().isEmpty() &&
95 (*it).extended().isEmpty() &&
96 (*it).street().isEmpty() &&
97 (*it).locality().isEmpty() &&
98 (*it).region().isEmpty() &&
99 (*it).postalCode().isEmpty() &&
100 (*it).country().isEmpty() );
102 address.append( (*it).postOfficeBox().replace(
';',
"\\;" ) );
103 address.append( (*it).extended().replace(
';',
"\\;" ) );
104 address.append( (*it).street().replace(
';',
"\\;" ) );
105 address.append( (*it).locality().replace(
';',
"\\;" ) );
106 address.append( (*it).region().replace(
';',
"\\;" ) );
107 address.append( (*it).postalCode().replace(
';',
"\\;" ) );
108 address.append( (*it).country().replace(
';',
"\\;" ) );
110 VCardLine adrLine(
"ADR", address.join(
";" ) );
111 if ( version == VCard::v2_1 && needsEncoding( address.join(
";" ) ) ) {
112 adrLine.addParameter(
"charset",
"UTF-8" );
113 adrLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
116 VCardLine labelLine(
"LABEL", (*it).label() );
117 if ( version == VCard::v2_1 && needsEncoding( (*it).label() ) ) {
118 labelLine.addParameter(
"charset",
"UTF-8" );
119 labelLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
122 bool hasLabel = !(*it).label().isEmpty();
123 TQMap<TQString, int>::ConstIterator typeIt;
124 for ( typeIt = mAddressTypeMap.constBegin(); typeIt != mAddressTypeMap.constEnd(); ++typeIt ) {
125 if ( typeIt.data() & (*it).type() ) {
126 adrLine.addParameter(
"TYPE", typeIt.key() );
128 labelLine.addParameter(
"TYPE", typeIt.key() );
133 card.addLine( adrLine );
135 card.addLine( labelLine );
139 card.addLine( createAgent( version, (*addrIt).agent() ) );
142 card.addLine( VCardLine(
"BDAY", createDateTime( TQT_TQDATETIME_OBJECT((*addrIt).birthday()) ) ) );
145 if ( version == VCard::v3_0 ) {
146 TQStringList categories = (*addrIt).categories();
147 TQStringList::Iterator catIt;
148 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt )
149 (*catIt).replace(
',',
"\\," );
151 VCardLine catLine(
"CATEGORIES", categories.join(
"," ) );
152 if ( version == VCard::v2_1 && needsEncoding( categories.join(
"," ) ) ) {
153 catLine.addParameter(
"charset",
"UTF-8" );
154 catLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
157 card.addLine( catLine );
161 if ( version == VCard::v3_0 ) {
162 card.addLine( createSecrecy( (*addrIt).secrecy() ) );
166 const TQStringList emails = (*addrIt).emails();
168 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) {
169 VCardLine line(
"EMAIL", *strIt );
170 if ( pref ==
true && emails.count() > 1 ) {
171 line.addParameter(
"TYPE",
"PREF" );
174 card.addLine( line );
178 VCardLine fnLine(
"FN", TQString((*addrIt).formattedName()) );
179 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).formattedName() ) ) {
180 fnLine.addParameter(
"charset",
"UTF-8" );
181 fnLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
183 card.addLine( fnLine );
186 Geo geo = (*addrIt).geo();
190 card.addLine( VCardLine(
"GEO", str ) );
194 const Key::List keys = (*addrIt).keys();
195 Key::List::ConstIterator keyIt;
196 for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt )
197 card.addLine( createKey( *keyIt ) );
200 card.addLine( createPicture(
"LOGO", (*addrIt).logo() ) );
203 VCardLine mailerLine(
"MAILER", TQString((*addrIt).mailer()) );
204 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).mailer() ) ) {
205 mailerLine.addParameter(
"charset",
"UTF-8" );
206 mailerLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
208 card.addLine( mailerLine );
212 name.append( (*addrIt).familyName().replace(
';',
"\\;" ) );
213 name.append( (*addrIt).givenName().replace(
';',
"\\;" ) );
214 name.append( (*addrIt).additionalName().replace(
';',
"\\;" ) );
215 name.append( (*addrIt).prefix().replace(
';',
"\\;" ) );
216 name.append( (*addrIt).suffix().replace(
';',
"\\;" ) );
218 VCardLine nLine(
"N", name.join(
";" ) );
219 if ( version == VCard::v2_1 && needsEncoding( name.join(
";" ) ) ) {
220 nLine.addParameter(
"charset",
"UTF-8" );
221 nLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
223 card.addLine( nLine );
226 VCardLine nameLine(
"NAME", TQString((*addrIt).name()) );
227 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).name() ) ) {
228 nameLine.addParameter(
"charset",
"UTF-8" );
229 nameLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
231 card.addLine( nameLine );
234 if ( version == VCard::v3_0 )
235 card.addLine( VCardLine(
"NICKNAME", TQString((*addrIt).nickName()) ) );
238 VCardLine noteLine(
"NOTE", TQString((*addrIt).note()) );
239 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).note() ) ) {
240 noteLine.addParameter(
"charset",
"UTF-8" );
241 noteLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
243 card.addLine( noteLine );
246 TQStringList organization;
247 organization.append( ( *addrIt ).organization().replace(
';',
"\\;" ) );
248 if ( !( *addrIt ).department().isEmpty() )
249 organization.append( ( *addrIt ).department().replace(
';',
"\\;" ) );
250 VCardLine orgLine(
"ORG", organization.join(
";" ) );
251 if ( version == VCard::v2_1 && needsEncoding( organization.join(
";" ) ) ) {
252 orgLine.addParameter(
"charset",
"UTF-8" );
253 orgLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
255 card.addLine( orgLine );
258 card.addLine( createPicture(
"PHOTO", (*addrIt).photo() ) );
261 if ( version == VCard::v3_0 )
262 card.addLine( VCardLine(
"PRODID", TQString((*addrIt).productId()) ) );
265 card.addLine( VCardLine(
"REV", createDateTime( TQT_TQDATETIME_OBJECT((*addrIt).revision()) ) ) );
268 VCardLine roleLine(
"ROLE", TQString((*addrIt).role()) );
269 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).role() ) ) {
270 roleLine.addParameter(
"charset",
"UTF-8" );
271 roleLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
273 card.addLine( roleLine );
276 if ( version == VCard::v3_0 )
277 card.addLine( VCardLine(
"SORT-STRING", TQString((*addrIt).sortString()) ) );
280 card.addLine( createSound( (*addrIt).sound() ) );
283 const PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers();
284 PhoneNumber::List::ConstIterator phoneIt;
285 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
286 VCardLine line(
"TEL", (*phoneIt).number() );
288 TQMap<TQString, int>::ConstIterator typeIt;
289 for ( typeIt = mPhoneTypeMap.constBegin(); typeIt != mPhoneTypeMap.constEnd(); ++typeIt ) {
290 if ( typeIt.data() & (*phoneIt).type() )
291 line.addParameter(
"TYPE", typeIt.key() );
294 card.addLine( line );
298 VCardLine titleLine(
"TITLE", TQString((*addrIt).title()) );
299 if ( version == VCard::v2_1 && needsEncoding( (*addrIt).title() ) ) {
300 titleLine.addParameter(
"charset",
"UTF-8" );
301 titleLine.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
303 card.addLine( titleLine );
306 TimeZone timeZone = (*addrIt).timeZone();
311 if ( timeZone.
offset() < 0 )
314 str.sprintf(
"%c%02d:%02d", ( timeZone.
offset() >= 0 ?
'+' :
'-' ),
315 ( timeZone.
offset() / 60 ) * neg,
316 ( timeZone.
offset() % 60 ) * neg );
318 card.addLine( VCardLine(
"TZ", str ) );
322 card.addLine( VCardLine(
"UID", (*addrIt).uid() ) );
325 card.addLine( VCardLine(
"URI", (*addrIt).uri() ) );
328 card.addLine( VCardLine(
"URL", (*addrIt).url().url() ) );
331 if ( version == VCard::v2_1 )
332 card.addLine( VCardLine(
"VERSION",
"2.1" ) );
333 if ( version == VCard::v3_0 )
334 card.addLine( VCardLine(
"VERSION",
"3.0" ) );
337 const TQStringList customs = (*addrIt).customs();
338 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) {
339 TQString identifier =
"X-" + (*strIt).left( (*strIt).find(
":" ) );
340 TQString value = (*strIt).mid( (*strIt).find(
":" ) + 1 );
341 if ( value.isEmpty() )
344 VCardLine line( identifier, value );
345 if ( version == VCard::v2_1 && needsEncoding( value ) ) {
346 line.addParameter(
"charset",
"UTF-8" );
347 line.addParameter(
"encoding",
"QUOTED-PRINTABLE" );
349 card.addLine( line );
352 vCardList.append( card );
355 return VCardParser::createVCards( vCardList );
358 Addressee::List VCardTool::parseVCards(
const TQString& vcard )
360 static const TQChar semicolonSep(
';' );
361 static const TQChar commaSep(
',' );
364 Addressee::List addrList;
365 const VCard::List vCardList = VCardParser::parseVCards( vcard );
367 VCard::List::ConstIterator cardIt;
368 VCard::List::ConstIterator listEnd( vCardList.end() );
369 for ( cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt ) {
372 const TQStringList idents = (*cardIt).identifiers();
373 TQStringList::ConstIterator identIt;
374 TQStringList::ConstIterator identEnd( idents.end() );
375 for ( identIt = idents.begin(); identIt != identEnd; ++identIt ) {
376 const VCardLine::List lines = (*cardIt).lines( (*identIt) );
377 VCardLine::List::ConstIterator lineIt;
380 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
381 identifier = (*lineIt).identifier().lower();
383 if ( identifier ==
"adr" ) {
385 const TQStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
386 if ( addrParts.count() > 0 )
388 if ( addrParts.count() > 1 )
390 if ( addrParts.count() > 2 )
392 if ( addrParts.count() > 3 )
394 if ( addrParts.count() > 4 )
396 if ( addrParts.count() > 5 )
398 if ( addrParts.count() > 6 )
403 const TQStringList types = (*lineIt).parameters(
"type" );
404 for ( TQStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
405 type += mAddressTypeMap[ (*it).lower() ];
412 else if ( identifier ==
"agent" )
413 addr.setAgent( parseAgent( *lineIt ) );
416 else if ( identifier ==
"bday" ) {
417 TQString s((*lineIt).value().asString());
418 if ( s.length() > 0 )
419 addr.setBirthday( parseDateTime( s ) );
423 else if ( identifier ==
"categories" ) {
424 const TQStringList categories = splitString( commaSep, (*lineIt).value().asString() );
429 else if ( identifier ==
"class" )
430 addr.setSecrecy( parseSecrecy( *lineIt ) );
433 else if ( identifier ==
"email" ) {
434 const TQStringList types = (*lineIt).parameters(
"type" );
435 addr.
insertEmail( (*lineIt).value().asString(), types.findIndex(
"PREF" ) != -1 );
439 else if ( identifier ==
"fn" )
440 addr.setFormattedName( (*lineIt).value().asString() );
443 else if ( identifier ==
"geo" ) {
446 const TQStringList geoParts = TQStringList::split(
';', (*lineIt).value().asString(), true );
454 else if ( identifier ==
"key" )
458 else if ( identifier ==
"label" ) {
461 const TQStringList types = (*lineIt).parameters(
"type" );
462 for ( TQStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
463 type += mAddressTypeMap[ (*it).lower() ];
465 bool available =
false;
467 TDEABC::Address::List::Iterator it;
468 for ( it = addressList.begin(); it != addressList.end(); ++it ) {
469 if ( (*it).type() == type ) {
470 (*it).setLabel( (*lineIt).value().asString() );
479 address.
setLabel( (*lineIt).value().asString() );
485 else if ( identifier ==
"logo" )
486 addr.setLogo( parsePicture( *lineIt ) );
489 else if ( identifier ==
"mailer" )
490 addr.setMailer( (*lineIt).value().asString() );
493 else if ( identifier ==
"n" ) {
494 const TQStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() );
495 if ( nameParts.count() > 0 )
496 addr.setFamilyName( nameParts[ 0 ] );
497 if ( nameParts.count() > 1 )
498 addr.setGivenName( nameParts[ 1 ] );
499 if ( nameParts.count() > 2 )
500 addr.setAdditionalName( nameParts[ 2 ] );
501 if ( nameParts.count() > 3 )
502 addr.setPrefix( nameParts[ 3 ] );
503 if ( nameParts.count() > 4 )
504 addr.setSuffix( nameParts[ 4 ] );
508 else if ( identifier ==
"name" )
509 addr.setName( (*lineIt).value().asString() );
512 else if ( identifier ==
"nickname" )
513 addr.setNickName( (*lineIt).value().asString() );
516 else if ( identifier ==
"note" )
517 addr.setNote( (*lineIt).value().asString() );
520 else if ( identifier ==
"org" ) {
521 const TQStringList orgParts = splitString( semicolonSep, (*lineIt).value().asString() );
522 if ( orgParts.count() > 0 )
523 addr.setOrganization( orgParts[ 0 ] );
524 if ( orgParts.count() > 1 )
525 addr.setDepartment( orgParts[ 1 ] );
529 else if ( identifier ==
"photo" )
530 addr.setPhoto( parsePicture( *lineIt ) );
533 else if ( identifier ==
"prodid" )
534 addr.setProductId( (*lineIt).value().asString() );
537 else if ( identifier ==
"rev" )
538 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) );
541 else if ( identifier ==
"role" )
542 addr.setRole( (*lineIt).value().asString() );
545 else if ( identifier ==
"sort-string" )
546 addr.setSortString( (*lineIt).value().asString() );
549 else if ( identifier ==
"sound" )
550 addr.setSound( parseSound( *lineIt ) );
553 else if ( identifier ==
"tel" ) {
555 phone.
setNumber( (*lineIt).value().asString() );
559 const TQStringList types = (*lineIt).parameters(
"type" );
560 for ( TQStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
561 type += mPhoneTypeMap[(*it).upper()];
569 else if ( identifier ==
"title" )
570 addr.setTitle( (*lineIt).value().asString() );
573 else if ( identifier ==
"tz" ) {
575 const TQString date = (*lineIt).value().
asString();
577 int hours = date.mid( 1, 2).toInt();
578 int minutes = date.mid( 4, 2 ).toInt();
579 int offset = ( hours * 60 ) + minutes;
580 offset = offset * ( date[ 0 ] ==
'+' ? 1 : -1 );
583 addr.setTimeZone( tz );
587 else if ( identifier ==
"uid" )
588 addr.
setUid( (*lineIt).value().asString() );
591 else if ( identifier ==
"uri" )
592 addr.
setUri( (*lineIt).value().asString() );
595 else if ( identifier ==
"url" )
596 addr.setUrl(
KURL( (*lineIt).value().asString() ) );
599 else if ( identifier.startsWith(
"x-" ) ) {
600 const TQString
key = (*lineIt).identifier().mid( 2 );
601 int dash = key.find(
"-" );
602 addr.
insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() );
607 addrList.append( addr );
613 TQDateTime VCardTool::parseDateTime(
const TQString &str)
636 TQRegExp re(
"(\\d{4})(?:-(\\d{2})(?:-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d+))?)?"
637 "(?:(Z)|([+-])(\\d{2}):(\\d{2})))?)?)?",
true,
false);
638 if (!re.exactMatch(str))
660 re.setPattern(
"(\\d{4})(?:(\\d{2})(?:(\\d{2})(?:T(\\d{2})(\\d{2})(?:(\\d{2})(?:(\\d+))?)?"
661 "(?:(Z)|([+-])(\\d{2})(\\d{2})))?)?)?");
663 if (re.exactMatch(str))
666 dateTime.setDate(TQDate(re.cap(1).toInt(),
667 !re.cap(2).isEmpty() ? re.cap(2).toInt() : 1,
668 !re.cap(3).isEmpty() ? re.cap(3).toInt() : 1));
669 if (!re.cap(4).isEmpty())
673 if (!re.cap(7).isEmpty())
675 millis += re.cap(7)[0].isDigit() ? re.cap(7)[0].digitValue() * 100 : 0;
676 millis += re.cap(7)[1].isDigit() ? re.cap(7)[1].digitValue() * 10 : 0;
677 millis += re.cap(7)[2].isDigit() ? re.cap(7)[2].digitValue() : 0;
679 dateTime.setTime(TQTime(re.cap(4).toInt(),
681 !re.cap(6).isEmpty() ? re.cap(6).toInt() : 0,
684 if (!re.cap(9).isEmpty())
686 int offset = re.cap(10).toInt() * 3600 + re.cap(11).toInt() * 60;
687 if (re.cap(9) ==
"+")
692 dateTime = dateTime.addSecs(offset);
699 TQString VCardTool::createDateTime(
const TQDateTime &dateTime )
703 if ( dateTime.date().isValid() ) {
704 str.sprintf(
"%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
705 dateTime.date().day() );
706 if ( dateTime.time().isValid() ) {
708 tmp.sprintf(
"T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(),
709 dateTime.time().second() );
717 Picture VCardTool::parsePicture(
const VCardLine &line )
721 const TQStringList params = line.parameterList();
722 if ( params.findIndex(
"encoding" ) != -1 ) {
724 img.loadFromData( line.value().asByteArray() );
726 }
else if ( params.findIndex(
"value" ) != -1 ) {
727 if ( line.parameter(
"value" ).lower() ==
"uri" )
728 pic.setUrl( line.value().asString() );
731 if ( params.findIndex(
"type" ) != -1 )
732 pic.setType( line.parameter(
"type" ) );
737 VCardLine VCardTool::createPicture(
const TQString &identifier,
const Picture &pic )
739 VCardLine line( identifier );
741 if ( pic.isIntern() ) {
742 if ( !pic.data().isNull() ) {
744 TQBuffer buffer( input );
745 buffer.open( IO_WriteOnly );
747 TQImageIO iio( &buffer,
"JPEG" );
748 iio.setImage( pic.data() );
749 iio.setQuality( 100 );
752 line.setValue( input );
753 line.addParameter(
"encoding",
"b" );
754 line.addParameter(
"type",
"image/jpeg" );
756 }
else if ( !pic.url().isEmpty() ) {
757 line.setValue( pic.url() );
758 line.addParameter(
"value",
"URI" );
764 Sound VCardTool::parseSound(
const VCardLine &line )
768 const TQStringList params = line.parameterList();
769 if ( params.findIndex(
"encoding" ) != -1 )
770 snd.
setData( line.value().asByteArray() );
771 else if ( params.findIndex(
"value" ) != -1 ) {
772 if ( line.parameter(
"value" ).lower() ==
"uri" )
773 snd.
setUrl( line.value().asString() );
784 VCardLine VCardTool::createSound(
const Sound &snd )
786 VCardLine line(
"SOUND" );
789 if ( !snd.
data().isEmpty() ) {
790 line.setValue( snd.
data() );
791 line.addParameter(
"encoding",
"b" );
794 }
else if ( !snd.
url().isEmpty() ) {
795 line.setValue( snd.
url() );
796 line.addParameter(
"value",
"URI" );
802 Key VCardTool::parseKey(
const VCardLine &line )
806 const TQStringList params = line.parameterList();
807 if ( params.findIndex(
"encoding" ) != -1 )
812 if ( params.findIndex(
"type" ) != -1 ) {
813 if ( line.parameter(
"type" ).lower() ==
"x509" )
815 else if ( line.parameter(
"type" ).lower() ==
"pgp" )
826 VCardLine VCardTool::createKey(
const Key &key )
828 VCardLine line(
"KEY" );
833 line.addParameter(
"encoding",
"b" );
835 }
else if ( !key.
textData().isEmpty() )
838 if ( key.
type() == Key::X509 )
839 line.addParameter(
"type",
"X509" );
840 else if ( key.
type() == Key::PGP )
841 line.addParameter(
"type",
"PGP" );
842 else if ( key.
type() == Key::Custom )
848 Secrecy VCardTool::parseSecrecy(
const VCardLine &line )
852 if ( line.value().asString().lower() ==
"public" )
853 secrecy.setType( Secrecy::Public );
854 if ( line.value().asString().lower() ==
"private" )
855 secrecy.setType( Secrecy::Private );
856 if ( line.value().asString().lower() ==
"confidential" )
857 secrecy.setType( Secrecy::Confidential );
862 VCardLine VCardTool::createSecrecy(
const Secrecy &secrecy )
864 VCardLine line(
"CLASS" );
866 int type = secrecy.type();
868 if ( type == Secrecy::Public )
869 line.setValue(
"PUBLIC" );
870 else if ( type == Secrecy::Private )
871 line.setValue(
"PRIVATE" );
872 else if ( type == Secrecy::Confidential )
873 line.setValue(
"CONFIDENTIAL" );
878 Agent VCardTool::parseAgent(
const VCardLine &line )
882 const TQStringList params = line.parameterList();
883 if ( params.findIndex(
"value" ) != -1 ) {
884 if ( line.parameter(
"value" ).lower() ==
"uri" )
885 agent.
setUrl( line.value().asString() );
887 TQString str = line.value().asString();
888 str.replace(
"\\n",
"\r\n" );
889 str.replace(
"\\N",
"\r\n" );
890 str.replace(
"\\;",
";" );
891 str.replace(
"\\:",
":" );
892 str.replace(
"\\,",
"," );
894 const Addressee::List list = parseVCards( str );
895 if ( list.count() > 0 ) {
905 VCardLine VCardTool::createAgent( VCard::Version version,
const Agent &agent )
907 VCardLine line(
"AGENT" );
911 Addressee::List list;
914 TQString str = createVCards( list, version );
915 str.replace(
"\r\n",
"\\n" );
916 str.replace(
";",
"\\;" );
917 str.replace(
":",
"\\:" );
918 str.replace(
",",
"\\," );
919 line.setValue( str );
921 }
else if ( !agent.
url().isEmpty() ) {
922 line.setValue( agent.
url() );
923 line.addParameter(
"value",
"URI" );
929 TQStringList VCardTool::splitString(
const TQChar &sep,
const TQString &str )
932 TQString value( str );
935 int pos = value.find( sep, start );
937 while ( pos != -1 ) {
938 if ( value[ pos - 1 ] !=
'\\' ) {
939 if ( pos > start && pos <= (
int)value.length() )
940 list << value.mid( start, pos - start );
942 list << TQString::null;
945 pos = value.find( sep, start );
948 value.replace( pos - 1, 2, sep );
949 pos = value.find( sep, pos );
951 pos = value.find( sep, pos + 1 );
955 int l = value.length() - 1;
956 if ( value.mid( start, l - start + 1 ).length() > 0 )
957 list << value.mid( start, l - start + 1 );
959 list << TQString::null;