diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-29 03:06:52 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-29 03:06:52 +0000 |
| commit | 179c3b8f309907d7178b16582389579d1da5d0cb (patch) | |
| tree | 752e8d0eda58236fc8a0c4ae8374677af3114e53 /src | |
| parent | 0be5a87d0dd2cadf1d5a84dcd3b272bf6ac6e67c (diff) | |
| download | qxmpp-179c3b8f309907d7178b16582389579d1da5d0cb.tar.gz | |
clean up and test vCard code
Diffstat (limited to 'src')
| -rw-r--r-- | src/QXmppVCard.cpp | 66 | ||||
| -rw-r--r-- | src/QXmppVCard.h | 18 |
2 files changed, 40 insertions, 44 deletions
diff --git a/src/QXmppVCard.cpp b/src/QXmppVCard.cpp index 77c9e2a4..0426d057 100644 --- a/src/QXmppVCard.cpp +++ b/src/QXmppVCard.cpp @@ -147,27 +147,33 @@ void QXmppVCard::setUrl(const QString& url) m_url = url; } -/// photo is not stored as base 64 -const QByteArray& QXmppVCard::photo() const +/// Returns the photo's binary contents. + +QByteArray QXmppVCard::photo() const { return m_photo; } +/// Sets the photo's binary contents. + void QXmppVCard::setPhoto(const QByteArray& photo) { m_photo = photo; } -#ifndef QXMPP_NO_GUI -void QXmppVCard::setPhoto(const QImage& image) +/// Returns the photo's MIME type. + +QString QXmppVCard::photoType() const { - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - image.save(&buffer, "PNG"); - m_photo = ba; + return m_photoType; +} + +/// Sets the photo's MIME type. + +void QXmppVCard::setPhotoType(const QString& photoType) +{ + m_photoType = photoType; } -#endif bool QXmppVCard::isVCard(const QDomElement &nodeRecv) { @@ -188,10 +194,11 @@ void QXmppVCard::parseElementFromChild(const QDomElement& nodeRecv) m_lastName = nameElement.firstChildElement("FAMILY").text(); m_middleName = nameElement.firstChildElement("MIDDLE").text(); m_url = cardElement.firstChildElement("URL").text(); - QByteArray base64data = cardElement. - firstChildElement("PHOTO"). + QDomElement photoElement = cardElement.firstChildElement("PHOTO"); + QByteArray base64data = photoElement. firstChildElement("BINVAL").text().toAscii(); - setPhoto(QByteArray::fromBase64(base64data)); + m_photo = QByteArray::fromBase64(base64data); + m_photoType = photoElement.firstChildElement("TYPE").text(); } void QXmppVCard::toXmlElementFromChild(QXmlStreamWriter *writer) const @@ -230,8 +237,11 @@ void QXmppVCard::toXmlElementFromChild(QXmlStreamWriter *writer) const if(!photo().isEmpty()) { writer->writeStartElement("PHOTO"); - helperToXmlAddTextElement(writer, "TYPE", getImageType(photo())); - helperToXmlAddTextElement(writer, "BINVAL", photo().toBase64()); + QString photoType = m_photoType; + if (photoType.isEmpty()) + photoType = getImageType(m_photo); + helperToXmlAddTextElement(writer, "TYPE", photoType); + helperToXmlAddTextElement(writer, "BINVAL", m_photo.toBase64()); writer->writeEndElement(); } @@ -247,27 +257,15 @@ QImage QXmppVCard::photoAsImage() const QImageReader imageReader(&buffer); return imageReader.read(); } -#endif -QString QXmppVCard::getFullName() const -{ - return m_fullName; -} - -QString QXmppVCard::getNickName() const -{ - return m_nickName; -} - -const QByteArray& QXmppVCard::getPhoto() const -{ - return m_photo; -} - -#ifndef QXMPP_NO_GUI -QImage QXmppVCard::getPhotoAsImage() const +void QXmppVCard::setPhoto(const QImage& image) { - return photoAsImage(); + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "PNG"); + m_photo = ba; + m_photoType = "image/png"; } #endif diff --git a/src/QXmppVCard.h b/src/QXmppVCard.h index 6c525ebf..133e027f 100644 --- a/src/QXmppVCard.h +++ b/src/QXmppVCard.h @@ -56,8 +56,11 @@ public: void setNickName(const QString&); void setUrl(const QString&); + QByteArray photo() const; void setPhoto(const QByteArray&); - void setPhoto(const QImage&); + + QString photoType() const; + void setPhotoType(const QString &type); QDate birthday() const; QString email() const; @@ -68,19 +71,13 @@ public: QString nickName() const; QString url() const; +#ifndef QXMPP_NO_GUI QImage photoAsImage() const; - const QByteArray& photo() const; + void setPhoto(const QImage&); +#endif static bool isVCard(const QDomElement &element); - // deprecated accessors, use the form without "get" instead - /// \cond - QString Q_DECL_DEPRECATED getFullName() const; - QString Q_DECL_DEPRECATED getNickName() const; - QImage Q_DECL_DEPRECATED getPhotoAsImage() const; - const QByteArray Q_DECL_DEPRECATED & getPhoto() const; - /// \endcond - protected: /// \cond void parseElementFromChild(const QDomElement&); @@ -99,6 +96,7 @@ private: // not as 64 base QByteArray m_photo; + QString m_photoType; }; #endif // QXMPPVCARD_H |
