Committing a lot of identity stuff which is still disabled.
[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 <QObject>
25 #include <QString>
26 #include <QVariant>
27
28 #include "message.h"
29
30 class Identity;
31 class Server;
32 class SignalProxy;
33 class Storage;
34
35 class QScriptEngine;
36
37 class CoreSession : public QObject {
38   Q_OBJECT
39
40 public:
41   CoreSession(UserId, Storage *, QObject *parent = 0);
42   virtual ~CoreSession();
43
44   NetworkId getNetworkId(const QString &network) const;
45   QList<BufferInfo> buffers() const;
46   UserId userId() const;
47   QVariant sessionState();
48
49   //! Retrieve a piece of session-wide data.
50   QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
51
52   SignalProxy *signalProxy() const;
53
54   void attachServer(Server *server);
55
56   //! Return necessary data for restoring the session after restarting the core
57   QVariant state() const;
58   void restoreState(const QVariant &previousState);
59
60 public slots:
61   //! Store a piece session-wide data and distribute it to connected clients.
62   void storeSessionData(const QString &key, const QVariant &data);
63
64   void serverStateRequested();
65
66   void addClient(QIODevice *connection);
67
68   void connectToNetwork(QString, const QVariant &previousState = QVariant());
69   //void connectToNetwork(NetworkId);
70
71   //void processSignal(ClientSignal, QVariant, QVariant, QVariant);
72   void sendBacklog(BufferInfo, QVariant, QVariant);
73   void msgFromGui(BufferInfo, QString message);
74
75   //! Create an identity and propagate the changes to the clients.
76   /** \param identity The identity to be created.
77    */
78   void createIdentity(const Identity &identity);
79
80   //! Update an identity and propagate the changes to the clients.
81   /** \param identity The identity to be updated.
82    */
83   void updateIdentity(const Identity &identity);
84
85   //! Remove identity and propagate that fact to the clients.
86   /** \param identity The identity to be removed.
87    */
88   void removeIdentity(IdentityId identity);
89
90 signals:
91   void msgFromGui(uint netid, QString buf, QString message);
92   void displayMsg(Message message);
93   void displayStatusMsg(QString, QString);
94
95   void connectToIrc(QString net);
96   void disconnectFromIrc(QString net);
97
98   void backlogData(BufferInfo, QVariantList, bool done);
99
100   void bufferInfoUpdated(BufferInfo);
101   void sessionDataChanged(const QString &key);
102   void sessionDataChanged(const QString &key, const QVariant &data);
103
104   void scriptResult(QString result);
105
106   //! Identity has been created.
107   /** This signal is propagated to the clients to tell them that the given identity has been created.
108    *  \param identity The new identity.
109    */
110   void identityCreated(const Identity &identity);
111
112   //! Identity has been removed.
113   /** This signal is propagated to the clients to inform them about the removal of the given identity.
114    *  \param identity The identity that has been removed.
115    */
116   void identityRemoved(IdentityId identity);
117
118 private slots:
119   void recvStatusMsgFromServer(QString msg);
120   void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
121   void serverConnected(uint networkid);
122   void serverDisconnected(uint networkid);
123
124   void scriptRequest(QString script);
125   
126 private:
127   void initScriptEngine();
128   
129   UserId user;
130   
131   SignalProxy *_signalProxy;
132   Storage *storage;
133   QHash<NetworkId, Server *> servers;
134   
135   QVariantMap sessionData;
136   QMutex mutex;
137
138   QScriptEngine *scriptEngine;
139
140   QHash<IdentityId, Identity *> _identities;
141 };
142
143 #endif