/* * Copyright (C) 2008-2019 The QXmpp developers * * Author: * Jeremy Lainé * * Source: * https://github.com/qxmpp-project/qxmpp * * This file is a part of QXmpp library. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * */ #include #include "QXmppConstants_p.h" #include "QXmppRegisterIq.h" class QXmppRegisterIqPrivate : public QSharedData { public: QXmppDataForm form; QString email; QString instructions; QString password; QString username; }; QXmppRegisterIq::QXmppRegisterIq() : d(new QXmppRegisterIqPrivate) { } QXmppRegisterIq::QXmppRegisterIq(const QXmppRegisterIq &other) = default; QXmppRegisterIq::~QXmppRegisterIq() = default; QXmppRegisterIq &QXmppRegisterIq::operator=(const QXmppRegisterIq& other) = default; /// Returns the email for this registration IQ. QString QXmppRegisterIq::email() const { return d->email; } /// Sets the \a email for this registration IQ. void QXmppRegisterIq::setEmail(const QString &email) { d->email = email; } /// Returns the QXmppDataForm for this registration IQ. QXmppDataForm QXmppRegisterIq::form() const { return d->form; } /// Sets the QXmppDataForm for this registration IQ. /// /// \param form void QXmppRegisterIq::setForm(const QXmppDataForm &form) { d->form = form; } /// Returns the instructions for this registration IQ. QString QXmppRegisterIq::instructions() const { return d->instructions; } /// Sets the \a instructions for this registration IQ. void QXmppRegisterIq::setInstructions(const QString &instructions) { d->instructions = instructions; } /// Returns the password for this registration IQ. QString QXmppRegisterIq::password() const { return d->password; } /// Sets the \a password for this registration IQ. void QXmppRegisterIq::setPassword(const QString &password) { d->password = password; } /// Returns the username for this registration IQ. QString QXmppRegisterIq::username() const { return d->username; } /// Sets the \a username for this registration IQ. void QXmppRegisterIq::setUsername(const QString &username) { d->username = username; } /// \cond bool QXmppRegisterIq::isRegisterIq(const QDomElement &element) { return (element.firstChildElement("query").namespaceURI() == ns_register); } void QXmppRegisterIq::parseElementFromChild(const QDomElement &element) { QDomElement queryElement = element.firstChildElement("query"); d->instructions = queryElement.firstChildElement("instructions").text(); d->username = queryElement.firstChildElement("username").text(); d->password = queryElement.firstChildElement("password").text(); d->email = queryElement.firstChildElement("email").text(); d->form.parse(queryElement.firstChildElement("x")); } void QXmppRegisterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const { writer->writeStartElement("query"); writer->writeAttribute("xmlns", ns_register); if (!d->instructions.isEmpty()) writer->writeTextElement("instructions", d->instructions); if (!d->username.isEmpty()) writer->writeTextElement("username", d->username); else if (!d->username.isNull()) writer->writeEmptyElement("username"); if (!d->password.isEmpty()) writer->writeTextElement("password", d->password); else if (!d->password.isNull()) writer->writeEmptyElement("password"); if (!d->email.isEmpty()) writer->writeTextElement("email", d->email); else if (!d->email.isNull()) writer->writeEmptyElement("email"); d->form.toXml(writer); writer->writeEndElement(); } /// \endcond