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 11ab220b authored by Laurent Montel's avatar Laurent Montel 😁

Add LANG support (vcard4.0)

parent 955d3fcf
......@@ -31,7 +31,6 @@
#include "addresseehelper.h"
#include "field.h"
#include "email.h"
#ifndef KDEPIM_NO_KRESOURCES
#include "resource.h"
#endif
......@@ -97,6 +96,7 @@ class Addressee::Private : public QSharedData
mAddresses = other.mAddresses;
mKeys = other.mKeys;
mEmails = other.mEmails;
mLangs = other.mLangs;
mCategories = other.mCategories;
mCustomFields = other.mCustomFields;
......@@ -142,6 +142,7 @@ class Addressee::Private : public QSharedData
Address::List mAddresses;
Key::List mKeys;
Email::List mEmails;
Lang::List mLangs;
QStringList mCategories;
QMap<QString, QString> mCustomFields;
......@@ -353,6 +354,10 @@ bool Addressee::operator==( const Addressee &addressee ) const
return false;
}
if (d->mLangs != addressee.d->mLangs) {
kDebug() << "langs differs";
return false;
}
return true;
}
......@@ -1306,6 +1311,38 @@ void Addressee::setEmails( const QStringList& emails )
}
}
void Addressee::removeLang( const QString &language )
{
for (int i = 0; i < d->mLangs.size(); ++i) {
if (d->mLangs.at(i).language() == language) {
d->mLangs.removeAt(i);
}
}
}
void Addressee::insertLang( const Lang &language )
{
const QString languageStr = language.language();
if (languageStr.simplified().isEmpty())
return;
d->mEmpty = false;
Lang::List::Iterator it;
Lang::List::Iterator end(d->mLangs.end());
for ( it = d->mLangs.begin(); it != end; ++it ) {
if ( ( *it ).language() == languageStr ) {
(*it).setParameters(language.parameters());
return;
}
}
d->mLangs.append( language );
}
Lang::List Addressee::langs() const
{
return d->mLangs;
}
void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
{
d->mEmpty = false;
......@@ -1512,6 +1549,15 @@ QString Addressee::toString() const
}
str += QLatin1String( " }\n" );
str += QLatin1String( " Langs {\n" );
const Lang::List listLang = d->mLangs;
Lang::List::ConstIterator it6;
for ( it6 = listLang.begin(); it6 != listLang.end(); ++it6 ) {
str += ( *it6 ).toString();
}
str += QLatin1String( " }\n" );
str += QLatin1String( " PhoneNumbers {\n" );
const PhoneNumber::List p = phoneNumbers();
PhoneNumber::List::ConstIterator it2;
......@@ -1948,6 +1994,7 @@ QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
s << a.d->mCategories;
s << a.customs();
s << a.d->mKeys;
s << a.d->mLangs;
return s;
}
......@@ -1988,7 +2035,7 @@ QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
s >> customFields;
a.setCustoms( customFields );
s >> a.d->mKeys;
s >> a.d->mLangs;
a.d->mEmpty = false;
return s;
......
......@@ -36,6 +36,7 @@
#include "kabc/secrecy.h"
#include "kabc/sound.h"
#include "kabc/email.h"
#include "kabc/lang.h"
#include "kabc/timezone.h"
#include "kabc/addresseelist.h" // for typedef QList<Addressee> List;
......@@ -982,6 +983,9 @@ class KABC_EXPORT Addressee
KABC::Email::List emailList() const;
void removeLang(const QString &language);
void insertLang(const Lang &language);
Lang::List langs() const;
private:
class Private;
QSharedDataPointer<Private> d;
......
......@@ -23,6 +23,7 @@
#include "picture.h"
#include "secrecy.h"
#include "sound.h"
#include "lang.h"
#include <QtCore/QString>
#include <QtCore/QBuffer>
......@@ -181,6 +182,21 @@ QByteArray VCardTool::createVCards( const Addressee::List &list,
card.addLine( createSecrecy( ( *addrIt ).secrecy() ) );
}
// LANG only for version == 4.0
if ( version == VCard::v4_0 ) {
const Lang::List langList = ( *addrIt ).langs();
Lang::List::ConstIterator langIt;
Lang::List::ConstIterator langEnd( langList.end() );
for ( langIt = langList.begin(); langIt != langEnd; ++langIt ) {
VCardLine line( QLatin1String( "LANG" ), (*langIt).language() );
QMapIterator<QString, QStringList> i((*langIt).parameters());
while (i.hasNext()) {
i.next();
line.addParameter( i.key(), i.value().join(QLatin1String(",")) );
}
card.addLine( line );
}
}
// EMAIL
const Email::List emailList = ( *addrIt ).emailList();
Email::List::ConstIterator emailIt;
......@@ -551,6 +567,13 @@ Addressee::List VCardTool::parseVCards( const QByteArray &vcard ) const
addr.insertEmail( ( *lineIt ).value().toString(),
types.contains( QLatin1String( "PREF" ) ), (*lineIt).parameterMap() );
}
// EMAIL
else if ( identifier == QLatin1String( "lang" ) ) {
Lang lang;
lang.setLanguage(( *lineIt ).value().toString());
lang.setParameters((*lineIt).parameterMap());
addr.insertLang(lang);
}
// FN
else if ( identifier == QLatin1String( "fn" ) ) {
......
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