1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef _NETWORKCONNECTION_H_
22 #define _NETWORKCONNECTION_H_
24 #include <QAbstractSocket>
26 #include <QStringList>
30 # include <QSslSocket>
33 # include <QTcpSocket>
39 #include "signalproxy.h"
44 class IrcServerHandler;
45 class UserInputHandler;
48 class NetworkConnection : public QObject {
52 NetworkConnection(Network *network, CoreSession *session);
55 NetworkId networkId() const;
56 QString networkName() const;
57 Network *network() const;
58 Identity *identity() const;
59 CoreSession *coreSession() const;
61 bool isConnected() const;
62 Network::ConnectionState connectionState() const;
64 IrcServerHandler *ircServerHandler() const;
65 UserInputHandler *userInputHandler() const;
66 CtcpHandler *ctcpHandler() const;
68 //! Decode a string using the server (network) decoding.
69 QString serverDecode(const QByteArray &string) const;
71 //! Decode a string using a channel-specific encoding if one is set (and use the standard encoding else).
72 QString channelDecode(const QString &channelName, const QByteArray &string) const;
74 //! Decode a string using an IrcUser-specific encoding, if one exists (using the standaed encoding else).
75 QString userDecode(const QString &userNick, const QByteArray &string) const;
77 //! Encode a string using the server (network) encoding.
78 QByteArray serverEncode(const QString &string) const;
80 //! Encode a string using the channel-specific encoding, if set, and use the standard encoding else.
81 QByteArray channelEncode(const QString &channelName, const QString &string) const;
83 //! Encode a string using the user-specific encoding, if set, and use the standard encoding else.
84 QByteArray userEncode(const QString &userNick, const QString &string) const;
86 inline QString channelKey(const QString &channel) const { return _channelKeys.value(channel.toLower(), QString()); }
87 inline QStringList persistentChannels() const { return _channelKeys.keys(); }
90 // void setServerOptions();
91 void connectToIrc(bool reconnecting = false);
92 void disconnectFromIrc(bool requested = true);
93 void userInput(BufferInfo bufferInfo, QString msg);
95 void putRawLine(QByteArray input);
96 void putCmd(const QString &cmd, const QVariantList ¶ms, const QByteArray &prefix = QByteArray());
98 void setChannelJoined(const QString &channel);
99 void setChannelParted(const QString &channel);
100 void addChannelKey(const QString &channel, const QString &key);
101 void removeChannelKey(const QString &channel);
105 void autoReconnectSettingsChanged();
106 void doAutoReconnect();
108 void nickChanged(const QString &newNick, const QString &oldNick); // this signal is inteded to rename query buffers in the storage backend
111 // #void networkState(QString net, QVariantMap data);
112 void recvRawServerMsg(QString);
113 void displayStatusMsg(QString);
114 //void displayMsg(Message msg);
115 void displayMsg(Message::Type, BufferInfo::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
116 void connected(NetworkId networkId); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
117 void disconnected(NetworkId networkId);
118 void connectionStateChanged(Network::ConnectionState);
119 void connectionInitialized(); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
120 void connectionError(const QString &errorMsg);
122 void quitRequested(NetworkId networkId);
124 //void queryRequested(QString network, QString nick);
125 void nickChanged(const NetworkId &networkId, const QString &newNick, const QString &oldNick); // this signal is inteded to rename query buffers in the storage backend
126 void channelJoined(NetworkId, const QString &channel, const QString &key = QString());
127 void channelParted(NetworkId, const QString &channel);
129 void sslErrors(const QVariant &errorData);
132 void socketHasData();
133 void socketError(QAbstractSocket::SocketError);
134 void socketConnected();
135 void socketInitialized();
136 void socketDisconnected();
137 void socketStateChanged(QAbstractSocket::SocketState);
138 void setConnectionState(Network::ConnectionState);
139 void networkInitialized(const QString ¤tServer);
141 #ifndef QT_NO_OPENSSL
142 void socketEncrypted();
143 void sslErrors(const QList<QSslError> &errors);
147 #ifndef QT_NO_OPENSSL
153 Network::ConnectionState _connectionState;
156 CoreSession *_coreSession;
157 BufferInfo _statusBufferInfo;
159 IrcServerHandler *_ircServerHandler;
160 UserInputHandler *_userInputHandler;
161 CtcpHandler *_ctcpHandler;
163 QHash<QString, QString> _channelKeys; // stores persistent channels and their passwords, if any
165 QTimer _autoReconnectTimer;
166 int _autoReconnectCount;
170 bool _previousConnectionAttemptFailed;
171 int _lastUsedServerlistIndex;
173 class ParseError : public Exception {
175 ParseError(QString cmd, QString prefix, QStringList params);
178 class UnknownCmdError : public Exception {
180 UnknownCmdError(QString cmd, QString prefix, QStringList params);