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_
31 class NetworkConnection;
38 class CoreSession : public QObject {
42 CoreSession(UserId, bool restoreState, QObject *parent = 0);
45 QList<BufferInfo> buffers() const;
47 Network *network(NetworkId) const;
48 NetworkConnection *networkConnection(NetworkId) const;
49 Identity *identity(IdentityId) const;
51 QVariant sessionState();
53 SignalProxy *signalProxy() const;
55 void attachNetworkConnection(NetworkConnection *conn);
57 //! Return necessary data for restoring the session after restarting the core
58 void saveSessionState() const;
59 void restoreSessionState();
62 void networkStateRequested();
64 void addClient(QObject *socket);
66 // void connectToNetwork(QString, const QVariant &previousState = QVariant());
67 void connectToNetwork(NetworkId);
68 void disconnectFromNetwork(NetworkId id);
70 //void processSignal(ClientSignal, QVariant, QVariant, QVariant);
71 void sendBacklog(BufferInfo, QVariant, QVariant);
72 void msgFromClient(BufferInfo, QString message);
74 //! Create an identity and propagate the changes to the clients.
75 /** \param identity The identity to be created.
77 void createIdentity(const Identity &identity);
79 //! Update an identity and propagate the changes to the clients.
80 /** \param identity The identity to be updated.
82 void updateIdentity(const Identity &identity);
84 //! Remove identity and propagate that fact to the clients.
85 /** \param identity The identity to be removed.
87 void removeIdentity(IdentityId identity);
89 //! Create a network and propagate the changes to the clients.
90 /** \param info The network's settings.
92 void createNetwork(const NetworkInfo &info);
94 //! Update a network and propagate the changes to the clients.
95 /** \param info The updated network settings.
97 void updateNetwork(const NetworkInfo &info);
99 //! Remove identity and propagate that fact to the clients.
100 /** \param identity The identity to be removed.
102 void removeNetwork(NetworkId network);
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.
108 void removeBufferRequested(BufferId bufferId);
110 //! Rename a Buffer for a given network
111 /* \param networkId The id of the network the buffer belongs to
112 * \param newName The new name of the buffer
113 * \param oldName The old name of the buffer
114 * emits bufferRenamed(bufferId, newName) on success.
116 void renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName);
121 //void msgFromGui(uint netid, QString buf, QString message);
122 void displayMsg(Message message);
123 void displayStatusMsg(QString, QString);
125 //void connectToIrc(QString net);
126 //void disconnectFromIrc(QString net);
128 void backlogData(BufferInfo, QVariantList, bool done);
130 void bufferInfoUpdated(BufferInfo);
132 void scriptResult(QString result);
134 //! Identity has been created.
135 /** This signal is propagated to the clients to tell them that the given identity has been created.
136 * \param identity The new identity.
138 void identityCreated(const Identity &identity);
140 //! Identity has been removed.
141 /** This signal is propagated to the clients to inform them about the removal of the given identity.
142 * \param identity The identity that has been removed.
144 void identityRemoved(IdentityId identity);
146 void networkCreated(NetworkId);
147 void networkRemoved(NetworkId);
148 void bufferRemoved(BufferId);
149 void bufferRenamed(BufferId, QString);
152 void recvStatusMsgFromServer(QString msg);
153 void recvMessageFromServer(Message::Type, BufferInfo::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
154 void networkConnected(NetworkId networkid);
155 void networkDisconnected(NetworkId networkid);
157 void destroyNetwork(NetworkId);
159 //! Called when storage updated a BufferInfo.
160 /** This emits bufferInfoUpdated() via SignalProxy, iff it's one of our buffers.
161 * \param user The buffer's owner (not necessarily us)
162 * \param bufferInfo The updated BufferInfo
164 void updateBufferInfo(UserId user, const BufferInfo &bufferInfo);
166 void storeBufferLastSeen(BufferId buffer, const QDateTime &lastSeen);
168 void scriptRequest(QString script);
172 void initScriptEngine();
176 SignalProxy *_signalProxy;
177 QHash<NetworkId, NetworkConnection *> _connections;
178 QHash<NetworkId, Network *> _networks;
179 QHash<NetworkId, Network *> _networksToRemove;
180 QHash<IdentityId, Identity *> _identities;
182 BufferSyncer *_bufferSyncer;
184 QScriptEngine *scriptEngine;