diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-08-03 16:00:00 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-08-03 16:00:00 +0200 |
| commit | 1268a64bdd1320639cad0d9c8331fb6fd682b30c (patch) | |
| tree | cdac8502f77722401370cc3987a38dd6a8afd21b /src/base/QXmppVCardIq.cpp | |
| parent | becafc386f14967df87659cd408b5cee5835227d (diff) | |
| download | qxmpp-1268a64bdd1320639cad0d9c8331fb6fd682b30c.tar.gz | |
add stub for addresses
Diffstat (limited to 'src/base/QXmppVCardIq.cpp')
| -rw-r--r-- | src/base/QXmppVCardIq.cpp | 100 |
1 files changed, 97 insertions, 3 deletions
diff --git a/src/base/QXmppVCardIq.cpp b/src/base/QXmppVCardIq.cpp index a961c63d..9dcd19c8 100644 --- a/src/base/QXmppVCardIq.cpp +++ b/src/base/QXmppVCardIq.cpp @@ -48,6 +48,79 @@ static QString getImageType(const QByteArray &contents) return "image/unknown"; } +class QXmppVCardAddressPrivate : public QSharedData +{ +public: + QXmppVCardAddressPrivate() : type(QXmppVCardAddress::None) {}; + QXmppVCardAddress::Type type; +}; + +/// Constructs an empty address. + +QXmppVCardAddress::QXmppVCardAddress() + : d(new QXmppVCardAddressPrivate) +{ +} + +/// Constructs a copy of \a other. + +QXmppVCardAddress::QXmppVCardAddress(const QXmppVCardAddress &other) + : d(other.d) +{ +} + +QXmppVCardAddress::~QXmppVCardAddress() +{ +} + +/// Assigns \a other to this address. + +QXmppVCardAddress& QXmppVCardAddress::operator=(const QXmppVCardAddress &other) +{ + d = other.d; + return *this; +} + +/// Returns the address type, which is a combination of TypeFlag. + +QXmppVCardAddress::Type QXmppVCardAddress::type() const +{ + return d->type; +} + +/// Sets the address \a type, which is a combination of TypeFlag. + +void QXmppVCardAddress::setType(QXmppVCardAddress::Type type) +{ + d->type = type; +} + +void QXmppVCardAddress::parse(const QDomElement &element) +{ + if (!element.firstChildElement("HOME").isNull()) + d->type |= Home; + if (!element.firstChildElement("WORK").isNull()) + d->type |= Work; + if (!element.firstChildElement("POSTAL").isNull()) + d->type |= Postal; + if (!element.firstChildElement("PREF").isNull()) + d->type |= Preferred; +} + +void QXmppVCardAddress::toXml(QXmlStreamWriter *writer) const +{ + writer->writeStartElement("ADR"); + if (d->type & Home) + writer->writeEmptyElement("HOME"); + if (d->type & Work) + writer->writeEmptyElement("WORK"); + if (d->type & Postal) + writer->writeEmptyElement("POSTAL"); + if (d->type & Preferred) + writer->writeEmptyElement("PREF"); + writer->writeEndElement(); +} + class QXmppVCardEmailPrivate : public QSharedData { public: @@ -190,14 +263,14 @@ void QXmppVCardPhone::setNumber(const QString &number) d->number = number; } -/// Returns the e-mail type, which is a combination of TypeFlag. +/// Returns the phone number type, which is a combination of TypeFlag. QXmppVCardPhone::Type QXmppVCardPhone::type() const { return d->type; } -/// Sets the e-mail \a type, which is a combination of TypeFlag. +/// Sets the phone number \a type, which is a combination of TypeFlag. void QXmppVCardPhone::setType(QXmppVCardPhone::Type type) { @@ -283,6 +356,7 @@ public: QByteArray photo; QString photoType; + QList<QXmppVCardAddress> addresses; QList<QXmppVCardEmail> emails; QList<QXmppVCardPhone> phones; }; @@ -503,6 +577,20 @@ void QXmppVCardIq::setPhotoType(const QString& photoType) d->photoType = photoType; } +/// Returns the addresses. + +QList<QXmppVCardAddress> QXmppVCardIq::addresses() const +{ + return d->addresses; +} + +/// Sets the addresses. + +void QXmppVCardIq::setAddresses(const QList<QXmppVCardAddress> &addresses) +{ + d->addresses = addresses; +} + /// Returns the e-mail addresses. QList<QXmppVCardEmail> QXmppVCardIq::emails() const @@ -556,7 +644,11 @@ void QXmppVCardIq::parseElementFromChild(const QDomElement& nodeRecv) QDomElement child = cardElement.firstChildElement(); while (!child.isNull()) { - if (child.tagName() == "EMAIL") { + if (child.tagName() == "ADR") { + QXmppVCardAddress address; + address.parse(child); + d->addresses << address; + } else if (child.tagName() == "EMAIL") { QXmppVCardEmail email; email.parse(child); d->emails << email; @@ -573,6 +665,8 @@ void QXmppVCardIq::toXmlElementFromChild(QXmlStreamWriter *writer) const { writer->writeStartElement("vCard"); writer->writeAttribute("xmlns", ns_vcard); + foreach (const QXmppVCardAddress &address, d->addresses) + address.toXml(writer); if (d->birthday.isValid()) helperToXmlAddTextElement(writer, "BDAY", d->birthday.toString("yyyy-MM-dd")); foreach (const QXmppVCardEmail &email, d->emails) |
