Communi  3.0.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-2013 The Communi Project
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
13 */
14 
15 #ifndef IRCCONNECTION_H
16 #define IRCCONNECTION_H
17 
18 #include <IrcGlobal>
19 #include <IrcMessage>
20 #include <IrcNetwork>
21 #include <QtCore/qobject.h>
22 #include <QtCore/qmetatype.h>
23 #include <QtCore/qscopedpointer.h>
24 #include <QtNetwork/qabstractsocket.h>
25 
26 IRC_BEGIN_NAMESPACE
27 
28 class IrcCommand;
29 class IrcProtocol;
30 class IrcConnectionPrivate;
31 
32 class IRC_CORE_EXPORT IrcConnection : public QObject
33 {
34  Q_OBJECT
35 
36  Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
37  Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
38  Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged)
39  Q_PROPERTY(QString nickName READ nickName WRITE setNickName NOTIFY nickNameChanged)
40  Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
41  Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
42  Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
43  Q_PROPERTY(QByteArray encoding READ encoding WRITE setEncoding)
44  Q_PROPERTY(Status status READ status NOTIFY statusChanged)
45  Q_PROPERTY(bool active READ isActive NOTIFY statusChanged)
46  Q_PROPERTY(bool connected READ isConnected NOTIFY statusChanged)
47  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
48  Q_PROPERTY(int reconnectDelay READ reconnectDelay WRITE setReconnectDelay NOTIFY reconnectDelayChanged)
49  Q_PROPERTY(QAbstractSocket* socket READ socket WRITE setSocket)
50  Q_PROPERTY(bool secure READ isSecure WRITE setSecure NOTIFY secureChanged)
51  Q_PROPERTY(QString saslMechanism READ saslMechanism WRITE setSaslMechanism NOTIFY saslMechanismChanged)
52  Q_PROPERTY(QStringList supportedSaslMechanisms READ supportedSaslMechanisms CONSTANT)
53  Q_PROPERTY(IrcNetwork* network READ network CONSTANT)
54  Q_ENUMS(Status)
55 
56 public:
57  explicit IrcConnection(QObject* parent = 0);
58  explicit IrcConnection(const QString& host, QObject* parent = 0);
59  virtual ~IrcConnection();
60 
61  QString host() const;
62  void setHost(const QString& host);
63 
64  int port() const;
65  void setPort(int port);
66 
67  QString userName() const;
68  void setUserName(const QString& name);
69 
70  QString nickName() const;
71  void setNickName(const QString& name);
72 
73  QString realName() const;
74  void setRealName(const QString& name);
75 
76  QString password() const;
77  void setPassword(const QString& password);
78 
79  QString displayName() const;
80  void setDisplayName(const QString& name);
81 
82  QByteArray encoding() const;
83  void setEncoding(const QByteArray& encoding);
84 
85  enum Status {
92  Error
93  };
94  Status status() const;
95  bool isActive() const;
96  bool isConnected() const;
97  bool isEnabled() const;
98 
99  int reconnectDelay() const;
100  void setReconnectDelay(int seconds);
101 
102  QAbstractSocket* socket() const;
103  void setSocket(QAbstractSocket* socket);
104 
105  bool isSecure() const;
106  void setSecure(bool secure);
107 
108  QString saslMechanism() const;
109  void setSaslMechanism(const QString& mechanism);
110 
111  static QStringList supportedSaslMechanisms();
112 
113  IrcNetwork* network() const;
114 
115  void installMessageFilter(QObject* filter);
116  void removeMessageFilter(QObject* filter);
117 
118  void installCommandFilter(QObject* filter);
119  void removeCommandFilter(QObject* filter);
120 
121 public Q_SLOTS:
122  void open();
123  void close();
124  void quit(const QString& reason = QString());
125  void setEnabled(bool enabled = true);
126  void setDisabled(bool disabled = true);
127 
128  bool sendCommand(IrcCommand* command);
129  bool sendData(const QByteArray& data);
130  bool sendRaw(const QString& message);
131 
132 Q_SIGNALS:
133  void connecting();
134  void nickNameReserved(QString* alternate);
135  void connected();
136  void disconnected();
137  void statusChanged(IrcConnection::Status status);
138  void socketError(QAbstractSocket::SocketError error);
139  void socketStateChanged(QAbstractSocket::SocketState state);
140 
141  void messageReceived(IrcMessage* message);
142 
143  void capabilityMessageReceived(IrcCapabilityMessage* message);
144  void errorMessageReceived(IrcErrorMessage* message);
145  void inviteMessageReceived(IrcInviteMessage* message);
146  void joinMessageReceived(IrcJoinMessage* message);
147  void kickMessageReceived(IrcKickMessage* message);
148  void modeMessageReceived(IrcModeMessage* message);
149  void namesMessageReceived(IrcNamesMessage* message);
150  void nickMessageReceived(IrcNickMessage* message);
151  void noticeMessageReceived(IrcNoticeMessage* message);
152  void numericMessageReceived(IrcNumericMessage* message);
153  void motdMessageReceived(IrcMotdMessage* message);
154  void partMessageReceived(IrcPartMessage* message);
155  void pingMessageReceived(IrcPingMessage* message);
156  void pongMessageReceived(IrcPongMessage* message);
157  void privateMessageReceived(IrcPrivateMessage* message);
158  void quitMessageReceived(IrcQuitMessage* message);
159  void topicMessageReceived(IrcTopicMessage* message);
160 
161  void hostChanged(const QString& host);
162  void portChanged(int port);
163  void userNameChanged(const QString& name);
164  void nickNameChanged(const QString& name);
165  void realNameChanged(const QString& name);
166  void passwordChanged(const QString& password);
167  void displayNameChanged(const QString& name);
168 
169  void reconnectDelayChanged(int seconds);
170  void enabledChanged(bool enabled);
171  void secureChanged(bool secure);
172  void saslMechanismChanged(const QString& mechanism);
173 
174 protected Q_SLOTS:
175  virtual IrcCommand* createCtcpReply(IrcPrivateMessage* request) const;
176 
177 protected:
178  IrcProtocol* protocol() const;
179  void setProtocol(IrcProtocol* protocol);
180 
181 private:
182  friend class IrcProtocol;
183  friend class IrcProtocolPrivate;
185  Q_DECLARE_PRIVATE(IrcConnection)
186  Q_DISABLE_COPY(IrcConnection)
187 
188  Q_PRIVATE_SLOT(d_func(), void _irc_connected())
189  Q_PRIVATE_SLOT(d_func(), void _irc_disconnected())
190  Q_PRIVATE_SLOT(d_func(), void _irc_error(QAbstractSocket::SocketError))
191  Q_PRIVATE_SLOT(d_func(), void _irc_state(QAbstractSocket::SocketState))
192  Q_PRIVATE_SLOT(d_func(), void _irc_reconnect())
193  Q_PRIVATE_SLOT(d_func(), void _irc_readData())
194  Q_PRIVATE_SLOT(d_func(), void _irc_filterDestroyed(QObject*))
195 };
196 
197 #ifndef QT_NO_DEBUG_STREAM
198 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, IrcConnection::Status status);
199 IRC_CORE_EXPORT QDebug operator<<(QDebug debug, const IrcConnection* connection);
200 #endif // QT_NO_DEBUG_STREAM
201 
202 IRC_END_NAMESPACE
203 
204 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcConnection*))
205 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcConnection::Status))
206 
207 #endif // IRCCONNECTION_H
Represents a join message.
Definition: ircmessage.h:174
Provides the most common commands.
Definition: irccommand.h:29
Represents a kick message.
Definition: ircmessage.h:190
Represents a part message.
Definition: ircmessage.h:327
The connection is being closed.
Definition: ircconnection.h:90
Represents a notice message.
Definition: ircmessage.h:289
The connection has been established.
Definition: ircconnection.h:89
Represents a names list message.
Definition: ircmessage.h:253
The connection is inactive.
Definition: ircconnection.h:86
Represents a capability message.
Definition: ircmessage.h:122
Provides means to establish a connection to an IRC server.
Definition: ircconnection.h:32
The connection has been closed.
Definition: ircconnection.h:91
Represents a mode message.
Definition: ircmessage.h:210
Represents a ping message.
Definition: ircmessage.h:345
Represents a quit message.
Definition: ircmessage.h:401
The base class of all messages.
Definition: ircmessage.h:32
Represents a pong message.
Definition: ircmessage.h:361
Represents a numeric message.
Definition: ircmessage.h:311
Represents an error message.
Definition: ircmessage.h:140
Status
Definition: ircconnection.h:85
The connection is being established.
Definition: ircconnection.h:88
Represents a private message.
Definition: ircmessage.h:377
Represents a message of the day.
Definition: ircmessage.h:237
The connection is waiting for a reconnect.
Definition: ircconnection.h:87
Represents a nick message.
Definition: ircmessage.h:271
Represents a topic message.
Definition: ircmessage.h:417
Represents an invite message.
Definition: ircmessage.h:156
Provides network information and capability management.
Definition: ircnetwork.h:29