23 m_N( false ), m_PHOTO( false ), m_LOGO( false )
29 m_N( false ), m_PHOTO( false ), m_LOGO( false )
31 checkField( vcard,
"FN", m_formattedname );
32 checkField( vcard,
"NICKNAME", m_nickname );
33 checkField( vcard,
"URL", m_url );
34 checkField( vcard,
"BDAY", m_bday );
35 checkField( vcard,
"JABBERID", m_jabberid );
36 checkField( vcard,
"TITLE", m_title );
37 checkField( vcard,
"ROLE", m_role );
38 checkField( vcard,
"NOTE", m_note );
39 checkField( vcard,
"DESC", m_desc );
40 checkField( vcard,
"MAILER", m_mailer );
41 checkField( vcard,
"TZ", m_tz );
42 checkField( vcard,
"PRODID", m_prodid );
43 checkField( vcard,
"REV", m_rev );
44 checkField( vcard,
"SORT-STRING", m_sortstring );
45 checkField( vcard,
"UID", m_uid );
47 Tag::TagList::const_iterator it = vcard->
children().begin();
48 for( ; it != vcard->
children().end(); ++it )
50 if( (*it)->name() ==
"N" )
53 if( (*it)->hasChild(
"FAMILY" ) )
54 m_name.
family = (*it)->findChild(
"FAMILY" )->cdata();
55 if( (*it)->hasChild(
"GIVEN" ) )
56 m_name.
given = (*it)->findChild(
"GIVEN" )->cdata();
57 if( (*it)->hasChild(
"MIDDLE" ) )
58 m_name.
middle = (*it)->findChild(
"MIDDLE" )->cdata();
59 if( (*it)->hasChild(
"PREFIX" ) )
60 m_name.
prefix = (*it)->findChild(
"PREFIX" )->cdata();
61 if( (*it)->hasChild(
"SUFFIX" ) )
62 m_name.
suffix = (*it)->findChild(
"SUFFIX" )->cdata();
64 else if( (*it)->name() ==
"PHOTO" )
66 if( (*it)->hasChild(
"EXTVAL" ) )
68 m_photo.
extval = (*it)->findChild(
"EXTVAL" )->cdata();
71 else if( (*it)->hasChild(
"TYPE" ) && (*it)->hasChild(
"BINVAL" ) )
73 std::string binval = (*it)->findChild(
"BINVAL" )->cdata();
74 std::string::size_type pos = 0;
75 while( ( pos = binval.find(
'\n' ) ) != std::string::npos )
76 binval.erase( pos, 1 );
77 m_photo.
type = (*it)->findChild(
"TYPE" )->cdata();
82 else if( (*it)->name() ==
"LOGO" )
84 if( (*it)->hasChild(
"EXTVAL" ) )
86 m_logo.
extval = (*it)->findChild(
"EXTVAL" )->cdata();
89 else if( (*it)->hasChild(
"TYPE" ) && (*it)->hasChild(
"BINVAL" ) )
91 std::string binval = (*it)->findChild(
"BINVAL" )->cdata();
92 std::string::size_type pos = 0;
93 while( ( pos = binval.find(
'\n' ) ) != std::string::npos )
94 binval.erase( pos, 1 );
95 m_logo.
type = (*it)->findChild(
"TYPE" )->cdata();
100 else if( (*it)->name() ==
"EMAIL" && (*it)->hasChild(
"USERID" ) )
103 item.
userid = (*it)->findChild(
"USERID" )->cdata();
104 item.
internet = (*it)->hasChild(
"INTERNET" );
105 item.
x400 = (*it)->hasChild(
"X400" );
106 item.
work = (*it)->hasChild(
"WORK" );
107 item.
home = (*it)->hasChild(
"HOME" );
108 item.
pref = (*it)->hasChild(
"PREF" );
109 m_emailList.push_back( item );
111 else if( (*it)->name() ==
"ADR" )
114 checkField( (*it),
"POBOX", item.
pobox );
115 checkField( (*it),
"EXTADD", item.
extadd );
116 checkField( (*it),
"STREET", item.
street );
117 checkField( (*it),
"LOCALITY", item.
locality );
118 checkField( (*it),
"REGION", item.
region );
119 checkField( (*it),
"PCODE", item.
pcode );
120 checkField( (*it),
"CTRY", item.
ctry );
121 item.
postal = (*it)->hasChild(
"POSTAL" );
122 item.
parcel = (*it)->hasChild(
"PARCEL" );
123 item.
work = (*it)->hasChild(
"WORK" );
124 item.
home = (*it)->hasChild(
"HOME" );
125 item.
pref = (*it)->hasChild(
"PREF" );
126 item.
dom = (*it)->hasChild(
"DOM" );
127 item.
intl = !item.
dom && (*it)->hasChild(
"INTL" );
128 m_addressList.push_back( item );
130 else if( (*it)->name() ==
"LABEL" )
133 Tag::TagList::const_iterator it2 = (*it)->children().begin();
134 for( ; it2 != (*it)->children().end(); ++it2 )
136 if( (*it2)->name() ==
"LINE" )
137 item.
lines.push_back( (*it)->cdata() );
138 item.
postal = (*it2)->name() ==
"POSTAL";
139 item.
parcel = (*it2)->name() ==
"PARCEL";
140 item.
work = (*it2)->name() ==
"WORK";
141 item.
home = (*it2)->name() ==
"HOME";
142 item.
pref = (*it2)->name() ==
"PREF";
143 item.
dom = (*it2)->name() ==
"DOM";
144 item.
intl = !item.
dom && (*it2)->name() ==
"INTL";
146 m_labelList.push_back( item );
148 else if( (*it)->name() ==
"TEL" && (*it)->hasChild(
"NUMBER" ) )
151 item.
number = (*it)->findChild(
"NUMBER" )->cdata();
152 item.
work = (*it)->hasChild(
"WORK" );
153 item.
home = (*it)->hasChild(
"HOME" );
154 item.
voice = (*it)->hasChild(
"VOICE" );
155 item.
fax = (*it)->hasChild(
"FAX" );
156 item.
pager = (*it)->hasChild(
"PAGER" );
157 item.
msg = (*it)->hasChild(
"MSG" );
158 item.
cell = (*it)->hasChild(
"CELL" );
159 item.
video = (*it)->hasChild(
"VIDEO" );
160 item.
bbs = (*it)->hasChild(
"BBS" );
161 item.
modem = (*it)->hasChild(
"MODEM" );
162 item.
isdn = (*it)->hasChild(
"ISDN" );
163 item.
pcs = (*it)->hasChild(
"PCS" );
164 item.
pref = (*it)->hasChild(
"PREF" );
165 m_telephoneList.push_back( item );
167 else if( (*it)->name() ==
"ORG" )
169 Tag::TagList::const_iterator ito = (*it)->children().begin();
170 for( ; ito != (*it)->children().end(); ++ito )
172 if( (*ito)->name() ==
"ORGNAME" )
173 m_org.
name = (*ito)->cdata();
174 else if( (*ito)->name() ==
"ORGUNIT" )
175 m_org.
units.push_back( (*ito)->cdata() );
178 else if( (*it)->name() ==
"GEO" )
180 checkField( (*it),
"LON", m_geo.
longitude );
181 checkField( (*it),
"LAT", m_geo.
latitude );
183 else if( (*it)->name() ==
"CLASS" )
185 if( (*it)->hasChild(
"PRIVATE" ) )
187 else if( (*it)->hasChild(
"PUBLIC" ) )
189 else if( (*it)->hasChild(
"CONFIDENTIAL" ) )
197 void VCard::checkField(
Tag *vcard,
const std::string& field, std::string& var )
203 void VCard::setName(
const std::string& family,
const std::string& given,
const std::string& middle,
204 const std::string& prefix,
const std::string& suffix )
207 m_name.
given = given;
216 if( !extval.empty() )
225 if( !type.empty() && !binval.empty() )
235 if( !extval.empty() )
244 if( !type.empty() && !binval.empty() )
265 m_emailList.push_back( item );
269 const std::string& street,
const std::string& locality,
270 const std::string& region,
const std::string& pcode,
271 const std::string& ctry,
int type )
273 if( pobox.empty() && extadd.empty() && street.empty() &&
274 locality.empty() && region.empty() && pcode.empty() && ctry.empty() )
293 m_addressList.push_back( item );
311 m_labelList.push_back( item );
335 m_telephoneList.push_back( item );
340 if( !lat.empty() && !lon.empty() )
349 if( !orgname.empty() )
351 m_org.
name = orgname;
352 m_org.
units = orgunits;
358 Tag *v =
new Tag(
"vCard" );
362 insertField( v,
"FN", m_formattedname );
363 insertField( v,
"NICKNAME", m_nickname );
364 insertField( v,
"URL", m_url );
365 insertField( v,
"BDAY", m_bday );
366 insertField( v,
"JABBERID", m_jabberid );
367 insertField( v,
"TITLE", m_title );
368 insertField( v,
"ROLE", m_role );
369 insertField( v,
"NOTE", m_note );
370 insertField( v,
"DESC", m_desc );
371 insertField( v,
"MAILER", m_mailer );
372 insertField( v,
"TZ", m_tz );
373 insertField( v,
"REV", m_rev );
374 insertField( v,
"SORT_STRING", m_sortstring );
375 insertField( v,
"UID", m_uid );
379 Tag *n =
new Tag( v,
"N" );
380 insertField( n,
"FAMILY", m_name.
family );
381 insertField( n,
"GIVEN", m_name.
given );
382 insertField( n,
"MIDDLE", m_name.
middle );
383 insertField( n,
"PREFIX", m_name.
prefix );
384 insertField( n,
"SUFFIX", m_name.
suffix );
389 Tag *p =
new Tag( v,
"PHOTO" );
390 if( !m_photo.
extval.empty() )
394 else if( !m_photo.
type.empty() && !m_photo.
binval.empty() )
396 new Tag( p,
"TYPE", m_photo.
type );
403 Tag *l =
new Tag( v,
"LOGO" );
404 if( !m_logo.
extval.empty() )
408 else if( !m_logo.
type.empty() && !m_logo.
binval.empty() )
410 new Tag( l,
"TYPE", m_logo.
type );
415 EmailList::const_iterator ite = m_emailList.begin();
416 for( ; ite != m_emailList.end(); ++ite )
418 Tag *e =
new Tag( v,
"EMAIL" );
419 insertField( e,
"INTERNET", (*ite).internet );
420 insertField( e,
"WORK", (*ite).work );
421 insertField( e,
"HOME", (*ite).home );
422 insertField( e,
"X400", (*ite).x400 );
423 insertField( e,
"PREF", (*ite).pref );
424 insertField( e,
"USERID", (*ite).userid );
427 AddressList::const_iterator ita = m_addressList.begin();
428 for( ; ita != m_addressList.end(); ++ita )
430 Tag *a =
new Tag( v,
"ADR" );
431 insertField( a,
"POSTAL", (*ita).postal );
432 insertField( a,
"PARCEL", (*ita).parcel );
433 insertField( a,
"HOME", (*ita).home );
434 insertField( a,
"WORK", (*ita).work );
435 insertField( a,
"PREF", (*ita).pref );
436 insertField( a,
"DOM", (*ita).dom );
438 insertField( a,
"INTL", (*ita).intl );
440 insertField( a,
"POBOX", (*ita).pobox );
441 insertField( a,
"EXTADD", (*ita).extadd );
442 insertField( a,
"STREET", (*ita).street );
443 insertField( a,
"LOCALITY", (*ita).locality );
444 insertField( a,
"REGION", (*ita).region );
445 insertField( a,
"PCODE", (*ita).pcode );
446 insertField( a,
"CTRY", (*ita).ctry );
449 TelephoneList::const_iterator itt = m_telephoneList.begin();
450 for( ; itt != m_telephoneList.end(); ++itt )
452 Tag *t =
new Tag( v,
"TEL" );
453 insertField( t,
"NUMBER", (*itt).number );
454 insertField( t,
"HOME", (*itt).home );
455 insertField( t,
"WORK", (*itt).work );
456 insertField( t,
"VOICE", (*itt).voice );
457 insertField( t,
"FAX", (*itt).fax );
458 insertField( t,
"PAGER", (*itt).pager );
459 insertField( t,
"MSG", (*itt).msg );
460 insertField( t,
"CELL", (*itt).cell );
461 insertField( t,
"VIDEO", (*itt).video );
462 insertField( t,
"BBS", (*itt).bbs );
463 insertField( t,
"MODEM", (*itt).modem );
464 insertField( t,
"ISDN", (*itt).isdn );
465 insertField( t,
"PCS", (*itt).pcs );
466 insertField( t,
"PREF", (*itt).pref );
471 Tag *g =
new Tag( v,
"GEO" );
476 if( !m_org.
name.empty() )
478 Tag *o =
new Tag( v,
"ORG" );
479 new Tag( o,
"ORGNAME", m_org.
name );
480 StringList::const_iterator ito = m_org.
units.begin();
481 for( ; ito != m_org.
units.end(); ++ito )
482 new Tag( o,
"ORGUNITS", (*ito) );
487 Tag *c =
new Tag( v,
"CLASS" );
491 new Tag( c,
"PUBLIC" );
494 new Tag( c,
"PRIVATE" );
497 new Tag( c,
"CONFIDENTIAL" );
507 void VCard::insertField(
Tag *vcard,
const std::string& field,
const std::string& var )
const
510 new Tag( vcard, field, var );
513 void VCard::insertField( Tag *vcard,
const std::string& field,
bool var )
const
516 new Tag( vcard, field );