Ok, things should be working again. Note to select modules, you now have to
[quassel.git] / src / client / client.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) 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 _CLIENT_H_
22 #define _CLIENT_H_
23
24 #include <QAbstractSocket>
25 #include <QTcpSocket>
26 #include <QList>
27 #include <QPointer>
28
29 #include "buffer.h" // needed for activity lvl
30 class BufferInfo;
31 class Message;
32
33 class NetworkInfo;
34
35
36 class AbstractUi;
37 class AbstractUiMsg;
38 class BufferTreeModel;
39 class SignalProxy;
40
41 class QTimer;
42
43
44 class Client : public QObject {
45   Q_OBJECT
46
47 public:
48   static Client *instance();
49   static void destroy();
50   static void init(AbstractUi *);
51
52   static QList<NetworkInfo *> networkInfos();
53   static NetworkInfo *networkInfo(uint networkid);
54   
55   static QList<BufferInfo> allBufferInfos();
56   static QList<Buffer *> buffers();
57   static Buffer *buffer(uint bufferUid);
58   static Buffer *buffer(BufferInfo);
59   static BufferInfo statusBufferInfo(QString net);
60   static BufferInfo bufferInfo(QString net, QString buf);
61
62   static BufferTreeModel *bufferModel();
63   static SignalProxy *signalProxy();
64
65   static AbstractUiMsg *layoutMsg(const Message &);
66
67   static bool isConnected();
68
69   static void storeSessionData(const QString &key, const QVariant &data);
70   static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
71   static QStringList sessionDataKeys();
72
73   enum ClientMode { LocalCore, RemoteCore };
74
75 signals:
76   void sendInput(BufferInfo, QString message);
77   void showBuffer(Buffer *);
78   void bufferSelected(Buffer *);
79   void bufferUpdated(Buffer *);
80   void bufferActivity(Buffer::ActivityLevel, Buffer *);
81   void bufferDestroyed(Buffer *);
82   void backlogReceived(Buffer *, QList<Message>);
83   void requestBacklog(BufferInfo, QVariant, QVariant);
84   void requestNetworkStates();
85
86   void recvPartialItem(uint avail, uint size);
87   void coreConnectionError(QString errorMsg);
88   void coreConnectionMsg(const QString &msg);
89   void coreConnectionProgress(uint part, uint total);
90
91   void connected();
92   void disconnected();
93
94   void sessionDataChanged(const QString &key);
95   void sessionDataChanged(const QString &key, const QVariant &data);
96   void sendSessionData(const QString &key, const QVariant &data);
97
98 public slots:
99   //void selectBuffer(Buffer *);
100   //void connectToLocalCore();
101   void connectToCore(const QVariantMap &);
102   void disconnectFromCore();
103
104 private slots:
105   void recvCoreState(const QVariant &state);
106   void recvSessionData(const QString &key, const QVariant &data);
107
108   void coreSocketError(QAbstractSocket::SocketError);
109   void coreHasData();
110   void coreSocketConnected();
111   void coreSocketDisconnected();
112   void coreSocketStateChanged(QAbstractSocket::SocketState);
113
114   void userInput(BufferInfo, QString);
115
116   void networkConnected(uint);
117   void networkDisconnected(uint);
118
119   void updateCoreConnectionProgress();
120   void recvMessage(const Message &message);
121   void recvStatusMsg(QString network, QString message);
122   void recvBacklogData(BufferInfo, QVariantList, bool);
123   void updateBufferInfo(BufferInfo);
124
125   void removeBuffer(Buffer *);
126
127   void layoutMsg();
128
129 private:
130   Client(QObject *parent = 0);
131   virtual ~Client();
132   void init();
133   
134   void syncToCore(const QVariant &coreState);
135   QVariant connectToLocalCore(QString user, QString passwd);  // defined in main.cpp
136   void disconnectFromLocalCore();                             // defined in main.cpp
137
138   static QPointer<Client> instanceptr;
139   
140   QPointer<QIODevice> socket;
141   QPointer<SignalProxy> _signalProxy;
142   QPointer<AbstractUi> mainUi;
143   QPointer<BufferTreeModel> _bufferModel;
144
145   ClientMode clientMode;
146
147   quint32 blockSize;
148   bool connectedToCore;
149   
150   QVariantMap coreConnectionInfo;
151   QHash<uint, Buffer *> _buffers;
152   QHash<uint, NetworkInfo*> _networkInfo;
153
154   QTimer *layoutTimer;
155   QList<Buffer *> layoutQueue;
156
157   QVariantMap sessionData;
158
159
160 };
161
162 #endif