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

Fix gender support

parent 9f43dd19
......@@ -35,11 +35,11 @@ public:
Private( const Private &other )
: QSharedData( other )
{
parameters = other.parameters;
comment = other.comment;
gender = other.gender;
}
QMap<QString, QStringList> parameters;
QString gender;
QString comment;
};
Gender::Gender()
......@@ -64,14 +64,9 @@ Gender::~Gender()
}
QMap<QString, QStringList> Gender::parameters() const
{
return d->parameters;
}
bool Gender::operator==(const Gender &other) const
{
return (d->parameters == other.parameters()) && (d->gender == other.gender());
return (d->comment == other.comment()) && (d->gender == other.gender());
}
bool Gender::operator!=(const Gender &other) const
......@@ -93,24 +88,11 @@ QString Gender::toString() const
QString str;
str += QString::fromLatin1( "Gender {\n" );
str += QString::fromLatin1( " gender: %1\n" ).arg( d->gender );
if (!d->parameters.isEmpty()) {
QMapIterator<QString, QStringList> i(d->parameters);
QString param;
while (i.hasNext()) {
i.next();
param += QString::fromLatin1("%1 %2").arg(i.key()).arg(i.value().join(QLatin1String(",")));
}
str += QString::fromLatin1( " parameters: %1\n" ).arg( param );
}
str += QString::fromLatin1( " comment: %1\n" ).arg( d->comment );
str += QString::fromLatin1( "}\n" );
return str;
}
void Gender::setParameters(const QMap<QString, QStringList> &params)
{
d->parameters = params;
}
void Gender::setGender(const QString &gender)
{
d->gender = gender;
......@@ -121,19 +103,29 @@ QString Gender::gender() const
return d->gender;
}
void Gender::setComment(const QString &comment)
{
d->comment = comment;
}
QString Gender::comment() const
{
return d->comment;
}
bool Gender::isValid() const
{
return !d->gender.isEmpty();
return !d->gender.isEmpty() || !d->comment.isEmpty();
}
QDataStream &KABC::operator<<(QDataStream &s, const Gender &gender)
{
return s << gender.d->parameters << gender.d->gender;
return s << gender.d->comment << gender.d->gender;
}
QDataStream &KABC::operator>>(QDataStream &s, Gender &gender)
{
s >> gender.d->parameters >> gender.d->gender;
s >> gender.d->comment >> gender.d->gender;
return s;
}
......@@ -50,10 +50,10 @@ public:
void setGender(const QString &gender);
QString gender() const;
bool isValid() const;
void setComment(const QString &comment);
QString comment() const;
void setParameters(const QMap<QString, QStringList> &params);
QMap<QString, QStringList> parameters() const;
bool isValid() const;
bool operator==( const Gender &other ) const;
bool operator!=( const Gender &other ) const;
......
......@@ -38,22 +38,20 @@ void GenderTest::shouldHaveDefaultValue()
KABC::Gender gender;
QVERIFY(!gender.isValid());
QVERIFY(gender.gender().isEmpty());
QVERIFY(gender.parameters().isEmpty());
QVERIFY(gender.comment().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);
const QString commentStr(QLatin1String("foo"));
gender.setComment(commentStr);
QVERIFY(gender.isValid());
QVERIFY(!gender.gender().isEmpty());
QCOMPARE(gender.gender(), genderStr);
QVERIFY(!gender.parameters().isEmpty());
QCOMPARE(gender.parameters(), params);
QVERIFY(!gender.comment().isEmpty());
QCOMPARE(gender.comment(), commentStr);
}
void GenderTest::shouldAssignExternal()
......@@ -72,10 +70,7 @@ void GenderTest::shouldSerialized()
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);
gender.setComment(QLatin1String("foo"));
QByteArray data;
......@@ -94,10 +89,7 @@ void GenderTest::shouldEqualGender()
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);
gender.setComment(QLatin1String("foo"));
result = gender;
QVERIFY( gender == result );
......
......@@ -472,15 +472,17 @@ QByteArray VCardTool::createVCards( const Addressee::List &list,
}
if (version == VCard::v4_0) {
// GENDER
// 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(",")) );
QString genderStr;
if (!gender.gender().isEmpty()) {
genderStr = gender.gender();
}
if (!gender.comment().isEmpty()) {
genderStr += QLatin1Char(';') + gender.comment();
}
VCardLine line( QLatin1String( "GENDER" ), genderStr );
card.addLine( line );
}
}
......@@ -602,10 +604,18 @@ Addressee::List VCardTool::parseVCards( const QByteArray &vcard ) const
}
// GENDER
else if ( identifier == QLatin1String( "gender" ) ) {
Gender gender;
gender.setGender(( *lineIt ).value().toString());
gender.setParameters((*lineIt).parameterMap());
addr.setGender(gender);
QString genderStr = ( *lineIt ).value().toString();
if (!genderStr.isEmpty()) {
Gender gender;
if (genderStr.at(0) != QLatin1Char(';')) {
gender.setGender(genderStr.at(0));
//TODO add comment
} else {
}
//TODO comment
addr.setGender(gender);
}
}
// 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