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>
33 #include "signalproxy.h"
38 class IrcServerHandler;
39 class UserInputHandler;
42 class NetworkConnection : public QObject {
46 NetworkConnection(Network *network, CoreSession *session, const QVariant &previousState = QVariant());
49 NetworkId networkId() const;
50 QString networkName() const;
51 Network *network() const;
52 Identity *identity() const;
53 CoreSession *coreSession() const;
55 bool isConnected() const;
56 Network::ConnectionState connectionState() const;
58 IrcServerHandler *ircServerHandler() const;
59 UserInputHandler *userInputHandler() const;
60 CtcpHandler *ctcpHandler() const;
62 //! Return data necessary to restore the connection state upon core restart
63 QVariant state() const;
65 //! Decode a string using the server (network) decoding.
66 QString serverDecode(const QByteArray &string) const;
68 //! Decode a string using a channel-specific encoding if one is set (and use the standard encoding else).
69 QString channelDecode(const QString &channelName, const QByteArray &string) const;
71 //! Decode a string using an IrcUser-specific encoding, if one exists (using the standaed encoding else).
72 QString userDecode(const QString &userNick, const QByteArray &string) const;
74 //! Encode a string using the server (network) encoding.
75 QByteArray serverEncode(const QString &string) const;
77 //! Encode a string using the channel-specific encoding, if set, and use the standard encoding else.
78 QByteArray channelEncode(const QString &channelName, const QString &string) const;
80 //! Encode a string using the user-specific encoding, if set, and use the standard encoding else.
81 QByteArray userEncode(const QString &userNick, const QString &string) const;
84 // void setServerOptions();
85 void connectToIrc(bool reconnecting = false);
86 void disconnectFromIrc();
87 void userInput(BufferInfo bufferInfo, QString msg);
89 void putRawLine(QByteArray input);
90 void putCmd(const QString &cmd, const QVariantList ¶ms, const QByteArray &prefix = QByteArray());
95 void autoReconnectSettingsChanged();
96 void doAutoReconnect();
99 // #void networkState(QString net, QVariantMap data);
100 void recvRawServerMsg(QString);
101 void displayStatusMsg(QString);
102 //void displayMsg(Message msg);
103 void displayMsg(Message::Type, BufferInfo::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
104 void connected(NetworkId networkId); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
105 void disconnected(NetworkId networkId);
106 void connectionStateChanged(Network::ConnectionState);
107 void connectionInitialized(); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
108 void connectionError(const QString &errorMsg);
110 void quitRequested(NetworkId networkId);
112 //void queryRequested(QString network, QString nick);
116 void socketHasData();
117 void socketError(QAbstractSocket::SocketError);
118 void socketConnected();
119 void socketDisconnected();
120 void socketStateChanged(QAbstractSocket::SocketState);
121 void setConnectionState(Network::ConnectionState);
122 void networkInitialized(const QString ¤tServer);
126 Network::ConnectionState _connectionState;
129 CoreSession *_coreSession;
131 IrcServerHandler *_ircServerHandler;
132 UserInputHandler *_userInputHandler;
133 CtcpHandler *_ctcpHandler;
135 QVariant _previousState;
137 QTimer _autoReconnectTimer;
138 int _autoReconnectCount;
140 class ParseError : public Exception {
142 ParseError(QString cmd, QString prefix, QStringList params);
145 class UnknownCmdError : public Exception {
147 UnknownCmdError(QString cmd, QString prefix, QStringList params);