51c14a7225cf4f314b6fed9b8aaf8aae3bdcdfdb
[quassel.git] / src / core / coresession.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 _CORESESSION_H_
22 #define _CORESESSION_H_
23
24 #include <QString>
25 #include <QVariant>
26
27 #include "message.h"
28
29 class Identity;
30 class NetworkConnection;
31 class Network;
32 struct NetworkInfo;
33 class SignalProxy;
34
35 class QScriptEngine;
36
37 class CoreSession : public QObject {
38   Q_OBJECT
39
40 public:
41   CoreSession(UserId, bool restoreState, QObject *parent = 0);
42   ~CoreSession();
43
44   QList<BufferInfo> buffers() const;
45   UserId user() const;
46   Network *network(NetworkId) const;
47   NetworkConnection *networkConnection(NetworkId) const;
48   Identity *identity(IdentityId) const;
49
50   QVariant sessionState();
51
52   SignalProxy *signalProxy() const;
53
54   void attachNetworkConnection(NetworkConnection *conn);
55
56   //! Return necessary data for restoring the session after restarting the core
57   void saveSessionState() const;
58   void restoreSessionState();
59
60 public slots:
61   void networkStateRequested();
62
63   void addClient(QObject *socket);
64
65   void connectToNetwork(QString, const QVariant &previousState = QVariant());
66   void connectToNetwork(NetworkId, const QVariant &previousState = QVariant());
67   void disconnectFromNetwork(NetworkId id);
68
69   //void processSignal(ClientSignal, QVariant, QVariant, QVariant);
70   void sendBacklog(BufferInfo, QVariant, QVariant);
71   void msgFromClient(BufferInfo, QString message);
72
73   //! Create an identity and propagate the changes to the clients.
74   /** \param identity The identity to be created.
75    */
76   void createIdentity(const Identity &identity);
77
78   //! Update an identity and propagate the changes to the clients.
79   /** \param identity The identity to be updated.
80    */
81   void updateIdentity(const Identity &identity);
82
83   //! Remove identity and propagate that fact to the clients.
84   /** \param identity The identity to be removed.
85    */
86   void removeIdentity(IdentityId identity);
87
88   //! Create a network and propagate the changes to the clients.
89   /** \param info The network's settings.
90    */
91   void createNetwork(const NetworkInfo &info);
92
93   //! Update a network and propagate the changes to the clients.
94   /** \param info The updated network settings.
95    */
96   void updateNetwork(const NetworkInfo &info);
97
98   //! Remove identity and propagate that fact to the clients.
99   /** \param identity The identity to be removed.
100    */
101   void removeNetwork(NetworkId network);
102
103 signals:
104   void initialized();
105
106   //void msgFromGui(uint netid, QString buf, QString message);
107   void displayMsg(Message message);
108   void displayStatusMsg(QString, QString);
109
110   //void connectToIrc(QString net);
111   //void disconnectFromIrc(QString net);
112
113   void backlogData(BufferInfo, QVariantList, bool done);
114
115   void bufferInfoUpdated(BufferInfo);
116
117   void scriptResult(QString result);
118
119   //! Identity has been created.
120   /** This signal is propagated to the clients to tell them that the given identity has been created.
121    *  \param identity The new identity.
122    */
123   void identityCreated(const Identity &identity);
124
125   //! Identity has been removed.
126   /** This signal is propagated to the clients to inform them about the removal of the given identity.
127    *  \param identity The identity that has been removed.
128    */
129   void identityRemoved(IdentityId identity);
130
131   void networkCreated(NetworkId);
132   void networkRemoved(NetworkId);
133
134 private slots:
135   void recvStatusMsgFromServer(QString msg);
136   void recvMessageFromServer(Message::Type, BufferInfo::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
137   void networkConnected(NetworkId networkid);
138   void networkDisconnected(NetworkId networkid);
139
140   void destroyNetwork(NetworkId);
141
142   //! Called when storage updated a BufferInfo.
143   /** This emits bufferInfoUpdated() via SignalProxy, iff it's one of our buffers.
144    *  \param user       The buffer's owner (not necessarily us)
145    *  \param bufferInfo The updated BufferInfo
146    */
147   void updateBufferInfo(UserId user, const BufferInfo &bufferInfo);
148
149   void scriptRequest(QString script);
150
151 private:
152   void loadSettings();
153   void initScriptEngine();
154
155   UserId _user;
156
157   SignalProxy *_signalProxy;
158   QHash<NetworkId, NetworkConnection *> _connections;
159   QHash<NetworkId, Network *> _networks;
160   QHash<NetworkId, Network *> _networksToRemove;
161   QHash<IdentityId, Identity *> _identities;
162
163   QScriptEngine *scriptEngine;
164
165 };
166
167 #endif