QXmpp  Version:0.7.5
 All Classes Functions Variables Enumerations Enumerator Properties Groups
QXmppClient.h
1 /*
2  * Copyright (C) 2008-2012 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 isAuthenticated() const;
141  bool isConnected() const;
142 
143  QXmppPresence clientPresence() const;
144  void setClientPresence(const QXmppPresence &presence);
145 
146  QXmppConfiguration &configuration();
147  QXmppLogger *logger() const;
148  void setLogger(QXmppLogger *logger);
149 
150  QAbstractSocket::SocketError socketError();
151  State state() const;
152  QXmppStanza::Error::Condition xmppStreamError();
153 
154  QXmppRosterManager& rosterManager();
155  QXmppVCardManager& vCardManager();
156  QXmppVersionManager& versionManager();
157 
158 signals:
159 
179  void connected();
180 
183  void disconnected();
184 
190  void error(QXmppClient::Error);
191 
193  void loggerChanged(QXmppLogger *logger);
194 
199  void messageReceived(const QXmppMessage &message);
200 
205  void presenceReceived(const QXmppPresence &presence);
206 
211  void iqReceived(const QXmppIq &iq);
212 
214  void stateChanged(QXmppClient::State state);
215 
216 public slots:
217  void connectToServer(const QString &jid,
218  const QString &password);
219  void disconnectFromServer();
220  bool sendPacket(const QXmppStanza&);
221  void sendMessage(const QString& bareJid, const QString& message);
222 
223 private slots:
224  void _q_elementReceived(const QDomElement &element, bool &handled);
225  void _q_reconnect();
226  void _q_socketStateChanged(QAbstractSocket::SocketState state);
227  void _q_streamConnected();
228  void _q_streamDisconnected();
229  void _q_streamError(QXmppClient::Error error);
230 
231 private:
232  QXmppClientPrivate * const d;
233 };
234 
235 #endif // QXMPPCLIENT_H