- connect(&socket, SIGNAL(readyRead()), this, SLOT(serverHasData()));
- connect(&socket, SIGNAL(connected()), this, SLOT(coreConnected()));
- connect(&socket, SIGNAL(disconnected()), this, SLOT(coreDisconnected()));
- connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError(QAbstractSocket::SocketError)));
-
- connect(Global::instance(), SIGNAL(dataPutLocally(UserId, QString)), this, SLOT(updateCoreData(UserId, QString)));
- connect(clientProxy, SIGNAL(csUpdateGlobalData(QString, QVariant)), this, SLOT(updateLocalData(QString, QVariant)));
- 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(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 data = state["CoreData"].toMap();
- foreach(QString key, data.keys()) {
- Global::updateData(key, data[key]);
- }
- //if(!Global::data("CoreReady").toBool()) {
- // qFatal("Something is wrong, getting invalid data from core!");
- //}
-
- 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);
- emit connected();
- }
+bool Client::isCoreFeatureEnabled(Quassel::Feature feature)
+{
+ return coreConnection()->peer() ? coreConnection()->peer()->hasFeature(feature) : false;
+}
+
+
+bool Client::isConnected()
+{
+ return instance()->_connected;
+}
+
+
+bool Client::internalCore()
+{
+ return currentCoreAccount().isInternal();
+}
+
+
+void Client::onDbUpgradeInProgress(bool inProgress)
+{
+ emit dbUpgradeInProgress(inProgress);
+}
+
+
+void Client::onExitRequested(int exitCode, const QString &reason)
+{
+ if (!reason.isEmpty()) {
+ qCritical() << reason;
+ emit exitRequested(reason);
+ }
+ QCoreApplication::exit(exitCode);
+}
+
+
+/*** Network handling ***/
+
+QList<NetworkId> Client::networkIds()
+{
+ return instance()->_networks.keys();
+}
+
+
+const Network *Client::network(NetworkId networkid)
+{
+ if (instance()->_networks.contains(networkid)) return instance()->_networks[networkid];
+ else return 0;
+}
+
+
+void Client::createNetwork(const NetworkInfo &info, const QStringList &persistentChannels)
+{
+ emit instance()->requestCreateNetwork(info, persistentChannels);
+}
+
+
+void Client::removeNetwork(NetworkId id)
+{
+ emit instance()->requestRemoveNetwork(id);
+}
+
+
+void Client::updateNetwork(const NetworkInfo &info)
+{
+ Network *netptr = instance()->_networks.value(info.networkId, 0);
+ if (!netptr) {
+ qWarning() << "Update for unknown network requested:" << info;
+ return;
+ }
+ netptr->requestSetNetworkInfo(info);
+}
+
+
+void Client::addNetwork(Network *net)
+{
+ net->setProxy(signalProxy());
+ signalProxy()->synchronize(net);
+ networkModel()->attachNetwork(net);
+ connect(net, SIGNAL(destroyed()), instance(), SLOT(networkDestroyed()));
+ instance()->_networks[net->networkId()] = net;
+ emit instance()->networkCreated(net->networkId());
+}
+
+
+void Client::coreNetworkCreated(NetworkId id)
+{
+ if (_networks.contains(id)) {
+ qWarning() << "Creation of already existing network requested!";
+ return;
+ }
+ Network *net = new Network(id, this);
+ addNetwork(net);
+}
+
+
+void Client::coreNetworkRemoved(NetworkId id)
+{
+ if (!_networks.contains(id))
+ return;
+ Network *net = _networks.take(id);
+ emit networkRemoved(net->networkId());
+ net->deleteLater();
+}
+
+
+/*** Identity handling ***/
+
+QList<IdentityId> Client::identityIds()
+{
+ return instance()->_identities.keys();
+}
+
+
+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));