Since we're going for one grand unified model to store all the stuff
[quassel.git] / src / core / coresession.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
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 Server;
31 class SignalProxy;
32 class Storage;
33
34 class QScriptEngine;
35
36 class CoreSession : public QObject {
37   Q_OBJECT
38
39 public:
40   CoreSession(UserId, Storage *, QObject *parent = 0);
41   virtual ~CoreSession();
42
43   NetworkId getNetworkId(const QString &network) const;
44   QList<BufferInfo> buffers() const;
45   UserId userId() const;
46   QVariant sessionState();
47
48   //! Retrieve a piece of session-wide data.
49   QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
50
51   SignalProxy *signalProxy() const;
52
53   void attachServer(Server *server);
54
55   //! Return necessary data for restoring the session after restarting the core
56   QVariant state() const;
57   void restoreState(const QVariant &previousState);
58
59 public slots:
60   //! Store a piece session-wide data and distribute it to connected clients.
61   void storeSessionData(const QString &key, const QVariant &data);
62
63   void serverStateRequested();
64
65   void addClient(QIODevice *connection);
66
67   void connectToNetwork(QString, const QVariant &previousState = QVariant());
68   //void connectToNetwork(NetworkId);
69
70   //void processSignal(ClientSignal, QVariant, QVariant, QVariant);
71   void sendBacklog(BufferInfo, QVariant, QVariant);
72   void msgFromGui(BufferInfo, QString message);
73
74 signals:
75   void msgFromGui(uint netid, QString buf, QString message);
76   void displayMsg(Message message);
77   void displayStatusMsg(QString, QString);
78
79   void connectToIrc(QString net);
80   void disconnectFromIrc(QString net);
81
82   void backlogData(BufferInfo, QVariantList, bool done);
83
84   void bufferInfoUpdated(BufferInfo);
85   void sessionDataChanged(const QString &key);
86   void sessionDataChanged(const QString &key, const QVariant &data);
87
88   void scriptResult(QString result);
89                                    
90 private slots:
91   void recvStatusMsgFromServer(QString msg);
92   void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
93   void serverConnected(uint networkid);
94   void serverDisconnected(uint networkid);
95
96   void scriptRequest(QString script);
97   
98 private:
99   void initScriptEngine();
100   
101   UserId user;
102   
103   SignalProxy *_signalProxy;
104   Storage *storage;
105   QHash<NetworkId, Server *> servers;
106   
107   QVariantMap sessionData;
108   QMutex mutex;
109
110   QScriptEngine *scriptEngine;
111 };
112
113 #endif