Refactoring the GUI. Work in progress.
[quassel.git] / gui / gui.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 _GUI_H_
22 #define _GUI_H_
23
24 #include <QtCore>
25 #include <QtGui>
26 #include <QtNetwork>
27
28 #include "global.h"
29 #include "buffer.h"
30 #include "message.h"
31 #include "guiproxy.h"
32
33 class MainWin;
34 class ClientProxy;
35 class BufferTreeModel;
36
37 class Client : public QObject {
38   Q_OBJECT
39
40   public:
41     static Client *instance();
42     static void destroy();
43
44     static Buffer *buffer(BufferId);
45     static BufferId statusBufferId(QString net);
46     static BufferId bufferId(QString net, QString buf);
47
48     static BufferTreeModel *bufferModel();
49
50   signals:
51     void sendInput(BufferId, QString message);
52     void showBuffer(Buffer *);
53     void bufferSelected(Buffer *);
54     void bufferUpdated(Buffer *);
55     void bufferActivity(Buffer::ActivityLevel, Buffer *);
56     void bufferDestroyed(Buffer *);
57     void backlogReceived(Buffer *, QList<Message>);
58     void requestBacklog(BufferId, QVariant, QVariant);
59
60     void recvPartialItem(quint32 avail, quint32 size);
61     void coreConnectionError(QString errorMsg);
62
63   public slots:
64     //void selectBuffer(Buffer *);
65     void connectToCore(QString host, quint16 port);
66     void disconnectFromCore();
67
68   private slots:
69     void updateCoreData(UserId, QString);
70     void updateLocalData(QString, QVariant);
71     void recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3);
72
73     void serverError(QAbstractSocket::SocketError);
74     void serverHasData();
75     void coreConnected();
76     void coreDisconnected();
77
78     void userInput(BufferId, QString);
79     void networkConnected(QString);
80     void networkDisconnected(QString);
81     void recvNetworkState(QString, QVariant);
82     void recvMessage(Message message);
83     void recvStatusMsg(QString network, QString message);
84     void setTopic(QString net, QString buf, QString);
85     void addNick(QString net, QString nick, VarMap props);
86     void removeNick(QString net, QString nick);
87     void renameNick(QString net, QString oldnick, QString newnick);
88     void updateNick(QString net, QString nick, VarMap props);
89     void setOwnNick(QString net, QString nick);
90     void recvBacklogData(BufferId, QList<QVariant>, bool);
91     void updateBufferId(BufferId);
92
93     void layoutMsg();
94
95   private:
96     Client();
97     ~Client();
98     void init();
99     static Client *instanceptr;
100
101     void syncToCore();
102
103     enum ClientMode { LocalCore, RemoteCore };
104     static ClientMode clientMode;
105
106     MainWin *mainWin;
107     ClientProxy *clientProxy;
108     BufferTreeModel *_bufferModel;
109
110     QTcpSocket socket;
111     quint32 blockSize;
112
113     static QHash<BufferId, Buffer *> buffers;
114     static QHash<uint, BufferId> bufferIds;
115     static QHash<QString, QHash<QString, VarMap> > nicks;
116     static QHash<QString, bool> connected;
117     static QHash<QString, QString> ownNick;
118     static QList<BufferId> coreBuffers;
119
120     QTimer *layoutTimer;
121     QList<Message> layoutQueue;
122 };
123
124 #endif