Added new hidden vCard URI parameter for certain CardDAV systems (such as Zimbra) that do not handle UID properly

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1141499 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 15 years ago
parent d855ad0ae0
commit f5dfb1faa6

@ -47,6 +47,7 @@ KABC::SortMode *Addressee::mSortMode = 0;
struct Addressee::AddresseeData : public KShared struct Addressee::AddresseeData : public KShared
{ {
QString uid; QString uid;
QString uri;
--VARIABLES-- --VARIABLES--
PhoneNumber::List phoneNumbers; PhoneNumber::List phoneNumbers;
@ -180,6 +181,24 @@ QString Addressee::uidLabel()
return i18n("Unique Identifier"); return i18n("Unique Identifier");
} }
void Addressee::setUri( const QString &id )
{
if ( id == mData->uri ) return;
detach();
mData->empty = false;
mData->uri = id;
}
QString Addressee::uri() const
{
return mData->uri;
}
QString Addressee::uriLabel()
{
return i18n("Unique Resource Identifier");
}
--DEFINITIONS-- --DEFINITIONS--
void Addressee::setNameFromString( const QString &s ) void Addressee::setNameFromString( const QString &s )

@ -110,6 +110,19 @@ class KABC_EXPORT Addressee
*/ */
static QString uidLabel(); static QString uidLabel();
/**
Set unique resource identifier.
*/
void setUri( const QString &uid );
/**
Return unique resource identifier.
*/
QString uri() const;
/**
Return translated label for uri field.
*/
static QString uriLabel();
--DECLARATIONS-- --DECLARATIONS--
/** /**
Set name fields by parsing the given string and trying to associate the Set name fields by parsing the given string and trying to associate the

@ -29,6 +29,8 @@
using namespace VCARD; using namespace VCARD;
// There are 31 possible types, not including extensions. // There are 31 possible types, not including extensions.
// URI is a custom field designed to store the upstream URI for each contact
// in order to handle certain limited CardDAV systems such as Zimbra
const QCString const QCString
VCARD::paramNames [] = VCARD::paramNames [] =
{ {
@ -62,7 +64,8 @@ VCARD::paramNames [] =
"URL", "URL",
"VERSION", "VERSION",
"CLASS", "CLASS",
"KEY" "KEY",
"URI"
}; };
const ParamType const ParamType
@ -99,6 +102,7 @@ VCARD::paramTypesTable[] = {
ParamNone, // CLASS ParamNone, // CLASS
ParamTextBin, // KEY ParamTextBin, // KEY
ParamTextNS // X ParamTextNS // X
ParamNone, // URI
}; };
ParamType ParamType
@ -152,6 +156,7 @@ VCARD::EntityTypeToParamType(EntityType e)
case EntityName: case EntityName:
case EntityVersion: case EntityVersion:
case EntityProfile: case EntityProfile:
case EntityURI:
default: t = ParamNone; break; default: t = ParamNone; break;
//---------------------------------------------------------------// //---------------------------------------------------------------//
@ -214,6 +219,7 @@ VCARD::EntityTypeToValueType(EntityType e)
case EntityProfile: case EntityProfile:
case EntityUID: case EntityUID:
case EntityNote: case EntityNote:
case EntityURI:
default: t = ValueText; break; default: t = ValueText; break;
//---------------------------------------------------------------// //---------------------------------------------------------------//
@ -344,6 +350,8 @@ VCARD::EntityNameToEntityType(const QCString & s)
t = EntityUID; t = EntityUID;
else if (s == "URL") else if (s == "URL")
t = EntityURL; t = EntityURL;
else if (s == "URI")
t = EntityURI;
case 'V': case 'V':
if (s == "VERSION") if (s == "VERSION")
t = EntityVersion; t = EntityVersion;

@ -61,6 +61,7 @@ enum EntityType {
EntitySortString, EntitySortString,
EntitySound, EntitySound,
EntityUID, EntityUID,
EntityURI,
EntityURL, EntityURL,
EntityVersion, EntityVersion,
EntityClass, EntityClass,

@ -137,6 +137,10 @@ bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCARD::VCard &v )
addressee.setUid( readTextValue( cl ) ); addressee.setUid( readTextValue( cl ) );
break; break;
case EntityURI:
addressee.setUri( readTextValue( cl ) );
break;
case EntityEmail: case EntityEmail:
addressee.insertEmail( readTextValue( cl ) ); addressee.insertEmail( readTextValue( cl ) );
break; break;
@ -278,6 +282,7 @@ void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCARD::VCard *v
addTextValue( v, EntityName, addressee.name() ); addTextValue( v, EntityName, addressee.name() );
addTextValue( v, EntityUID, addressee.uid() ); addTextValue( v, EntityUID, addressee.uid() );
addTextValue( v, EntityURI, addressee.uri() );
addTextValue( v, EntityFullName, addressee.formattedName() ); addTextValue( v, EntityFullName, addressee.formattedName() );
QStringList emails = addressee.emails(); QStringList emails = addressee.emails();

@ -227,54 +227,64 @@ QString VCardParser::createVCards( const VCard::List& list )
// iterate over the lines // iterate over the lines
for ( lineIt = lines.constBegin(); lineIt != lines.constEnd(); ++lineIt ) { for ( lineIt = lines.constBegin(); lineIt != lines.constEnd(); ++lineIt ) {
if ( !(*lineIt).value().asString().isEmpty() ) { if ( !(*lineIt).value().asString().isEmpty() ) {
if ( (*lineIt).hasGroup() ) if ((*lineIt).identifier() != QString("URI")) {
textLine = (*lineIt).group() + "." + (*lineIt).identifier(); if ( (*lineIt).hasGroup() )
else textLine = (*lineIt).group() + "." + (*lineIt).identifier();
textLine = (*lineIt).identifier(); else
textLine = (*lineIt).identifier();
params = (*lineIt).parameterList();
hasEncoding = false; params = (*lineIt).parameterList();
if ( params.count() > 0 ) { // we have parameters hasEncoding = false;
for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) { if ( params.count() > 0 ) { // we have parameters
if ( (*paramIt) == "encoding" ) { for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) {
hasEncoding = true; if ( (*paramIt) == "encoding" ) {
encodingType = (*lineIt).parameter( "encoding" ).lower(); hasEncoding = true;
encodingType = (*lineIt).parameter( "encoding" ).lower();
}
values = (*lineIt).parameters( *paramIt );
for ( valueIt = values.constBegin(); valueIt != values.constEnd(); ++valueIt ) {
textLine.append( ";" + (*paramIt).upper() );
if ( !(*valueIt).isEmpty() )
textLine.append( "=" + (*valueIt) );
}
} }
}
values = (*lineIt).parameters( *paramIt ); if ( hasEncoding ) { // have to encode the data
for ( valueIt = values.constBegin(); valueIt != values.constEnd(); ++valueIt ) { QByteArray input, output;
textLine.append( ";" + (*paramIt).upper() ); if ( encodingType == "b" ) {
if ( !(*valueIt).isEmpty() ) input = (*lineIt).value().toByteArray();
textLine.append( "=" + (*valueIt) ); KCodecs::base64Encode( input, output );
} else if ( encodingType == "quoted-printable" ) {
input = (*lineIt).value().toString().utf8();
input.resize( input.size() - 1 ); // strip \0
KCodecs::quotedPrintableEncode( input, output, false );
} }
}
}
if ( hasEncoding ) { // have to encode the data QString value( output );
QByteArray input, output; addEscapes( value );
if ( encodingType == "b" ) { textLine.append( ":" + value );
input = (*lineIt).value().toByteArray(); } else {
KCodecs::base64Encode( input, output ); QString value( (*lineIt).value().asString() );
} else if ( encodingType == "quoted-printable" ) { addEscapes( value );
input = (*lineIt).value().toString().utf8(); textLine.append( ":" + value );
input.resize( input.size() - 1 ); // strip \0
KCodecs::quotedPrintableEncode( input, output, false );
} }
QString value( output ); if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line
addEscapes( value ); for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i )
textLine.append( ":" + value ); text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" );
} else { } else
text.append( textLine + "\r\n" );
}
else {
// URIs can be full of weird symbols, etc. so bypass all checks
textLine = (*lineIt).identifier();
QString value( (*lineIt).value().asString() ); QString value( (*lineIt).value().asString() );
addEscapes( value ); addEscapes( value );
textLine.append( ":" + value ); textLine.append( ":" + value );
}
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( textLine + "\r\n" );
}
} }
} }
} }

@ -320,6 +320,9 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
// UID // UID
card.addLine( VCardLine( "UID", (*addrIt).uid() ) ); card.addLine( VCardLine( "UID", (*addrIt).uid() ) );
// UID
card.addLine( VCardLine( "URI", (*addrIt).uri() ) );
// URL // URL
card.addLine( VCardLine( "URL", (*addrIt).url().url() ) ); card.addLine( VCardLine( "URL", (*addrIt).url().url() ) );
@ -580,6 +583,10 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
else if ( identifier == "uid" ) else if ( identifier == "uid" )
addr.setUid( (*lineIt).value().asString() ); addr.setUid( (*lineIt).value().asString() );
// URI
else if ( identifier == "uri" )
addr.setUri( (*lineIt).value().asString() );
// URL // URL
else if ( identifier == "url" ) else if ( identifier == "url" )
addr.setUrl( KURL( (*lineIt).value().asString() ) ); addr.setUrl( KURL( (*lineIt).value().asString() ) );

Loading…
Cancel
Save