author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (side-by-side diff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kabc/vcardparser | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-p1.zip kdepimpi-p1.tar.gz kdepimpi-p1.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | kabc/vcardparser/vcard.h | 4 | ||||
-rw-r--r-- | kabc/vcardparser/vcardline.cpp | 6 | ||||
-rw-r--r-- | kabc/vcardparser/vcardline.h | 8 | ||||
-rw-r--r-- | kabc/vcardparser/vcardparser.cpp | 2 | ||||
-rw-r--r-- | kabc/vcardparser/vcardtool.cpp | 2 |
5 files changed, 12 insertions, 10 deletions
diff --git a/kabc/vcardparser/vcard.h b/kabc/vcardparser/vcard.h index 0bee441..85b50e4 100644 --- a/kabc/vcardparser/vcard.h +++ b/kabc/vcardparser/vcard.h @@ -1,91 +1,91 @@ /* This file is part of libkabc. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef VCARDPARSER_VCARD_H #define VCARDPARSER_VCARD_H #include "vcardline.h" #include <qmap.h> #include <qstringlist.h> -#include <qvaluelist.h> +#include <q3valuelist.h> namespace KABC { class VCard { public: - typedef QValueList<VCard> List; + typedef Q3ValueList<VCard> List; typedef QMap< QString, VCardLine::List > LineMap; enum Version { v2_1, v3_0 }; VCard(); VCard( const VCard& ); ~VCard(); VCard& operator=( const VCard& ); /** * Removes all lines from the vCard. */ void clear(); /** * Returns a list of all identifiers that exists in the * vCard. */ QStringList identifiers() const; /** * Adds a VCardLine to the VCard */ void addLine( const VCardLine& line ); /** * Returns all lines of the vcard with a special identifier. */ VCardLine::List lines( const QString& identifier ) const; /** * Returns only the first line of the vcard with a special identifier. */ VCardLine line( const QString& identifier ) const; /** * Set the version of the vCard. */ void setVersion( Version version ); /** * Returns the version of this vCard. */ Version version() const; private: LineMap mLineMap; class VCardPrivate; VCardPrivate *d; }; } #endif diff --git a/kabc/vcardparser/vcardline.cpp b/kabc/vcardparser/vcardline.cpp index 8df2d32..c7254a0 100644 --- a/kabc/vcardparser/vcardline.cpp +++ b/kabc/vcardparser/vcardline.cpp @@ -1,175 +1,177 @@ /* This file is part of libkabc. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "vcardline.h" +//Added by qt3to4: +#include <Q3CString> using namespace KABC; class VCardLine::VCardLinePrivate { public: QString mGroup; }; VCardLine::VCardLine() : d( 0 ) { } VCardLine::VCardLine( const QString &identifier ) : d( 0 ) { mIdentifier = identifier; } VCardLine::VCardLine( const QString &identifier, const QString &value ) : d( 0 ) { mIdentifier = identifier; - mValue.assign( value.data(), value.length() ); + mValue = value; } VCardLine::VCardLine( const VCardLine& line ) : d( 0 ) { mParamMap = line.mParamMap; mValue = line.mValue; mIdentifier = line.mIdentifier; } VCardLine::~VCardLine() { delete d; d = 0; } VCardLine& VCardLine::operator=( const VCardLine& line ) { if ( &line == this ) return *this; mParamMap = line.mParamMap; mValue = line.mValue; mIdentifier = line.mIdentifier; return *this; } void VCardLine::setIdentifier( const QString& identifier ) { mIdentifier = identifier; } QString VCardLine::identifier() const { return mIdentifier; } void VCardLine::setValueString( const QString& value ) { setValueCString( value.utf8() ); } -void VCardLine::setValueCString( const QCString& value ) +void VCardLine::setValueCString( const Q3CString& value ) { mValue.duplicate( value.data(), value.length() ); } void VCardLine::setValueBytes( const QByteArray& value ) { mValue = value; } QString VCardLine::valueString() const { return QString::fromUtf8( mValue.data(), mValue.size() ); } QByteArray VCardLine::valueBytes() const { return mValue; } void VCardLine::setGroup( const QString& group ) { if ( !d ) d = new VCardLinePrivate(); d->mGroup = group; } QString VCardLine::group() const { if ( d ) return d->mGroup; else return QString(); } bool VCardLine::hasGroup() const { if ( !d ) return false; else return d->mGroup.isEmpty(); } QStringList VCardLine::parameterList() const { //return mParamMap.keys(); //US method QMap::keys() not available yet. SO collect the data manually //US return mParamMap->keys(); QStringList result; QMap<QString, QStringList>::ConstIterator it; for( it = mParamMap.begin(); it != mParamMap.end(); ++it ) { result << it.key().latin1(); } return result; } void VCardLine::addParameter( const QString& param, const QString& value ) { QStringList &list = mParamMap[ param ]; if ( list.findIndex( value ) == -1 ) // not included yet list.append( value ); } QStringList VCardLine::parameters( const QString& param ) const { ParamMap::ConstIterator it = mParamMap.find( param ); if ( it == mParamMap.end() ) return QStringList(); else return *it; } QString VCardLine::parameter( const QString& param ) const { ParamMap::ConstIterator it = mParamMap.find( param ); if ( it == mParamMap.end() ) return QString::null; else { if ( (*it).isEmpty() ) return QString::null; else return (*it).first(); } } diff --git a/kabc/vcardparser/vcardline.h b/kabc/vcardparser/vcardline.h index 8dc9322..dc4bdec 100644 --- a/kabc/vcardparser/vcardline.h +++ b/kabc/vcardparser/vcardline.h @@ -1,119 +1,119 @@ /* This file is part of libkabc. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef VCARDLINE_H #define VCARDLINE_H #include <qstringlist.h> -#include <qvaluelist.h> -#include <qcstring.h> +#include <q3valuelist.h> +#include <q3cstring.h> #include <qvariant.h> #include <qmap.h> #include <qstring.h> namespace KABC { class VCardLine { public: - typedef QValueList<VCardLine> List; + typedef Q3ValueList<VCardLine> List; typedef QMap<QString, QStringList> ParamMap; VCardLine(); VCardLine( const QString &identifier ); VCardLine( const QString &identifier, const QString &value ); VCardLine( const VCardLine& ); ~VCardLine(); VCardLine& operator=( const VCardLine& ); /** * Sets the identifier of this line e.g. UID, FN, CLASS */ void setIdentifier( const QString& identifier ); /** * Returns the identifier of this line. */ QString identifier() const; /** * Sets the value of of this line. */ void setValueString( const QString& value ); - void setValueCString( const QCString& value ); + void setValueCString( const Q3CString& value ); void setValueBytes( const QByteArray& value ); /** * Returns the value of this line. */ QString valueString() const; QByteArray valueBytes() const; /** * Sets the group the line belongs to. */ void setGroup( const QString& group ); /** * Returns the group the line belongs to. */ QString group() const; /** * Returns whether the line belongs to a group. */ bool hasGroup() const; /** * Returns all parameters. */ QStringList parameterList() const; /** * Add a new parameter to the line. */ void addParameter( const QString& param, const QString& value ); /** * Returns the values of a special parameter. * You can get a list of all parameters with paramList(). */ QStringList parameters( const QString& param ) const; /** * Returns only the first value of a special parameter. * You can get a list of all parameters with paramList(). */ QString parameter( const QString& param ) const; private: ParamMap mParamMap; QString mIdentifier; QByteArray mValue; class VCardLinePrivate; VCardLinePrivate *d; }; } #endif diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp index 11622a0..a319531 100644 --- a/kabc/vcardparser/vcardparser.cpp +++ b/kabc/vcardparser/vcardparser.cpp @@ -29,212 +29,212 @@ using namespace KABC; VCardParser::VCardParser() { } VCardParser::~VCardParser() { } VCard::List VCardParser::parseVCards( const QString& text ) { static QRegExp sep( "[\x0d\x0a]" ); VCard currentVCard; VCard::List vCardList; QString currentLine; const QStringList lines = QStringList::split( sep, text ); QStringList::ConstIterator it; bool inVCard = false; QStringList::ConstIterator linesEnd( lines.end() ); for ( it = lines.begin(); it != linesEnd; ++it ) { if ( (*it).isEmpty() ) // empty line continue; if ( (*it)[ 0 ] == ' ' || (*it)[ 0 ] == '\t' ) { // folded line => append to previous currentLine += QString( *it ).remove( 0, 1 ); continue; } else { if ( inVCard && !currentLine.isEmpty() ) { // now parse the line int colon = currentLine.find( ':' ); if ( colon == -1 ) { // invalid line currentLine = (*it); continue; } VCardLine vCardLine; const QString key = currentLine.left( colon ).stripWhiteSpace(); QString value = currentLine.mid( colon + 1 ); QStringList params = QStringList::split( ';', key ); // check for group if ( params[0].find( '.' ) != -1 ) { const QStringList groupList = QStringList::split( '.', params[0] ); vCardLine.setGroup( groupList[0] ); vCardLine.setIdentifier( groupList[1] ); } else vCardLine.setIdentifier( params[0] ); if ( params.count() > 1 ) { // find all parameters QStringList::ConstIterator paramIt = params.begin(); for ( ++paramIt; paramIt != params.end(); ++paramIt ) { QStringList pair = QStringList::split( '=', *paramIt ); if ( pair.count() == 1 ) { // correct the fucking 2.1 'standard' if ( pair[0].lower() == "quoted-printable" ) { pair[0] = "encoding"; pair[1] = "quoted-printable"; } else if ( pair[0].lower() == "base64" ) { pair[0] = "encoding"; pair[1] = "base64"; } else { pair.prepend( "type" ); } } // This is pretty much a faster pair[1].contains( ',' )... if ( pair[1].find( ',' ) != -1 ) { // parameter in type=x,y,z format const QStringList args = QStringList::split( ',', pair[ 1 ] ); QStringList::ConstIterator argIt; for ( argIt = args.begin(); argIt != args.end(); ++argIt ) vCardLine.addParameter( pair[0].lower(), *argIt ); } else vCardLine.addParameter( pair[0].lower(), pair[1] ); } } params = vCardLine.parameterList(); if ( params.findIndex( "encoding" ) != -1 ) { // have to decode the data QByteArray input, output; if ( vCardLine.parameter( "encoding" ).lower() == "b" || vCardLine.parameter( "encoding" ).lower() == "base64" ) { input = value.local8Bit(); KCodecs::base64Decode( input, output ); } else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" ) { // join any qp-folded lines while ( value.mid(value.length()-1,1) == "=" && it != linesEnd ) { value = value.remove( value.length()-1, 1 ) + (*it); ++it; } input = value.local8Bit(); KCodecs::quotedPrintableDecode( input, output ); } //PP our vcards are *supposed* to be in UTF-8 // if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) { // vCardLine.setValue( QString::fromUtf8( output.data(), output.size() ) ); // } else vCardLine.setValueBytes( output ); //PP our vcards are *supposed* to be in UTF-8 // } else if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) { // vCardLine.setValue( QString::fromUtf8( value.ascii() ) ); } else vCardLine.setValueString( value.replace( QRegExp("\\\\n"), "\n" ) ); currentVCard.addLine( vCardLine ); } // we do not save the start and end tag as vcardline if ( (*it).lower().startsWith( "begin:vcard" ) ) { inVCard = true; currentLine = ""; currentVCard.clear(); // flush vcard continue; } if ( (*it).lower().startsWith( "end:vcard" ) ) { inVCard = false; vCardList.append( currentVCard ); currentLine = ""; currentVCard.clear(); // flush vcard continue; } currentLine = (*it); } } return vCardList; } QString VCardParser::createVCards( const VCard::List& list ) { QString text; QString textLine; QString encodingType; QStringList idents; QStringList params; QStringList values; QStringList::ConstIterator identIt; QStringList::Iterator paramIt; QStringList::ConstIterator valueIt; VCardLine::List lines; VCardLine::List::ConstIterator lineIt; VCard::List::ConstIterator cardIt; bool hasEncoding; // iterate over the cards VCard::List::ConstIterator listEnd( list.end() ); for ( cardIt = list.begin(); cardIt != listEnd; ++cardIt ) { text.append( "BEGIN:VCARD\r\n" ); idents = (*cardIt).identifiers(); for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { lines = (*cardIt).lines( (*identIt) ); // iterate over the lines for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { if ( !(*lineIt).valueString().isEmpty() ) { if ( (*lineIt).hasGroup() ) textLine = (*lineIt).group() + "." + (*lineIt).identifier(); else textLine = (*lineIt).identifier(); params = (*lineIt).parameterList(); hasEncoding = false; if ( params.count() > 0 ) { // we have parameters for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) { if ( (*paramIt) == "encoding" ) { hasEncoding = true; encodingType = (*lineIt).parameter( "encoding" ).lower(); } values = (*lineIt).parameters( *paramIt ); for ( valueIt = values.begin(); valueIt != values.end(); ++valueIt ) { textLine.append( ";" + (*paramIt).upper() ); if ( !(*valueIt).isEmpty() ) textLine.append( "=" + (*valueIt) ); } } } if ( hasEncoding ) { // have to encode the data QByteArray input, output; input = (*lineIt).valueBytes(); if ( encodingType == "b" ) KCodecs::base64Encode( input, output ); else if ( encodingType == "quoted-printable" ) - KCodecs::quotedPrintableEncode( input, output ); + KCodecs::quotedPrintableEncode( input, output, true ); textLine.append( ":" + QString( output ) ); } else textLine.append( ":" + (*lineIt).valueString().replace( QRegExp("\n"), "\\n" ) ); if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" ); } else text.append( textLine + "\r\n" ); } } } text.append( "END:VCARD\r\n" ); text.append( "\r\n" ); } return text; } diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp index 204326e..435c3b0 100644 --- a/kabc/vcardparser/vcardtool.cpp +++ b/kabc/vcardparser/vcardtool.cpp @@ -463,385 +463,385 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) } } // LOGO else if ( identifier == "logo" ) addr.setLogo( parsePicture( *lineIt ) ); // MAILER else if ( identifier == "mailer" ) addr.setMailer( (*lineIt).valueString() ); // N else if ( identifier == "n" ) { const QStringList nameParts = splitString( semicolonSep, (*lineIt).valueString() ); if ( nameParts.count() > 0 ) addr.setFamilyName( nameParts[ 0 ] ); if ( nameParts.count() > 1 ) addr.setGivenName( nameParts[ 1 ] ); if ( nameParts.count() > 2 ) addr.setAdditionalName( nameParts[ 2 ] ); if ( nameParts.count() > 3 ) addr.setPrefix( nameParts[ 3 ] ); if ( nameParts.count() > 4 ) addr.setSuffix( nameParts[ 4 ] ); } // NAME else if ( identifier == "name" ) addr.setName( (*lineIt).valueString() ); // NICKNAME else if ( identifier == "nickname" ) addr.setNickName( (*lineIt).valueString() ); // NOTE else if ( identifier == "note" ) addr.setNote( (*lineIt).valueString() ); // ORGANIZATION else if ( identifier == "org" ) addr.setOrganization( (*lineIt).valueString() ); // PHOTO else if ( identifier == "photo" ) addr.setPhoto( parsePicture( *lineIt ) ); // PROID else if ( identifier == "prodid" ) addr.setProductId( (*lineIt).valueString() ); // REV else if ( identifier == "rev" ) addr.setRevision( parseDateTime( (*lineIt).valueString() ) ); // ROLE else if ( identifier == "role" ) addr.setRole( (*lineIt).valueString() ); // SORT-STRING else if ( identifier == "sort-string" ) addr.setSortString( (*lineIt).valueString() ); // SOUND else if ( identifier == "sound" ) addr.setSound( parseSound( *lineIt ) ); // TEL else if ( identifier == "tel" ) { PhoneNumber phone; phone.setNumber( (*lineIt).valueString() ); int type = 0; const QStringList types = (*lineIt).parameters( "type" ); for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) type += mPhoneTypeMap[(*it).upper()]; phone.setType( type ); addr.insertPhoneNumber( phone ); } // TITLE else if ( identifier == "title" ) addr.setTitle( (*lineIt).valueString() ); // TZ else if ( identifier == "tz" ) { TimeZone tz; const QString date = (*lineIt).valueString(); int hours = date.mid( 1, 2).toInt(); int minutes = date.mid( 4, 2 ).toInt(); int offset = ( hours * 60 ) + minutes; offset = offset * ( date[ 0 ] == '+' ? 1 : -1 ); tz.setOffset( offset ); addr.setTimeZone( tz ); } // UID else if ( identifier == "uid" ) addr.setUid( (*lineIt).valueString() ); // URL else if ( identifier == "url" ) addr.setUrl( KURL( (*lineIt).valueString() ) ); // X- else if ( identifier.startsWith( "x-" ) ) { const QString key = (*lineIt).identifier().mid( 2 ); int dash = key.find( "-" ); addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).valueString() ); } } } addr.makePhoneNumbersOLcompatible(); addrList.append( addr ); } return addrList; } QDateTime VCardTool::parseDateTime( const QString &str ) { QDateTime dateTime; if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd) dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(), str.mid( 6, 2 ).toInt() ) ); if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), str.mid( 17, 2 ).toInt() ) ); } else { // is extended format yyyy-mm-dd dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(), str.mid( 8, 2 ).toInt() ) ); if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), str.mid( 17, 2 ).toInt() ) ); } return dateTime; } QString VCardTool::createDateTime( const QDateTime &dateTime ) { QString str; if ( dateTime.date().isValid() ) { str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(), dateTime.date().day() ); if ( dateTime.time().isValid() ) { QString tmp; tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(), dateTime.time().second() ); str += tmp; } } return str; } Picture VCardTool::parsePicture( const VCardLine &line ) { Picture pic; const QStringList params = line.parameterList(); if ( params.findIndex( "encoding" ) != -1 ) { QImage img; img.loadFromData( line.valueBytes() ); pic.setData( img ); } else if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) pic.setUrl( line.valueString() ); } if ( params.findIndex( "type" ) != -1 ) pic.setType( line.parameter( "type" ) ); return pic; } VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) { VCardLine line( identifier ); if ( pic.isIntern() ) { if ( !pic.data().isNull() ) { QByteArray input; - QDataStream s( input, IO_WriteOnly ); + QDataStream s( &input, QIODevice::WriteOnly ); s.setVersion( 4 ); s << pic.data(); line.setValueBytes( input ); line.addParameter( "encoding", "b" ); line.addParameter( "type", "image/png" ); } } else if ( !pic.url().isEmpty() ) { QByteArray ba; line.setValueString( pic.url() ); line.addParameter( "value", "URI" ); } return line; } Sound VCardTool::parseSound( const VCardLine &line ) { Sound snd; const QStringList params = line.parameterList(); if ( params.findIndex( "encoding" ) != -1 ) snd.setData( line.valueBytes() ); else if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) snd.setUrl( line.valueString() ); } /* TODO: support sound types if ( params.contains( "type" ) ) snd.setType( line.parameter( "type" ) ); */ return snd; } VCardLine VCardTool::createSound( const Sound &snd ) { VCardLine line( "SOUND" ); if ( snd.isIntern() ) { if ( !snd.data().isEmpty() ) { line.setValueBytes( snd.data() ); line.addParameter( "encoding", "b" ); // TODO: need to store sound type!!! } } else if ( !snd.url().isEmpty() ) { line.setValueString( snd.url() ); line.addParameter( "value", "URI" ); } return line; } Key VCardTool::parseKey( const VCardLine &line ) { Key key; const QStringList params = line.parameterList(); if ( params.findIndex( "encoding" ) != -1 ) key.setBinaryData( line.valueBytes() ); else key.setTextData( line.valueString() ); if ( params.findIndex( "type" ) != -1 ) { if ( line.parameter( "type" ).lower() == "x509" ) key.setType( Key::X509 ); else if ( line.parameter( "type" ).lower() == "pgp" ) key.setType( Key::PGP ); else { key.setType( Key::Custom ); key.setCustomTypeString( line.parameter( "type" ) ); } } return key; } VCardLine VCardTool::createKey( const Key &key ) { VCardLine line( "KEY" ); if ( key.isBinary() ) { if ( !key.binaryData().isEmpty() ) { line.setValueBytes( key.binaryData() ); line.addParameter( "encoding", "b" ); } } else if ( !key.textData().isEmpty() ) line.setValueString( key.textData() ); if ( key.type() == Key::X509 ) line.addParameter( "type", "X509" ); else if ( key.type() == Key::PGP ) line.addParameter( "type", "PGP" ); else if ( key.type() == Key::Custom ) line.addParameter( "type", key.customTypeString() ); return line; } Secrecy VCardTool::parseSecrecy( const VCardLine &line ) { Secrecy secrecy; if ( line.valueString().lower() == "public" ) secrecy.setType( Secrecy::Public ); if ( line.valueString().lower() == "private" ) secrecy.setType( Secrecy::Private ); if ( line.valueString().lower() == "confidential" ) secrecy.setType( Secrecy::Confidential ); return secrecy; } VCardLine VCardTool::createSecrecy( const Secrecy &secrecy ) { VCardLine line( "CLASS" ); int type = secrecy.type(); if ( type == Secrecy::Public ) line.setValueString( "PUBLIC" ); else if ( type == Secrecy::Private ) line.setValueString( "PRIVATE" ); else if ( type == Secrecy::Confidential ) line.setValueString( "CONFIDENTIAL" ); return line; } Agent VCardTool::parseAgent( const VCardLine &line ) { Agent agent; const QStringList params = line.parameterList(); if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) agent.setUrl( line.valueString() ); } else { QString str = line.valueString(); str.replace( QRegExp("\\\\n"), "\r\n" ); str.replace( QRegExp("\\\\N"), "\r\n" ); str.replace( QRegExp("\\\\;"), ";" ); str.replace( QRegExp("\\\\:"), ":" ); str.replace( QRegExp("\\\\,"), "," ); const Addressee::List list = parseVCards( str ); if ( list.count() > 0 ) { Addressee *addr = new Addressee; *addr = list[ 0 ]; agent.setAddressee( addr ); } } return agent; } VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent ) { VCardLine line( "AGENT" ); if ( agent.isIntern() ) { if ( agent.addressee() != 0 ) { Addressee::List list; list.append( *agent.addressee() ); QString str = createVCards( list, version ); str.replace( QRegExp("\\r\\n"), "\\n" ); str.replace( QRegExp(";"), "\\;" ); str.replace( QRegExp(":"), "\\:" ); str.replace( QRegExp(","), "\\," ); line.setValueString( str ); } } else if ( !agent.url().isEmpty() ) { line.setValueString( agent.url() ); line.addParameter( "value", "URI" ); } return line; } QStringList VCardTool::splitString( const QChar &sep, const QString &str ) { QStringList list; QString value( str ); int start = 0; int pos = value.find( sep, start ); while ( pos != -1 ) { if ( value[ pos - 1 ] != '\\' ) { if ( pos > start && pos <= (int)value.length() ) list << value.mid( start, pos - start ); |