QXmppExportData Class

The QXmppExportData class contains the data of an account that is exported or imported by the QXmppAccountMigrationManager. More...

Header: #include <QXmppAccountMigrationManager.h>
Since: QXmpp 1.8

Public Types

ExtensionParser
ExtensionSerializer
(since QXmpp 1.17) enum class Format { QXmpp, Xep0227 }
Result

Public Functions

QXmppExportData()
const QString &accountJid() const
std::optional<T> extension() const
void setAccountJid(const QString &jid)
void setExtension(T &&value)
(since QXmpp 1.17) void toXml(QXmlStreamWriter *writer, QXmppExportData::Format format) const

Static Public Members

std::variant<QXmppExportData, QXmppError> fromDom(const QDomElement &el)
bool isExtensionRegistered()
void registerExtension(QStringView tagName, QStringView xmlns)
(since QXmpp 1.17) void registerExtension(QXmppExportData::Format format, QStringView tagName, QStringView xmlns)

Detailed Description

The data consists of the JID of the account and a set of extensions. Each extension is an arbitrary data type that has been registered with registerExtension(), so it can be serialized to and parsed from XML. QXmppAccountMigrationManager::exportData() fills the extensions with the data of all registered export data types and QXmppAccountMigrationManager::importData() imports them to the connected account.

The data can be serialized with toXml() and parsed with fromDom(), either in QXmpp's own format or as XEP-0227: Portable Import/Export Format for XMPP-IM Servers.

Member Type Documentation

[alias] template <typename T> QXmppExportData::ExtensionParser

Function that parses an extension of type T from a QDomElement.

[alias] template <typename T> QXmppExportData::ExtensionSerializer

Function that serializes an extension of type T to a QXmlStreamWriter.

[since QXmpp 1.17] enum class QXmppExportData::Format

Output format used when serializing account data.

ConstantValueDescription
QXmppExportData::Format::QXmpp0QXmpp's own format, rooted at <account-data/> (org.qxmpp.export).
QXmppExportData::Format::Xep02271XEP-0227: Portable Import/Export Format for XMPP-IM Servers

, rooted at <server-data/> (urn:xmpp:pie:0).

This enum was introduced in QXmpp 1.17.

[alias] template <typename T = QXmpp::Success> QXmppExportData::Result

Contains T or QXmppError.

Member Function Documentation

QXmppExportData::QXmppExportData()

Constructs empty export data.

const QString &QXmppExportData::accountJid() const

Returns the bare JID of the exported account.

See also setAccountJid().

template <typename T> std::optional<T> QXmppExportData::extension() const

Returns the extension of type T, or std::nullopt if the data does not contain one.

See also setExtension().

[static] std::variant<QXmppExportData, QXmppError> QXmppExportData::fromDom(const QDomElement &el)

Parses account data from el.

Both the QXmpp format (<account-data/>) and XEP-0227: Portable Import/Export Format for XMPP-IM Servers (<server-data/>) are accepted; the format is detected from the root element. When an XEP-0227 document carries the same data both as a native element and as an embedded QXmpp fallback, the native XEP-0227 element is preferred.

Note: XEP-0227 documents may contain multiple hosts and users, but as this is used for single-account client-side migration only the first host and user are read.

[static] template <typename T> bool QXmppExportData::isExtensionRegistered()

Returns whether the extension type T has been registered for any format.

[static] template < typename T, QXmppExportData::ExtensionParser<T> parse, QXmppExportData::ExtensionSerializer<T> serialize > void QXmppExportData::registerExtension(QStringView tagName, QStringView xmlns)

Registers the extension type T for the QXmpp format.

The extension is serialized as an XML element with the name tagName and the namespace xmlns using the functions parse and serialize.

This is equivalent to calling registerExtension(Format, QStringView, QStringView) with Format::QXmpp.

[static, since QXmpp 1.17] template < typename T, QXmppExportData::ExtensionParser<T> parse, QXmppExportData::ExtensionSerializer<T> serialize > void QXmppExportData::registerExtension(QXmppExportData::Format format, QStringView tagName, QStringView xmlns)

Registers the extension type T for format.

The extension is serialized as an XML element with the name tagName and the namespace xmlns using the functions parse and serialize.

A type may be registered for both formats. When serializing to Format::Xep0227, types that are only registered for Format::QXmpp are embedded as a QXmpp specific fallback.

This function was introduced in QXmpp 1.17.

void QXmppExportData::setAccountJid(const QString &jid)

Sets the bare JID of the exported account to jid.

See also accountJid().

template <typename T> void QXmppExportData::setExtension(T &&value)

Sets the extension of type T to value.

The type T must have been registered with registerExtension() before.

See also extension().

[since QXmpp 1.17] void QXmppExportData::toXml(QXmlStreamWriter *writer, QXmppExportData::Format format) const

Serializes the account data to writer using format.

Pass Format::QXmpp to write QXmpp's own format (<account-data/>), or Format::Xep0227 to write XEP-0227: Portable Import/Export Format for XMPP-IM Servers; in the latter case data types without a native XEP-0227 representation (e.g. MIX) are embedded as a QXmpp-specific fallback so no data is lost, and standard servers ignore those elements.

This function was introduced in QXmpp 1.17.