66e273546bc20f838947ff1ffb744d2c18321696
[quassel.git] / src / core / coresession.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel IRC Development 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) any later version.                                   *
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 CoreSession : public QObject {
35   Q_OBJECT
36
37   public:
38     CoreSession(UserId, Storage *, QObject *parent = 0);
39     ~CoreSession();
40
41     QList<BufferId> buffers() const;
42     UserId userId() const;
43     QVariant sessionState();
44
45   public slots:
46     //! Store a piece session-wide data and distribute it to connected clients.
47     void storeSessionData(const QString &key, const QVariant &data);
48
49     void addClient(QIODevice *connection);
50
51   public:
52     //! Retrieve a piece of session-wide data.
53     QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
54
55     SignalProxy *signalProxy() const;
56
57   public slots:
58     void connectToNetwork(QString);
59     //void processSignal(ClientSignal, QVariant, QVariant, QVariant);
60     void sendBacklog(BufferId, QVariant, QVariant);
61     void msgFromGui(BufferId, QString message);
62     void sendServerStates();
63
64   signals:
65     void msgFromGui(QString net, QString buf, QString message);
66     void displayMsg(Message message);
67     void displayStatusMsg(QString, QString);
68
69     void connectToIrc(QString net);
70     void disconnectFromIrc(QString net);
71     void serverStateRequested();
72
73     void backlogData(BufferId, QVariantList, bool done);
74
75     void bufferIdUpdated(BufferId);
76     void sessionDataChanged(const QString &key);
77     void sessionDataChanged(const QString &key, const QVariant &data);
78
79   private slots:
80     void recvStatusMsgFromServer(QString msg);
81     void recvMessageFromServer(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
82     void serverConnected(QString net);
83     void serverDisconnected(QString net);
84
85   private:
86     UserId user;
87
88    SignalProxy *_signalProxy;
89     Storage *storage;
90     QHash<QString, Server *> servers;
91
92     QVariantMap sessionData;
93     QMutex mutex;
94 };
95
96 #endif