1 /***************************************************************************
2 * Copyright (C) 2005-07 by The Quassel IRC Development Team *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
24 #include <QAbstractSocket>
31 #include "proxy_common.h"
35 class BufferTreeModel;
41 class Client : public QObject {
45 static Client *instance();
46 static void init(AbstractUi *);
47 static void destroy();
49 static QList<BufferId> allBufferIds();
50 static Buffer *buffer(BufferId);
51 static BufferId statusBufferId(QString net);
52 static BufferId bufferId(QString net, QString buf);
54 static BufferTreeModel *bufferModel();
55 static SignalProxy *signalProxy();
57 static AbstractUiMsg *layoutMsg(const Message &);
59 static bool isConnected();
61 static void storeSessionData(const QString &key, const QVariant &data);
62 static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
63 static QStringList sessionDataKeys();
65 enum ClientMode { LocalCore, RemoteCore };
66 static ClientMode clientMode;
69 void sendInput(BufferId, QString message);
70 void showBuffer(Buffer *);
71 void bufferSelected(Buffer *);
72 void bufferUpdated(Buffer *);
73 void bufferActivity(Buffer::ActivityLevel, Buffer *);
74 void bufferDestroyed(Buffer *);
75 void backlogReceived(Buffer *, QList<Message>);
76 void requestBacklog(BufferId, QVariant, QVariant);
77 void requestNetworkStates();
79 void recvPartialItem(uint avail, uint size);
80 void coreConnectionError(QString errorMsg);
81 void coreConnectionMsg(const QString &msg);
82 void coreConnectionProgress(uint part, uint total);
87 void sessionDataChanged(const QString &key);
88 void sessionDataChanged(const QString &key, const QVariant &data);
89 void sendSessionData(const QString &key, const QVariant &data);
92 //void selectBuffer(Buffer *);
93 //void connectToLocalCore();
94 void connectToCore(const QVariantMap &);
95 void disconnectFromCore();
98 void recvCoreState(const QVariant &state);
99 void recvSessionData(const QString &key, const QVariant &data);
100 void recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3);
102 void coreSocketError(QAbstractSocket::SocketError);
104 void coreSocketConnected();
105 void coreSocketDisconnected();
106 void coreSocketStateChanged(QAbstractSocket::SocketState);
108 void userInput(BufferId, QString);
109 void networkConnected(QString);
110 void networkDisconnected(QString);
111 void recvNetworkState(QString, QVariant);
112 void recvMessage(const Message &message);
113 void recvStatusMsg(QString network, QString message);
114 void setTopic(QString net, QString buf, QString);
115 void addNick(QString net, QString nick, QVariantMap props);
116 void removeNick(QString net, QString nick);
117 void renameNick(QString net, QString oldnick, QString newnick);
118 void updateNick(QString net, QString nick, QVariantMap props);
119 void setOwnNick(QString net, QString nick);
120 void recvBacklogData(BufferId, QVariantList, bool);
121 void updateBufferId(BufferId);
123 void removeBuffer(Buffer *);
131 static Client *instanceptr;
133 void syncToCore(const QVariant &coreState);
134 QVariant connectToLocalCore(QString user, QString passwd); // defined in main.cpp
135 void disconnectFromLocalCore(); // defined in main.cpp
138 //ClientProxy *clientProxy;
139 SignalProxy *_signalProxy;
140 BufferTreeModel *_bufferModel;
142 QPointer<QIODevice> socket;
145 static bool connectedToCore;
146 static QVariantMap coreConnectionInfo;
147 static QHash<BufferId, Buffer *> buffers;
148 static QHash<uint, BufferId> bufferIds;
149 static QHash<QString, QHash<QString, QVariantMap> > nicks;
150 static QHash<QString, bool> netConnected;
151 static QStringList netsAwaitingInit;
152 static QHash<QString, QString> ownNick;
155 QList<Buffer *> layoutQueue;
157 QVariantMap sessionData;