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>
34 class BufferTreeModel;
40 class Client : public QObject {
44 static Client *instance();
45 static void init(AbstractUi *);
46 static void destroy();
48 static QList<BufferId> allBufferIds();
49 static Buffer *buffer(BufferId);
50 static BufferId statusBufferId(QString net);
51 static BufferId bufferId(QString net, QString buf);
53 static BufferTreeModel *bufferModel();
54 static SignalProxy *signalProxy();
56 static AbstractUiMsg *layoutMsg(const Message &);
58 static bool isConnected();
60 static void storeSessionData(const QString &key, const QVariant &data);
61 static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
62 static QStringList sessionDataKeys();
64 enum ClientMode { LocalCore, RemoteCore };
65 static ClientMode clientMode;
68 void sendInput(BufferId, QString message);
69 void showBuffer(Buffer *);
70 void bufferSelected(Buffer *);
71 void bufferUpdated(Buffer *);
72 void bufferActivity(Buffer::ActivityLevel, Buffer *);
73 void bufferDestroyed(Buffer *);
74 void backlogReceived(Buffer *, QList<Message>);
75 void requestBacklog(BufferId, QVariant, QVariant);
76 void requestNetworkStates();
78 void recvPartialItem(uint avail, uint size);
79 void coreConnectionError(QString errorMsg);
80 void coreConnectionMsg(const QString &msg);
81 void coreConnectionProgress(uint part, uint total);
86 void sessionDataChanged(const QString &key);
87 void sessionDataChanged(const QString &key, const QVariant &data);
88 void sendSessionData(const QString &key, const QVariant &data);
91 //void selectBuffer(Buffer *);
92 //void connectToLocalCore();
93 void connectToCore(const QVariantMap &);
94 void disconnectFromCore();
97 void recvCoreState(const QVariant &state);
98 void recvSessionData(const QString &key, const QVariant &data);
100 void coreSocketError(QAbstractSocket::SocketError);
102 void coreSocketConnected();
103 void coreSocketDisconnected();
104 void coreSocketStateChanged(QAbstractSocket::SocketState);
106 void userInput(BufferId, QString);
107 void networkConnected(QString);
108 void networkDisconnected(QString);
109 void recvNetworkState(QString, QVariant);
110 void recvMessage(const Message &message);
111 void recvStatusMsg(QString network, QString message);
112 void setTopic(QString net, QString buf, QString);
113 void addNick(QString net, QString nick, QVariantMap props);
114 void removeNick(QString net, QString nick);
115 void renameNick(QString net, QString oldnick, QString newnick);
116 void updateNick(QString net, QString nick, QVariantMap props);
117 void setOwnNick(QString net, QString nick);
118 void recvBacklogData(BufferId, QVariantList, bool);
119 void updateBufferId(BufferId);
121 void removeBuffer(Buffer *);
129 static Client *instanceptr;
131 void syncToCore(const QVariant &coreState);
132 QVariant connectToLocalCore(QString user, QString passwd); // defined in main.cpp
133 void disconnectFromLocalCore(); // defined in main.cpp
136 SignalProxy *_signalProxy;
137 BufferTreeModel *_bufferModel;
139 QPointer<QIODevice> socket;
142 static bool connectedToCore;
143 static QVariantMap coreConnectionInfo;
144 static QHash<BufferId, Buffer *> buffers;
145 static QHash<uint, BufferId> bufferIds;
146 static QHash<QString, QHash<QString, QVariantMap> > nicks;
147 static QHash<QString, bool> netConnected;
148 static QStringList netsAwaitingInit;
149 static QHash<QString, QString> ownNick;
152 QList<Buffer *> layoutQueue;
154 QVariantMap sessionData;