X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=772601f54c928231916cfbf7496e0d5e028ed180;hp=899991f7c17696c627c572eeebcf87558eb21cec;hb=e7696b65e76e50137b8bab0ec3e43ce66a94f190;hpb=99c92e21b3b9eb5ed661632cdfb69aabfc6b2deb diff --git a/src/client/client.cpp b/src/client/client.cpp index 899991f7..772601f5 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 * @@ -21,21 +21,23 @@ #include "client.h" #include "bufferinfo.h" -#include "buffertreemodel.h" #include "global.h" +#include "identity.h" #include "ircchannel.h" #include "ircuser.h" #include "message.h" -#include "networkinfo.h" +#include "network.h" +#include "networkmodel.h" +#include "buffermodel.h" +#include "nickmodel.h" #include "quasselui.h" #include "signalproxy.h" #include "util.h" QPointer Client::instanceptr = 0; -// ============================== -// public Static Methods -// ============================== +/*** Initialization/destruction ***/ + Client *Client::instance() { if(!instanceptr) instanceptr = new Client(); @@ -43,7 +45,8 @@ Client *Client::instance() { } void Client::destroy() { - delete instanceptr; + //delete instanceptr; + instanceptr->deleteLater(); } void Client::init(AbstractUi *ui) { @@ -51,17 +54,81 @@ void Client::init(AbstractUi *ui) { instance()->init(); } -QList Client::networkInfos() { - return instance()->_networkInfo.values(); +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) +{ + _monitorBuffer = new Buffer(BufferInfo(), this); } -NetworkInfo *Client::networkInfo(uint networkid) { - if(instance()->_networkInfo.contains(networkid)) - return instance()->_networkInfo[networkid]; - else - return 0; +Client::~Client() { + disconnectFromCore(); +} + +void Client::init() { + + _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))); +/* + p->attachSignal(this, SIGNAL(requestCreateNetwork(const NetworkInfo &)), SIGNAL(createNetwork(const NetworkInfo &))); + p->attachSignal(this, SIGNAL(requestUpdateNetwork(const NetworkInfo &)), SIGNAL(updateNetwork(const NetworkInfo &))); + p->attachSignal(this, SIGNAL(requestRemoveNetwork(NetworkId)), SIGNAL(removeNetwork(NetworkId))); + p->attachSlot(SIGNAL(networkCreated(const NetworkInfo &)), this, SLOT(coreNetworkCreated(const NetworkInfo &))); + p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId))); +*/ + 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())); + + layoutTimer = new QTimer(this); + layoutTimer->setInterval(0); + layoutTimer->setSingleShot(false); + connect(layoutTimer, SIGNAL(timeout()), this, SLOT(layoutMsg())); + } +/*** public static methods ***/ + QList Client::allBufferInfos() { QList bufferids; foreach(Buffer *buffer, buffers()) { @@ -74,196 +141,157 @@ QList Client::buffers() { return instance()->_buffers.values(); } -Buffer *Client::buffer(uint bufferUid) { + +// FIXME remove +Buffer *Client::buffer(BufferId bufferUid) { if(instance()->_buffers.contains(bufferUid)) return instance()->_buffers[bufferUid]; else return 0; } +// 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(bufferUpdated(Buffer *)), - client, SIGNAL(bufferUpdated(Buffer *))); connect(buff, SIGNAL(destroyed()), client, SLOT(bufferDestroyed())); client->_buffers[id.uid()] = buff; - emit client->bufferUpdated(buff); + emit client->bufferUpdated(id); } Q_ASSERT(buff); return buff; } -// FIXME switch to netids! -// WHEN IS THIS NEEDED ANYHOW!? -BufferInfo Client::bufferInfo(QString net, QString buf) { - foreach(Buffer *buffer_, buffers()) { - BufferInfo bufferInfo = buffer_->bufferInfo(); - if(bufferInfo.network() == net && bufferInfo.buffer() == buf) - return bufferInfo; - } - Q_ASSERT(false); // should never happen! - return BufferInfo(); +Buffer *Client::monitorBuffer() { + return instance()->_monitorBuffer; } -BufferInfo Client::statusBufferInfo(QString net) { - return bufferInfo(net, ""); + +NetworkModel *Client::networkModel() { + return instance()->_networkModel; } -BufferTreeModel *Client::bufferModel() { +BufferModel *Client::bufferModel() { return instance()->_bufferModel; } +NickModel *Client::nickModel() { + return instance()->_nickModel; +} + + SignalProxy *Client::signalProxy() { return instance()->_signalProxy; } -// ============================== -// Constructor / Decon -// ============================== -Client::Client(QObject *parent) - : QObject(parent), - socket(0), - _signalProxy(new SignalProxy(SignalProxy::Client, this)), - mainUi(0), - _bufferModel(0), - connectedToCore(false) -{ +bool Client::isConnected() { + return instance()->_connectedToCore; } -Client::~Client() { +bool Client::isSynced() { + return instance()->_syncedToCore; } -void Client::init() { - blockSize = 0; - - _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))); +/*** Network handling ***/ +QList Client::networkIds() { + return instance()->_networks.keys(); +} - 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())); +const Network * Client::network(NetworkId networkid) { + if(instance()->_networks.contains(networkid)) return instance()->_networks[networkid]; + else return 0; +} - 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())); +/*** Identity handling ***/ - layoutTimer = new QTimer(this); - layoutTimer->setInterval(0); - layoutTimer->setSingleShot(false); - connect(layoutTimer, SIGNAL(timeout()), this, SLOT(layoutMsg())); +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; } -bool Client::isConnected() { - return instance()->connectedToCore; +void Client::createIdentity(const Identity &id) { + emit instance()->requestCreateIdentity(id); } -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::updateIdentity(const Identity &id) { + emit instance()->requestUpdateIdentity(id); } -void Client::fakeInput(BufferInfo bufferInfo, QString message) { - fakeInput(bufferInfo, message); +void Client::removeIdentity(IdentityId id) { + emit instance()->requestRemoveIdentity(id); } -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(); +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 { - 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()); + qWarning() << tr("Identity already exists in client!"); } } -void Client::disconnectFromCore() { - socket->close(); +void Client::coreIdentityRemoved(IdentityId id) { + if(_identities.contains(id)) { + emit identityRemoved(id); + Identity *i = _identities.take(id); + i->deleteLater(); + } } -void Client::setCoreConfiguration(const QVariantMap &settings) { - writeDataToDevice(socket, settings); +/*** ***/ +void Client::userInput(BufferInfo bufferInfo, QString message) { + emit instance()->sendInput(bufferInfo, message); } -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); +/*** core connection stuff ***/ + +void Client::setConnectedToCore(QIODevice *sock) { + socket = sock; + signalProxy()->addPeer(socket); + _connectedToCore = true; } -void Client::coreSocketDisconnected() { - instance()->connectedToCore = false; +void Client::setSyncedToCore() { + _syncedToCore = true; + emit connected(); + emit coreConnectionStateChanged(true); +} + +void Client::disconnectFromCore() { + if(socket) { + socket->close(); + socket->deleteLater(); + } + _connectedToCore = false; + _syncedToCore = false; emit disconnected(); - socket->deleteLater(); - blockSize = 0; + emit coreConnectionStateChanged(false); + + // Clear internal data. Hopefully nothing relies on it at this point. + _networkModel->clear(); - /* Clear internal data. Hopefully nothing relies on it at this point. */ - _bufferModel->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(); + QHash::iterator bufferIter = _buffers.begin(); while(bufferIter != _buffers.end()) { Buffer *buffer = bufferIter.value(); disconnect(buffer, SIGNAL(destroyed()), this, 0); @@ -272,120 +300,25 @@ void Client::coreSocketDisconnected() { } Q_ASSERT(_buffers.isEmpty()); - - QHash::iterator netIter = _networkInfo.begin(); - while(netIter != _networkInfo.end()) { - NetworkInfo *net = netIter.value(); - disconnect(net, SIGNAL(destroyed()), this, 0); - netIter = _networkInfo.erase(netIter); - net->deleteLater(); + 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(_networkInfo.isEmpty()); - - coreConnectionInfo.clear(); + Q_ASSERT(_identities.isEmpty()); + sessionData.clear(); layoutQueue.clear(); layoutTimer->stop(); } -void Client::recvCoreState(const QVariant &state) { - disconnect(this, SIGNAL(recvPartialItem(uint, uint)), this, SIGNAL(coreConnectionProgress(uint, uint))); - disconnect(socket, 0, this, 0); // rest of communication happens through SignalProxy - signalProxy()->addPeer(socket); - syncToCore(state); -} - -// TODO: auth errors -void Client::syncToCore(const QVariant &coreState) { - if(!coreState.toMap().contains("SessionState")) { - emit coreConnectionError(tr("Invalid data received from core!")); - disconnectFromCore(); - return; - } - - QVariantMap sessionState = coreState.toMap()["SessionState"].toMap(); - - // store sessionData - QVariantMap sessData = sessionState["SessionData"].toMap(); - foreach(QString key, sessData.keys()) - recvSessionData(key, sessData[key]); - - // store Buffer details - QVariantList coreBuffers = sessionState["Buffers"].toList(); - /* make lookups by id faster */ - foreach(QVariant vid, coreBuffers) { - buffer(vid.value()); // create all buffers, so we see them in the network views - } - - // create networkInfo objects - QVariantList networkids = sessionState["Networks"].toList(); - foreach(QVariant networkid, networkids) { - networkConnected(networkid.toUInt()); - } - - instance()->connectedToCore = true; - updateCoreConnectionProgress(); - +void Client::setCoreConfiguration(const QVariantMap &settings) { + SignalProxy::writeDataToDevice(socket, settings); } -void Client::updateCoreConnectionProgress() { - // we'll do this in three steps: - // 1.) networks - // 2.) channels - // 3.) ircusers - - int numNets = networkInfos().count(); - int numNetsWaiting = 0; - - int numIrcUsers = 0; - int numIrcUsersWaiting = 0; - - int numChannels = 0; - int numChannelsWaiting = 0; - - foreach(NetworkInfo *net, networkInfos()) { - if(! net->initialized()) - numNetsWaiting++; - - numIrcUsers += net->ircUsers().count(); - foreach(IrcUser *user, net->ircUsers()) { - if(! user->initialized()) - numIrcUsersWaiting++; - } - - numChannels += net->ircChannels().count(); - foreach(IrcChannel *channel, net->ircChannels()) { - if(! channel->initialized()) - numChannelsWaiting++; - } - } - - if(numNetsWaiting > 0) { - emit coreConnectionMsg(tr("Requesting network states...")); - emit coreConnectionProgress(numNets - numNetsWaiting, numNets); - return; - } - - if(numIrcUsersWaiting > 0) { - emit coreConnectionMsg(tr("Requesting User states...")); - emit coreConnectionProgress(numIrcUsers - numIrcUsersWaiting, numIrcUsers); - return; - } - - if(numChannelsWaiting > 0) { - emit coreConnectionMsg(tr("Requesting Channel states...")); - emit coreConnectionProgress(numChannels - numChannelsWaiting, numChannels); - return; - } - - emit coreConnectionProgress(1,1); - emit connected(); - foreach(NetworkInfo *net, networkInfos()) { - disconnect(net, 0, this, SLOT(updateCoreConnectionProgress())); - } - - // signalProxy()->dumpProxyStats(); -} +/*** Session data ***/ void Client::recvSessionData(const QString &key, const QVariant &data) { sessionData[key] = data; @@ -409,96 +342,95 @@ QStringList Client::sessionDataKeys() { return instance()->sessionData.keys(); } -void Client::coreSocketError(QAbstractSocket::SocketError) { - emit coreConnectionError(socket->errorString()); - socket->deleteLater(); -} +/*** ***/ -void Client::coreHasData() { - QVariant item; - if(readDataFromDevice(socket, blockSize, item)) { - emit recvPartialItem(1,1); - QVariantMap msg = item.toMap(); - if (!msg["StartWizard"].toBool()) { - recvCoreState(msg["Reply"]); - } else { - qWarning("Core not configured!"); - qDebug() << "Available storage providers: " << msg["StorageProviders"].toStringList(); - emit showConfigWizard(msg); - } - blockSize = 0; - return; - } - if(blockSize > 0) { - emit recvPartialItem(socket->bytesAvailable(), blockSize); - } +// FIXME +void Client::disconnectFromNetwork(NetworkId id) { + if(!instance()->_networks.contains(id)) return; + Network *net = instance()->_networks[id]; + net->requestDisconnect(); } +/* void Client::networkConnected(uint netid) { // TODO: create statusBuffer / switch to networkids //BufferInfo id = statusBufferInfo(net); //Buffer *b = buffer(id); //b->setActive(true); - NetworkInfo *netinfo = new NetworkInfo(netid, this); + Network *netinfo = new Network(netid, this); netinfo->setProxy(signalProxy()); - - if(!isConnected()) { - connect(netinfo, SIGNAL(initDone()), this, SLOT(updateCoreConnectionProgress())); - connect(netinfo, SIGNAL(ircUserInitDone()), this, SLOT(updateCoreConnectionProgress())); - connect(netinfo, SIGNAL(ircChannelInitDone()), this, SLOT(updateCoreConnectionProgress())); - } - connect(netinfo, SIGNAL(destroyed()), this, SLOT(networkInfoDestroyed())); - _networkInfo[netid] = netinfo; + networkModel()->attachNetwork(netinfo); + connect(netinfo, SIGNAL(destroyed()), this, SLOT(networkDestroyed())); + _networks[netid] = netinfo; } -void Client::networkDisconnected(uint networkid) { - foreach(Buffer *buffer, buffers()) { - if(buffer->bufferInfo().networkId() != networkid) - continue; - - //buffer->displayMsg(Message(bufferid, Message::Server, tr("Server disconnected."))); FIXME - buffer->setActive(false); +void Client::networkDisconnected(NetworkId networkid) { + if(!_networks.contains(networkid)) { + qWarning() << "Client::networkDisconnected(uint): unknown Network" << networkid; + return; } - - Q_ASSERT(networkInfo(networkid)); - if(!networkInfo(networkid)->initialized()) { + + Network *net = _networks.take(networkid); + if(!net->isInitialized()) { qDebug() << "Network" << networkid << "disconnected while not yet initialized!"; updateCoreConnectionProgress(); } + net->deleteLater(); +} +*/ + +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::createNetwork(const NetworkInfo &info) { + + +} + +/*** ***/ + void Client::updateBufferInfo(BufferInfo id) { - buffer(id)->updateBufferInfo(id); + emit bufferUpdated(id); } void Client::bufferDestroyed() { Buffer *buffer = static_cast(sender()); - uint bufferUid = buffer->uid(); - if(_buffers.contains(bufferUid)) - _buffers.remove(bufferUid); + QHash::iterator iter = _buffers.begin(); + while(iter != _buffers.end()) { + if(iter.value() == buffer) { + iter = _buffers.erase(iter); + break; + } + iter++; + } } -void Client::networkInfoDestroyed() { - NetworkInfo *netinfo = static_cast(sender()); - uint networkId = netinfo->networkId(); - if(_networkInfo.contains(networkId)) - _networkInfo.remove(networkId); +void Client::networkDestroyed() { + // FIXME this is not gonna work, net is a QObject here already! + Network *net = static_cast(sender()); + NetworkId networkId = net->networkId(); + if(_networks.contains(networkId)) + _networks.remove(networkId); } void Client::recvMessage(const Message &msg) { Buffer *b = buffer(msg.buffer()); + b->appendMsg(msg); + networkModel()->updateBufferActivity(msg); - 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; + if(msg.type() == Message::Plain || msg.type() == Message::Notice || msg.type() == Message::Action) { + QString sender = msg.buffer().network() + ":" + msg.buffer().buffer() + ":" + msg.sender(); + Message mmsg = Message(msg.timestamp(), msg.buffer(), msg.type(), msg.text(), sender, msg.flags()); + monitorBuffer()->appendMsg(mmsg); } - emit bufferActivity(level, b); - b->appendMsg(msg); } void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) { @@ -510,6 +442,7 @@ void Client::recvBacklogData(BufferInfo id, QVariantList msgs, bool /*done*/) { foreach(QVariant v, msgs) { Message msg = v.value(); b->prependMsg(msg); + // networkModel()->updateBufferActivity(msg); if(!layoutQueue.contains(b)) layoutQueue.append(b); } if(layoutQueue.count() && !layoutTimer->isActive()) layoutTimer->start(); @@ -530,7 +463,3 @@ AbstractUiMsg *Client::layoutMsg(const Message &msg) { return instance()->mainUi->layoutMsg(msg); } -void Client::userInput(BufferInfo id, QString msg) { - emit sendInput(id, msg); -} -