Communi  3.2.0
A cross-platform IRC framework written with Qt
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Macros Groups Pages
ircconnection.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2014 The Communi Project
3 
4  You may use this file under the terms of BSD license as follows:
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the copyright holder nor the names of its
14  contributors may be used to endorse or promote products derived
15  from this software without specific prior written permission.
16 
17  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
21  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef IRCCONNECTION_H
30 #define IRCCONNECTION_H
31 
32 #include <IrcGlobal>
33 #include <IrcMessage>
34 #include <IrcNetwork>
35 #include <QtCore/qobject.h>
36 #include <QtCore/qvariant.h>
37 #include <QtCore/qmetatype.h>
38 #include <QtCore/qscopedpointer.h>
39 #include <QtNetwork/qabstractsocket.h>
40 
41 IRC_BEGIN_NAMESPACE
42 
43 class IrcCommand;
44 class IrcProtocol;
45 class IrcConnectionPrivate;
46 
47 class IRC_CORE_EXPORT IrcConnection : public QObject
48 {
49  Q_OBJECT
50 
51  Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
52  Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
53  Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged)
54  Q_PROPERTY(QString nickName READ nickName WRITE setNickName NOTIFY nickNameChanged)
55  Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
56  Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
57  Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
58  Q_PROPERTY(QVariantMap userData READ userData WRITE setUserData NOTIFY userDataChanged)
59  Q_PROPERTY(QByteArray encoding READ encoding WRITE setEncoding)
60  Q_PROPERTY(Status status READ status NOTIFY statusChanged)
61  Q_PROPERTY(bool active READ isActive NOTIFY statusChanged)
62  Q_PROPERTY(bool connected READ isConnected NOTIFY statusChanged)
63  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
64  Q_PROPERTY(int reconnectDelay READ reconnectDelay WRITE setReconnectDelay NOTIFY reconnectDelayChanged)
65  Q_PROPERTY(QAbstractSocket* socket READ socket WRITE setSocket)
66  Q_PROPERTY(bool secure READ isSecure WRITE setSecure NOTIFY secureChanged)
67  Q_PROPERTY(bool secureSupported READ isSecureSupported)
68  Q_PROPERTY(QString saslMechanism READ saslMechanism WRITE setSaslMechanism NOTIFY saslMechanismChanged)
69  Q_PROPERTY(QStringList supportedSaslMechanisms READ supportedSaslMechanisms CONSTANT)
70  Q_PROPERTY(IrcNetwork* network READ network CONSTANT)
71  Q_PROPERTY(IrcProtocol* protocol READ protocol WRITE setProtocol)
72  Q_ENUMS(Status)
73 
74 public:
75  explicit IrcConnection(QObject* parent = 0);
76  explicit IrcConnection(const QString& host, QObject* parent = 0);
77  virtual ~IrcConnection();
78 
79  QString host() const;
80  void setHost(const QString& host);
81 
82  int port() const;
83  void setPort(int port);
84 
85  QString userName() const;
86  void setUserName(const QString& name);
87 
88  QString nickName() const;
89  void setNickName(const QString& name);
90 
91  QString realName() const;
92  void setRealName(const QString& name);
93 
94  QString password() const;
95  void setPassword(const QString& password);
96 
97  QString displayName() const;
98  void setDisplayName(const QString& name);
99 
100  QVariantMap userData() const;
101  void setUserData(const QVariantMap& data);
102 
103  QByteArray encoding() const;
104  void setEncoding(const QByteArray& encoding);
105 
106  enum Status {
113  Error
114  };
115  Status status() const;
116  bool isActive() const;
117  bool isConnected() const;
118  bool isEnabled() const;
119 
120  int reconnectDelay() const;
121  void setReconnectDelay(int seconds);
122 
123  QAbstractSocket* socket() const;
124  void setSocket(QAbstractSocket* socket);
125 
126  bool isSecure() const;
127  void setSecure(bool secure);
128  static bool isSecureSupported();
129 
130  QString saslMechanism() const;
131  void setSaslMechanism(const QString& mechanism);
132 
133  static QStringList supportedSaslMechanisms();
134 
135  IrcNetwork* network() const;
136 
137  IrcProtocol* protocol() const;
138  void setProtocol(IrcProtocol* protocol);
139 
140  void installMessageFilter(QObject* filter);
141  void removeMessageFilter(QObject* filter);
142 
143  void installCommandFilter(QObject* filter);
144  void removeCommandFilter(QObject* filter);
145 
146  Q_INVOKABLE QByteArray saveState(int version = 0) const;
147  Q_INVOKABLE bool restoreState(const QByteArray& state, int version = 0);
148 
149 public Q_SLOTS:
150  void open();
151  void close();
152  void quit(const QString& reason = QString());
153  void setEnabled(bool enabled = true);
154  void setDisabled(bool disabled = true);
155 
156  bool sendCommand(IrcCommand* command);
157  bool sendData(const QByteArray& data);
158  bool sendRaw(const QString& message);
159 
160 Q_SIGNALS:
161  void connecting();
162  void connected();
163  void disconnected();
164  void statusChanged(IrcConnection::Status status);
165  void socketError(QAbstractSocket::SocketError error);
166  void socketStateChanged(QAbstractSocket::SocketState state);
167  void secureError();
168 
169  void nickNameReserved(QString* alternate); // deprecated
170  void nickNameRequired(const QString& reserved, QString* alternate);
171  void channelKeyRequired(const QString& channel, QString* key);
172 
173  void messageReceived(IrcMessage* message);
174 
175  void capabilityMessageReceived(IrcCapabilityMessage* message);
176  void errorMessageReceived(IrcErrorMessage* message);
177  void inviteMessageReceived(IrcInviteMessage* message);
178  void joinMessageReceived(IrcJoinMessage* message);
179  void kickMessageReceived(IrcKickMessage* message);
180  void modeMessageReceived(IrcModeMessage* message);
181  void namesMessageReceived(IrcNamesMessage* message);
182  void nickMessageReceived(IrcNickMessage* message);
183  void noticeMessageReceived(IrcNoticeMessage* message);
184  void numericMessageReceived(IrcNumericMessage* message);
185  void motdMessageReceived(IrcMotdMessage* message);
186  void partMessageReceived(IrcPartMessage* message);
187  void pingMessageReceived(IrcPingMessage* message);
188  void pongMessageReceived(IrcPongMessage* message);
189  void privateMessageReceived(IrcPrivateMessage* message);
190  void quitMessageReceived(IrcQuitMessage* message);
191  void topicMessageReceived(IrcTopicMessage* message);
192  void whoReplyMessageReceived(IrcWhoReplyMessage* message);
193 
194  void hostChanged(const QString& host);
195  void portChanged(int port);
196  void userNameChanged(const QString& name);
197  void nickNameChanged(const QString& name);
198  void realNameChanged(const QString& name);
199  void passwordChanged(const QString& password);
200  void displayNameChanged(const QString& name);
201  void userDataChanged(const QVariantMap& data);
202 
203  void reconnectDelayChanged(int seconds);
204  void enabledChanged(bool enabled);
205  void secureChanged(bool secure);
206  void saslMechanismChanged(const QString& mechanism);
207 
208  void destroyed(IrcConnection* connection);
209 
210 protected Q_SLOTS:
211  virtual IrcCommand* createCtcpReply(IrcPrivateMessage* request) const;
212 
213 private:
214  friend class IrcProtocol;
215  friend class IrcProtocolPrivate;
217  Q_DECLARE_PRIVATE(IrcConnection)
218  Q_DISABLE_COPY(IrcConnection)
219 
220  Q_PRIVATE_SLOT(d_func(), void _irc_connected())
221  Q_PRIVATE_SLOT(d_func(), void _irc_disconnected())
222  Q_PRIVATE_SLOT(d_func(), void _irc_error(QAbstractSocket::SocketError))
223  Q_PRIVATE_SLOT(d_func(), void _irc_state(QAbstractSocket::SocketState))
224  Q_PRIVATE_SLOT(d_func(), void _irc_sslErrors())
225  Q_PRIVATE_SLOT(d_func(), void _irc_reconnect())
226  Q_PRIVATE_SLOT(d_func(), void _irc_readData())
227  Q_PRIVATE_SLOT(d_func(), void _irc_filterDestroyed(QObject*))
228 };
229 
230 #ifndef QT_NO_DEBUG_STREAM
231 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcConnection::Status status);
232 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, const IrcConnection* connection);
233 #endif // QT_NO_DEBUG_STREAM
234 
235 IRC_END_NAMESPACE
236 
237 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcConnection*))
238 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcConnection::Status))
239 
240 #endif // IRCCONNECTION_H
Represents an invite message.
Definition: ircmessage.h:181
Represents a private message.
Definition: ircmessage.h:404
Represents a names list message.
Definition: ircmessage.h:280
Provides means to establish a connection to an IRC server.
Definition: ircconnection.h:47
Provides network information and capability management.
Definition: ircnetwork.h:43
The connection is being established.
Definition: ircconnection.h:109
Represents a numeric message.
Definition: ircmessage.h:338
Represents an error message.
Definition: ircmessage.h:165
Represents a quit message.
Definition: ircmessage.h:428
Represents a join message.
Definition: ircmessage.h:199
The connection is being closed.
Definition: ircconnection.h:111
Represents a pong message.
Definition: ircmessage.h:388
Q_INVOKABLE QString version()
Definition: irc.cpp:56
Represents a nick message.
Definition: ircmessage.h:298
Represents a ping message.
Definition: ircmessage.h:372
The connection is inactive.
Definition: ircconnection.h:107
The connection has been established.
Definition: ircconnection.h:110
Provides the most common commands.
Definition: irccommand.h:43
Status
Definition: ircconnection.h:106
The connection has been closed.
Definition: ircconnection.h:112
Represents a kick message.
Definition: ircmessage.h:215
Implements the IRC protocol and provides means for implementing support for custom protocols...
Definition: ircprotocol.h:45
Represents a reply message to a WHO command.
Definition: ircmessage.h:464
Represents a capability message.
Definition: ircmessage.h:147
Represents a part message.
Definition: ircmessage.h:354
Represents a topic message.
Definition: ircmessage.h:444
The base class of all messages.
Definition: ircmessage.h:47
Represents a mode message.
Definition: ircmessage.h:235
Represents a message of the day.
Definition: ircmessage.h:264
The connection is waiting for a reconnect.
Definition: ircconnection.h:108
void destroyed(QObject *obj)
Represents a notice message.
Definition: ircmessage.h:316