Fixed those nasty "Client::updateLastSeen(): Unknown buffer $bufferId" messages.
[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(NetworkId);
67   void disconnectFromNetwork(NetworkId id);
68
69   void sendBacklog(BufferInfo, QVariant, QVariant);
70   void msgFromClient(BufferInfo, QString message);
71
72   //! Create an identity and propagate the changes to the clients.
73   /** \param identity The identity to be created.
74    */
75   void createIdentity(const Identity &identity);
76
77   //! Update an identity and propagate the changes to the clients.
78   /** \param identity The identity to be updated.
79    */
80   void updateIdentity(const Identity &identity);
81
82   //! Remove identity and propagate that fact to the clients.
83   /** \param identity The identity to be removed.
84    */
85   void removeIdentity(IdentityId identity);
86
87   //! Create a network and propagate the changes to the clients.
88   /** \param info The network's settings.
89    */
90   void createNetwork(const NetworkInfo &info);
91
92   //! Update a network and propagate the changes to the clients.
93   /** \param info The updated network settings.
94    */
95   void updateNetwork(const NetworkInfo &info);
96
97   //! Remove identity and propagate that fact to the clients.
98   /** \param identity The identity to be removed.
99    */
100   void removeNetwork(NetworkId network);
101
102   //! Remove a buffer and it's backlog permanently
103   /** \param bufferId The id of the buffer to be removed.
104    *  emits bufferRemoved(bufferId) on success.
105    */
106   void removeBufferRequested(BufferId bufferId);
107
108   //! Rename a Buffer for a given network
109   /* \param networkId The id of the network the buffer belongs to
110    * \param newName   The new name of the buffer
111    * \param oldName   The old name of the buffer
112    * emits bufferRenamed(bufferId, newName) on success.
113    */
114   void renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName);
115
116   void channelJoined(NetworkId id, const QString &channel, const QString &key = QString());
117   void channelParted(NetworkId, const QString &channel);
118   QHash<QString, QString> persistentChannels(NetworkId) const;
119
120 signals:
121   void initialized();
122
123   //void msgFromGui(uint netid, QString buf, QString message);
124   void displayMsg(Message message);
125   void displayStatusMsg(QString, QString);
126
127   //void connectToIrc(QString net);
128   //void disconnectFromIrc(QString net);
129
130   void backlogData(BufferInfo, QVariantList, bool done);
131
132   void bufferInfoUpdated(BufferInfo);
133
134   void scriptResult(QString result);
135
136   //! Identity has been created.
137   /** This signal is propagated to the clients to tell them that the given identity has been created.
138    *  \param identity The new identity.
139    */
140   void identityCreated(const Identity &identity);
141
142   //! Identity has been removed.
143   /** This signal is propagated to the clients to inform them about the removal of the given identity.
144    *  \param identity The identity that has been removed.
145    */
146   void identityRemoved(IdentityId identity);
147
148   void networkCreated(NetworkId);
149   void networkRemoved(NetworkId);
150   void bufferRemoved(BufferId);
151   void bufferRenamed(BufferId, QString);
152
153 private slots:
154   void recvStatusMsgFromServer(QString msg);
155   void recvMessageFromServer(Message::Type, BufferInfo::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
156   void networkConnected(NetworkId networkid);
157   void networkDisconnected(NetworkId networkid);
158
159   void destroyNetwork(NetworkId);
160
161   //! Called when storage updated a BufferInfo.
162   /** This emits bufferInfoUpdated() via SignalProxy, iff it's one of our buffers.
163    *  \param user       The buffer's owner (not necessarily us)
164    *  \param bufferInfo The updated BufferInfo
165    */
166   void updateBufferInfo(UserId user, const BufferInfo &bufferInfo);
167
168   void storeBufferLastSeen(BufferId buffer, const QDateTime &lastSeen);
169
170   void scriptRequest(QString script);
171
172 private:
173   void loadSettings();
174   void initScriptEngine();
175
176   UserId _user;
177
178   SignalProxy *_signalProxy;
179   QHash<NetworkId, NetworkConnection *> _connections;
180   QHash<NetworkId, Network *> _networks;
181   QHash<NetworkId, Network *> _networksToRemove;
182   QHash<IdentityId, Identity *> _identities;
183
184   BufferSyncer *_bufferSyncer;
185
186   QScriptEngine *scriptEngine;
187
188 };
189
190 #endif