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