Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit f0e76e27 authored by Laurent Montel's avatar Laurent Montel 😁

Fix GEO support in vcard v4.0

parent f9369ec6
......@@ -325,7 +325,7 @@ QByteArray VCardParser::createVCards( const VCard::List &list )
} else {
output = input;
}
addEscapes( output, ( *lineIt ).identifier() == QLatin1String( "CATEGORIES" ) );
addEscapes( output, (( *lineIt ).identifier() == QLatin1String( "CATEGORIES" )|| ( *lineIt ).identifier() == QLatin1String( "GEO" )) );
if ( !output.isEmpty() ) {
textLine.append( ':' + output );
......
......@@ -251,7 +251,11 @@ QByteArray VCardTool::createVCards( const Addressee::List &list,
const Geo geo = ( *addrIt ).geo();
if ( geo.isValid() ) {
QString str;
str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() );
if (version == VCard::v4_0 ) {
str.sprintf( "geo:%.6f,%.6f", geo.latitude(), geo.longitude() );
} else {
str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() );
}
card.addLine( VCardLine( QLatin1String( "GEO" ), str ) );
}
......@@ -583,13 +587,24 @@ Addressee::List VCardTool::parseVCards( const QByteArray &vcard ) const
// GEO
else if ( identifier == QLatin1String( "geo" ) ) {
Geo geo;
const QStringList geoParts =
( *lineIt ).value().toString().split( QLatin1Char( ';' ), QString::KeepEmptyParts );
if ( geoParts.size() >= 2 ) {
geo.setLatitude( geoParts.at( 0 ).toFloat() );
geo.setLongitude( geoParts.at( 1 ).toFloat() );
addr.setGeo( geo );
QString lineStr = ( *lineIt ).value().toString();
if (lineStr.startsWith(QLatin1String("geo:"))) { //VCard 4.0
lineStr.remove(QLatin1String("geo:"));
const QStringList geoParts =
lineStr.split( QLatin1Char( ',' ), QString::KeepEmptyParts );
if ( geoParts.size() >= 2 ) {
geo.setLatitude( geoParts.at( 0 ).toFloat() );
geo.setLongitude( geoParts.at( 1 ).toFloat() );
addr.setGeo( geo );
}
} else {
const QStringList geoParts =
lineStr.split( QLatin1Char( ';' ), QString::KeepEmptyParts );
if ( geoParts.size() >= 2 ) {
geo.setLatitude( geoParts.at( 0 ).toFloat() );
geo.setLongitude( geoParts.at( 1 ).toFloat() );
addr.setGeo( geo );
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment