Big, big, major commit this time:
[quassel.git] / network / server.h
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel Team                             *
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) any later version.                                   *
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 _SERVER_H_
22 #define _SERVER_H_
23
24 #include <QtCore>
25 #include <QTimer>
26 #include <QtNetwork>
27
28 #include "quassel.h"
29
30 #define DEFAULT_PORT 6667
31
32 /*! \file */
33
34 /*! \class Server
35  * This is a server object, managing a single connection to an IRC server, handling the associated channels and so on.
36  * We have this run in its own thread mainly to not block other server objects or the core if something goes wrong,
37  * e.g. if some scripts starts running wild...
38  */
39
40 class Server : public QThread {
41   Q_OBJECT
42
43   public:
44     Server();
45     ~Server();
46     static void init();
47
48     void run();
49
50     // serverState state();
51     bool isConnected() { return socket.state() == QAbstractSocket::ConnectedState; }
52
53   public slots:
54     // void setServerOptions();
55     void connectToIrc(const QString &host, quint16 port = DEFAULT_PORT);
56     void disconnectFromIrc();
57
58     void putRawLine(QString input);
59     void putCmd(QString cmd, QStringList params, QString prefix = 0);
60
61   signals:
62     //void outputLine(const QString & /*, Buffer *target = 0 */);
63
64     void recvRawServerMsg(QString);
65     void recvLine(QString); // temp, should send a message to the GUI
66
67   private slots:
68     void socketHasData();
69     void socketError(QAbstractSocket::SocketError);
70     void socketConnected();
71     void socketDisconnected();
72     void socketStateChanged(QAbstractSocket::SocketState);
73
74     /* Message Handlers */
75     /* handleXxxxFromServer(QString prefix, QStringList params); */
76     void handleNoticeFromServer(QString, QStringList);
77     void handlePingFromServer(QString, QStringList);
78
79     void defaultHandlerForServer(QString cmd, QString prefix, QStringList params);
80
81   private:
82     QTcpSocket socket;
83     QTextStream stream;
84
85     void handleServerMsg(QString rawMsg);
86     void handleUserMsg(QString usrMsg);
87     //static inline void dispatchServerMsg(Message *msg) { msg->getServer()->handleServerMsg(msg); }
88     //static inline void dispatchUserMsg(Message *msg)   { msg->getServer()->handleUserMsg(msg); }
89
90     class ParseError : public Exception {
91       public:
92         ParseError(QString cmd, QString prefix, QStringList params);
93     };
94
95     class UnknownCmdError : public Exception {
96       public:
97         UnknownCmdError(QString cmd, QString prefix, QStringList params);
98     };
99 };
100
101 class Buffer {};
102
103
104 #endif