1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #ifndef _CORESESSION_H_
22 #define _CORESESSION_H_
27 #include "corecoreinfo.h"
31 class CoreBacklogManager;
32 class CoreBufferViewManager;
33 class CoreIrcListHelper;
35 class NetworkConnection;
42 class CoreSession : public QObject {
46 CoreSession(UserId, bool restoreState, QObject *parent = 0);
49 QList<BufferInfo> buffers() const;
51 CoreNetwork *network(NetworkId) const;
52 NetworkConnection *networkConnection(NetworkId) const;
53 Identity *identity(IdentityId) const;
55 QVariant sessionState();
57 SignalProxy *signalProxy() const;
59 inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; }
61 void attachNetworkConnection(NetworkConnection *conn);
63 //! Return necessary data for restoring the session after restarting the core
64 void saveSessionState() const;
65 void restoreSessionState();
68 void networkStateRequested();
70 void addClient(QObject *socket);
72 void connectToNetwork(NetworkId);
73 void disconnectFromNetwork(NetworkId id);
75 void msgFromClient(BufferInfo, QString message);
77 //! Create an identity and propagate the changes to the clients.
78 /** \param identity The identity to be created.
80 void createIdentity(const Identity &identity);
82 //! Update an identity and propagate the changes to the clients.
83 /** \param identity The identity to be updated.
85 void updateIdentity(const Identity &identity);
87 //! Remove identity and propagate that fact to the clients.
88 /** \param identity The identity to be removed.
90 void removeIdentity(IdentityId identity);
92 //! Create a network and propagate the changes to the clients.
93 /** \param info The network's settings.
95 void createNetwork(const NetworkInfo &info);
97 //! Update a network and propagate the changes to the clients.
98 /** \param info The updated network settings.
100 void updateNetwork(const NetworkInfo &info);
102 //! Remove identity and propagate that fact to the clients.
103 /** \param identity The identity to be removed.
105 void removeNetwork(NetworkId network);
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.
111 void removeBufferRequested(BufferId bufferId);
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.
119 void renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName);
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;
128 //void msgFromGui(uint netid, QString buf, QString message);
129 void displayMsg(Message message);
130 void displayStatusMsg(QString, QString);
132 //void connectToIrc(QString net);
133 //void disconnectFromIrc(QString net);
135 void bufferInfoUpdated(BufferInfo);
137 void scriptResult(QString result);
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.
143 void identityCreated(const Identity &identity);
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.
149 void identityRemoved(IdentityId identity);
151 void networkCreated(NetworkId);
152 void networkRemoved(NetworkId);
153 void bufferRemoved(BufferId);
154 void bufferRenamed(BufferId, QString);
157 void removeClient(QIODevice *dev);
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);
164 void destroyNetwork(NetworkId);
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
171 void updateBufferInfo(UserId user, const BufferInfo &bufferInfo);
173 void storeBufferLastSeenMsg(BufferId buffer, const MsgId &msgId);
175 void scriptRequest(QString script);
179 void initScriptEngine();
183 SignalProxy *_signalProxy;
184 QHash<NetworkId, NetworkConnection *> _connections;
185 QHash<NetworkId, CoreNetwork *> _networks;
186 // QHash<NetworkId, CoreNetwork *> _networksToRemove;
187 QHash<IdentityId, Identity *> _identities;
189 BufferSyncer *_bufferSyncer;
190 CoreBacklogManager *_backlogManager;
191 CoreBufferViewManager *_bufferViewManager;
192 CoreIrcListHelper *_ircListHelper;
193 CoreCoreInfo _coreInfo;
195 QScriptEngine *scriptEngine;