The Quassel Core now remembers on exit which networks where connected and which channels
[quassel.git] / src / core / server.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC 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) 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 _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, NetworkId networkId, QString network, const QVariant &previousState = QVariant());
52   ~Server();
53
54   UserId userId() const { return _userId; } 
55
56   // serverState state();
57   bool isConnected() const { return socket.state() == QAbstractSocket::ConnectedState; }
58
59   NetworkId networkId() const;
60   QString networkName() const;  // hasbeen getNetwork()
61
62   NetworkInfo *networkInfo() const { return _networkInfo; }
63   IrcServerHandler *ircServerHandler() const { return _ircServerHandler; }
64   UserInputHandler *userInputHandler() const { return _userInputHandler; }
65   CtcpHandler *ctcpHandler() const { return _ctcpHandler; }
66
67   QVariant state(); ///< Return data necessary to restore the server's state upon core restart
68   
69 public slots:
70   // void setServerOptions();
71   void connectToIrc(QString net);
72   void disconnectFromIrc(QString net);
73   void userInput(uint netid, QString buffer, QString msg);
74
75   void putRawLine(QString input);
76   void putCmd(QString cmd, QStringList params, QString prefix = 0);
77
78
79 private slots:
80   void threadFinished();
81   void sendPerform();
82
83 signals:
84   void serverState(QString net, QVariantMap data);
85   void recvRawServerMsg(QString);
86   void displayStatusMsg(QString);
87   //void displayMsg(Message msg);
88   void displayMsg(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
89   void connected(uint networkId);
90   void disconnected(uint networkId);
91
92   void connectionInitialized(); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
93
94   void synchronizeClients();
95   
96   void queryRequested(QString network, QString nick);
97
98
99 private slots:
100   void run();
101   void socketHasData();
102   void socketError(QAbstractSocket::SocketError);
103   void socketConnected();
104   void socketStateChanged(QAbstractSocket::SocketState);
105
106 private:
107   UserId _userId;
108   NetworkId _networkId;
109
110   QTcpSocket socket;
111
112   IrcServerHandler *_ircServerHandler;
113   UserInputHandler *_userInputHandler;
114   CtcpHandler *_ctcpHandler;
115
116   NetworkInfo *_networkInfo;
117
118   QVariantMap networkSettings;
119   QVariantMap identity;
120
121   QVariant _previousState;
122
123   CoreSession *coreSession() const;
124   
125   class ParseError : public Exception {
126   public:
127     ParseError(QString cmd, QString prefix, QStringList params);
128   };
129
130   class UnknownCmdError : public Exception {
131   public:
132     UnknownCmdError(QString cmd, QString prefix, QStringList params);
133   };
134     
135 };
136
137 #endif