Started to reorganize the Buffer{Model|View|Filter}. Mostly cleanup at the moment.
[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 fakeInput(uint bufferUid, QString message);
70   static void fakeInput(BufferInfo bufferInfo, QString message);
71   
72   static void storeSessionData(const QString &key, const QVariant &data);
73   static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
74   static QStringList sessionDataKeys();
75
76   enum ClientMode { LocalCore, RemoteCore };
77
78 signals:
79   void sendInput(BufferInfo, QString message);
80   void showBuffer(Buffer *);
81   void bufferSelected(Buffer *);
82   void bufferUpdated(Buffer *);
83   void bufferActivity(Buffer::ActivityLevel, Buffer *);
84   void bufferDestroyed(Buffer *);
85   void backlogReceived(Buffer *, QList<Message>);
86   void requestBacklog(BufferInfo, QVariant, QVariant);
87   void requestNetworkStates();
88
89   void recvPartialItem(uint avail, uint size);
90   void coreConnectionError(QString errorMsg);
91   void coreConnectionMsg(const QString &msg);
92   void coreConnectionProgress(uint part, uint total);
93
94   void connected();
95   void disconnected();
96
97   void sessionDataChanged(const QString &key);
98   void sessionDataChanged(const QString &key, const QVariant &data);
99   void sendSessionData(const QString &key, const QVariant &data);
100
101 public slots:
102   //void selectBuffer(Buffer *);
103   //void connectToLocalCore();
104   void connectToCore(const QVariantMap &);
105   void disconnectFromCore();
106
107 private slots:
108   void recvCoreState(const QVariant &state);
109   void recvSessionData(const QString &key, const QVariant &data);
110
111   void coreSocketError(QAbstractSocket::SocketError);
112   void coreHasData();
113   void coreSocketConnected();
114   void coreSocketDisconnected();
115   void coreSocketStateChanged(QAbstractSocket::SocketState);
116
117   void userInput(BufferInfo, QString);
118
119   void networkConnected(uint);
120   void networkDisconnected(uint);
121
122   void updateCoreConnectionProgress();
123   void recvMessage(const Message &message);
124   void recvStatusMsg(QString network, QString message);
125   void recvBacklogData(BufferInfo, QVariantList, bool);
126   void updateBufferInfo(BufferInfo);
127
128   void removeBuffer(Buffer *);
129
130   void layoutMsg();
131
132 private:
133   Client(QObject *parent = 0);
134   virtual ~Client();
135   void init();
136   
137   void syncToCore(const QVariant &coreState);
138   QVariant connectToLocalCore(QString user, QString passwd);  // defined in main.cpp
139   void disconnectFromLocalCore();                             // defined in main.cpp
140
141   static QPointer<Client> instanceptr;
142   
143   QPointer<QIODevice> socket;
144   QPointer<SignalProxy> _signalProxy;
145   QPointer<AbstractUi> mainUi;
146   QPointer<BufferTreeModel> _bufferModel;
147
148   ClientMode clientMode;
149
150   quint32 blockSize;
151   bool connectedToCore;
152   
153   QVariantMap coreConnectionInfo;
154   QHash<uint, Buffer *> _buffers;
155   QHash<uint, NetworkInfo*> _networkInfo;
156
157   QTimer *layoutTimer;
158   QList<Buffer *> layoutQueue;
159
160   QVariantMap sessionData;
161
162
163 };
164
165 #endif