Moving branches/0.3 to trunk
[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 CoreBacklogManager;
31 class CoreBufferViewManager;
32 class Identity;
33 class NetworkConnection;
34 class Network;
35 struct NetworkInfo;
36 class SignalProxy;
37
38 class QScriptEngine;
39
40 class CoreSession : public QObject {
41   Q_OBJECT
42
43 public:
44   CoreSession(UserId, bool restoreState, QObject *parent = 0);
45   ~CoreSession();
46
47   QList<BufferInfo> buffers() const;
48   UserId user() const;
49   Network *network(NetworkId) const;
50   NetworkConnection *networkConnection(NetworkId) const;
51   Identity *identity(IdentityId) const;
52
53   QVariant sessionState();
54
55   SignalProxy *signalProxy() const;
56
57   void attachNetworkConnection(NetworkConnection *conn);
58
59   //! Return necessary data for restoring the session after restarting the core
60   void saveSessionState() const;
61   void restoreSessionState();
62
63 public slots:
64   void networkStateRequested();
65
66   void addClient(QObject *socket);
67
68   void connectToNetwork(NetworkId);
69   void disconnectFromNetwork(NetworkId id);
70
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   //! Remove a buffer and it's backlog permanently
104   /** \param bufferId The id of the buffer to be removed.
105    *  emits bufferRemoved(bufferId) on success.
106    */
107   void removeBufferRequested(BufferId bufferId);
108
109   //! Rename a Buffer for a given network
110   /* \param networkId The id of the network the buffer belongs to
111    * \param newName   The new name of the buffer
112    * \param oldName   The old name of the buffer
113    * emits bufferRenamed(bufferId, newName) on success.
114    */
115   void renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName);
116
117   void channelJoined(NetworkId id, const QString &channel, const QString &key = QString());
118   void channelParted(NetworkId, const QString &channel);
119   QHash<QString, QString> persistentChannels(NetworkId) const;
120
121 signals:
122   void initialized();
123
124   //void msgFromGui(uint netid, QString buf, QString message);
125   void displayMsg(Message message);
126   void displayStatusMsg(QString, QString);
127
128   //void connectToIrc(QString net);
129   //void disconnectFromIrc(QString net);
130
131   void bufferInfoUpdated(BufferInfo);
132
133   void scriptResult(QString result);
134
135   //! Identity has been created.
136   /** This signal is propagated to the clients to tell them that the given identity has been created.
137    *  \param identity The new identity.
138    */
139   void identityCreated(const Identity &identity);
140
141   //! Identity has been removed.
142   /** This signal is propagated to the clients to inform them about the removal of the given identity.
143    *  \param identity The identity that has been removed.
144    */
145   void identityRemoved(IdentityId identity);
146
147   void networkCreated(NetworkId);
148   void networkRemoved(NetworkId);
149   void bufferRemoved(BufferId);
150   void bufferRenamed(BufferId, QString);
151
152 private slots:
153   void removeClient(QIODevice *dev);
154
155   void recvStatusMsgFromServer(QString msg);
156   void recvMessageFromServer(Message::Type, BufferInfo::Type, QString target, QString text, QString sender = "", Message::Flags flags = Message::None);
157   void networkConnected(NetworkId networkid);
158   void networkDisconnected(NetworkId networkid);
159
160   void destroyNetwork(NetworkId);
161
162   //! Called when storage updated a BufferInfo.
163   /** This emits bufferInfoUpdated() via SignalProxy, iff it's one of our buffers.
164    *  \param user       The buffer's owner (not necessarily us)
165    *  \param bufferInfo The updated BufferInfo
166    */
167   void updateBufferInfo(UserId user, const BufferInfo &bufferInfo);
168
169   void storeBufferLastSeenMsg(BufferId buffer, const MsgId &msgId);
170
171   void scriptRequest(QString script);
172
173 private:
174   void loadSettings();
175   void initScriptEngine();
176
177   UserId _user;
178
179   SignalProxy *_signalProxy;
180   QHash<NetworkId, NetworkConnection *> _connections;
181   QHash<NetworkId, Network *> _networks;
182   QHash<NetworkId, Network *> _networksToRemove;
183   QHash<IdentityId, Identity *> _identities;
184
185   BufferSyncer *_bufferSyncer;
186   CoreBacklogManager *_backlogManager;
187   CoreBufferViewManager *_bufferViewManager;
188
189   QScriptEngine *scriptEngine;
190
191 };
192
193 #endif