|
static bool | isItem (const QDomElement &element) |
|
|
template<typename PayloadChecker > |
static bool | isItem (const QDomElement &element, PayloadChecker isPayloadValid) |
|
The QXmppPubSubBaseItem class represents a publish-subscribe item as defined by XEP-0060: Publish-Subscribe.
To access the payload of an item, you need to create a derived class of this and override QXmppPubSubBaseItem::parsePayload() and QXmppPubSubBaseItem::serializePayload().
It is also required that you override QXmppPubSubBaseItem::isItem() and also check for the correct payload of the PubSub item. This can be easily done by using the protected overload of isItem() with an function that checks the tag name and namespace of the payload. The function is only called if a payload exists.
In short, you need to reimplement these methods:
- Since
- QXmpp 1.5
◆ QXmppPubSubBaseItem()
QXmppPubSubBaseItem::QXmppPubSubBaseItem |
( |
const QString & |
id = {} , |
|
|
const QString & |
publisher = {} |
|
) |
| |
Constructs an item with id and publisher.
- Parameters
-
◆ id()
QString QXmppPubSubBaseItem::id |
( |
| ) |
const |
Returns the ID of the PubSub item.
◆ isItem() [1/2]
bool QXmppPubSubBaseItem::isItem |
( |
const QDomElement & |
element | ) |
|
|
static |
Returns true, if the element is possibly a PubSub item.
◆ isItem() [2/2]
template<typename PayloadChecker >
bool QXmppPubSubBaseItem::isItem |
( |
const QDomElement & |
element, |
|
|
PayloadChecker |
isPayloadValid |
|
) |
| |
|
staticprotected |
Returns true, if the element is a valid PubSub item and (if existant) the payload is correct.
- Parameters
-
element | The element to be checked to be an <item/> element. |
isPayloadValid | A function that validates the payload element (first child element). The functions needs to return true, if the payload is valid. In case there is no payload, the function is not called. |
Here is an example covering how this could be used to check for the XEP-0118: User Tune payload:
auto isPayloadValid = [](const QDomElement &payload) -> bool {
return payload.tagName() == "tune" && payload.namespaceURI() == ns_tune;
};
bool valid = QXmppPubSubItem::isItem(itemElement, isPayloadValid);
◆ parsePayload()
void QXmppPubSubBaseItem::parsePayload |
( |
const QDomElement & |
payloadElement | ) |
|
|
protectedvirtual |
Parses the payload of the item (the child element of the <item/>).
This method needs to be overriden to perform the payload-specific parsing.
◆ publisher()
QString QXmppPubSubBaseItem::publisher |
( |
| ) |
const |
Returns the JID of the publisher of the item.
◆ serializePayload()
void QXmppPubSubBaseItem::serializePayload |
( |
QXmlStreamWriter * |
writer | ) |
const |
|
protectedvirtual |
Serializes the payload of the item (the child element of the <item/>).
This method needs to be overriden to perform the payload-specific serialization.
◆ setId()
void QXmppPubSubBaseItem::setId |
( |
const QString & |
id | ) |
|
Sets the ID of the PubSub item.
- Parameters
-
◆ setPublisher()
void QXmppPubSubBaseItem::setPublisher |
( |
const QString & |
publisher | ) |
|
Sets the JID of the publisher of the item.
The documentation for this class was generated from the following files: