(no commit message)
[quassel.git] / src / core / 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 <QAbstractSocket>
25 #include <QString>
26 #include <QStringList>
27 #include <QTcpSocket>
28 #include <QThread>
29 #include <QTimer>
30
31 #include "message.h"
32 #include "signalproxy.h"
33
34 class NetworkInfo;
35
36 class IrcServerHandler;
37 class UserInputHandler;
38 class CtcpHandler;
39 class CoreSession;
40
41 /*!
42  * This is a server object, managing a single connection to an IRC server, handling the associated channels and so on.
43  * We have this running in its own thread mainly to not block other server objects or the core if something goes wrong,
44  * e.g. if some scripts starts running wild...
45  */
46
47 class Server : public QThread {
48   Q_OBJECT
49
50 public:
51   Server(UserId uid, uint networkId, QString network);
52   ~Server();
53
54   UserId userId() const { return _userId; } 
55
56   // serverState state();
57   bool isConnected() const { return socket.state() == QAbstractSocket::ConnectedState; }
58
59   uint networkId() const;
60   QString networkName();  // hasbeen getNetwork()
61
62   NetworkInfo *networkInfo() { return _networkInfo; }
63   IrcServerHandler *ircServerHandler() {return _ircServerHandler; }
64   UserInputHandler *userInputHandler() {return _userInputHandler; }
65   CtcpHandler *ctcpHandler() {return _ctcpHandler; }
66   
67 public slots:
68   // void setServerOptions();
69   void connectToIrc(QString net);
70   void disconnectFromIrc(QString net);
71   void userInput(uint netid, QString buffer, QString msg);
72
73   void putRawLine(QString input);
74   void putCmd(QString cmd, QStringList params, QString prefix = 0);
75
76
77 private slots:
78   void threadFinished();
79
80 signals:
81   void serverState(QString net, QVariantMap data);
82   void recvRawServerMsg(QString);
83   void displayStatusMsg(QString);
84   //void displayMsg(Message msg);
85   void displayMsg(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
86   void connected(uint networkId);
87   void disconnected(uint networkId);
88
89   void synchronizeClients();
90   
91   void queryRequested(QString network, QString nick);
92
93
94 private slots:
95   void run();
96   void socketHasData();
97   void socketError(QAbstractSocket::SocketError);
98   void socketConnected();
99   void socketStateChanged(QAbstractSocket::SocketState);
100
101 private:
102   UserId _userId;
103   uint _networkId;
104
105   QTcpSocket socket;
106
107   IrcServerHandler *_ircServerHandler;
108   UserInputHandler *_userInputHandler;
109   CtcpHandler *_ctcpHandler;
110
111   NetworkInfo *_networkInfo;
112
113   QVariantMap networkSettings;
114   QVariantMap identity;
115
116   CoreSession *coreSession() const;
117   
118   class ParseError : public Exception {
119   public:
120     ParseError(QString cmd, QString prefix, QStringList params);
121   };
122
123   class UnknownCmdError : public Exception {
124   public:
125     UnknownCmdError(QString cmd, QString prefix, QStringList params);
126   };
127     
128 };
129
130 #endif