This is the long-awaited monster commit, bringing you a redesigned core arch and...
[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, 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   QVariant state() const;
60   void restoreState(const QVariant &previousState);
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
73   //void processSignal(ClientSignal, QVariant, QVariant, QVariant);
74   void sendBacklog(BufferInfo, QVariant, QVariant);
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 signals:
93   void initialized();
94
95   //void msgFromGui(uint netid, QString buf, QString message);
96   void displayMsg(Message message);
97   void displayStatusMsg(QString, QString);
98
99   //void connectToIrc(QString net);
100   //void disconnectFromIrc(QString net);
101
102   void backlogData(BufferInfo, QVariantList, bool done);
103
104   void bufferInfoUpdated(BufferInfo);
105   void sessionDataChanged(const QString &key);
106   void sessionDataChanged(const QString &key, const QVariant &data);
107
108   void scriptResult(QString result);
109
110   //! Identity has been created.
111   /** This signal is propagated to the clients to tell them that the given identity has been created.
112    *  \param identity The new identity.
113    */
114   void identityCreated(const Identity &identity);
115
116   //! Identity has been removed.
117   /** This signal is propagated to the clients to inform them about the removal of the given identity.
118    *  \param identity The identity that has been removed.
119    */
120   void identityRemoved(IdentityId identity);
121
122 private slots:
123   void recvStatusMsgFromServer(QString msg);
124   void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
125   void networkConnected(uint networkid);
126   void networkDisconnected(uint networkid);
127
128   //! Called when storage updated a BufferInfo.
129   /** This emits bufferInfoUpdated() via SignalProxy, iff it's one of our buffers.
130    *  \param user       The buffer's owner (not necessarily us)
131    *  \param bufferInfo The updated BufferInfo
132    */
133   void updateBufferInfo(UserId user, const BufferInfo &bufferInfo);
134
135   void scriptRequest(QString script);
136
137 private:
138   void initScriptEngine();
139
140   UserId _user;
141
142   SignalProxy *_signalProxy;
143   QHash<NetworkId, NetworkConnection *> _connections;
144   QHash<NetworkId, Network *> _networks;
145   QHash<IdentityId, Identity *> _identities;
146
147   QVariantMap sessionData;
148
149   QScriptEngine *scriptEngine;
150
151 };
152
153 #endif