X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoresession.cpp;h=dcc5641f1d60e373e6b2c65f42e67a14e74baaa3;hp=8e1fe93f5c19e703765dd13a19ddec0091e3a6df;hb=e3198912416b2e4ed3708d66953fd6f4928a2382;hpb=2039f5e28eeb431e394f1c2468a26218bd926538 diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 8e1fe93f..dcc5641f 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by The Quassel IRC Development Team * + * Copyright (C) 2005-07 by the Quassel IRC Team * * 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 * @@ -20,12 +20,24 @@ #include "coresession.h" #include "server.h" + +#include "signalproxy.h" #include "storage.h" + +#include "networkinfo.h" +#include "ircuser.h" +#include "ircchannel.h" + #include "util.h" -CoreSession::CoreSession(UserId uid, Storage *_storage) : user(uid), storage(_storage) { - coreProxy = new CoreProxy(); +CoreSession::CoreSession(UserId uid, Storage *_storage, QObject *parent) + : QObject(parent), + user(uid), + _signalProxy(new SignalProxy(SignalProxy::Server, 0, this)), + storage(_storage) +{ + QSettings s; s.beginGroup(QString("SessionData/%1").arg(user)); mutex.lock(); @@ -34,34 +46,38 @@ CoreSession::CoreSession(UserId uid, Storage *_storage) : user(uid), storage(_st } mutex.unlock(); - connect(coreProxy, SIGNAL(send(CoreSignal, QVariant, QVariant, QVariant)), this, SIGNAL(proxySignal(CoreSignal, QVariant, QVariant, QVariant))); - connect(coreProxy, SIGNAL(requestServerStates()), this, SIGNAL(serverStateRequested())); - connect(coreProxy, SIGNAL(gsRequestConnect(QStringList)), this, SLOT(connectToIrc(QStringList))); - connect(coreProxy, SIGNAL(gsUserInput(BufferId, QString)), this, SLOT(msgFromGui(BufferId, QString))); - connect(coreProxy, SIGNAL(gsImportBacklog()), storage, SLOT(importOldBacklog())); - connect(coreProxy, SIGNAL(gsRequestBacklog(BufferId, QVariant, QVariant)), this, SLOT(sendBacklog(BufferId, QVariant, QVariant))); - connect(coreProxy, SIGNAL(gsRequestNetworkStates()), this, SLOT(sendServerStates())); - connect(this, SIGNAL(displayMsg(Message)), coreProxy, SLOT(csDisplayMsg(Message))); - connect(this, SIGNAL(displayStatusMsg(QString, QString)), coreProxy, SLOT(csDisplayStatusMsg(QString, QString))); - connect(this, SIGNAL(backlogData(BufferId, QList, bool)), coreProxy, SLOT(csBacklogData(BufferId, QList, bool))); - connect(this, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId))); - connect(storage, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId))); - connect(this, SIGNAL(sessionDataChanged(const QString &, const QVariant &)), coreProxy, SLOT(csSessionDataChanged(const QString &, const QVariant &))); - connect(coreProxy, SIGNAL(gsSessionDataChanged(const QString &, const QVariant &)), this, SLOT(storeSessionData(const QString &, const QVariant &))); + SignalProxy *p = signalProxy(); + + p->attachSlot(SIGNAL(requestNetworkStates()), this, SLOT(serverStateRequested())); + p->attachSlot(SIGNAL(requestConnect(QString)), this, SLOT(connectToNetwork(QString))); + p->attachSlot(SIGNAL(sendInput(BufferInfo, QString)), this, SLOT(msgFromGui(BufferInfo, QString))); + p->attachSlot(SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)), this, SLOT(sendBacklog(BufferInfo, QVariant, QVariant))); + p->attachSignal(this, SIGNAL(displayMsg(Message))); + p->attachSignal(this, SIGNAL(displayStatusMsg(QString, QString))); + p->attachSignal(this, SIGNAL(backlogData(BufferInfo, QVariantList, bool))); + p->attachSignal(this, SIGNAL(bufferInfoUpdated(BufferInfo))); + p->attachSignal(storage, SIGNAL(bufferInfoUpdated(BufferInfo))); + p->attachSignal(this, SIGNAL(sessionDataChanged(const QString &, const QVariant &)), SIGNAL(coreSessionDataChanged(const QString &, const QVariant &))); + p->attachSlot(SIGNAL(clientSessionDataChanged(const QString &, const QVariant &)), this, SLOT(storeSessionData(const QString &, const QVariant &))); + /* Autoconnect. (When) do we actually do this? + QStringList list; + QVariantMap networks = retrieveSessionData("Networks").toMap(); + foreach(QString net, networks.keys()) { + if(networks[net].toMap()["AutoConnect"].toBool()) { + list << net; + } + } qDebug() << list; + if(list.count()) connectToIrc(list); + */ } CoreSession::~CoreSession() { - } UserId CoreSession::userId() const { return user; } -void CoreSession::processSignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { - coreProxy->recv(sig, arg1, arg2, arg3); -} - void CoreSession::storeSessionData(const QString &key, const QVariant &data) { QSettings s; s.beginGroup(QString("SessionData/%1").arg(user)); @@ -83,104 +99,119 @@ QVariant CoreSession::retrieveSessionData(const QString &key, const QVariant &de return data; } -void CoreSession::connectToIrc(QStringList networks) { - foreach(QString net, networks) { - if(servers.contains(net)) { - - } else { - Server *server = new Server(userId(), net); - connect(this, SIGNAL(serverStateRequested()), server, SLOT(sendState())); - connect(this, SIGNAL(connectToIrc(QString)), server, SLOT(connectToIrc(QString))); - connect(this, SIGNAL(disconnectFromIrc(QString)), server, SLOT(disconnectFromIrc(QString))); - connect(this, SIGNAL(msgFromGui(QString, QString, QString)), server, SLOT(userInput(QString, QString, QString))); - - connect(server, SIGNAL(connected(QString)), this, SLOT(serverConnected(QString))); - connect(server, SIGNAL(disconnected(QString)), this, SLOT(serverDisconnected(QString))); - - connect(server, SIGNAL(serverState(QString, VarMap)), coreProxy, SLOT(csServerState(QString, VarMap))); - //connect(server, SIGNAL(displayMsg(Message)), this, SLOT(recvMessageFromServer(Message))); - connect(server, SIGNAL(displayMsg(Message::Type, QString, QString, QString, quint8)), this, SLOT(recvMessageFromServer(Message::Type, QString, QString, QString, quint8))); - connect(server, SIGNAL(displayStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString))); - connect(server, SIGNAL(modeSet(QString, QString, QString)), coreProxy, SLOT(csModeSet(QString, QString, QString))); - connect(server, SIGNAL(topicSet(QString, QString, QString)), coreProxy, SLOT(csTopicSet(QString, QString, QString))); - connect(server, SIGNAL(nickAdded(QString, QString, VarMap)), coreProxy, SLOT(csNickAdded(QString, QString, VarMap))); - connect(server, SIGNAL(nickRenamed(QString, QString, QString)), coreProxy, SLOT(csNickRenamed(QString, QString, QString))); - connect(server, SIGNAL(nickRemoved(QString, QString)), coreProxy, SLOT(csNickRemoved(QString, QString))); - connect(server, SIGNAL(nickUpdated(QString, QString, VarMap)), coreProxy, SLOT(csNickUpdated(QString, QString, VarMap))); - connect(server, SIGNAL(ownNickSet(QString, QString)), coreProxy, SLOT(csOwnNickSet(QString, QString))); - connect(server, SIGNAL(queryRequested(QString, QString)), coreProxy, SLOT(csQueryRequested(QString, QString))); - // TODO add error handling - connect(server, SIGNAL(connected(QString)), coreProxy, SLOT(csServerConnected(QString))); - connect(server, SIGNAL(disconnected(QString)), coreProxy, SLOT(csServerDisconnected(QString))); - - server->start(); - servers[net] = server; - } - emit connectToIrc(net); +// FIXME switch to NetworkIDs +void CoreSession::connectToNetwork(QString network) { + uint networkid = getNetworkId(network); + if(networkid == 0) { + qWarning() << "unable to connect to Network" << network << "(User:" << userId() << "): unable to determine NetworkId"; + return; + } + if(!servers.contains(networkid)) { + Server *server = new Server(userId(), networkid, network); + servers[networkid] = server; + attachServer(server); + server->start(); } + emit connectToIrc(network); +} + +void CoreSession::attachServer(Server *server) { + connect(this, SIGNAL(connectToIrc(QString)), server, SLOT(connectToIrc(QString))); + connect(this, SIGNAL(disconnectFromIrc(QString)), server, SLOT(disconnectFromIrc(QString))); + connect(this, SIGNAL(msgFromGui(uint, QString, QString)), server, SLOT(userInput(uint, QString, QString))); + + connect(server, SIGNAL(connected(uint)), this, SLOT(serverConnected(uint))); + connect(server, SIGNAL(disconnected(uint)), this, SLOT(serverDisconnected(uint))); + connect(server, SIGNAL(displayMsg(Message::Type, QString, QString, QString, quint8)), this, SLOT(recvMessageFromServer(Message::Type, QString, QString, QString, quint8))); + connect(server, SIGNAL(displayStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString))); + + // connect serversignals to proxy + signalProxy()->attachSignal(server, SIGNAL(serverState(QString, QVariantMap)), SIGNAL(networkState(QString, QVariantMap))); + signalProxy()->attachSignal(server, SIGNAL(connected(uint)), SIGNAL(networkConnected(uint))); + signalProxy()->attachSignal(server, SIGNAL(disconnected(uint)), SIGNAL(networkDisconnected(uint))); + // TODO add error handling +} + +void CoreSession::serverStateRequested() { } -void CoreSession::serverConnected(QString net) { - storage->getBufferId(userId(), net); // create status buffer +void CoreSession::addClient(QIODevice *device) { + signalProxy()->addPeer(device); } -void CoreSession::serverDisconnected(QString net) { - delete servers[net]; - servers.remove(net); - coreProxy->csServerDisconnected(net); +SignalProxy *CoreSession::signalProxy() const { + return _signalProxy; } -void CoreSession::msgFromGui(BufferId bufid, QString msg) { - emit msgFromGui(bufid.network(), bufid.buffer(), msg); +void CoreSession::serverConnected(uint networkid) { + storage->getBufferInfo(userId(), servers[networkid]->networkName()); // create status buffer +} + +void CoreSession::serverDisconnected(uint networkid) { + Q_ASSERT(servers.contains(networkid)); + servers.take(networkid)->deleteLater(); + Q_ASSERT(!servers.contains(networkid)); +} + +void CoreSession::msgFromGui(BufferInfo bufid, QString msg) { + emit msgFromGui(bufid.networkId(), bufid.buffer(), msg); } // ALL messages coming pass through these functions before going to the GUI. // So this is the perfect place for storing the backlog and log stuff. - void CoreSession::recvMessageFromServer(Message::Type type, QString target, QString text, QString sender, quint8 flags) { Server *s = qobject_cast(this->sender()); Q_ASSERT(s); - BufferId buf; + BufferInfo buf; if((flags & Message::PrivMsg) && !(flags & Message::Self)) { - buf = storage->getBufferId(user, s->getNetwork(), nickFromMask(sender)); + buf = storage->getBufferInfo(user, s->networkName(), nickFromMask(sender)); } else { - buf = storage->getBufferId(user, s->getNetwork(), target); + buf = storage->getBufferInfo(user, s->networkName(), target); } Message msg(buf, type, text, sender, flags); - msg.msgId = storage->logMessage(msg); - Q_ASSERT(msg.msgId); + msg.setMsgId(storage->logMessage(msg)); + Q_ASSERT(msg.msgId()); emit displayMsg(msg); } void CoreSession::recvStatusMsgFromServer(QString msg) { Server *s = qobject_cast(sender()); Q_ASSERT(s); - emit displayStatusMsg(s->getNetwork(), msg); + emit displayStatusMsg(s->networkName(), msg); } -QList CoreSession::buffers() const { +uint CoreSession::getNetworkId(const QString &net) const { + return storage->getNetworkId(user, net); +} + +QList CoreSession::buffers() const { return storage->requestBuffers(user); } QVariant CoreSession::sessionState() { - VarMap v; - QList bufs; - foreach(BufferId id, storage->requestBuffers(user)) { bufs.append(QVariant::fromValue(id)); } + QVariantMap v; + + QVariantList bufs; + foreach(BufferInfo id, storage->requestBuffers(user)) + bufs.append(QVariant::fromValue(id)); v["Buffers"] = bufs; + mutex.lock(); v["SessionData"] = sessionData; mutex.unlock(); - v["Networks"] = QVariant(servers.keys()); - return v; -} -void CoreSession::sendServerStates() { - emit serverStateRequested(); + QVariantList networks; + foreach(uint networkid, servers.keys()) + networks.append(QVariant(networkid)); + v["Networks"] = QVariant(networks); + + // v["Payload"] = QByteArray(100000000, 'a'); // for testing purposes + return v; } -void CoreSession::sendBacklog(BufferId id, QVariant v1, QVariant v2) { +void CoreSession::sendBacklog(BufferInfo id, QVariant v1, QVariant v2) { QList log; QList msglist; if(v1.type() == QVariant::DateTime) {