- _bufferModel = new BufferTreeModel(this);
-
- connect(this, SIGNAL(bufferSelected(Buffer *)), _bufferModel, SLOT(selectBuffer(Buffer *)));
- connect(this, SIGNAL(bufferUpdated(Buffer *)), _bufferModel, SLOT(bufferUpdated(Buffer *)));
- connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), _bufferModel, SLOT(bufferActivity(Buffer::ActivityLevel, Buffer *)));
-
- // TODO: make this configurable (allow monolithic client to connect to remote cores)
- if(Global::runMode == Global::Monolithic) clientMode = LocalCore;
- else clientMode = RemoteCore;
- connectedToCore = false;
-}
-
-void Client::init(AbstractUi *ui) {
- instance()->mainUi = ui;
- instance()->init();
-}
-
-void Client::init() {
- blockSize = 0;
-
- connect(&socket, SIGNAL(readyRead()), this, SLOT(serverHasData()));
- connect(&socket, SIGNAL(connected()), this, SLOT(coreSocketConnected()));
- connect(&socket, SIGNAL(disconnected()), this, SLOT(coreSocketDisconnected()));
- connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError(QAbstractSocket::SocketError)));
-
- connect(this, SIGNAL(sendSessionData(const QString &, const QVariant &)), clientProxy, SLOT(gsSessionDataChanged(const QString &, const QVariant &)));
- connect(clientProxy, SIGNAL(csSessionDataChanged(const QString &, const QVariant &)), this, SLOT(recvSessionData(const QString &, const QVariant &)));
-
- connect(clientProxy, SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), this, SLOT(recvProxySignal(ClientSignal, QVariant, QVariant, QVariant)));
- connect(clientProxy, SIGNAL(csCoreState(QVariant)), this, SLOT(recvCoreState(const QVariant &)));
- connect(clientProxy, SIGNAL(csServerState(QString, QVariant)), this, SLOT(recvNetworkState(QString, QVariant)));
- connect(clientProxy, SIGNAL(csServerConnected(QString)), this, SLOT(networkConnected(QString)));
- connect(clientProxy, SIGNAL(csServerDisconnected(QString)), this, SLOT(networkDisconnected(QString)));
- connect(clientProxy, SIGNAL(csDisplayMsg(Message)), this, SLOT(recvMessage(const Message &)));
- connect(clientProxy, SIGNAL(csDisplayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString)));
- connect(clientProxy, SIGNAL(csTopicSet(QString, QString, QString)), this, SLOT(setTopic(QString, QString, QString)));
- connect(clientProxy, SIGNAL(csNickAdded(QString, QString, VarMap)), this, SLOT(addNick(QString, QString, VarMap)));
- connect(clientProxy, SIGNAL(csNickRemoved(QString, QString)), this, SLOT(removeNick(QString, QString)));
- connect(clientProxy, SIGNAL(csNickRenamed(QString, QString, QString)), this, SLOT(renameNick(QString, QString, QString)));
- connect(clientProxy, SIGNAL(csNickUpdated(QString, QString, VarMap)), this, SLOT(updateNick(QString, QString, VarMap)));
- connect(clientProxy, SIGNAL(csOwnNickSet(QString, QString)), this, SLOT(setOwnNick(QString, QString)));
- connect(clientProxy, SIGNAL(csBacklogData(BufferId, const QList<QVariant> &, bool)), this, SLOT(recvBacklogData(BufferId, QList<QVariant>, bool)));
- connect(clientProxy, SIGNAL(csUpdateBufferId(BufferId)), this, SLOT(updateBufferId(BufferId)));
- connect(this, SIGNAL(sendInput(BufferId, QString)), clientProxy, SLOT(gsUserInput(BufferId, QString)));
- connect(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)), clientProxy, SLOT(gsRequestBacklog(BufferId, QVariant, QVariant)));
- connect(this, SIGNAL(requestNetworkStates()), clientProxy, SLOT(gsRequestNetworkStates()));
-
- connect(mainUi, SIGNAL(connectToCore(const VarMap &)), this, SLOT(connectToCore(const VarMap &)));
- connect(mainUi, SIGNAL(disconnectFromCore()), this, SLOT(disconnectFromCore()));
- connect(this, SIGNAL(connected()), mainUi, SLOT(connectedToCore()));
- connect(this, SIGNAL(disconnected()), mainUi, SLOT(disconnectedFromCore()));
-
- layoutTimer = new QTimer(this);
- layoutTimer->setInterval(0);
- layoutTimer->setSingleShot(false);
- connect(layoutTimer, SIGNAL(timeout()), this, SLOT(layoutMsg()));
-
-}
-
-Client::~Client() {
- //delete mainUi;
- //delete _bufferModel;
- foreach(Buffer *buf, buffers.values()) delete buf; // this is done by disconnectFromCore()!
- ClientProxy::destroy();
- Q_ASSERT(!buffers.count());
-}
-
-BufferTreeModel *Client::bufferModel() {
- return instance()->_bufferModel;
-}
-
-bool Client::isConnected() { return connectedToCore; }
-
-void Client::connectToCore(const VarMap &conn) {
- // TODO implement SSL
- coreConnectionInfo = conn;
- if(isConnected()) {
- emit coreConnectionError(tr("Already connected to Core!"));
- return;
- }
- if(conn["Host"].toString().isEmpty()) {
- clientMode = LocalCore;
- QVariant state = connectToLocalCore(coreConnectionInfo["User"].toString(), coreConnectionInfo["Password"].toString());
- syncToCore(state);
- } else {
- clientMode = RemoteCore;
- emit coreConnectionMsg(tr("Connecting..."));
- socket.connectToHost(conn["Host"].toString(), conn["Port"].toUInt());
- }
-}
-
-void Client::disconnectFromCore() {
- if(clientMode == RemoteCore) {
- socket.close();
- } else {
- disconnectFromLocalCore();
- coreSocketDisconnected();
- }
-}
-
-void Client::coreSocketConnected() {
- connect(this, SIGNAL(recvPartialItem(uint, uint)), this, SIGNAL(coreConnectionProgress(uint, uint)));
- emit coreConnectionMsg(tr("Synchronizing to core..."));
- VarMap clientInit;
- clientInit["GuiProtocol"] = GUI_PROTOCOL;
- clientInit["User"] = coreConnectionInfo["User"].toString();
- clientInit["Password"] = coreConnectionInfo["Password"].toString();
- writeDataToDevice(&socket, clientInit);
-}
-
-void Client::coreSocketDisconnected() {
- connectedToCore = false;
- emit disconnected();
- /* Clear internal data. Hopefully nothing relies on it at this point. */
- _bufferModel->clear();
- // Buffers, if deleted, send a signal that causes their removal from buffers and bufferIds.
- // So we cannot simply go through the array in a loop (or use qDeleteAll) for deletion...
- while(buffers.count()) { delete buffers.take(buffers.keys()[0]); }
- Q_ASSERT(!buffers.count()); // should be empty now!
- Q_ASSERT(!bufferIds.count());
- coreConnectionInfo.clear();
- sessionData.clear();
- nicks.clear();
- netConnected.clear();
- netsAwaitingInit.clear();
- ownNick.clear();
- layoutQueue.clear();
- layoutTimer->stop();
-}
-
-void Client::recvCoreState(const QVariant &state) {
- disconnect(this, SIGNAL(recvPartialItem(uint, uint)), this, SIGNAL(coreConnectionProgress(uint, uint)));
- syncToCore(state);
-
-}
-
-void Client::syncToCore(const QVariant &coreState) {
- VarMap sessionState = coreState.toMap()["SessionState"].toMap();
- VarMap sessData = sessionState["SessionData"].toMap();
-
- foreach(QString key, sessData.keys()) {
- recvSessionData(key, sessData[key]);
- }
- QList<QVariant> coreBuffers = sessionState["Buffers"].toList();
- /* make lookups by id faster */
- foreach(QVariant vid, coreBuffers) {
- BufferId id = vid.value<BufferId>();
- bufferIds[id.uid()] = id; // make lookups by id faster
- buffer(id); // create all buffers, so we see them in the network views
- }
- netsAwaitingInit = sessionState["Networks"].toStringList();
- connectedToCore = true;
- if(netsAwaitingInit.count()) {
- emit coreConnectionMsg(tr("Requesting network states..."));
- emit coreConnectionProgress(0, netsAwaitingInit.count());
- emit requestNetworkStates();
- }
- else {
- emit coreConnectionProgress(1, 1);
+void Client::sendBufferedUserInput()
+{
+ for (int i = 0; i < _userInputBuffer.count(); i++)
+ userInput(_userInputBuffer.at(i).first, _userInputBuffer.at(i).second);
+
+ _userInputBuffer.clear();
+}
+
+
+/*** core connection stuff ***/
+
+void Client::connectionStateChanged(CoreConnection::ConnectionState state)
+{
+ switch (state) {
+ case CoreConnection::Disconnected:
+ setDisconnectedFromCore();
+ break;
+ case CoreConnection::Synchronized:
+ setSyncedToCore();
+ break;
+ default:
+ break;
+ }
+}
+
+
+void Client::setSyncedToCore()
+{
+ // create buffersyncer
+ Q_ASSERT(!_bufferSyncer);
+ _bufferSyncer = new BufferSyncer(this);
+ connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), _networkModel, SLOT(setLastSeenMsgId(BufferId, MsgId)));
+ connect(bufferSyncer(), SIGNAL(markerLineSet(BufferId, MsgId)), _networkModel, SLOT(setMarkerLineMsgId(BufferId, MsgId)));
+ connect(bufferSyncer(), SIGNAL(bufferRemoved(BufferId)), this, SLOT(bufferRemoved(BufferId)));
+ connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString)));
+ connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), this, SLOT(buffersPermanentlyMerged(BufferId, BufferId)));
+ connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), _messageModel, SLOT(buffersPermanentlyMerged(BufferId, BufferId)));
+ connect(bufferSyncer(), SIGNAL(bufferMarkedAsRead(BufferId)), SIGNAL(bufferMarkedAsRead(BufferId)));
+ connect(networkModel(), SIGNAL(requestSetLastSeenMsg(BufferId, MsgId)), bufferSyncer(), SLOT(requestSetLastSeenMsg(BufferId, const MsgId &)));
+
+ SignalProxy *p = signalProxy();
+
+ if ((Client::coreFeatures() & Quassel::PasswordChange)) {
+ p->attachSignal(this, SIGNAL(clientChangePassword(QString)));
+ }
+
+ p->synchronize(bufferSyncer());
+
+ // create a new BufferViewManager
+ Q_ASSERT(!_bufferViewManager);
+ _bufferViewManager = new ClientBufferViewManager(p, this);
+ connect(_bufferViewManager, SIGNAL(initDone()), _bufferViewOverlay, SLOT(restore()));
+
+ // create AliasManager
+ Q_ASSERT(!_aliasManager);
+ _aliasManager = new ClientAliasManager(this);
+ connect(aliasManager(), SIGNAL(initDone()), SLOT(sendBufferedUserInput()));
+ p->synchronize(aliasManager());
+
+ // create NetworkConfig
+ Q_ASSERT(!_networkConfig);
+ _networkConfig = new NetworkConfig("GlobalNetworkConfig", this);
+ p->synchronize(networkConfig());
+
+ // create IgnoreListManager
+ Q_ASSERT(!_ignoreListManager);
+ _ignoreListManager = new ClientIgnoreListManager(this);
+ p->synchronize(ignoreListManager());
+
+ Q_ASSERT(!_transferManager);
+ _transferManager = new ClientTransferManager(this);
+ p->synchronize(transferManager());
+
+ // trigger backlog request once all active bufferviews are initialized
+ connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
+
+ _connected = true;