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

Add Gender support (need by vcard4.0)

parent 6d434366
#include "../../kabc/gender.h"
......@@ -50,6 +50,7 @@ set(kabc_LIB_SRCS
email.cpp
field.cpp
geo.cpp
gender.cpp
key.cpp
ldapdn.cpp
ldif.cpp
......
/*
This file is part of libkabc.
Copyright (c) 2015 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "gender.h"
#include <QMap>
#include <qstringlist.h>
using namespace KABC;
class Gender::Private : public QSharedData
{
public:
Private()
{
}
Private( const Private &other )
: QSharedData( other )
{
parameters = other.parameters;
gender = other.gender;
}
QMap<QString, QStringList> parameters;
QString gender;
};
Gender::Gender()
: d( new Private )
{
}
Gender::Gender(const QString &gender)
: d( new Private )
{
d->gender = gender;
}
Gender::Gender( const Gender &other )
: d( other.d )
{
}
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());
}
bool Gender::operator!=(const Gender &other) const
{
return !( other == *this );
}
Gender &Gender::operator=(const Gender &other)
{
if ( this != &other ) {
d = other.d;
}
return *this;
}
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( "}\n" );
return str;
}
void Gender::setParameters(const QMap<QString, QStringList> &params)
{
d->parameters = params;
}
void Gender::setGender(const QString &gender)
{
d->gender = gender;
}
QString Gender::gender() const
{
return d->gender;
}
bool Gender::isValid() const
{
return !d->gender.isEmpty();
}
QDataStream &KABC::operator<<(QDataStream &s, const Gender &gender)
{
return s << gender.d->parameters << gender.d->gender;
}
QDataStream &KABC::operator>>(QDataStream &s, Gender &gender)
{
s >> gender.d->parameters >> gender.d->gender;
return s;
}
/*
This file is part of libkabc.
Copyright (c) 2015 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef GENDER_H
#define GENDER_H
#include "kabc_export.h"
#include <QtCore/QSharedDataPointer>
#include <QtCore/QString>
#include <QtCore/QMap>
/** @short Class that holds a Gender for a contact.
* @since 4.14.5
*/
namespace KABC {
class KABC_EXPORT Gender
{
friend KABC_EXPORT QDataStream &operator<<( QDataStream &, const Gender & );
friend KABC_EXPORT QDataStream &operator>>( QDataStream &, Gender & );
public:
/**
* Creates an empty Gender object.
*/
Gender();
Gender(const Gender &other);
Gender(const QString &gender);
~Gender();
void setGender(const QString &gender);
QString gender() const;
bool isValid() const;
void setParameters(const QMap<QString, QStringList> &params);
QMap<QString, QStringList> parameters() const;
bool operator==( const Gender &other ) const;
bool operator!=( const Gender &other ) const;
Gender &operator=( const Gender &other );
QString toString() const;
private:
class Private;
QSharedDataPointer<Private> d;
};
KABC_EXPORT QDataStream &operator<<( QDataStream &stream, const Gender &object );
KABC_EXPORT QDataStream &operator>>( QDataStream &stream, Gender &object );
}
#endif // GENDER_H
......@@ -206,3 +206,13 @@ kde4_add_unit_test(langtest TESTNAME kabc-langtest ${langtest_SRCS})
target_link_libraries(langtest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY})
########### next target ###############
set(gendertest_SRCS gendertest.cpp)
kde4_add_unit_test(gendertest TESTNAME kabc-gendertest ${gendertest_SRCS})
target_link_libraries(gendertest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY})
/*
This file is part of libkabc.
Copyright (c) 2015 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "gendertest.h"
#include <qtest_kde.h>
GenderTest::GenderTest(QObject *parent)
: QObject(parent)
{
}
GenderTest::~GenderTest()
{
}
QTEST_KDEMAIN(GenderTest, NoGUI)
/*
This file is part of libkabc.
Copyright (c) 2015 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef GENDERTEST_H
#define GENDERTEST_H
#include <QObject>
class GenderTest : public QObject
{
Q_OBJECT
public:
explicit GenderTest(QObject *parent = 0);
~GenderTest();
};
#endif // GENDERTEST_H
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