Provides means to establish a connection to an IRC server. More...
Inherits QObject.
Inherited by IrcBot.
Public Types |
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 | channelKeyRequired (const QString &channel, QString *key) |
void | connecting () |
void | disconnected () |
void | messageReceived (IrcMessage *message) |
void | nickNameRequired (const QString &reserved, QString *alternate) |
void | secureError () |
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 () |
Q_INVOKABLE IrcConnection * | clone (QObject *parent=0) const |
void | installCommandFilter (QObject *filter) |
void | installMessageFilter (QObject *filter) |
void | removeCommandFilter (QObject *filter) |
void | removeMessageFilter (QObject *filter) |
Q_INVOKABLE bool | restoreState (const QByteArray &state, int version=0) |
Q_INVOKABLE QByteArray | saveState (int version=0) const |
Static Public Member Functions | |
static bool | isSecureSupported () |
static Q_INVOKABLE bool | isValidServer (const QString &server) |
Protected Slots | |
virtual IrcCommand * | createCtcpReply (IrcPrivateMessage *request) const |
Properties | |
bool | active |
bool | connected |
QVariantMap | ctcpReplies |
QString | displayName |
bool | enabled |
QByteArray | encoding |
QString | host |
IrcNetwork | network |
QString | nickName |
QStringList | nickNames |
QString | password |
int | port |
IrcProtocol | protocol |
QString | realName |
int | reconnectDelay |
QString | saslMechanism |
bool | secure |
QStringList | servers |
QAbstractSocket | socket |
Status | status |
QStringList | supportedSaslMechanisms |
QVariantMap | userData |
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.
This signal is emitted when joining a channel requires a key. The key may be set via the provided argument, or by sending a new join command directly.
IrcConnection * IrcConnection::clone | ( | QObject * | parent = 0 | ) | const |
Clones 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 first checks whether the ctcpReplies property contains a user-supplied reply for the request. In case it does, the reply is sent automatically. In case there is no user-supplied reply, 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.
|
static |
|
static |
Returns true
if the server line syntax is valid.
The syntax is:
where port is optional (defaults to 6667
) and +
prefix denotes SSL.
|
signal |
This signal is emitted when a message is received.
In addition, message type specific signals are provided for convenience:
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.
bool IrcConnection::restoreState | ( | const QByteArray & | state, |
int | version = 0 |
||
) |
Restores the state of the connection. The version number is compared with that stored in state. If they do not match, the connection state is left unchanged, and this function returns false
; otherwise, the state is restored, and true
is returned.
QByteArray IrcConnection::saveState | ( | int | version = 0 | ) | const |
Saves the state of the connection. The version number is stored as part of the state data.
To restore the saved state, pass the return value and version number to restoreState().
|
signal |
This signal is emitted when SSL socket error occurs.
Either QSslSocket::sslErrors() was emitted, or the handshake failed meaning that the server is not SSL-enabled.
|
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 CTCP (client to client protocol) replies.
This is a convenient request-reply map for customized static CTCP replies. For dynamic replies, override createCtcpReply() instead.
|
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 |
This property holds the nick names.
The list of nick names is automatically cycled through when the current nick name is reserved. If all provided nick names are reserved, the nickNameRequired() signal is emitted.
|
readwrite |
|
readwrite |
This property holds the server port.
The default value is 6667
.
|
readwrite |
This property holds the protocol.
The previously set protocol is deleted if its parent is this
.
|
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 list of servers.
The list of servers is automatically cycled through when reconnecting.
|
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 |
|
readwrite |
This property holds arbitrary user data.