📄 vcard.cpp
字号:
/* Copyright (c) 2006-2008 by Jakob Schroeter <js@camaya.net> This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license agreement can be found in the file LICENSE in this distribution. This software may not be copied, modified, sold or distributed other than expressed in the named license agreement. This software is distributed without any warranty.*/#include "vcard.h"#include "tag.h"#include "base64.h"namespace gloox{ VCard::VCard() : m_class( ClassNone ), m_prodid( "gloox" + GLOOX_VERSION ), m_N( false ), m_PHOTO( false ), m_LOGO( false ) { } VCard::VCard( Tag *vcard ) : m_class( ClassNone ), m_prodid( "gloox" + GLOOX_VERSION ), m_N( false ), m_PHOTO( false ), m_LOGO( false ) { checkField( vcard, "FN", m_formattedname ); checkField( vcard, "NICKNAME", m_nickname ); checkField( vcard, "URL", m_url ); checkField( vcard, "BDAY", m_bday ); checkField( vcard, "JABBERID", m_jabberid ); checkField( vcard, "TITLE", m_title ); checkField( vcard, "ROLE", m_role ); checkField( vcard, "NOTE", m_note ); checkField( vcard, "DESC", m_desc ); checkField( vcard, "MAILER", m_mailer ); checkField( vcard, "TZ", m_tz ); checkField( vcard, "PRODID", m_prodid ); checkField( vcard, "REV", m_rev ); checkField( vcard, "SORT-STRING", m_sortstring ); checkField( vcard, "UID", m_uid ); Tag::TagList::const_iterator it = vcard->children().begin(); for( ; it != vcard->children().end(); ++it ) { if( (*it)->name() == "N" ) { m_N = true; if( (*it)->hasChild( "FAMILY" ) ) m_name.family = (*it)->findChild( "FAMILY" )->cdata(); if( (*it)->hasChild( "GIVEN" ) ) m_name.given = (*it)->findChild( "GIVEN" )->cdata(); if( (*it)->hasChild( "MIDDLE" ) ) m_name.middle = (*it)->findChild( "MIDDLE" )->cdata(); if( (*it)->hasChild( "PREFIX" ) ) m_name.prefix = (*it)->findChild( "PREFIX" )->cdata(); if( (*it)->hasChild( "SUFFIX" ) ) m_name.suffix = (*it)->findChild( "SUFFIX" )->cdata(); } else if( (*it)->name() == "PHOTO" ) { if( (*it)->hasChild( "EXTVAL" ) ) { m_photo.extval = (*it)->findChild( "EXTVAL" )->cdata(); m_PHOTO = true; } else if( (*it)->hasChild( "TYPE" ) && (*it)->hasChild( "BINVAL" ) ) { std::string binval = (*it)->findChild( "BINVAL" )->cdata(); std::string::size_type pos = 0; while( ( pos = binval.find( '\n' ) ) != std::string::npos ) binval.erase( pos, 1 ); m_photo.type = (*it)->findChild( "TYPE" )->cdata(); m_photo.binval = Base64::decode64( binval ); m_PHOTO = true; } } else if( (*it)->name() == "LOGO" ) { if( (*it)->hasChild( "EXTVAL" ) ) { m_logo.extval = (*it)->findChild( "EXTVAL" )->cdata(); m_LOGO = true; } else if( (*it)->hasChild( "TYPE" ) && (*it)->hasChild( "BINVAL" ) ) { std::string binval = (*it)->findChild( "BINVAL" )->cdata(); std::string::size_type pos = 0; while( ( pos = binval.find( '\n' ) ) != std::string::npos ) binval.erase( pos, 1 ); m_logo.type = (*it)->findChild( "TYPE" )->cdata(); m_logo.binval = Base64::decode64( binval ); m_LOGO = true; } } else if( (*it)->name() == "EMAIL" && (*it)->hasChild( "USERID" ) ) { Email item; item.userid = (*it)->findChild( "USERID" )->cdata(); item.internet = (*it)->hasChild( "INTERNET" ); item.x400 = (*it)->hasChild( "X400" ); item.work = (*it)->hasChild( "WORK" ); item.home = (*it)->hasChild( "HOME" ); item.pref = (*it)->hasChild( "PREF" ); m_emailList.push_back( item ); } else if( (*it)->name() == "ADR" ) { Address item; checkField( (*it), "POBOX", item.pobox ); checkField( (*it), "EXTADD", item.extadd ); checkField( (*it), "STREET", item.street ); checkField( (*it), "LOCALITY", item.locality ); checkField( (*it), "REGION", item.region ); checkField( (*it), "PCODE", item.pcode ); checkField( (*it), "CTRY", item.ctry ); item.postal = (*it)->hasChild( "POSTAL" ); item.parcel = (*it)->hasChild( "PARCEL" ); item.work = (*it)->hasChild( "WORK" ); item.home = (*it)->hasChild( "HOME" ); item.pref = (*it)->hasChild( "PREF" ); item.dom = (*it)->hasChild( "DOM" ); item.intl = !item.dom && (*it)->hasChild( "INTL" ); m_addressList.push_back( item ); } else if( (*it)->name() == "LABEL" ) { Label item; Tag::TagList::const_iterator it2 = (*it)->children().begin(); for( ; it2 != (*it)->children().end(); ++it2 ) { if( (*it2)->name() == "LINE" ) item.lines.push_back( (*it)->cdata() ); item.postal = (*it2)->name() == "POSTAL"; item.parcel = (*it2)->name() == "PARCEL"; item.work = (*it2)->name() == "WORK"; item.home = (*it2)->name() == "HOME"; item.pref = (*it2)->name() == "PREF"; item.dom = (*it2)->name() == "DOM"; item.intl = !item.dom && (*it2)->name() == "INTL"; } m_labelList.push_back( item ); } else if( (*it)->name() == "TEL" && (*it)->hasChild( "NUMBER" ) ) { Telephone item; item.number = (*it)->findChild( "NUMBER" )->cdata(); item.work = (*it)->hasChild( "WORK" ); item.home = (*it)->hasChild( "HOME" ); item.voice = (*it)->hasChild( "VOICE" ); item.fax = (*it)->hasChild( "FAX" ); item.pager = (*it)->hasChild( "PAGER" ); item.msg = (*it)->hasChild( "MSG" ); item.cell = (*it)->hasChild( "CELL" ); item.video = (*it)->hasChild( "VIDEO" ); item.bbs = (*it)->hasChild( "BBS" ); item.modem = (*it)->hasChild( "MODEM" ); item.isdn = (*it)->hasChild( "ISDN" ); item.pcs = (*it)->hasChild( "PCS" ); item.pref = (*it)->hasChild( "PREF" ); m_telephoneList.push_back( item ); } else if( (*it)->name() == "ORG" ) { Tag::TagList::const_iterator ito = (*it)->children().begin(); for( ; ito != (*it)->children().end(); ++ito ) { if( (*ito)->name() == "ORGNAME" ) m_org.name = (*ito)->cdata(); else if( (*ito)->name() == "ORGUNIT" ) m_org.units.push_back( (*ito)->cdata() ); } } else if( (*it)->name() == "GEO" ) { checkField( (*it), "LON", m_geo.longitude ); checkField( (*it), "LAT", m_geo.latitude ); } else if( (*it)->name() == "CLASS" ) { if( (*it)->hasChild( "PRIVATE" ) ) m_class = ClassPrivate; else if( (*it)->hasChild( "PUBLIC" ) ) m_class = ClassPublic; else if( (*it)->hasChild( "CONFIDENTIAL" ) ) m_class = ClassConfidential; } } } void VCard::checkField( Tag *vcard, const std::string& field, std::string& var ) { if( vcard->hasChild( field ) ) var = vcard->findChild( field )->cdata(); } void VCard::setName( const std::string& family, const std::string& given, const std::string& middle, const std::string& prefix, const std::string& suffix ) { m_name.family = family; m_name.given = given; m_name.middle = middle; m_name.prefix = prefix; m_name.suffix = suffix; m_N = true; } void VCard::setPhoto( const std::string& extval ) { if( !extval.empty() ) { m_photo.extval= extval; m_PHOTO = true; } } void VCard::setPhoto( const std::string& type, const std::string& binval ) { if( !type.empty() && !binval.empty() ) { m_photo.type = type; m_photo.binval = binval; m_PHOTO = true; } } void VCard::setLogo( const std::string& extval ) { if( !extval.empty() ) { m_logo.extval = extval; m_LOGO = true; } } void VCard::setLogo( const std::string& type, const std::string& binval ) { if( !type.empty() && !binval.empty() ) { m_logo.type = type; m_logo.binval = binval; m_LOGO = true; } } void VCard::addEmail( const std::string& userid, int type ) { if( userid.empty() ) return; Email item; item.userid = userid; item.internet = type & AddrTypeInet ? true : false; item.x400 = type & AddrTypeX400 ? true : false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -