Permalink
Browse files

mix iq: Use d-pointer to remain binary compatibility

  • Loading branch information...
lnjX authored and jlaine committed Jan 22, 2019
1 parent 95063b1 commit 9df7e7f24a2a6c313e7367d596601e07dbd2baeb
Showing with 53 additions and 33 deletions.
  1. +47 −28 src/base/QXmppMixIq.cpp
  2. +6 −5 src/base/QXmppMixIq.h
@@ -31,28 +31,47 @@ static const QStringList MIX_ACTION_TYPES = QStringList() << ""
<< "client-join" << "client-leave" << "join" << "leave"
<< "update-subscription" << "setnick" << "create" << "destroy";

class QXmppMixIqPrivate : QSharedData
{
public:
QString jid;
QString channelName;
QStringList nodes;
QString nick;
QXmppMixIq::Type actionType = QXmppMixIq::None;
};

QXmppMixIq::QXmppMixIq()
: d(new QXmppMixIqPrivate)
{
}

QXmppMixIq::~QXmppMixIq()
{
}

/// Returns the channel JID. It also contains a participant id for Join/
/// ClientJoin results.

QString QXmppMixIq::jid() const
{
return m_jid;
return d->jid;
}

/// Sets the channel JID. For results of Join/ClientJoin queries this also
/// needs to contain a participant id.

void QXmppMixIq::setJid(const QString& jid)
{
m_jid = jid;
d->jid = jid;
}

/// Returns the channel name (the name part of the channel JID). This may still
/// be empty, if a JID was set.

QString QXmppMixIq::channelName() const
{
return m_channelName;
return d->channelName;
}

/// Sets the channel name for creating/destroying specific channels. When you
@@ -61,50 +80,50 @@ QString QXmppMixIq::channelName() const

void QXmppMixIq::setChannelName(const QString& channelName)
{
m_channelName = channelName;
d->channelName = channelName;
}

/// Returns the list of nodes to subscribe to.

QStringList QXmppMixIq::nodes() const
{
return m_nodes;
return d->nodes;
}

/// Sets the nodes to subscribe to. Note that for UpdateSubscription queries
/// you only need to include the new subscriptions.

void QXmppMixIq::setNodes(const QStringList& nodes)
{
m_nodes = nodes;
d->nodes = nodes;
}

/// Returns the user's nickname in the channel.

QString QXmppMixIq::nick() const
{
return m_nick;
return d->nick;
}

/// Sets the nickname for the channel.

void QXmppMixIq::setNick(const QString& nick)
{
m_nick = nick;
d->nick = nick;
}

/// Returns the MIX channel action type.

QXmppMixIq::Type QXmppMixIq::actionType() const
{
return m_actionType;
return d->actionType;
}

/// Sets the channel action.

void QXmppMixIq::setActionType(QXmppMixIq::Type type)
{
m_actionType = type;
d->actionType = type;
}

/// \cond
@@ -119,27 +138,27 @@ void QXmppMixIq::parseElementFromChild(const QDomElement& element)
{
QDomElement child = element.firstChildElement();
// determine action type
m_actionType = (QXmppMixIq::Type) MIX_ACTION_TYPES.indexOf(child.tagName());
d->actionType = (QXmppMixIq::Type) MIX_ACTION_TYPES.indexOf(child.tagName());

if (child.namespaceURI() == ns_mix_pam) {
if (child.hasAttribute("channel"))
m_jid = child.attribute("channel");
d->jid = child.attribute("channel");

child = child.firstChildElement();
}

if (!child.isNull() && child.namespaceURI() == ns_mix) {
if (child.hasAttribute("jid"))
m_jid = child.attribute("jid");
d->jid = child.attribute("jid");
if (child.hasAttribute("channel"))
m_channelName = child.attribute("channel");
d->channelName = child.attribute("channel");

QDomElement subChild = child.firstChildElement();
while (!subChild.isNull()) {
if (subChild.tagName() == "subscribe")
m_nodes << subChild.attribute("node");
d->nodes << subChild.attribute("node");
else if (subChild.tagName() == "nick")
m_nick = subChild.text();
d->nick = subChild.text();

subChild = subChild.nextSiblingElement();
}
@@ -148,36 +167,36 @@ void QXmppMixIq::parseElementFromChild(const QDomElement& element)

void QXmppMixIq::toXmlElementFromChild(QXmlStreamWriter* writer) const
{
if (m_actionType == None)
if (d->actionType == None)
return;

writer->writeStartElement(MIX_ACTION_TYPES.at(m_actionType));
if (m_actionType == ClientJoin || m_actionType == ClientLeave) {
writer->writeStartElement(MIX_ACTION_TYPES.at(d->actionType));
if (d->actionType == ClientJoin || d->actionType == ClientLeave) {
writer->writeAttribute("xmlns", ns_mix_pam);
if (type() == Set)
helperToXmlAddAttribute(writer, "channel", m_jid);
helperToXmlAddAttribute(writer, "channel", d->jid);

if (m_actionType == ClientJoin)
if (d->actionType == ClientJoin)
writer->writeStartElement("join");
else if (m_actionType == ClientLeave)
else if (d->actionType == ClientLeave)
writer->writeStartElement("leave");
}

writer->writeAttribute("xmlns", ns_mix);
helperToXmlAddAttribute(writer, "channel", m_channelName);
helperToXmlAddAttribute(writer, "channel", d->channelName);
if (type() == Result)
helperToXmlAddAttribute(writer, "jid", m_jid);
helperToXmlAddAttribute(writer, "jid", d->jid);

for (auto node : m_nodes) {
for (auto node : d->nodes) {
writer->writeStartElement("subscribe");
writer->writeAttribute("node", node);
writer->writeEndElement();
}
if (!m_nick.isEmpty())
writer->writeTextElement("nick", m_nick);
if (!d->nick.isEmpty())
writer->writeTextElement("nick", d->nick);

writer->writeEndElement();
if (m_actionType == ClientJoin || m_actionType == ClientLeave)
if (d->actionType == ClientJoin || d->actionType == ClientLeave)
writer->writeEndElement();
}
/// \endcond
@@ -26,6 +26,8 @@

#include "QXmppIq.h"

class QXmppMixIqPrivate;

/// \brief The QXmppMixIq class represents an IQ used to do actions on a MIX
/// channel as defined by XEP-0369: Mediated Information eXchange (MIX)
/// (v0.14.1) and XEP-0405: Mediated Information eXchange (MIX): Participant
@@ -48,6 +50,9 @@ class QXMPP_EXPORT QXmppMixIq : public QXmppIq
Destroy
};

QXmppMixIq();
~QXmppMixIq();

QXmppMixIq::Type actionType() const;
void setActionType(QXmppMixIq::Type);

@@ -74,11 +79,7 @@ class QXMPP_EXPORT QXmppMixIq : public QXmppIq
/// \endcond

private:
QString m_jid;
QString m_channelName;
QStringList m_nodes;
QString m_nick;
QXmppMixIq::Type m_actionType = QXmppMixIq::None;
QXmppMixIqPrivate *d;
};

#endif // QXMPPMIXIQ_H

0 comments on commit 9df7e7f

Please sign in to comment.