QXmpp  Version:1.0.0
QXmppClient.h
1 /*
2  * Copyright (C) 2008-2019 The QXmpp developers
3  *
4  * Author:
5  * Manjeet Dahiya
6  *
7  * Source:
8  * https://github.com/qxmpp-project/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 
34 class QSslError;
35 
37 class QXmppClientPrivate;
38 class QXmppPresence;
39 class QXmppMessage;
40 class QXmppIq;
41 class QXmppStream;
42 
43 // managers
44 class QXmppDiscoveryIq;
45 class QXmppRosterManager;
46 class QXmppVCardManager;
48 
50 
52 
79 
80 class QXMPP_EXPORT QXmppClient : public QXmppLoggable
81 {
82  Q_OBJECT
83  Q_ENUMS(Error State)
84  Q_PROPERTY(QXmppLogger* logger READ logger WRITE setLogger NOTIFY loggerChanged)
85  Q_PROPERTY(State state READ state NOTIFY stateChanged)
86 
87 public:
90  enum Error
91  {
95  XmppStreamError
96  };
97 
99  enum State
100  {
103  ConnectedState
104  };
105 
106  QXmppClient(QObject *parent = 0);
107  ~QXmppClient();
108 
109  bool addExtension(QXmppClientExtension* extension);
110  bool insertExtension(int index, QXmppClientExtension* extension);
111  bool removeExtension(QXmppClientExtension* extension);
112 
113  QList<QXmppClientExtension*> extensions();
114 
127  template<typename T>
129  {
130  QList<QXmppClientExtension*> list = extensions();
131  for (int i = 0; i < list.size(); ++i)
132  {
133  T* extension = qobject_cast<T*>(list.at(i));
134  if(extension)
135  return extension;
136  }
137  return 0;
138  }
139 
140  bool isAuthenticated() const;
141  bool isConnected() const;
142 
143  bool isActive() const;
144  void setActive(bool active);
145 
146  QXmppPresence clientPresence() const;
147  void setClientPresence(const QXmppPresence &presence);
148 
149  QXmppConfiguration &configuration();
150  QXmppLogger *logger() const;
151  void setLogger(QXmppLogger *logger);
152 
153  QAbstractSocket::SocketError socketError();
154  QString socketErrorString() const;
155  State state() const;
156  QXmppStanza::Error::Condition xmppStreamError();
157 
158  QXmppRosterManager& rosterManager();
159  QXmppVCardManager& vCardManager();
160  QXmppVersionManager& versionManager();
161 
162 signals:
163 
183  void connected();
184 
187  void disconnected();
188 
194  void error(QXmppClient::Error);
195 
197  void loggerChanged(QXmppLogger *logger);
198 
203  void messageReceived(const QXmppMessage &message);
204 
209  void presenceReceived(const QXmppPresence &presence);
210 
215  void iqReceived(const QXmppIq &iq);
216 
219  void sslErrors(const QList<QSslError> &errors);
220 
222  void stateChanged(QXmppClient::State state);
223 
224 public slots:
225  void connectToServer(const QXmppConfiguration&,
226  const QXmppPresence& initialPresence =
227  QXmppPresence());
228  void connectToServer(const QString &jid,
229  const QString &password);
230  void disconnectFromServer();
231  bool sendPacket(const QXmppStanza&);
232  void sendMessage(const QString& bareJid, const QString& message);
233 
234 private slots:
235  void _q_elementReceived(const QDomElement &element, bool &handled);
236  void _q_reconnect();
237  void _q_socketStateChanged(QAbstractSocket::SocketState state);
238  void _q_streamConnected();
239  void _q_streamDisconnected();
240  void _q_streamError(QXmppClient::Error error);
241 
242 private:
243  QXmppClientPrivate * const d;
244 };
245 
246 #endif // QXMPPCLIENT_H
QXmppPresence
The QXmppPresence class represents an XMPP presence stanza.
Definition: QXmppPresence.h:36
QXmppClient::KeepAliveError
Error due to no response to a keep alive.
Definition: QXmppClient.h:94
QXmppRosterManager
The QXmppRosterManager class provides access to a connected client's roster.
Definition: QXmppRosterManager.h:64
QXmppVCardManager
The QXmppVCardManager class gets/sets XMPP vCards. It is an implementation of XEP-0054: vcard-temp.
Definition: QXmppVCardManager.h:56
QXmppClientExtension
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:47
QXmppStanza
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:90
QXmppClient::SocketError
Error due to TCP socket.
Definition: QXmppClient.h:93
QXmppClient::findExtension
T * findExtension()
Returns the extension which can be cast into type T*, or 0 if there is no such extension.
Definition: QXmppClient.h:128
QXmppClient::Error
Error
Definition: QXmppClient.h:90
QXmppClient::NoError
No error.
Definition: QXmppClient.h:92
QXmppClient::State
State
This enumeration describes a client state.
Definition: QXmppClient.h:99
QXmppLogger
The QXmppLogger class represents a sink for logging messages.
Definition: QXmppLogger.h:45
QXmppConfiguration
The QXmppConfiguration class holds configuration options.
Definition: QXmppConfiguration.h:48
QXmppClient::DisconnectedState
Disconnected from the server.
Definition: QXmppClient.h:101
QXmppStream
The QXmppStream class is the base class for all XMPP streams.
Definition: QXmppStream.h:41
QXmppClient::ConnectingState
Trying to connect to the server.
Definition: QXmppClient.h:102
QXmppIq
The QXmppIq class is the base class for all IQs.
Definition: QXmppIq.h:42
QXmppClient
The QXmppClient class is the main class for using QXmpp.
Definition: QXmppClient.h:80
QXmppLoggable
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:111
QXmppVersionManager
The QXmppVersionManager class makes it possible to request for the software version of an entity as d...
Definition: QXmppVersionManager.h:37
QXmppMessage
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:38