diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-02-18 14:35:48 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-02-18 14:35:48 +0000 |
| commit | c5a44ae2523a298737d3ba8be0b32318a03d7260 (patch) | |
| tree | e6be40f0a9d053a1edd3f859574897cf191f84e5 /source | |
| parent | 87b7c17bb63e55109e3c0b67dd5dd97803562897 (diff) | |
| download | qxmpp-c5a44ae2523a298737d3ba8be0b32318a03d7260.tar.gz | |
add support for XEP-0085 : Chat State Notifications
Diffstat (limited to 'source')
| -rw-r--r-- | source/QXmppConstants.cpp | 1 | ||||
| -rw-r--r-- | source/QXmppConstants.h | 1 | ||||
| -rw-r--r-- | source/QXmppMessage.cpp | 41 | ||||
| -rw-r--r-- | source/QXmppMessage.h | 16 |
4 files changed, 58 insertions, 1 deletions
diff --git a/source/QXmppConstants.cpp b/source/QXmppConstants.cpp index 02855c74..f461ff93 100644 --- a/source/QXmppConstants.cpp +++ b/source/QXmppConstants.cpp @@ -46,3 +46,4 @@ const char *ns_muc = "http://jabber.org/protocol/muc"; const char *ns_muc_admin = "http://jabber.org/protocol/muc#admin"; const char *ns_muc_owner = "http://jabber.org/protocol/muc#owner"; const char *ns_muc_user = "http://jabber.org/protocol/muc#user"; +const char *ns_chat_states = "http://jabber.org/protocol/chatstates"; diff --git a/source/QXmppConstants.h b/source/QXmppConstants.h index 1bcf9f46..fc97e342 100644 --- a/source/QXmppConstants.h +++ b/source/QXmppConstants.h @@ -47,5 +47,6 @@ extern const char *ns_muc; extern const char *ns_muc_admin; extern const char *ns_muc_owner; extern const char *ns_muc_user; +extern const char *ns_chat_states; #endif // QXMPPCONSTANTS_H diff --git a/source/QXmppMessage.cpp b/source/QXmppMessage.cpp index cd8c905c..78fc75d4 100644 --- a/source/QXmppMessage.cpp +++ b/source/QXmppMessage.cpp @@ -22,14 +22,24 @@ */ +#include "QXmppConstants.h" #include "QXmppMessage.h" #include "QXmppUtils.h" #include <QDomElement> #include <QXmlStreamWriter> +static const char* chat_states[] = { + "", + "active", + "inactive", + "gone", + "composing", + "paused", +}; + QXmppMessage::QXmppMessage(const QString& from, const QString& to, const QString& body, const QString& thread) - : QXmppStanza(from, to), m_type(Chat), m_body(body), m_thread(thread) + : QXmppStanza(from, to), m_type(Chat), m_state(None), m_body(body), m_thread(thread) { } @@ -109,6 +119,16 @@ void QXmppMessage::setTypeFromStr(const QString& str) } } +QXmppMessage::State QXmppMessage::getState() const +{ + return m_state; +} + +void QXmppMessage::setState(QXmppMessage::State state) +{ + m_state = state; +} + void QXmppMessage::parse(QDomElement &element) { setFrom(element.attribute("from")); @@ -128,6 +148,17 @@ void QXmppMessage::parse(QDomElement &element) setError(error); } + for (int i = Active; i <= Paused; i++) + { + QDomElement stateElement = element.firstChildElement(chat_states[i]); + if (!stateElement.isNull() && + stateElement.namespaceURI() == ns_chat_states) + { + m_state = static_cast<QXmppMessage::State>(i); + break; + } + } + QDomElement xElement = element.firstChildElement("x"); if(!xElement.isNull()) setExtension(QXmppElement(xElement)); @@ -148,6 +179,14 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const if (!getThread().isEmpty()) helperToXmlAddTextElement(xmlWriter,"thread", getThread()); getError().toXml(xmlWriter); + + if (m_state > None && m_state <= Paused) + { + xmlWriter->writeStartElement(chat_states[m_state]); + helperToXmlAddAttribute(xmlWriter, "xmlns", ns_chat_states); + xmlWriter->writeEndElement(); + } + getExtension().toXml(xmlWriter); xmlWriter->writeEndElement(); } diff --git a/source/QXmppMessage.h b/source/QXmppMessage.h index e985706c..2590e088 100644 --- a/source/QXmppMessage.h +++ b/source/QXmppMessage.h @@ -39,6 +39,18 @@ public: Headline }; + // XEP-0085 : Chat State Notifications + // http://xmpp.org/extensions/xep-0085.html + enum State + { + None = 0, + Active, + Inactive, + Gone, + Composing, + Paused, + }; + QXmppMessage(const QString& from = "", const QString& to = "", const QString& body = "", const QString& thread = ""); ~QXmppMessage(); @@ -48,6 +60,9 @@ public: void setType(QXmppMessage::Type); void setTypeFromStr(const QString&); + QXmppMessage::State getState() const; + void setState(QXmppMessage::State); + QString getBody() const; void setBody(const QString&); QString getSubject() const; @@ -60,6 +75,7 @@ public: private: Type m_type; + State m_state; QString m_body; QString m_subject; |
