diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-08-03 14:15:58 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-08-03 14:15:58 +0200 |
| commit | 34a30caf544899975b489e7e037fca9afb504267 (patch) | |
| tree | d161b6eba6571324b4dce8618289cdf0678e4f17 /src/base | |
| parent | db39d34c691cf201830fe221ea72982071809247 (diff) | |
| download | qxmpp-34a30caf544899975b489e7e037fca9afb504267.tar.gz | |
add a QXmppVCardEmail class
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/QXmppVCardIq.cpp | 94 | ||||
| -rw-r--r-- | src/base/QXmppVCardIq.h | 39 |
2 files changed, 132 insertions, 1 deletions
diff --git a/src/base/QXmppVCardIq.cpp b/src/base/QXmppVCardIq.cpp index 0d8ab988..51e40d9b 100644 --- a/src/base/QXmppVCardIq.cpp +++ b/src/base/QXmppVCardIq.cpp @@ -48,6 +48,100 @@ static QString getImageType(const QByteArray &contents) return "image/unknown"; } +class QXmppVCardEmailPrivate : public QSharedData +{ +public: + QXmppVCardEmailPrivate() : type(QXmppVCardEmail::None) {}; + QString address; + QXmppVCardEmail::Type type; +}; + +/// Constructs an empty vCard e-mail address. + +QXmppVCardEmail::QXmppVCardEmail() + : d(new QXmppVCardEmailPrivate) +{ +} + +/// Constructs a copy of \a other. + +QXmppVCardEmail::QXmppVCardEmail(const QXmppVCardEmail &other) + : d(other.d) +{ +} + +QXmppVCardEmail::~QXmppVCardEmail() +{ +} + +/// Assigns \a other to this vCard e-mail address. + +QXmppVCardEmail& QXmppVCardEmail::operator=(const QXmppVCardEmail &other) +{ + d = other.d; + return *this; +} + +/// Returns the e-mail address. + +QString QXmppVCardEmail::address() const +{ + return d->address; +} + +/// Sets the e-mail \a address. + +void QXmppVCardEmail::setAddress(const QString &address) +{ + d->address = address; +} + +/// Returns the e-mail type, which is a combination of TypeFlag. + +QXmppVCardEmail::Type QXmppVCardEmail::type() const +{ + return d->type; +} + +/// Sets the e-mail \a type, which is a combination of TypeFlag. + +void QXmppVCardEmail::setType(QXmppVCardEmail::Type type) +{ + d->type = type; +} + +void QXmppVCardEmail::parse(const QDomElement &element) +{ + if (!element.firstChildElement("HOME").isNull()) + d->type |= Home; + if (!element.firstChildElement("WORK").isNull()) + d->type |= Work; + if (!element.firstChildElement("INTERNET").isNull()) + d->type |= Internet; + if (!element.firstChildElement("PREF").isNull()) + d->type |= Preferred; + if (!element.firstChildElement("X400").isNull()) + d->type |= X400; + d->address = element.firstChildElement("USERID").text(); +} + +void QXmppVCardEmail::toXml(QXmlStreamWriter *writer) const +{ + writer->writeStartElement("EMAIL"); + if (d->type & Home) + writer->writeEmptyElement("HOME"); + if (d->type & Work) + writer->writeEmptyElement("WORK"); + if (d->type & Internet) + writer->writeEmptyElement("INTERNET"); + if (d->type & Preferred) + writer->writeEmptyElement("PREF"); + if (d->type & X400) + writer->writeEmptyElement("X400"); + writer->writeTextElement("USERID", d->address); + writer->writeEndElement(); +} + /// Constructs a QXmppVCardIq for the specified recipient. /// /// \param jid diff --git a/src/base/QXmppVCardIq.h b/src/base/QXmppVCardIq.h index f70826c8..b75f01f3 100644 --- a/src/base/QXmppVCardIq.h +++ b/src/base/QXmppVCardIq.h @@ -30,7 +30,44 @@ #include <QMap> #include <QDomElement> -class QImage; +class QXmppVCardEmailPrivate; + +/// \brief Represents a vCard e-mail address. + +class QXMPP_EXPORT QXmppVCardEmail +{ +public: + /// \brief Describes e-mail address types. + enum TypeFlag { + None = 0x0, + Home = 0x1, + Work = 0x2, + Internet = 0x4, + Preferred = 0x8, + X400 = 0x10 + }; + Q_DECLARE_FLAGS(Type, TypeFlag); + + QXmppVCardEmail(); + QXmppVCardEmail(const QXmppVCardEmail &other); + ~QXmppVCardEmail(); + + QXmppVCardEmail& operator=(const QXmppVCardEmail &other); + + QString address() const; + void setAddress(const QString &address); + + Type type() const; + void setType(Type type); + + /// \cond + void parse(const QDomElement &element); + void toXml(QXmlStreamWriter *stream) const; + /// \endcond + +private: + QSharedDataPointer<QXmppVCardEmailPrivate> d; +}; /// \brief Represents the XMPP vCard. /// |
