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>
31 #include "signalproxy.h"
36 class IrcServerHandler;
37 class UserInputHandler;
40 class NetworkConnection : public QObject {
44 NetworkConnection(Network *network, CoreSession *session, const QVariant &previousState = QVariant());
47 NetworkId networkId() const;
48 QString networkName() const;
49 Network *network() const;
50 CoreSession *coreSession() const;
52 bool isConnected() const;
54 IrcServerHandler *ircServerHandler() const;
55 UserInputHandler *userInputHandler() const;
56 CtcpHandler *ctcpHandler() const;
58 //! Return data necessary to restore the connection state upon core restart
59 QVariant state() const;
61 //! Decode a string using the server (network) decoding.
62 QString serverDecode(const QByteArray &string) const;
64 //! Decode a string using a buffer-specific encoding if one is set (and use the server encoding else).
65 QString bufferDecode(const QString &bufferName, const QByteArray &string) const;
67 //! Decode a string using a IrcUser specific encoding, if one exists (using the server encoding else).
68 QString userDecode(const QString &userNick, const QByteArray &string) const;
70 //! Encode a string using the server (network) encoding.
71 QByteArray serverEncode(const QString &string) const;
73 //! Encode a string using the buffer-specific encoding, if set, and use the server encoding else.
74 QByteArray bufferEncode(const QString &bufferName, const QString &string) const;
76 //! Encode a string using the user-specific encoding, if set, and use the server encoding else.
77 QByteArray userEncode(const QString &userNick, const QString &string) const;
80 // void setServerOptions();
82 void disconnectFromIrc();
83 void userInput(QString buffer, QString msg);
85 void putRawLine(QString input);
86 void putCmd(QString cmd, QStringList params, QString prefix = 0);
93 // #void networkState(QString net, QVariantMap data);
94 void recvRawServerMsg(QString);
95 void displayStatusMsg(QString);
96 //void displayMsg(Message msg);
97 void displayMsg(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
98 void connected(NetworkId networkId);
99 void disconnected(NetworkId networkId);
101 void connectionInitialized(); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
103 //void queryRequested(QString network, QString nick);
107 void socketHasData();
108 void socketError(QAbstractSocket::SocketError);
109 void socketConnected();
110 void socketStateChanged(QAbstractSocket::SocketState);
116 CoreSession *_coreSession;
118 IrcServerHandler *_ircServerHandler;
119 UserInputHandler *_userInputHandler;
120 CtcpHandler *_ctcpHandler;
122 QVariantMap networkSettings;
123 QVariantMap identity;
125 QVariant _previousState;
127 class ParseError : public Exception {
129 ParseError(QString cmd, QString prefix, QStringList params);
132 class UnknownCmdError : public Exception {
134 UnknownCmdError(QString cmd, QString prefix, QStringList params);