QXmpp Version:0.3.91
|
The QXmppClient class is the main class for using QXmpp. More...
#include <QXmppClient.h>
Public Types | |
enum | Error { NoError, SocketError, KeepAliveError, XmppStreamError } |
enum | State { DisconnectedState, ConnectingState, ConnectedState } |
This enumeration describes a client state. More... | |
Public Slots | |
void | connectToServer (const QString &jid, const QString &password) |
void | disconnectFromServer () |
bool | sendPacket (const QXmppPacket &) |
void | sendMessage (const QString &bareJid, const QString &message) |
Signals | |
void | connected () |
void | disconnected () |
void | error (QXmppClient::Error) |
void | loggerChanged (QXmppLogger *logger) |
This signal is emitted when the logger changes. | |
void | messageReceived (const QXmppMessage &message) |
void | presenceReceived (const QXmppPresence &presence) |
void | iqReceived (const QXmppIq &iq) |
void | stateChanged (State state) |
This signal is emitted when the client state changes. | |
Public Member Functions | |
QXmppClient (QObject *parent=0) | |
~QXmppClient () | |
bool | addExtension (QXmppClientExtension *extension) |
bool | removeExtension (QXmppClientExtension *extension) |
QList< QXmppClientExtension * > | extensions () |
template<typename T > | |
T * | findExtension () |
Returns the extension which can be cast into type T*, or 0 if there is no such extension. | |
void | connectToServer (const QXmppConfiguration &, const QXmppPresence &initialPresence=QXmppPresence()) |
bool | isConnected () const |
QXmppPresence | clientPresence () const |
void | setClientPresence (const QXmppPresence &presence) |
QXmppConfiguration & | configuration () |
QXmppLogger * | logger () const |
void | setLogger (QXmppLogger *logger) |
Sets the QXmppLogger associated with the current QXmppClient. | |
QAbstractSocket::SocketError | socketError () |
State | state () const |
QXmppStanza::Error::Condition | xmppStreamError () |
QXmppRosterManager & | rosterManager () |
QXmppVCardManager & | vCardManager () |
QXmppVersionManager & | versionManager () |
QXmppReconnectionManager * | reconnectionManager () |
bool | setReconnectionManager (QXmppReconnectionManager *) |
Properties | |
QXmppLogger | logger |
Returns the QXmppLogger associated with the current QXmppClient. | |
State | state |
Returns the client's current state. |
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 QXmppVersionManager (software version information).
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.
Not all the managers or extensions have been enabled by default. One can enable/disable the managers using the funtions addExtension() and removeExtension(). findExtension() can be used to find reference/pointer to particular instansiated and enabled manager.
List of managers enabled by default:
enum QXmppClient::Error |
enum QXmppClient::State |
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.
bool QXmppClient::addExtension | ( | QXmppClientExtension * | extension | ) |
Registers a new extension with the client.
extension |
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, password 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 & | jid, |
const QString & | password | ||
) | [slot] |
Overloaded function to simply connect to an XMPP server with a JID and password.
jid | JID for the account. |
password | Password for the account. |
void QXmppClient::disconnected | ( | ) | [signal] |
This signal is emitted when the XMPP connection disconnects.
void QXmppClient::disconnectFromServer | ( | ) | [slot] |
Disconnects the client and the current presence of client changes to QXmppPresence::Unavailable and status text changes to "Logged out".
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.
QList< QXmppClientExtension * > QXmppClient::extensions | ( | ) |
Returns a list containing all the client's extensions.
T* QXmppClient::findExtension | ( | ) | [inline] |
Returns the extension which can be cast into type T*, or 0 if there is no such extension.
Usage example:
QXmppDiscoveryManager* ext = client->findExtension<QXmppDiscoveryManager>(); if(ext) { //extension found, do stuff... }
void QXmppClient::iqReceived | ( | const QXmppIq & | iq | ) | [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 & | message | ) | [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.
void QXmppClient::presenceReceived | ( | const QXmppPresence & | presence | ) | [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.
bool QXmppClient::removeExtension | ( | QXmppClientExtension * | extension | ) |
Unregisters the given extension from the client. If the extension is found, it will be destroyed.
extension |
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. If there are no resources available, that is the contact is offline or not present in the roster, it will still send a message to the 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.
QXmppVCardManager & QXmppClient::vCardManager | ( | ) |
Returns the reference to QXmppVCardManager, implementation of XEP-0054. http://xmpp.org/extensions/xep-0054.html
QXmppVersionManager & QXmppClient::versionManager | ( | ) |
Returns the reference to QXmppVersionManager, implementation of XEP-0092. http://xmpp.org/extensions/xep-0092.html
QXmppStanza::Error::Condition QXmppClient::xmppStreamError | ( | ) |
Returns the XMPP stream error if QXmppClient::Error is QXmppClient::XmppStreamError.