Still working on the authentification stuff. Technically, now even in the monolithic...
[quassel.git] / src / client / client.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 _CLIENT_H_
22 #define _CLIENT_H_
23
24 #include <QtCore>
25 #include <QtNetwork>
26
27 #include "quasselui.h"
28 #include "buffer.h"
29 #include "message.h"
30 #include "proxy_common.h"
31
32 class ClientProxy;
33 class BufferTreeModel;
34
35 class Client : public QObject {
36   Q_OBJECT
37
38   public:
39     static Client *instance();
40     static void init(AbstractUi *);
41     static void destroy();
42
43     static QList<BufferId> allBufferIds();
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     static AbstractUiMsg *layoutMsg(const Message &);
51
52     static bool isConnected();
53
54   signals:
55     void sendInput(BufferId, QString message);
56     void showBuffer(Buffer *);
57     void bufferSelected(Buffer *);
58     void bufferUpdated(Buffer *);
59     void bufferActivity(Buffer::ActivityLevel, Buffer *);
60     void bufferDestroyed(Buffer *);
61     void backlogReceived(Buffer *, QList<Message>);
62     void requestBacklog(BufferId, QVariant, QVariant);
63     void requestNetworkStates();
64
65     void recvPartialItem(quint32 avail, quint32 size);
66     void coreConnectionError(QString errorMsg);
67
68     void connected();
69     void disconnected();
70
71   public slots:
72     //void selectBuffer(Buffer *);
73     //void connectToLocalCore();
74     void connectToCore(const VarMap &);
75     void disconnectFromCore();
76
77   private slots:
78     void updateCoreData(UserId, QString);
79     void updateLocalData(QString, QVariant);
80     void recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3);
81
82     void serverError(QAbstractSocket::SocketError);
83     void serverHasData();
84     void coreConnected();
85     void coreDisconnected();
86
87     void userInput(BufferId, QString);
88     void networkConnected(QString);
89     void networkDisconnected(QString);
90     void recvNetworkState(QString, QVariant);
91     void recvMessage(const Message &message);
92     void recvStatusMsg(QString network, QString message);
93     void setTopic(QString net, QString buf, QString);
94     void addNick(QString net, QString nick, VarMap props);
95     void removeNick(QString net, QString nick);
96     void renameNick(QString net, QString oldnick, QString newnick);
97     void updateNick(QString net, QString nick, VarMap props);
98     void setOwnNick(QString net, QString nick);
99     void recvBacklogData(BufferId, const QList<QVariant> &, bool);
100     void updateBufferId(BufferId);
101
102     void layoutMsg();
103
104   private:
105     Client();
106     ~Client();
107     void init();
108     static Client *instanceptr;
109
110     void syncToCore();
111     QVariant connectToLocalCore(QString user, QString passwd);  // defined in main.cpp
112     void disconnectFromLocalCore();                             // defined in main.cpp
113
114     enum ClientMode { LocalCore, RemoteCore };
115     static ClientMode clientMode;
116
117     AbstractUi *mainUi;
118     ClientProxy *clientProxy;
119     BufferTreeModel *_bufferModel;
120
121     QTcpSocket socket;
122     quint32 blockSize;
123
124     static bool connectedToCore;
125     static QHash<BufferId, Buffer *> buffers;
126     static QHash<uint, BufferId> bufferIds;
127     static QHash<QString, QHash<QString, VarMap> > nicks;
128     static QHash<QString, bool> netConnected;
129     static QHash<QString, QString> ownNick;
130     //static QList<BufferId> coreBuffers;
131
132     QTimer *layoutTimer;
133     QList<Buffer *> layoutQueue;
134 };
135
136 #endif