QXmpp Version:0.3.91
|
00001 /* 00002 * Copyright (C) 2008-2011 The QXmpp developers 00003 * 00004 * Author: 00005 * Manjeet Dahiya 00006 * 00007 * Source: 00008 * http://code.google.com/p/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 QXmppClientExtension; 00035 class QXmppClientPrivate; 00036 class QXmppPresence; 00037 class QXmppMessage; 00038 class QXmppPacket; 00039 class QXmppIq; 00040 class QXmppStream; 00041 00042 // managers 00043 class QXmppDiscoveryIq; 00044 class QXmppReconnectionManager; 00045 class QXmppRosterManager; 00046 class QXmppVCardManager; 00047 class QXmppVersionManager; 00048 00050 00052 00079 00080 class 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 removeExtension(QXmppClientExtension* extension); 00111 00112 QList<QXmppClientExtension*> extensions(); 00113 00126 template<typename T> 00127 T* findExtension() 00128 { 00129 QList<QXmppClientExtension*> list = extensions(); 00130 for (int i = 0; i < list.size(); ++i) 00131 { 00132 T* extension = qobject_cast<T*>(list.at(i)); 00133 if(extension) 00134 return extension; 00135 } 00136 return 0; 00137 } 00138 00139 void connectToServer(const QXmppConfiguration&, 00140 const QXmppPresence& initialPresence = 00141 QXmppPresence()); 00142 bool isConnected() const; 00143 00144 QXmppPresence clientPresence() const; 00145 void setClientPresence(const QXmppPresence &presence); 00146 00147 QXmppConfiguration &configuration(); 00148 QXmppLogger *logger() const; 00149 void setLogger(QXmppLogger *logger); 00150 00151 QAbstractSocket::SocketError socketError(); 00152 State state() const; 00153 QXmppStanza::Error::Condition xmppStreamError(); 00154 00155 QXmppRosterManager& rosterManager(); 00156 QXmppVCardManager& vCardManager(); 00157 QXmppVersionManager& versionManager(); 00158 00159 QXmppReconnectionManager* reconnectionManager(); 00160 bool setReconnectionManager(QXmppReconnectionManager*); 00161 00162 signals: 00163 00183 void connected(); 00184 00187 void disconnected(); 00188 00194 void error(QXmppClient::Error); 00195 00197 void loggerChanged(QXmppLogger *logger); 00198 00203 void messageReceived(const QXmppMessage &message); 00204 00209 void presenceReceived(const QXmppPresence &presence); 00210 00215 void iqReceived(const QXmppIq &iq); 00216 00218 void stateChanged(State state); 00219 00221 // Deprecated in release 0.3.0 00222 // Use QXmppDiscoveryManager::informationReceived(const QXmppDiscoveryIq&) 00223 // Notifies that an XMPP service discovery iq stanza is received. 00224 void discoveryIqReceived(const QXmppDiscoveryIq&); 00226 00227 public slots: 00228 void connectToServer(const QString &jid, 00229 const QString &password); 00230 void disconnectFromServer(); 00231 bool sendPacket(const QXmppPacket&); 00232 void sendMessage(const QString& bareJid, const QString& message); 00233 00234 private slots: 00235 void _q_elementReceived(const QDomElement &element, bool &handled); 00236 void _q_socketStateChanged(QAbstractSocket::SocketState state); 00237 void _q_streamConnected(); 00238 void _q_streamDisconnected(); 00239 00240 private: 00241 QXmppClientPrivate * const d; 00242 }; 00243 00244 #endif // QXMPPCLIENT_H