Provides means to establish a connection to an IRC server. More...
Inherits QObject.
Inherited by IrcBot.
Public Types | |
enum | Status { Inactive, Waiting, Connecting, Connected, Closing, Closed, Error } |
Public Slots | |
void | close () |
void | open () |
void | quit (const QString &reason=QString()) |
bool | sendCommand (IrcCommand *command) |
bool | sendData (const QByteArray &data) |
bool | sendRaw (const QString &message) |
Signals | |
void | connecting () |
void | disconnected () |
void | messageReceived (IrcMessage *message) |
void | nickNameReserved (QString *alternate) |
void | socketError (QAbstractSocket::SocketError error) |
void | socketStateChanged (QAbstractSocket::SocketState state) |
Public Member Functions | |
IrcConnection (QObject *parent=0) | |
IrcConnection (const QString &host, QObject *parent=0) | |
virtual | ~IrcConnection () |
void | installCommandFilter (QObject *filter) |
void | installMessageFilter (QObject *filter) |
void | removeCommandFilter (QObject *filter) |
void | removeMessageFilter (QObject *filter) |
Protected Slots | |
virtual IrcCommand * | createCtcpReply (IrcPrivateMessage *request) const |
Properties | |
bool | active |
bool | connected |
QString | displayName |
bool | enabled |
QByteArray | encoding |
QString | host |
IrcNetwork | network |
QString | nickName |
QString | password |
int | port |
QString | realName |
int | reconnectDelay |
QString | saslMechanism |
bool | secure |
QAbstractSocket | socket |
Status | status |
QStringList | supportedSaslMechanisms |
QString | userName |
Before opening a connection, it must be first initialized with host, userName, nickName and realName.
The connection status may be queried at any time via status(). Also isActive() and isConnected() are provided for convenience. In addition to the statusChanged() signal, the most important statuses are informed via the following convenience signals:
Whenever a message is received from the server, the messageReceived() signal is emitted. Also message type specific signals are provided for convenience. See messageReceived() and IrcMessage and its subclasses for more details.
Sending commands to a server is most conveniently done by creating them via the various static IrcCommand::createXxx() methods and passing them to sendCommand(). Also sendData() is provided for more low-level access. See IrcCommand for more details.
This enum describes the connection status.
|
explicit |
Constructs a new IRC connection with parent.
Constructs a new IRC connection with host and parent.
|
virtual |
Destructs the IRC connection.
|
slot |
Immediately closes the connection to the server.
Calling close() makes the connection close immediately and thus might lead to "remote host closed the connection". In order to quit gracefully, call quit() first. This function attempts to flush the underlying socket, but this does not guarantee that the server ever receives the QUIT command if the connection is closed immediately after sending the command. In order to ensure a graceful quit, let the server handle closing the connection.
C++ example:
QML example:
|
signal |
This signal is emitted when the connection is being established.
The underlying socket has connected, but the IRC handshake is not yet finished and the server is not yet ready to receive commands.
|
protectedvirtualslot |
Creates a reply command for the CTCP request.
The default implementation handles the following CTCP requests: CLIENTINFO, PING, SOURCE, TIME and VERSION.
Reimplement this function in order to alter or omit the default replies.
|
signal |
This signal is emitted when the connection has been lost.
void IrcConnection::installCommandFilter | ( | QObject * | filter | ) |
Installs a command filter on the connection. The filter must implement the IrcCommandFilter interface.
A command filter receives all commands that are sent from the connection. The filter receives commands via the commandFilter() function. The function must return true
if the command should be filtered, (i.e. stopped); otherwise it must return false
.
If multiple command filters are installed on the same connection, the filter that was installed last is activated first.
void IrcConnection::installMessageFilter | ( | QObject * | filter | ) |
Installs a message filter on the connection. The filter must implement the IrcMessageFilter interface.
A message filter receives all messages that are sent to the connection. The filter receives messages via the messageFilter() function. The function must return true
if the message should be filtered, (i.e. stopped); otherwise it must return false
.
If multiple message filters are installed on the same connection, the filter that was installed last is activated first.
|
signal |
This signal is emitted when a message is received.
In addition, message type specific signals are provided for convenience:
|
signal |
This signal is emitted when the requested nick name is reserved and an alternate nick name should be provided.
An alternate nick name may be set via the provided argument, by changing the nickName property, or by sending a nick command directly.
|
slot |
Sends a quit command with an optionally specified reason.
This method is provided for convenience. It is equal to:
void IrcConnection::removeCommandFilter | ( | QObject * | filter | ) |
Removes a command filter from the connection.
The request is ignored if such command filter has not been installed. All command filters for a connection are automatically removed when the connection is destroyed.
void IrcConnection::removeMessageFilter | ( | QObject * | filter | ) |
Removes a message filter from the connection.
The request is ignored if such message filter has not been installed. All message filters for a connection are automatically removed when the connection is destroyed.
|
slot |
Sends a command to the server.
If the connection is not active, the command is queued and sent later when the connection has been established.
|
slot |
Sends raw data to the server.
|
slot |
Sends raw message to the server using UTF-8 encoding.
|
signal |
This signal is emitted when a socket error occurs.
|
signal |
This signal is emitted when the state of the underlying socket changes.
|
read |
This property holds whether the connection is active.
The connection is considered active when its either connecting, connected or closing.
|
read |
This property holds whether the connection has been established.
The connection has been established when the welcome message has been received and the server is ready to receive commands.
|
readwrite |
This property holds the display name.
Unless explicitly set, display name resolves to IrcNetwork::name or IrcConnection::host while the former is not known.
|
readwrite |
This property holds whether the connection is enabled.
The default value is true
.
When set to false
, a disabled connection does nothing when open() is called.
|
readwrite |
This property holds the FALLBACK encoding for received messages.
The fallback encoding is used when the message is detected not to be valid UTF-8
and the consequent auto-detection of message encoding fails. See QTextCodec::availableCodecs() for the list of supported encodings.
The default value is ISO-8859-15
.
|
readwrite |
|
read |
This property holds the network information.
|
readwrite |
|
readwrite |
|
readwrite |
This property holds the server port.
The default value is 6667
.
|
readwrite |
|
readwrite |
This property holds the reconnect delay in seconds.
A positive (greater than zero) value enables automatic reconnect. When the connection is lost due to a socket error, IrcConnection will automatically attempt to reconnect after the specified delay.
The default value is 0
(automatic reconnect disabled).
|
readwrite |
This property holds the used SASL (Simple Authentication and Security Layer) mechanism.
|
readwrite |
This property holds whether the socket is an SSL socket.
This property is provided for convenience. Calling
is equivalent to:
|
readwrite |
This property holds the socket. The default value is an instance of QTcpSocket.
The previously set socket is deleted if its parent is this
.
|
read |
This property holds the connection status.
|
read |
This property holds the list of supported SASL (Simple Authentication and Security Layer) mechanisms.