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