aboutsummaryrefslogtreecommitdiff
path: root/source/QXmppVCard.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-03-10 08:14:25 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-03-10 08:14:25 +0000
commit519d53a7e8ce3057a3cacc4b5dd6737efb17f5d0 (patch)
tree06d757d2d2059630172cea34fbbede956060765e /source/QXmppVCard.cpp
parentf6c2c215ab8bb438b01d44a99feaf3c0aaf1e9b7 (diff)
downloadqxmpp-519d53a7e8ce3057a3cacc4b5dd6737efb17f5d0.tar.gz
add support for first/middle/last name in vCards
Diffstat (limited to 'source/QXmppVCard.cpp')
-rw-r--r--source/QXmppVCard.cpp63
1 files changed, 55 insertions, 8 deletions
diff --git a/source/QXmppVCard.cpp b/source/QXmppVCard.cpp
index de865f5b..4385166f 100644
--- a/source/QXmppVCard.cpp
+++ b/source/QXmppVCard.cpp
@@ -36,6 +36,16 @@ QXmppVCard::QXmppVCard(const QString& jid) : QXmppIq(QXmppIq::Get)
setTo(jid);
}
+QString QXmppVCard::firstName() const
+{
+ return m_firstName;
+}
+
+void QXmppVCard::setFirstName(const QString &firstName)
+{
+ m_firstName = firstName;
+}
+
QString QXmppVCard::fullName() const
{
return m_fullName;
@@ -46,6 +56,26 @@ void QXmppVCard::setFullName(const QString& str)
m_fullName = str;
}
+QString QXmppVCard::lastName() const
+{
+ return m_lastName;
+}
+
+void QXmppVCard::setLastName(const QString &lastName)
+{
+ m_lastName = lastName;
+}
+
+QString QXmppVCard::middleName() const
+{
+ return m_middleName;
+}
+
+void QXmppVCard::setMiddleName(const QString &middleName)
+{
+ m_middleName = middleName;
+}
+
QString QXmppVCard::nickName() const
{
return m_nickName;
@@ -82,11 +112,14 @@ void QXmppVCard::parse(const QDomElement& nodeRecv)
setTypeFromStr(nodeRecv.attribute("type"));
// vCard
- setFullName(nodeRecv.firstChildElement("vCard").
- firstChildElement("FN").text());
- setNickName(nodeRecv.firstChildElement("vCard").
- firstChildElement("NICKNAME").text());
- QByteArray base64data = nodeRecv.firstChildElement("vCard").
+ QDomElement cardElement = nodeRecv.firstChildElement("vCard");
+ m_fullName = cardElement.firstChildElement("FN").text();
+ m_nickName = cardElement.firstChildElement("NICKNAME").text();
+ QDomElement nameElement = cardElement.firstChildElement("N");
+ m_firstName = nameElement.firstChildElement("GIVEN").text();
+ m_lastName = nameElement.firstChildElement("FAMILY").text();
+ m_middleName = nameElement.firstChildElement("MIDDLE").text();
+ QByteArray base64data = cardElement.
firstChildElement("PHOTO").
firstChildElement("BINVAL").text().toAscii();
setPhoto(QByteArray::fromBase64(base64data));
@@ -96,9 +129,23 @@ void QXmppVCard::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
writer->writeStartElement("vCard");
helperToXmlAddAttribute(writer,"xmlns", ns_vcard);
- helperToXmlAddTextElement(writer, "FN", fullName());
- if(!nickName().isEmpty())
- helperToXmlAddTextElement(writer, "NICKNAME", nickName());
+ if (!m_fullName.isEmpty())
+ helperToXmlAddTextElement(writer, "FN", m_fullName);
+ if(!m_nickName.isEmpty())
+ helperToXmlAddTextElement(writer, "NICKNAME", m_nickName);
+ if (!m_firstName.isEmpty() ||
+ !m_lastName.isEmpty() ||
+ !m_middleName.isEmpty())
+ {
+ writer->writeStartElement("N");
+ if (!m_firstName.isEmpty())
+ helperToXmlAddTextElement(writer, "GIVEN", m_firstName);
+ if (!m_lastName.isEmpty())
+ helperToXmlAddTextElement(writer, "FAMILY", m_lastName);
+ if (!m_middleName.isEmpty())
+ helperToXmlAddTextElement(writer, "MIDDLE", m_middleName);
+ writer->writeEndElement();
+ }
if(!photo().isEmpty())
{