- _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 *)));
-
- SignalProxy *p = signalProxy();
- p->attachSignal(this, SIGNAL(sendSessionData(const QString &, const QVariant &)),
- SIGNAL(clientSessionDataChanged(const QString &, const QVariant &)));
- p->attachSlot(SIGNAL(coreSessionDataChanged(const QString &, const QVariant &)),
- this, SLOT(recvSessionData(const QString &, const QVariant &)));
- p->attachSlot(SIGNAL(coreState(const QVariant &)),
- this, SLOT(recvCoreState(const QVariant &)));
- p->attachSlot(SIGNAL(networkConnected(uint)),
- this, SLOT(networkConnected(uint)));
- p->attachSlot(SIGNAL(networkDisconnected(uint)),
- this, SLOT(networkDisconnected(uint)));
- p->attachSlot(SIGNAL(displayMsg(const Message &)),
- this, SLOT(recvMessage(const Message &)));
- p->attachSlot(SIGNAL(displayStatusMsg(QString, QString)),
- this, SLOT(recvStatusMsg(QString, QString)));
-
-
- p->attachSlot(SIGNAL(backlogData(BufferInfo, const QVariantList &, bool)), this, SLOT(recvBacklogData(BufferInfo, const QVariantList &, bool)));
- p->attachSlot(SIGNAL(bufferInfoUpdated(BufferInfo)), this, SLOT(updateBufferInfo(BufferInfo)));
- p->attachSignal(this, SIGNAL(sendInput(BufferInfo, QString)));
- p->attachSignal(this, SIGNAL(requestNetworkStates()));
-
- connect(mainUi, SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &)));
- 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()));
-
-}
-
-bool Client::isConnected() {
- return instance()->connectedToCore;
-}
-
-void Client::fakeInput(uint bufferUid, QString message) {
- Buffer *buff = buffer(bufferUid);
- if(!buff)
- qWarning() << "No Buffer with uid" << bufferUid << "can't send Input" << message;
- else
- emit instance()->sendInput(buff->bufferInfo(), message);
-}
-
-void Client::fakeInput(BufferInfo bufferInfo, QString message) {
- fakeInput(bufferInfo, message);
-}
-
-void Client::connectToCore(const QVariantMap &conn) {
- // TODO implement SSL
- coreConnectionInfo = conn;
- if(isConnected()) {
- emit coreConnectionError(tr("Already connected to Core!"));
- return;
- }
-
- if(socket != 0)
- socket->deleteLater();
-
- if(conn["Host"].toString().isEmpty()) {
- clientMode = LocalCore;
- socket = new QBuffer(this);
- connect(socket, SIGNAL(readyRead()), this, SLOT(coreHasData()));
- socket->open(QIODevice::ReadWrite);
- //QVariant state = connectToLocalCore(coreConnectionInfo["User"].toString(), coreConnectionInfo["Password"].toString());
- //syncToCore(state);
- coreSocketConnected();
- } else {
- clientMode = RemoteCore;
- emit coreConnectionMsg(tr("Connecting..."));
- Q_ASSERT(!socket);
- QTcpSocket *sock = new QTcpSocket(this);
- socket = sock;
- connect(sock, SIGNAL(readyRead()), this, SLOT(coreHasData()));
- connect(sock, SIGNAL(connected()), this, SLOT(coreSocketConnected()));
- connect(signalProxy(), SIGNAL(disconnected()), this, SLOT(coreSocketDisconnected()));
- connect(sock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(coreSocketError(QAbstractSocket::SocketError)));
- sock->connectToHost(conn["Host"].toString(), conn["Port"].toUInt());
- }
-}
-
-void Client::disconnectFromCore() {
- socket->close();
-}
-
-void Client::setCoreConfiguration(const QVariantMap &settings) {
- writeDataToDevice(socket, settings);
-}
-
-void Client::coreSocketConnected() {
- connect(this, SIGNAL(recvPartialItem(uint, uint)), this, SIGNAL(coreConnectionProgress(uint, uint)));
- emit coreConnectionMsg(tr("Synchronizing to core..."));
- QVariantMap clientInit;
- clientInit["GuiProtocol"] = GUI_PROTOCOL;
- clientInit["User"] = coreConnectionInfo["User"].toString();
- clientInit["Password"] = coreConnectionInfo["Password"].toString();
- writeDataToDevice(socket, clientInit);
-}
-
-void Client::coreSocketDisconnected() {
- instance()->connectedToCore = false;
- emit disconnected();
- socket->deleteLater();
- blockSize = 0;
-
- /* Clear internal data. Hopefully nothing relies on it at this point. */
- _bufferModel->clear();
-
- QHash<uint, Buffer *>::iterator bufferIter = _buffers.begin();
- while(bufferIter != _buffers.end()) {
- Buffer *buffer = bufferIter.value();
- disconnect(buffer, SIGNAL(destroyed()), this, 0);
- bufferIter = _buffers.erase(bufferIter);
- buffer->deleteLater();
- }
- Q_ASSERT(_buffers.isEmpty());
-
-
- QHash<uint, NetworkInfo*>::iterator netIter = _networkInfo.begin();
- while(netIter != _networkInfo.end()) {
- NetworkInfo *net = netIter.value();
- disconnect(net, SIGNAL(destroyed()), this, 0);
- netIter = _networkInfo.erase(netIter);
- net->deleteLater();
- }
- Q_ASSERT(_networkInfo.isEmpty());