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

Implement Gender support (vcard4.0)

parent feda600a
......@@ -127,6 +127,7 @@ install(FILES
geo.h
key.h
lang.h
gender.h
ldifconverter.h
lock.h
locknull.h
......
......@@ -97,6 +97,7 @@ class Addressee::Private : public QSharedData
mKeys = other.mKeys;
mEmails = other.mEmails;
mLangs = other.mLangs;
mGender = other.mGender;
mCategories = other.mCategories;
mCustomFields = other.mCustomFields;
......@@ -143,6 +144,7 @@ class Addressee::Private : public QSharedData
Key::List mKeys;
Email::List mEmails;
Lang::List mLangs;
KABC::Gender mGender;
QStringList mCategories;
QMap<QString, QString> mCustomFields;
......@@ -358,6 +360,10 @@ bool Addressee::operator==( const Addressee &addressee ) const
kDebug() << "langs differs";
return false;
}
if (d->mGender != addressee.d->mGender) {
kDebug() << "gender differs";
return false;
}
return true;
}
......@@ -1340,7 +1346,21 @@ void Addressee::insertLang( const Lang &language )
Lang::List Addressee::langs() const
{
return d->mLangs;
return d->mLangs;
}
void Addressee::setGender(const Gender &gender)
{
if ( gender == d->mGender )
return;
d->mEmpty = false;
d->mGender = gender;
}
Gender Addressee::gender() const
{
return d->mGender;
}
void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
......@@ -1540,6 +1560,7 @@ QString Addressee::toString() const
str += QString::fromLatin1( " Logo: %1\n" ).arg( logo().toString() );
str += QString::fromLatin1( " Photo: %1\n" ).arg( photo().toString() );
str += QString::fromLatin1( " Sound: %1\n" ).arg( sound().toString() );
str += QString::fromLatin1( " Gender: %1\n" ).arg( gender().toString() );
str += QLatin1String( " Emails {\n" );
const Email::List listEmail = d->mEmails;
......@@ -1995,6 +2016,7 @@ QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
s << a.customs();
s << a.d->mKeys;
s << a.d->mLangs;
s << a.d->mGender;
return s;
}
......@@ -2036,6 +2058,7 @@ QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
a.setCustoms( customFields );
s >> a.d->mKeys;
s >> a.d->mLangs;
s >> a.d->mGender;
a.d->mEmpty = false;
return s;
......
......@@ -37,6 +37,7 @@
#include "kabc/sound.h"
#include "kabc/email.h"
#include "kabc/lang.h"
#include "kabc/gender.h"
#include "kabc/timezone.h"
#include "kabc/addresseelist.h" // for typedef QList<Addressee> List;
......@@ -986,6 +987,10 @@ class KABC_EXPORT Addressee
void removeLang(const QString &language);
void insertLang(const Lang &language);
Lang::List langs() const;
void setGender(const KABC::Gender &gender);
KABC::Gender gender() const;
private:
class Private;
QSharedDataPointer<Private> d;
......
......@@ -19,6 +19,7 @@
*/
#include "gendertest.h"
#include "gender.h"
#include <qtest_kde.h>
GenderTest::GenderTest(QObject *parent)
......@@ -32,4 +33,74 @@ GenderTest::~GenderTest()
}
void GenderTest::shouldHaveDefaultValue()
{
KABC::Gender gender;
QVERIFY(!gender.isValid());
QVERIFY(gender.gender().isEmpty());
QVERIFY(gender.parameters().isEmpty());
}
void GenderTest::shouldAssignValue()
{
const QString genderStr(QLatin1String("F"));
QMap<QString, QStringList> params;
params.insert(QLatin1String("Foo1"), QStringList()<< QLatin1String("bla1") <<QLatin1String("blo1"));
params.insert(QLatin1String("Foo2"), QStringList()<< QLatin1String("bla2") <<QLatin1String("blo2"));
KABC::Gender gender(genderStr);
gender.setParameters(params);
QVERIFY(gender.isValid());
QVERIFY(!gender.gender().isEmpty());
QCOMPARE(gender.gender(), genderStr);
QVERIFY(!gender.parameters().isEmpty());
QCOMPARE(gender.parameters(), params);
}
void GenderTest::shouldAssignExternal()
{
KABC::Gender gender;
const QString genderStr(QLatin1String("H"));
gender.setGender(genderStr);
QVERIFY(gender.isValid());
QVERIFY(!gender.gender().isEmpty());
QCOMPARE(gender.gender(), genderStr);
}
void GenderTest::shouldSerialized()
{
KABC::Gender gender;
KABC::Gender result;
const QString genderStr(QLatin1String("H"));
gender.setGender(genderStr);
QMap<QString, QStringList> params;
params.insert(QLatin1String("Foo1"), QStringList()<< QLatin1String("bla1") <<QLatin1String("blo1"));
params.insert(QLatin1String("Foo2"), QStringList()<< QLatin1String("bla2") <<QLatin1String("blo2"));
gender.setParameters(params);
QByteArray data;
QDataStream s( &data, QIODevice::WriteOnly );
s << gender;
QDataStream t( &data, QIODevice::ReadOnly );
t >> result;
QVERIFY( gender == result );
}
void GenderTest::shouldEqualGender()
{
KABC::Gender gender;
KABC::Gender result;
const QString genderStr(QLatin1String("H"));
gender.setGender(genderStr);
QMap<QString, QStringList> params;
params.insert(QLatin1String("Foo1"), QStringList()<< QLatin1String("bla1") <<QLatin1String("blo1"));
params.insert(QLatin1String("Foo2"), QStringList()<< QLatin1String("bla2") <<QLatin1String("blo2"));
gender.setParameters(params);
result = gender;
QVERIFY( gender == result );
}
QTEST_KDEMAIN(GenderTest, NoGUI)
......@@ -29,6 +29,13 @@ class GenderTest : public QObject
public:
explicit GenderTest(QObject *parent = 0);
~GenderTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAssignValue();
void shouldAssignExternal();
void shouldSerialized();
void shouldEqualGender();
};
#endif // GENDERTEST_H
......@@ -24,6 +24,7 @@
#include "secrecy.h"
#include "sound.h"
#include "lang.h"
#include "gender.h"
#include <QtCore/QString>
#include <QtCore/QBuffer>
......@@ -470,6 +471,19 @@ QByteArray VCardTool::createVCards( const Addressee::List &list,
}
}
if (version == VCard::v4_0) {
// GENDER
const Gender gender = ( *addrIt ).gender();
if (gender.isValid()) {
VCardLine line( QLatin1String( "GENDER" ), gender.gender() );
QMapIterator<QString, QStringList> i(gender.parameters());
while (i.hasNext()) {
i.next();
line.addParameter( i.key(), i.value().join(QLatin1String(",")) );
}
card.addLine( line );
}
}
if (identifier.toLower() == QLatin1String( "x-kaddressbook-x-anniversary" ) && version == VCard::v4_0) {
// ANNIVERSARY
if (!value.isEmpty()) {
......@@ -586,6 +600,14 @@ Addressee::List VCardTool::parseVCards( const QByteArray &vcard ) const
addr.insertEmail( ( *lineIt ).value().toString(),
types.contains( QLatin1String( "PREF" ) ), (*lineIt).parameterMap() );
}
// GENDER
else if ( identifier == QLatin1String( "gender" ) ) {
Gender gender;
gender.setGender(( *lineIt ).value().toString());
gender.setParameters((*lineIt).parameterMap());
addr.setGender(gender);
}
// LANG
else if ( identifier == QLatin1String( "lang" ) ) {
Lang lang;
......
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