- connect(clientProxy, SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), this, SLOT(recvProxySignal(ClientSignal, QVariant, QVariant, 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;
- ClientProxy::destroy();
-
-}
-
-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;
- syncToCore();
- } 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();
- coreDisconnected();
- }
- /* Clear internal data. Hopefully nothing relies on it at this point. */
- coreConnectionInfo.clear();
- sessionData.clear();
- //foreach(Buffer *buf, buffers.values()) delete buf;
- qDebug() << "barfoo";
- _bufferModel->clear();
- //qDeleteAll(buffers);
- qDebug() << "foobar";
-}
-
-void Client::coreConnected() {
- syncToCore();
-
-}
-
-void Client::coreDisconnected() {
- connectedToCore = false;
- emit disconnected();
-}
-
-void Client::syncToCore() {
- VarMap state;
- if(clientMode == LocalCore) {
- state = connectToLocalCore(coreConnectionInfo["User"].toString(), coreConnectionInfo["Password"].toString()).toMap();
- } else {
- // TODO connect to remote cores
- }
-
- VarMap sessionState = state["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);
+
+const Identity *Client::identity(IdentityId id)
+{
+ if (instance()->_identities.contains(id)) return instance()->_identities[id];
+ else return 0;
+}
+
+
+void Client::createIdentity(const CertIdentity &id)
+{
+ QVariantMap additional;
+#ifdef HAVE_SSL
+ additional["KeyPem"] = id.sslKey().toPem();
+ additional["CertPem"] = id.sslCert().toPem();
+#endif
+ emit instance()->requestCreateIdentity(id, additional);
+}
+
+
+void Client::updateIdentity(IdentityId id, const QVariantMap &ser)
+{
+ Identity *idptr = instance()->_identities.value(id, 0);
+ if (!idptr) {
+ qWarning() << "Update for unknown identity requested:" << id;
+ return;
+ }
+ idptr->requestUpdate(ser);
+}
+
+
+void Client::removeIdentity(IdentityId id)
+{
+ emit instance()->requestRemoveIdentity(id);
+}
+
+
+void Client::coreIdentityCreated(const Identity &other)
+{
+ if (!_identities.contains(other.id())) {
+ Identity *identity = new Identity(other, this);
+ _identities[other.id()] = identity;
+ identity->setInitialized();
+ signalProxy()->synchronize(identity);
+ emit identityCreated(other.id());
+ }
+ else {
+ qWarning() << tr("Identity already exists in client!");
+ }
+}
+
+
+void Client::coreIdentityRemoved(IdentityId id)
+{
+ if (_identities.contains(id)) {
+ emit identityRemoved(id);
+ Identity *i = _identities.take(id);
+ i->deleteLater();
+ }
+}
+
+
+/*** User input handling ***/
+
+void Client::userInput(const BufferInfo &bufferInfo, const QString &message)
+{
+ // we need to make sure that AliasManager is ready before processing input
+ if (aliasManager() && aliasManager()->isInitialized())
+ inputHandler()->handleUserInput(bufferInfo, message);
+ else
+ instance()->_userInputBuffer.append(qMakePair(bufferInfo, message));
+}
+
+
+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()->synchronize(bufferSyncer());
+
+ // create a new BufferViewManager
+ Q_ASSERT(!_bufferViewManager);
+ _bufferViewManager = new ClientBufferViewManager(signalProxy(), this);
+ connect(_bufferViewManager, SIGNAL(initDone()), _bufferViewOverlay, SLOT(restore()));
+
+ // create AliasManager
+ Q_ASSERT(!_aliasManager);
+ _aliasManager = new ClientAliasManager(this);
+ connect(aliasManager(), SIGNAL(initDone()), SLOT(sendBufferedUserInput()));
+ signalProxy()->synchronize(aliasManager());
+
+ // create NetworkConfig
+ Q_ASSERT(!_networkConfig);
+ _networkConfig = new NetworkConfig("GlobalNetworkConfig", this);
+ signalProxy()->synchronize(networkConfig());
+
+ // create IgnoreListManager
+ Q_ASSERT(!_ignoreListManager);
+ _ignoreListManager = new ClientIgnoreListManager(this);
+ signalProxy()->synchronize(ignoreListManager());
+
+ Q_ASSERT(!_transferManager);
+ _transferManager = new ClientTransferManager(this);
+ signalProxy()->synchronize(transferManager());
+
+ // trigger backlog request once all active bufferviews are initialized
+ connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
+
+ _connected = true;