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>
32 #include "signalproxy.h"
37 class IrcServerHandler;
38 class UserInputHandler;
41 class NetworkConnection : public QObject {
45 NetworkConnection(Network *network, CoreSession *session, const QVariant &previousState = QVariant());
48 NetworkId networkId() const;
49 QString networkName() const;
50 Network *network() const;
51 CoreSession *coreSession() const;
53 bool isConnected() const;
54 Network::ConnectionState connectionState() const;
56 IrcServerHandler *ircServerHandler() const;
57 UserInputHandler *userInputHandler() const;
58 CtcpHandler *ctcpHandler() const;
60 //! Return data necessary to restore the connection state upon core restart
61 QVariant state() const;
63 //! Decode a string using the server (network) decoding.
64 QString serverDecode(const QByteArray &string) const;
66 //! Decode a string using a buffer-specific encoding if one is set (and use the server encoding else).
67 QString bufferDecode(const QString &bufferName, const QByteArray &string) const;
69 //! Decode a string using a IrcUser specific encoding, if one exists (using the server encoding else).
70 QString userDecode(const QString &userNick, const QByteArray &string) const;
72 //! Encode a string using the server (network) encoding.
73 QByteArray serverEncode(const QString &string) const;
75 //! Encode a string using the buffer-specific encoding, if set, and use the server encoding else.
76 QByteArray bufferEncode(const QString &bufferName, const QString &string) const;
78 //! Encode a string using the user-specific encoding, if set, and use the server encoding else.
79 QByteArray userEncode(const QString &userNick, const QString &string) const;
82 // void setServerOptions();
84 void disconnectFromIrc();
85 void userInput(BufferInfo bufferInfo, QString msg);
87 void putRawLine(QString input);
88 void putCmd(QString cmd, QStringList params, QString prefix = 0);
95 // #void networkState(QString net, QVariantMap data);
96 void recvRawServerMsg(QString);
97 void displayStatusMsg(QString);
98 //void displayMsg(Message msg);
99 void displayMsg(Message::Type, BufferInfo::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
100 void connected(NetworkId networkId); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
101 void disconnected(NetworkId networkId);
102 void connectionStateChanged(Network::ConnectionState);
103 void connectionInitialized(); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
104 void connectionError(const QString &errorMsg);
106 //void queryRequested(QString network, QString nick);
110 void socketHasData();
111 void socketError(QAbstractSocket::SocketError);
112 void socketConnected();
113 void socketDisconnected();
114 void socketStateChanged(QAbstractSocket::SocketState);
115 void setConnectionState(Network::ConnectionState);
116 void networkInitialized();
120 Network::ConnectionState _connectionState;
123 CoreSession *_coreSession;
125 IrcServerHandler *_ircServerHandler;
126 UserInputHandler *_userInputHandler;
127 CtcpHandler *_ctcpHandler;
129 QVariantMap networkSettings;
130 QVariantMap identity;
132 QVariant _previousState;
134 class ParseError : public Exception {
136 ParseError(QString cmd, QString prefix, QStringList params);
139 class UnknownCmdError : public Exception {
141 UnknownCmdError(QString cmd, QString prefix, QStringList params);