- implemented on request a chat monitor: a simple buffer which shows
[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 Identity;
30 class NetworkConnection;  // FIXME get rid of
31 class Network;
32 class SignalProxy;
33
34 class QScriptEngine;
35
36 class CoreSession : public QObject {
37   Q_OBJECT
38
39 public:
40   CoreSession(UserId, bool restoreState, QObject *parent = 0);
41   ~CoreSession();
42
43   QList<BufferInfo> buffers() const;
44   UserId user() const;
45   Network *network(NetworkId) const;
46   NetworkConnection *networkConnection(NetworkId) const;
47   Identity *identity(IdentityId) const;
48
49   QVariant sessionState();
50
51   //! Retrieve a piece of session-wide data.
52   QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
53
54   SignalProxy *signalProxy() const;
55
56   void attachNetworkConnection(NetworkConnection *conn);
57
58   //! Return necessary data for restoring the session after restarting the core
59   void saveSessionState() const;
60   void restoreSessionState();
61
62 public slots:
63   //! Store a piece session-wide data and distribute it to connected clients.
64   void storeSessionData(const QString &key, const QVariant &data);
65
66   void networkStateRequested();
67
68   void addClient(QObject *socket);
69
70   void connectToNetwork(QString, const QVariant &previousState = QVariant());
71   void connectToNetwork(NetworkId, const QVariant &previousState = QVariant());
72   void disconnectFromNetwork(NetworkId id);
73
74   //void processSignal(ClientSignal, QVariant, QVariant, QVariant);
75   void sendBacklog(BufferInfo, QVariant, QVariant);
76   void msgFromClient(BufferInfo, QString message);
77
78   //! Create an identity and propagate the changes to the clients.
79   /** \param identity The identity to be created.
80    */
81   void createIdentity(const Identity &identity);
82
83   //! Update an identity and propagate the changes to the clients.
84   /** \param identity The identity to be updated.
85    */
86   void updateIdentity(const Identity &identity);
87
88   //! Remove identity and propagate that fact to the clients.
89   /** \param identity The identity to be removed.
90    */
91   void removeIdentity(IdentityId identity);
92
93 signals:
94   void initialized();
95
96   //void msgFromGui(uint netid, QString buf, QString message);
97   void displayMsg(Message message);
98   void displayStatusMsg(QString, QString);
99
100   //void connectToIrc(QString net);
101   //void disconnectFromIrc(QString net);
102
103   void backlogData(BufferInfo, QVariantList, bool done);
104
105   void bufferInfoUpdated(BufferInfo);
106   void sessionDataChanged(const QString &key);
107   void sessionDataChanged(const QString &key, const QVariant &data);
108
109   void scriptResult(QString result);
110
111   //! Identity has been created.
112   /** This signal is propagated to the clients to tell them that the given identity has been created.
113    *  \param identity The new identity.
114    */
115   void identityCreated(const Identity &identity);
116
117   //! Identity has been removed.
118   /** This signal is propagated to the clients to inform them about the removal of the given identity.
119    *  \param identity The identity that has been removed.
120    */
121   void identityRemoved(IdentityId identity);
122
123 private slots:
124   void recvStatusMsgFromServer(QString msg);
125   void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
126   void networkConnected(NetworkId networkid);
127   void networkDisconnected(NetworkId networkid);
128
129   //! Called when storage updated a BufferInfo.
130   /** This emits bufferInfoUpdated() via SignalProxy, iff it's one of our buffers.
131    *  \param user       The buffer's owner (not necessarily us)
132    *  \param bufferInfo The updated BufferInfo
133    */
134   void updateBufferInfo(UserId user, const BufferInfo &bufferInfo);
135
136   void scriptRequest(QString script);
137
138 private:
139   void initScriptEngine();
140
141   UserId _user;
142
143   SignalProxy *_signalProxy;
144   QHash<NetworkId, NetworkConnection *> _connections;
145   QHash<NetworkId, Network *> _networks;
146   QHash<IdentityId, Identity *> _identities;
147
148   QVariantMap sessionData;
149
150   QScriptEngine *scriptEngine;
151
152 };
153
154 #endif