QXmpp  Version:0.8.0
 All Classes Functions Variables Enumerations Enumerator Properties Groups
QXmppClient.h
1 /*
2  * Copyright (C) 2008-2014 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 insertExtension(int index, QXmppClientExtension* extension);
109  bool removeExtension(QXmppClientExtension* extension);
110 
111  QList<QXmppClientExtension*> extensions();
112 
125  template<typename T>
127  {
128  QList<QXmppClientExtension*> list = extensions();
129  for (int i = 0; i < list.size(); ++i)
130  {
131  T* extension = qobject_cast<T*>(list.at(i));
132  if(extension)
133  return extension;
134  }
135  return 0;
136  }
137 
138  void connectToServer(const QXmppConfiguration&,
139  const QXmppPresence& initialPresence =
140  QXmppPresence());
141  bool isAuthenticated() const;
142  bool isConnected() const;
143 
144  QXmppPresence clientPresence() const;
145  void setClientPresence(const QXmppPresence &presence);
146 
147  QXmppConfiguration &configuration();
148  QXmppLogger *logger() const;
149  void setLogger(QXmppLogger *logger);
150 
151  QAbstractSocket::SocketError socketError();
152  State state() const;
153  QXmppStanza::Error::Condition xmppStreamError();
154 
155  QXmppRosterManager& rosterManager();
156  QXmppVCardManager& vCardManager();
157  QXmppVersionManager& versionManager();
158 
159 signals:
160 
180  void connected();
181 
184  void disconnected();
185 
191  void error(QXmppClient::Error);
192 
194  void loggerChanged(QXmppLogger *logger);
195 
200  void messageReceived(const QXmppMessage &message);
201 
206  void presenceReceived(const QXmppPresence &presence);
207 
212  void iqReceived(const QXmppIq &iq);
213 
215  void stateChanged(QXmppClient::State state);
216 
217 public slots:
218  void connectToServer(const QString &jid,
219  const QString &password);
220  void disconnectFromServer();
221  bool sendPacket(const QXmppStanza&);
222  void sendMessage(const QString& bareJid, const QString& message);
223 
224 private slots:
225  void _q_elementReceived(const QDomElement &element, bool &handled);
226  void _q_reconnect();
227  void _q_socketStateChanged(QAbstractSocket::SocketState state);
228  void _q_streamConnected();
229  void _q_streamDisconnected();
230  void _q_streamError(QXmppClient::Error error);
231 
232 private:
233  QXmppClientPrivate * const d;
234 };
235 
236 #endif // QXMPPCLIENT_H
The QXmppVersionManager class makes it possible to request for the software version of an entity as d...
Definition: QXmppVersionManager.h:37
The QXmppConfiguration class holds configuration options.
Definition: QXmppConfiguration.h:48
Error due to no response to a keep alive.
Definition: QXmppClient.h:92
The QXmppVCardManager class gets/sets XMPP vCards. It is an implementation of XEP-0054: vcard-temp...
Definition: QXmppVCardManager.h:56
Disconnected from the server.
Definition: QXmppClient.h:99
Trying to connect to the server.
Definition: QXmppClient.h:100
Connected to the server.
Definition: QXmppClient.h:101
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:90
No error.
Definition: QXmppClient.h:90
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:111
Error
Definition: QXmppClient.h:88
Error due to XML stream.
Definition: QXmppClient.h:93
The QXmppRosterManager class provides access to a connected client's roster.
Definition: QXmppRosterManager.h:64
The QXmppLogger class represents a sink for logging messages.
Definition: QXmppLogger.h:45
The QXmppStream class is the base class for all XMPP streams.
Definition: QXmppStream.h:41
The QXmppPresence class represents an XMPP presence stanza.
Definition: QXmppPresence.h:36
The QXmppIq class is the base class for all IQs.
Definition: QXmppIq.h:42
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:38
T * findExtension()
Returns the extension which can be cast into type T*, or 0 if there is no such extension.
Definition: QXmppClient.h:126
State
This enumeration describes a client state.
Definition: QXmppClient.h:97
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:47
Error due to TCP socket.
Definition: QXmppClient.h:91
The QXmppClient class is the main class for using QXmpp.
Definition: QXmppClient.h:78