Syncing my current state, Network settings still not fully functional, so don't use...
[quassel.git] / src / core / networkconnection.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef _NETWORKCONNECTION_H_
22 #define _NETWORKCONNECTION_H_
23
24 #include <QAbstractSocket>
25 #include <QString>
26 #include <QStringList>
27 #include <QTcpSocket>
28 #include <QTimer>
29
30 #include "message.h"
31 #include "signalproxy.h"
32
33 class CoreSession;
34 class Network;
35
36 class IrcServerHandler;
37 class UserInputHandler;
38 class CtcpHandler;
39
40 class NetworkConnection : public QObject {
41   Q_OBJECT
42
43 public:
44   NetworkConnection(Network *network, CoreSession *session, const QVariant &previousState = QVariant());
45   ~NetworkConnection();
46
47   NetworkId networkId() const;
48   QString networkName() const;
49   Network *network() const;
50   CoreSession *coreSession() const;
51
52   bool isConnected() const;
53
54   IrcServerHandler *ircServerHandler() const;
55   UserInputHandler *userInputHandler() const;
56   CtcpHandler *ctcpHandler() const;
57
58   //! Return data necessary to restore the connection state upon core restart
59   QVariant state() const;
60
61   //! Decode a string using the server (network) decoding.
62   QString serverDecode(const QByteArray &string) const;
63
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;
66
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;
69
70   //! Encode a string using the server (network) encoding.
71   QByteArray serverEncode(const QString &string) const;
72
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;
75
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;
78
79 public slots:
80   // void setServerOptions();
81   void connectToIrc();
82   void disconnectFromIrc();
83   void userInput(QString buffer, QString msg);
84
85   void putRawLine(QString input);
86   void putCmd(QString cmd, QStringList params, QString prefix = 0);
87
88
89 private slots:
90   void sendPerform();
91
92 signals:
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);
100
101   void connectionInitialized(); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
102
103   //void queryRequested(QString network, QString nick);
104
105
106 private slots:
107   void socketHasData();
108   void socketError(QAbstractSocket::SocketError);
109   void socketConnected();
110   void socketDisconnected();
111   void socketStateChanged(QAbstractSocket::SocketState);
112
113 private:
114   QTcpSocket socket;
115
116   Network *_network;
117   CoreSession *_coreSession;
118
119   IrcServerHandler *_ircServerHandler;
120   UserInputHandler *_userInputHandler;
121   CtcpHandler *_ctcpHandler;
122
123   QVariantMap networkSettings;
124   QVariantMap identity;
125
126   QVariant _previousState;
127
128   class ParseError : public Exception {
129   public:
130     ParseError(QString cmd, QString prefix, QStringList params);
131   };
132
133   class UnknownCmdError : public Exception {
134   public:
135     UnknownCmdError(QString cmd, QString prefix, QStringList params);
136   };
137     
138 };
139
140 #endif