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