The QXmppClient class is the main class for using QXmpp. More...
#include <QXmppClient.h>
Public Types | |
enum | Error { SocketError, KeepAliveError, XmppStreamError } |
Public Slots | |
bool | sendPacket (const QXmppPacket &) |
void | sendMessage (const QString &bareJid, const QString &message) |
Signals | |
void | connected () |
void | disconnected () |
void | error (QXmppClient::Error) |
void | elementReceived (const QDomElement &element, bool &handled) |
void | messageReceived (const QXmppMessage &) |
void | presenceReceived (const QXmppPresence &) |
void | iqReceived (const QXmppIq &) |
void | discoveryIqReceived (const QXmppDiscoveryIq &) |
Notifies that an XMPP service discovery iq stanza is received. | |
void | logMessage (QXmppLogger::MessageType type, const QString &msg) |
This signal is emitted to send logging messages. | |
Public Member Functions | |
QXmppClient (QObject *parent=0) | |
~QXmppClient () | |
void | connectToServer (const QString &host, const QString &user, const QString &passwd, const QString &domain, int port=5222, const QXmppPresence &initialPresence=QXmppPresence()) |
void | connectToServer (const QString &host, const QString &bareJid, const QString &passwd, int port=5222, const QXmppPresence &initialPresence=QXmppPresence()) |
void | connectToServer (const QXmppConfiguration &, const QXmppPresence &initialPresence=QXmppPresence()) |
void | disconnectFromServer () |
bool | isConnected () const |
QXmppPresence | clientPresence () const |
void | setClientPresence (const QXmppPresence &presence) |
QXmppConfiguration & | configuration () |
QXmppLogger * | logger () |
Returns the QXmppLogger associated with the current QXmppClient. | |
void | setLogger (QXmppLogger *logger) |
Sets the QXmppLogger associated with the current QXmppClient. | |
QAbstractSocket::SocketError | socketError () |
QXmppStanza::Error::Condition | xmppStreamError () |
QXmppArchiveManager & | archiveManager () |
QXmppCallManager & | callManager () |
QXmppMucManager & | mucManager () |
QXmppRosterManager & | rosterManager () |
QXmppTransferManager & | transferManager () |
QXmppVCardManager & | vCardManager () |
QXmppReconnectionManager * | reconnectionManager () |
bool | setReconnectionManager (QXmppReconnectionManager *) |
The QXmppClient class is the main class for using QXmpp.
It provides the user all the required functionality to connect to the server and perform operations afterwards.
This class will provide the handle/reference to QXmppRosterManager (roster management), QXmppVCardManager (vCard manager), QXmppReconnectionManager (reconnection mechanism) and QXmppTransferManager (file transfers).
By default, a reconnection mechanism exists, which makes sure of reconnecting to the server on disconnections due to an error. User can have a custom reconnection mechanism as well.
For removing QXmpp dependency in QtGui, use DEFINES += QXMPP_NO_GUI in the source.pro file and build as usual.
enum QXmppClient::Error |
QXmppClient::QXmppClient | ( | QObject * | parent = 0 |
) |
Creates a QXmppClient object.
parent | is passed to the QObject's constructor. The default value is 0. |
QXmppClient::~QXmppClient | ( | ) |
Destructor, destroys the QXmppClient object.
QXmppArchiveManager & QXmppClient::archiveManager | ( | ) |
Returns the reference to QXmppArchiveManager, implementation of XEP-0136. http://xmpp.org/extensions/xep-0136.html
QXmppCallManager & QXmppClient::callManager | ( | ) |
Returns the reference to QXmppCallManager, implementation of XEP-0166. http://xmpp.org/extensions/xep-0166.html
QXmppPresence QXmppClient::clientPresence | ( | ) | const |
Returns the client's current presence.
QXmppConfiguration & QXmppClient::configuration | ( | ) |
Returns a modifiable reference to the current configuration of QXmppClient.
void QXmppClient::connected | ( | ) | [signal] |
This signal is emitted when the client connects successfully to the XMPP server i.e. when a successful XMPP connection is established. XMPP Connection involves following sequential steps:
After all these steps a successful XMPP connection is established and connected() signal is emitted.
After the connected() signal is emitted QXmpp will send the roster request to the server. On receiving the roster, QXmpp will emit QXmppRosterManager::rosterReceived(). After this signal, QXmppRosterManager object gets populated and you can use rosterManager() to get the handle of QXmppRosterManager object.
void QXmppClient::connectToServer | ( | const QXmppConfiguration & | config, | |
const QXmppPresence & | initialPresence = QXmppPresence() | |||
) |
Attempts to connect to the XMPP server. Server details and other configurations are specified using the config parameter. Use signals connected(), error(QXmppClient::Error) and disconnected() to know the status of the connection.
config | Specifies the configuration object for connecting the XMPP server. This contains the host name, user, passwd etc. See QXmppConfiguration for details. | |
initialPresence | The initial presence which will be set for this user after establishing the session. The default value is QXmppPresence::Available |
void QXmppClient::connectToServer | ( | const QString & | host, | |
const QString & | bareJid, | |||
const QString & | passwd, | |||
int | port = 5222 , |
|||
const QXmppPresence & | initialPresence = QXmppPresence() | |||
) |
Overloaded function.
host | host name of the XMPP server where connection has to be made (e.g. "jabber.org" and "talk.google.com"). It can also be an IP address in the form of a string (e.g. "192.168.1.25"). | |
bareJid | BareJid of the account at the specified XMPP server. (e.g. "qxmpp.test1@gmail.com" or qxmpptest@jabber.org.) | |
passwd | Password for the specified username | |
port | Port number at which the XMPP server is listening. The default value is 5222. | |
initialPresence | The initial presence which will be set for this user after establishing the session. The default value is QXmppPresence::Available |
void QXmppClient::connectToServer | ( | const QString & | host, | |
const QString & | user, | |||
const QString & | passwd, | |||
const QString & | domain, | |||
int | port = 5222 , |
|||
const QXmppPresence & | initialPresence = QXmppPresence() | |||
) |
Overloaded function.
host | host name of the XMPP server where connection has to be made (e.g. "jabber.org" and "talk.google.com"). It can also be an IP address in the form of a string (e.g. "192.168.1.25"). | |
user | Username of the account at the specified XMPP server. It should be the name without the domain name. E.g. "qxmpp.test1" and not "qxmpp.test1@gmail.com" | |
passwd | Password for the specified username | |
domain | Domain name e.g. "gmail.com" and "jabber.org". | |
port | Port number at which the XMPP server is listening. The default value is 5222. | |
initialPresence | The initial presence which will be set for this user after establishing the session. The default value is QXmppPresence::Available |
void QXmppClient::disconnected | ( | ) | [signal] |
This signal is emitted when the XMPP connection disconnects.
void QXmppClient::disconnectFromServer | ( | ) |
Disconnects the client and the current presence of client changes to QXmppPresence::Unavailable and status text changes to "Logged out".
void QXmppClient::elementReceived | ( | const QDomElement & | element, | |
bool & | handled | |||
) | [signal] |
This signal is emitted when a raw XML element is received. You can connect to this signal if you want to handle raw XML elements yourself.
WARNING: this signal is experimental and you can seriously disrupt packet handling when using it, so use with care and at your own risk.
Set 'handled' to true if you handled the element yourself and you wish to bypass normal handling for the element. If you do this, QXmpp will do absolutely no processing itself, so do not expect the usual signals to be emitted.
void QXmppClient::error | ( | QXmppClient::Error | ) | [signal] |
This signal is emitted when the XMPP connection encounters any error. The QXmppClient::Error parameter specifies the type of error occurred. It could be due to TCP socket or the xml stream or the stanza. Depending upon the type of error occurred use the respective get function to know the error.
void QXmppClient::iqReceived | ( | const QXmppIq & | ) | [signal] |
Notifies that an XMPP iq stanza is received. The QXmppIq parameter contains the details of the iq sent to this client. IQ stanzas provide a structured request-response mechanism. Roster management, setting-getting vCards etc is done using iq stanzas.
bool QXmppClient::isConnected | ( | ) | const |
Returns true if the client is connected to the XMPP server.
void QXmppClient::messageReceived | ( | const QXmppMessage & | ) | [signal] |
Notifies that an XMPP message stanza is received. The QXmppMessage parameter contains the details of the message sent to this client. In other words whenever someone sends you a message this signal is emitted.
QXmppMucManager & QXmppClient::mucManager | ( | ) |
Returns the reference to QXmppMucManager, implementation of XEP-0045. http://xmpp.org/extensions/xep-045.html
void QXmppClient::presenceReceived | ( | const QXmppPresence & | ) | [signal] |
Notifies that an XMPP presence stanza is received. The QXmppPresence parameter contains the details of the presence sent to this client. This signal is emitted when someone login/logout or when someone's status changes Busy, Idle, Invisible etc.
QXmppReconnectionManager * QXmppClient::reconnectionManager | ( | ) |
Function to get reconnection manager. By default there exists a reconnection manager. See QXmppReconnectionManager for more details of the reconnection mechanism.
QXmppRosterManager & QXmppClient::rosterManager | ( | ) |
Returns the reference to QXmppRosterManager object of the client.
void QXmppClient::sendMessage | ( | const QString & | bareJid, | |
const QString & | message | |||
) | [slot] |
Utility function to send message to all the resources associated with the specified bareJid.
bareJid | bareJid of the receiving entity | |
message | Message string to be sent. |
bool QXmppClient::sendPacket | ( | const QXmppPacket & | packet | ) | [slot] |
After successfully connecting to the server use this function to send stanzas to the server. This function can solely be used to send various kind of stanzas to the server. QXmppPacket is a parent class of all the stanzas QXmppMessage, QXmppPresence, QXmppIq, QXmppBind, QXmppRosterIq, QXmppSession and QXmppVCard.
Following code snippet illustrates how to send a message using this function:
QXmppMessage message(from, to, message); client.sendPacket(message);
packet | A valid XMPP stanza. It can be an iq, a message or a presence stanza. |
void QXmppClient::setClientPresence | ( | const QXmppPresence & | presence | ) |
Changes the presence of the connected client.
The connection to the server will be updated accordingly:
presence | QXmppPresence object |
bool QXmppClient::setReconnectionManager | ( | QXmppReconnectionManager * | reconnectionManager | ) |
Sets the user defined reconnection manager.
QAbstractSocket::SocketError QXmppClient::socketError | ( | ) |
Returns the socket error if error() is QXmppClient::SocketError.
QXmppTransferManager & QXmppClient::transferManager | ( | ) |
Returns the reference to QXmppTransferManager, implementation of:
XEP-0047: In-Band Bytestreams XEP-0095: Stream Initiation XEP-0096: SI File Transfer
QXmppVCardManager & QXmppClient::vCardManager | ( | ) |
Returns the reference to QXmppVCardManager, implimentation of XEP-0054. http://xmpp.org/extensions/xep-0054.html
QXmppStanza::Error::Condition QXmppClient::xmppStreamError | ( | ) |
Returns the XMPP stream error if QXmppClient::Error is QXmppClient::XmppStreamError.