QXmpp  Version:0.4.92
 All Classes Functions Enumerations Enumerator Properties Groups
QXmppClient.h
1 /*
2  * Copyright (C) 2008-2011 The QXmpp developers
3  *
4  * Author:
5  * Manjeet Dahiya
6  *
7  * Source:
8  * http://code.google.com/p/qxmpp
9  *
10  * This file is a part of QXmpp library.
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  */
23 
24 #ifndef QXMPPCLIENT_H
25 #define QXMPPCLIENT_H
26 
27 #include <QObject>
28 #include <QAbstractSocket>
29 
30 #include "QXmppConfiguration.h"
31 #include "QXmppLogger.h"
32 #include "QXmppPresence.h"
33 
35 class QXmppClientPrivate;
36 class QXmppPresence;
37 class QXmppMessage;
38 class QXmppIq;
39 class QXmppStream;
40 
41 // managers
42 class QXmppDiscoveryIq;
43 class QXmppRosterManager;
44 class QXmppVCardManager;
46 
48 
50 
77 
78 class QXMPP_EXPORT QXmppClient : public QXmppLoggable
79 {
80  Q_OBJECT
81  Q_ENUMS(Error State)
82  Q_PROPERTY(QXmppLogger* logger READ logger WRITE setLogger NOTIFY loggerChanged)
83  Q_PROPERTY(State state READ state NOTIFY stateChanged)
84 
85 public:
88  enum Error
89  {
94  };
95 
97  enum State
98  {
102  };
103 
104  QXmppClient(QObject *parent = 0);
105  ~QXmppClient();
106 
107  bool addExtension(QXmppClientExtension* extension);
108  bool removeExtension(QXmppClientExtension* extension);
109 
110  QList<QXmppClientExtension*> extensions();
111 
124  template<typename T>
125  T* findExtension()
126  {
127  QList<QXmppClientExtension*> list = extensions();
128  for (int i = 0; i < list.size(); ++i)
129  {
130  T* extension = qobject_cast<T*>(list.at(i));
131  if(extension)
132  return extension;
133  }
134  return 0;
135  }
136 
137  void connectToServer(const QXmppConfiguration&,
138  const QXmppPresence& initialPresence =
139  QXmppPresence());
140  bool isConnected() const;
141 
142  QXmppPresence clientPresence() const;
143  void setClientPresence(const QXmppPresence &presence);
144 
145  QXmppConfiguration &configuration();
146  QXmppLogger *logger() const;
147  void setLogger(QXmppLogger *logger);
148 
149  QAbstractSocket::SocketError socketError();
150  State state() const;
151  QXmppStanza::Error::Condition xmppStreamError();
152 
153  QXmppRosterManager& rosterManager();
154  QXmppVCardManager& vCardManager();
155  QXmppVersionManager& versionManager();
156 
157 signals:
158 
178  void connected();
179 
182  void disconnected();
183 
189  void error(QXmppClient::Error);
190 
192  void loggerChanged(QXmppLogger *logger);
193 
198  void messageReceived(const QXmppMessage &message);
199 
204  void presenceReceived(const QXmppPresence &presence);
205 
210  void iqReceived(const QXmppIq &iq);
211 
213  void stateChanged(QXmppClient::State state);
214 
216  // Deprecated in release 0.3.0
217  // Use QXmppDiscoveryManager::informationReceived(const QXmppDiscoveryIq&)
218  // Notifies that an XMPP service discovery iq stanza is received.
219  void discoveryIqReceived(const QXmppDiscoveryIq&);
221 
222 public slots:
223  void connectToServer(const QString &jid,
224  const QString &password);
225  void disconnectFromServer();
226  bool sendPacket(const QXmppStanza&);
227  void sendMessage(const QString& bareJid, const QString& message);
228 
229 private slots:
230  void _q_elementReceived(const QDomElement &element, bool &handled);
231  void _q_reconnect();
232  void _q_socketStateChanged(QAbstractSocket::SocketState state);
233  void _q_streamConnected();
234  void _q_streamDisconnected();
235  void _q_streamError(QXmppClient::Error error);
236 
237 private:
238  QXmppClientPrivate * const d;
239 };
240 
241 #endif // QXMPPCLIENT_H