X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=cedc0422679c1287f55890cf9da0ba39288c9191;hp=30eeb51d8968383b81614b2aa2788726bec48522;hb=c5cbe5eb77fce2ab954a98399a1450803108217b;hpb=8836fdc8e4107437e5fff0e10e18d581297d59e4 diff --git a/src/client/client.cpp b/src/client/client.cpp index 30eeb51d..cedc0422 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by The Quassel Team * + * Copyright (C) 2005-08 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -19,47 +19,34 @@ ***************************************************************************/ #include "client.h" -#include "clientproxy.h" -#include "buffer.h" -#include "buffertreemodel.h" -#include "util.h" -Client * Client::instanceptr = 0; +#include "bufferinfo.h" +#include "global.h" +#include "identity.h" +#include "ircchannel.h" +#include "ircuser.h" +#include "message.h" +#include "network.h" +#include "networkmodel.h" +#include "buffermodel.h" +#include "nickmodel.h" +#include "quasselui.h" +#include "signalproxy.h" +#include "util.h" -bool Client::connectedToCore = false; -Client::ClientMode Client::clientMode; -QHash Client::buffers; -QHash Client::bufferIds; -QHash > Client::nicks; -QHash Client::netConnected; -QHash Client::ownNick; -//QList Client::coreBuffers; +QPointer Client::instanceptr = 0; +/*** Initialization/destruction ***/ Client *Client::instance() { - if(instanceptr) return instanceptr; - instanceptr = new Client(); + if(!instanceptr) + instanceptr = new Client(); return instanceptr; } void Client::destroy() { - delete instanceptr; - instanceptr = 0; -} - -Client::Client() { - clientProxy = ClientProxy::instance(); - - _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; + //delete instanceptr; + instanceptr->deleteLater(); } void Client::init(AbstractUi *ui) { @@ -67,36 +54,61 @@ void Client::init(AbstractUi *ui) { instance()->init(); } +Client::Client(QObject *parent) + : QObject(parent), + socket(0), + _signalProxy(new SignalProxy(SignalProxy::Client, this)), + mainUi(0), + _networkModel(0), + _bufferModel(0), + _nickModel(0), + _connectedToCore(false), + _syncedToCore(false) +{ +} + +Client::~Client() { + disconnectFromCore(); +} + void Client::init() { - blockSize = 0; - - 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(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 &, bool)), this, SLOT(recvBacklogData(BufferId, QList, 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 &))); + + _networkModel = new NetworkModel(this); + connect(this, SIGNAL(bufferUpdated(BufferInfo)), + _networkModel, SLOT(bufferUpdated(BufferInfo))); + + _bufferModel = new BufferModel(_networkModel); + _nickModel = new NickModel(_networkModel); + + 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(networkConnected(uint)), + //FIXME this, SLOT(networkConnected(uint))); + //p->attachSlot(SIGNAL(networkDisconnected(uint)), + //FIXME 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())); + + p->attachSignal(this, SIGNAL(requestCreateIdentity(const Identity &)), SIGNAL(createIdentity(const Identity &))); + p->attachSignal(this, SIGNAL(requestUpdateIdentity(const Identity &)), SIGNAL(updateIdentity(const Identity &))); + p->attachSignal(this, SIGNAL(requestRemoveIdentity(IdentityId)), SIGNAL(removeIdentity(IdentityId))); + p->attachSlot(SIGNAL(identityCreated(const Identity &)), this, SLOT(coreIdentityCreated(const Identity &))); + p->attachSlot(SIGNAL(identityRemoved(IdentityId)), this, SLOT(coreIdentityRemoved(IdentityId))); + + connect(p, SIGNAL(disconnected()), this, SLOT(disconnectFromCore())); + + //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())); @@ -108,214 +120,320 @@ void Client::init() { } -Client::~Client() { - //delete mainUi; - //delete _bufferModel; - foreach(Buffer *buf, buffers.values()) delete buf; - ClientProxy::destroy(); +/*** public static methods ***/ +QList Client::allBufferInfos() { + QList bufferids; + foreach(Buffer *buffer, buffers()) { + bufferids << buffer->bufferInfo(); + } + return bufferids; } -BufferTreeModel *Client::bufferModel() { - return instance()->_bufferModel; +QList Client::buffers() { + return instance()->_buffers.values(); } -bool Client::isConnected() { return connectedToCore; } -void Client::connectToCore(const VarMap &conn) { - // TODO implement SSL - if(isConnected()) { - qDebug() << "Already connected to core!"; - return; - } - if(conn["Host"].toString().isEmpty()) { - clientMode = LocalCore; - syncToCore(); // TODO send user and pw from conn info - } else { - clientMode = RemoteCore; - socket.connectToHost(conn["Host"].toString(), conn["Port"].toUInt()); - } +// FIXME remove +Buffer *Client::buffer(BufferId bufferUid) { + if(instance()->_buffers.contains(bufferUid)) + return instance()->_buffers[bufferUid]; + else + return 0; } -void Client::disconnectFromCore() { - if(clientMode == RemoteCore) { - socket.close(); - } else { - disconnectFromLocalCore(); - coreDisconnected(); +// FIXME remove +Buffer *Client::buffer(BufferInfo id) { + Buffer *buff = buffer(id.uid()); + + if(!buff) { + Client *client = Client::instance(); + buff = new Buffer(id, client); + + connect(buff, SIGNAL(userInput(BufferInfo, QString)), + client, SLOT(userInput(BufferInfo, QString))); + connect(buff, SIGNAL(destroyed()), + client, SLOT(bufferDestroyed())); + client->_buffers[id.uid()] = buff; + emit client->bufferUpdated(id); } - // TODO clear internal data + Q_ASSERT(buff); + return buff; } -void Client::coreConnected() { - syncToCore(); +NetworkModel *Client::networkModel() { + return instance()->_networkModel; } -void Client::coreDisconnected() { - connectedToCore = false; - emit disconnected(); +BufferModel *Client::bufferModel() { + return instance()->_bufferModel; } -void Client::syncToCore() { - VarMap state; - if(clientMode == LocalCore) { - state = connectToLocalCore("Default", "password").toMap(); // TODO make this configurable - } else { +NickModel *Client::nickModel() { + return instance()->_nickModel; +} - } - VarMap data = state["CoreData"].toMap(); - foreach(QString key, data.keys()) { - Global::updateData(key, data[key]); +SignalProxy *Client::signalProxy() { + return instance()->_signalProxy; +} + +bool Client::isConnected() { + return instance()->_connectedToCore; +} + +bool Client::isSynced() { + return instance()->_syncedToCore; +} + +/*** Network handling ***/ + +QList Client::networkIds() { + return instance()->_networks.keys(); +} + +const Network * Client::network(NetworkId networkid) { + if(instance()->_networks.contains(networkid)) return instance()->_networks[networkid]; + else return 0; +} + +/*** Identity handling ***/ + +QList 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 Identity &id) { + emit instance()->requestCreateIdentity(id); +} + +void Client::updateIdentity(const Identity &id) { + emit instance()->requestUpdateIdentity(id); +} + +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!"); } - //if(!Global::data("CoreReady").toBool()) { - // qFatal("Something is wrong, getting invalid data from core!"); - //} - - VarMap sessionState = state["SessionState"].toMap(); - QList coreBuffers = sessionState["Buffers"].toList(); - /* make lookups by id faster */ - foreach(QVariant vid, coreBuffers) { - BufferId id = vid.value(); - bufferIds[id.uid()] = id; // make lookups by id faster - buffer(id); // create all buffers, so we see them in the network views - //emit requestBacklog(id, -1, -1); // TODO: use custom settings for backlog request +} + +void Client::coreIdentityRemoved(IdentityId id) { + if(_identities.contains(id)) { + emit identityRemoved(id); + Identity *i = _identities.take(id); + i->deleteLater(); } - connectedToCore = true; - emit connected(); - emit requestNetworkStates(); } -void Client::updateCoreData(UserId, QString key) { - if(clientMode == LocalCore) return; - QVariant data = Global::data(key); - recvProxySignal(GS_UPDATE_GLOBAL_DATA, key, data, QVariant()); +/*** ***/ + +void Client::fakeInput(BufferId 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::updateLocalData(QString key, QVariant data) { - Global::updateData(key, data); +void Client::fakeInput(BufferInfo bufferInfo, QString message) { + fakeInput(bufferInfo, message); } -void Client::recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { - if(clientMode == LocalCore) return; - QList sigdata; - sigdata.append(sig); sigdata.append(arg1); sigdata.append(arg2); sigdata.append(arg3); - //qDebug() << "Sending signal: " << sigdata; - writeDataToDevice(&socket, QVariant(sigdata)); +/*** core connection stuff ***/ + +void Client::setConnectedToCore(QIODevice *sock) { + socket = sock; + signalProxy()->addPeer(socket); + _connectedToCore = true; } -void Client::serverError(QAbstractSocket::SocketError) { - emit coreConnectionError(socket.errorString()); +void Client::setSyncedToCore() { + _syncedToCore = true; + emit connected(); + emit coreConnectionStateChanged(true); } -void Client::serverHasData() { - QVariant item; - while(readDataFromDevice(&socket, blockSize, item)) { - emit recvPartialItem(1,1); - QList sigdata = item.toList(); - Q_ASSERT(sigdata.size() == 4); - ClientProxy::instance()->recv((CoreSignal)sigdata[0].toInt(), sigdata[1], sigdata[2], sigdata[3]); - blockSize = 0; +void Client::disconnectFromCore() { + if(socket) { + socket->close(); + socket->deleteLater(); + } + _connectedToCore = false; + _syncedToCore = false; + emit disconnected(); + emit coreConnectionStateChanged(false); + + // Clear internal data. Hopefully nothing relies on it at this point. + _networkModel->clear(); + + QHash::iterator netIter = _networks.begin(); + while(netIter != _networks.end()) { + Network *net = netIter.value(); + disconnect(net, SIGNAL(destroyed()), this, 0); + netIter = _networks.erase(netIter); + net->deleteLater(); + } + Q_ASSERT(_networks.isEmpty()); + + QHash::iterator bufferIter = _buffers.begin(); + while(bufferIter != _buffers.end()) { + Buffer *buffer = bufferIter.value(); + disconnect(buffer, SIGNAL(destroyed()), this, 0); + bufferIter = _buffers.erase(bufferIter); + buffer->deleteLater(); } - if(blockSize > 0) { - emit recvPartialItem(socket.bytesAvailable(), blockSize); + Q_ASSERT(_buffers.isEmpty()); + + QHash::iterator idIter = _identities.begin(); + while(idIter != _identities.end()) { + Identity *id = idIter.value(); + emit identityRemoved(id->id()); + idIter = _identities.erase(idIter); + id->deleteLater(); } + Q_ASSERT(_identities.isEmpty()); + + sessionData.clear(); + layoutQueue.clear(); + layoutTimer->stop(); } -void Client::networkConnected(QString net) { - netConnected[net] = true; - BufferId id = statusBufferId(net); - Buffer *b = buffer(id); - b->setActive(true); - //b->displayMsg(Message(id, Message::Server, tr("Connected."))); - // TODO buffersUpdated(); +void Client::setCoreConfiguration(const QVariantMap &settings) { + SignalProxy::writeDataToDevice(socket, settings); } -void Client::networkDisconnected(QString net) { - foreach(BufferId id, buffers.keys()) { - if(id.network() != net) continue; - Buffer *b = buffer(id); - //b->displayMsg(Message(id, Message::Server, tr("Server disconnected."))); FIXME - b->setActive(false); - } - netConnected[net] = false; +/*** Session data ***/ + +void Client::recvSessionData(const QString &key, const QVariant &data) { + sessionData[key] = data; + emit sessionDataChanged(key, data); + emit sessionDataChanged(key); } -void Client::updateBufferId(BufferId id) { - bufferIds[id.uid()] = id; // make lookups by id faster - buffer(id); +void Client::storeSessionData(const QString &key, const QVariant &data) { + // Not sure if this is a good idea, but we'll try it anyway: + // Calling this function only sends a signal to core. Data is stored upon reception of the update signal, + // rather than immediately. + emit instance()->sendSessionData(key, data); } -BufferId Client::bufferId(QString net, QString buf) { - foreach(BufferId id, buffers.keys()) { - if(id.network() == net && id.buffer() == buf) return id; - } - Q_ASSERT(false); // should never happen! - return BufferId(); +QVariant Client::retrieveSessionData(const QString &key, const QVariant &def) { + if(instance()->sessionData.contains(key)) return instance()->sessionData[key]; + else return def; } -BufferId Client::statusBufferId(QString net) { - return bufferId(net, ""); +QStringList Client::sessionDataKeys() { + return instance()->sessionData.keys(); } +/*** ***/ -Buffer * Client::buffer(BufferId id) { - Client *client = Client::instance(); - if(!buffers.contains(id)) { - Buffer *b = new Buffer(id); - b->setOwnNick(ownNick[id.network()]); - connect(b, SIGNAL(userInput(BufferId, QString)), client, SLOT(userInput(BufferId, QString))); - connect(b, SIGNAL(bufferUpdated(Buffer *)), client, SIGNAL(bufferUpdated(Buffer *))); - connect(b, SIGNAL(bufferDestroyed(Buffer *)), client, SIGNAL(bufferDestroyed(Buffer *))); - buffers[id] = b; - emit client->bufferUpdated(b); +/* +void Client::networkConnected(uint netid) { + // TODO: create statusBuffer / switch to networkids + //BufferInfo id = statusBufferInfo(net); + //Buffer *b = buffer(id); + //b->setActive(true); + + Network *netinfo = new Network(netid, this); + netinfo->setProxy(signalProxy()); + networkModel()->attachNetwork(netinfo); + connect(netinfo, SIGNAL(destroyed()), this, SLOT(networkDestroyed())); + _networks[netid] = netinfo; +} + +void Client::networkDisconnected(NetworkId networkid) { + if(!_networks.contains(networkid)) { + qWarning() << "Client::networkDisconnected(uint): unknown Network" << networkid; + return; } - return buffers[id]; + + Network *net = _networks.take(networkid); + if(!net->isInitialized()) { + qDebug() << "Network" << networkid << "disconnected while not yet initialized!"; + updateCoreConnectionProgress(); + } + net->deleteLater(); } +*/ -QList Client::allBufferIds() { - return buffers.keys(); +void Client::addNetwork(NetworkId netid) { + Network *net = new Network(netid, instance()); + addNetwork(net); } -void Client::recvNetworkState(QString net, QVariant state) { - netConnected[net] = true; - setOwnNick(net, state.toMap()["OwnNick"].toString()); - buffer(statusBufferId(net))->setActive(true); - VarMap t = state.toMap()["Topics"].toMap(); - VarMap n = state.toMap()["Nicks"].toMap(); - foreach(QVariant v, t.keys()) { - QString buf = v.toString(); - BufferId id = bufferId(net, buf); - buffer(id)->setActive(true); - setTopic(net, buf, t[buf].toString()); - } - foreach(QString nick, n.keys()) { - addNick(net, nick, n[nick].toMap()); +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()->networkAdded(net->networkId()); + //if(net->networkId() == 1) net->requestConnect(); // FIXME +} + +/*** ***/ + +void Client::updateBufferInfo(BufferInfo id) { + emit bufferUpdated(id); +} + +void Client::bufferDestroyed() { + Buffer *buffer = static_cast(sender()); + QHash::iterator iter = _buffers.begin(); + while(iter != _buffers.end()) { + if(iter.value() == buffer) { + iter = _buffers.erase(iter); + break; + } + iter++; } } +void Client::networkDestroyed() { + Network *netinfo = static_cast(sender()); + NetworkId networkId = netinfo->networkId(); + if(_networks.contains(networkId)) + _networks.remove(networkId); +} + void Client::recvMessage(const Message &msg) { - Buffer *b = buffer(msg.buffer); + Buffer *b = buffer(msg.buffer()); - Buffer::ActivityLevel level = Buffer::OtherActivity; - if(msg.type == Message::Plain || msg.type == Message::Notice){ - level |= Buffer::NewMessage; - } - if(msg.flags & Message::Highlight){ - level |= Buffer::Highlight; - } - emit bufferActivity(level, b); +// Buffer::ActivityLevel level = Buffer::OtherActivity; +// if(msg.type() == Message::Plain || msg.type() == Message::Notice){ +// level |= Buffer::NewMessage; +// } +// if(msg.flags() & Message::Highlight){ +// level |= Buffer::Highlight; +// } +// emit bufferActivity(level, b); b->appendMsg(msg); } void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) { //recvMessage(net, Message::server("", QString("[STATUS] %1").arg(msg))); - } -void Client::recvBacklogData(BufferId id, const QList &msgs, bool /*done*/) { +void Client::recvBacklogData(BufferInfo id, QVariantList msgs, bool /*done*/) { Buffer *b = buffer(id); foreach(QVariant v, msgs) { Message msg = v.value(); @@ -328,80 +446,19 @@ void Client::recvBacklogData(BufferId id, const QList &msgs, bool /*do void Client::layoutMsg() { if(layoutQueue.count()) { Buffer *b = layoutQueue.takeFirst(); // TODO make this the current buffer - if(b->layoutMsg()) layoutQueue.append(b); // Buffer has more messages in its queue --> Round Robin + if(b->layoutMsg()) + layoutQueue.append(b); // Buffer has more messages in its queue --> Round Robin } - if(!layoutQueue.count()) layoutTimer->stop(); + + if(!layoutQueue.count()) + layoutTimer->stop(); } AbstractUiMsg *Client::layoutMsg(const Message &msg) { return instance()->mainUi->layoutMsg(msg); } -void Client::userInput(BufferId id, QString msg) { +void Client::userInput(BufferInfo id, QString msg) { emit sendInput(id, msg); } -void Client::setTopic(QString net, QString buf, QString topic) { - BufferId id = bufferId(net, buf); - if(!netConnected[id.network()]) return; - Buffer *b = buffer(id); - b->setTopic(topic); - //if(!b->isActive()) { - // b->setActive(true); - // buffersUpdated(); - //} -} - -void Client::addNick(QString net, QString nick, VarMap props) { - if(!netConnected[net]) return; - nicks[net][nick] = props; - VarMap chans = props["Channels"].toMap(); - QStringList c = chans.keys(); - foreach(QString bufname, c) { - buffer(bufferId(net, bufname))->addNick(nick, props); - } -} - -void Client::renameNick(QString net, QString oldnick, QString newnick) { - if(!netConnected[net]) return; - QStringList chans = nicks[net][oldnick]["Channels"].toMap().keys(); - foreach(QString c, chans) { - buffer(bufferId(net, c))->renameNick(oldnick, newnick); - } - nicks[net][newnick] = nicks[net].take(oldnick); -} - -void Client::updateNick(QString net, QString nick, VarMap props) { - if(!netConnected[net]) return; - QStringList oldchans = nicks[net][nick]["Channels"].toMap().keys(); - QStringList newchans = props["Channels"].toMap().keys(); - foreach(QString c, newchans) { - if(oldchans.contains(c)) buffer(bufferId(net, c))->updateNick(nick, props); - else buffer(bufferId(net, c))->addNick(nick, props); - } - foreach(QString c, oldchans) { - if(!newchans.contains(c)) buffer(bufferId(net, c))->removeNick(nick); - } - nicks[net][nick] = props; -} - -void Client::removeNick(QString net, QString nick) { - if(!netConnected[net]) return; - VarMap chans = nicks[net][nick]["Channels"].toMap(); - foreach(QString bufname, chans.keys()) { - buffer(bufferId(net, bufname))->removeNick(nick); - } - nicks[net].remove(nick); -} - -void Client::setOwnNick(QString net, QString nick) { - if(!netConnected[net]) return; - ownNick[net] = nick; - foreach(BufferId id, buffers.keys()) { - if(id.network() == net) { - buffers[id]->setOwnNick(nick); - } - } -} - -