Skip to content

Commit

Permalink
Client: Add constructor that allows to create without extensions
Browse files Browse the repository at this point in the history
Closes #585.
  • Loading branch information
lnjX committed Nov 8, 2023
1 parent 905daf1 commit 17ee9fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/client/QXmppClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,16 @@ bool process(QXmppClient *client, const QList<QXmppClientExtension *> &extension
/// \since QXmpp 1.5
///

///
/// Creates a QXmppClient object.
/// \param parent is passed to the QObject's constructor.
/// The default value is 0.

QXmppClient::QXmppClient(QObject *parent)
///
/// \param initialExtensions can be used to set the initial set of extensions.
/// \param parent is passed to the QObject's constructor. The default value is 0.
///
QXmppClient::QXmppClient(InitialExtensions initialExtensions, QObject *parent)
: QXmppLoggable(parent),
d(new QXmppClientPrivate(this))
{

d->stream = new QXmppOutgoingClient(this);
d->addProperCapability(d->clientPresence);

Expand Down Expand Up @@ -236,12 +237,29 @@ QXmppClient::QXmppClient(QObject *parent)
// logging
setLogger(QXmppLogger::getLogger());

// always add TLS manager (it is private and can't be added by the user)
addExtension(new QXmppTlsManager);
addExtension(new QXmppRosterManager(this));
addExtension(new QXmppVCardManager);
addExtension(new QXmppVersionManager);
addExtension(new QXmppEntityTimeManager());
addExtension(new QXmppDiscoveryManager());

switch (initialExtensions) {
case NoExtensions:
break;
case BasicExtensions:
addExtension(new QXmppRosterManager(this));
addExtension(new QXmppVCardManager);
addExtension(new QXmppVersionManager);
addExtension(new QXmppEntityTimeManager());
addExtension(new QXmppDiscoveryManager());
break;
}
}

///
/// Creates a QXmppClient object.
/// \param parent is passed to the QObject's constructor.
///
QXmppClient::QXmppClient(QObject *parent)
: QXmppClient(BasicExtensions, parent)
{
}

QXmppClient::~QXmppClient() = default;
Expand Down
10 changes: 10 additions & 0 deletions src/client/QXmppClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ class QXMPP_EXPORT QXmppClient : public QXmppLoggable
ResumedStream
};

/// Used to decide which extensions should be added by default.
/// \since QXmpp 1.6
enum InitialExtensions {
/// Creates a client without any extensions.
NoExtensions,
/// Creates a client with the default set of extensions.
BasicExtensions,
};

QXmppClient(InitialExtensions, QObject *parent = nullptr);
QXmppClient(QObject *parent = nullptr);
~QXmppClient() override;

Expand Down

0 comments on commit 17ee9fa

Please sign in to comment.