QXmpp  Version:0.9.3
QXmppClient.h
00001 /*
00002  * Copyright (C) 2008-2014 The QXmpp developers
00003  *
00004  * Author:
00005  *  Manjeet Dahiya
00006  *
00007  * Source:
00008  *  https://github.com/qxmpp-project/qxmpp
00009  *
00010  * This file is a part of QXmpp library.
00011  *
00012  * This library is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 2.1 of the License, or (at your option) any later version.
00016  *
00017  * This library is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  */
00023 
00024 #ifndef QXMPPCLIENT_H
00025 #define QXMPPCLIENT_H
00026 
00027 #include <QObject>
00028 #include <QAbstractSocket>
00029 
00030 #include "QXmppConfiguration.h"
00031 #include "QXmppLogger.h"
00032 #include "QXmppPresence.h"
00033 
00034 class QSslError;
00035 
00036 class QXmppClientExtension;
00037 class QXmppClientPrivate;
00038 class QXmppPresence;
00039 class QXmppMessage;
00040 class QXmppIq;
00041 class QXmppStream;
00042 
00043 // managers
00044 class QXmppDiscoveryIq;
00045 class QXmppRosterManager;
00046 class QXmppVCardManager;
00047 class QXmppVersionManager;
00048 
00050 
00052 
00079 
00080 class QXMPP_EXPORT QXmppClient : public QXmppLoggable
00081 {
00082     Q_OBJECT
00083     Q_ENUMS(Error State)
00084     Q_PROPERTY(QXmppLogger* logger READ logger WRITE setLogger NOTIFY loggerChanged)
00085     Q_PROPERTY(State state READ state NOTIFY stateChanged)
00086 
00087 public:
00090     enum Error
00091     {
00092         NoError,            
00093         SocketError,        
00094         KeepAliveError,     
00095         XmppStreamError     
00096     };
00097 
00099     enum State
00100     {
00101         DisconnectedState,  
00102         ConnectingState,    
00103         ConnectedState      
00104     };
00105 
00106     QXmppClient(QObject *parent = 0);
00107     ~QXmppClient();
00108 
00109     bool addExtension(QXmppClientExtension* extension);
00110     bool insertExtension(int index, QXmppClientExtension* extension);
00111     bool removeExtension(QXmppClientExtension* extension);
00112 
00113     QList<QXmppClientExtension*> extensions();
00114 
00127     template<typename T>
00128     T* findExtension()
00129     {
00130         QList<QXmppClientExtension*> list = extensions();
00131         for (int i = 0; i < list.size(); ++i)
00132         {
00133             T* extension = qobject_cast<T*>(list.at(i));
00134             if(extension)
00135                 return extension;
00136         }
00137         return 0;
00138     }
00139 
00140     bool isAuthenticated() const;
00141     bool isConnected() const;
00142 
00143     QXmppPresence clientPresence() const;
00144     void setClientPresence(const QXmppPresence &presence);
00145 
00146     QXmppConfiguration &configuration();
00147     QXmppLogger *logger() const;
00148     void setLogger(QXmppLogger *logger);
00149 
00150     QAbstractSocket::SocketError socketError();
00151     QString socketErrorString() const;
00152     State state() const;
00153     QXmppStanza::Error::Condition xmppStreamError();
00154 
00155     QXmppRosterManager& rosterManager();
00156     QXmppVCardManager& vCardManager();
00157     QXmppVersionManager& versionManager();
00158 
00159 signals:
00160 
00180     void connected();
00181 
00184     void disconnected();
00185 
00191     void error(QXmppClient::Error);
00192 
00194     void loggerChanged(QXmppLogger *logger);
00195 
00200     void messageReceived(const QXmppMessage &message);
00201 
00206     void presenceReceived(const QXmppPresence &presence);
00207 
00212     void iqReceived(const QXmppIq &iq);
00213 
00216     void sslErrors(const QList<QSslError> &errors);
00217 
00219     void stateChanged(QXmppClient::State state);
00220 
00221 public slots:
00222     void connectToServer(const QXmppConfiguration&,
00223                          const QXmppPresence& initialPresence =
00224                          QXmppPresence());
00225     void connectToServer(const QString &jid,
00226                          const QString &password);
00227     void disconnectFromServer();
00228     bool sendPacket(const QXmppStanza&);
00229     void sendMessage(const QString& bareJid, const QString& message);
00230 
00231 private slots:
00232     void _q_elementReceived(const QDomElement &element, bool &handled);
00233     void _q_reconnect();
00234     void _q_socketStateChanged(QAbstractSocket::SocketState state);
00235     void _q_streamConnected();
00236     void _q_streamDisconnected();
00237     void _q_streamError(QXmppClient::Error error);
00238 
00239 private:
00240     QXmppClientPrivate * const d;
00241 };
00242 
00243 #endif // QXMPPCLIENT_H
 All Classes Functions Enumerations Enumerator Properties