X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Fcoresession.cpp;h=8e667380e3633d5bf65962ecde9b359e47adc3fb;hb=85583b32135dd4028edecef9029661dd11919150;hp=112f60c2bab554987f8bafc26d307453002e5551;hpb=6623fd2d46dadd0168e4e28d1db6944c26c2a773;p=quassel.git diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 112f60c2..8e667380 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -43,9 +43,6 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) : QObje SignalProxy *p = signalProxy(); - CoreUserSettings s(user()); - sessionData = s.sessionData(); - p->attachSlot(SIGNAL(requestConnect(QString)), this, SLOT(connectToNetwork(QString))); p->attachSlot(SIGNAL(disconnectFromNetwork(NetworkId)), this, SLOT(disconnectFromNetwork(NetworkId))); // FIXME p->attachSlot(SIGNAL(sendInput(BufferInfo, QString)), this, SLOT(msgFromClient(BufferInfo, QString))); @@ -55,9 +52,6 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) : QObje p->attachSignal(this, SIGNAL(backlogData(BufferInfo, QVariantList, bool))); p->attachSignal(this, 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 &))); - p->attachSignal(this, SIGNAL(identityCreated(const Identity &))); p->attachSignal(this, SIGNAL(identityRemoved(IdentityId))); p->attachSlot(SIGNAL(createIdentity(const Identity &)), this, SLOT(createIdentity(const Identity &))); @@ -82,10 +76,10 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) : QObje CoreSession::~CoreSession() { saveSessionState(); foreach(NetworkConnection *conn, _connections.values()) { - conn->deleteLater(); + delete conn; } foreach(Network *net, _networks.values()) { - net->deleteLater(); + delete net; } } @@ -134,14 +128,15 @@ void CoreSession::loadSettings() { createIdentity(i); } + // FIXME switch to a pure DB storage foreach(NetworkId id, s.networkIds()) { NetworkInfo info = s.networkInfo(id); - createNetwork(info, true); + createNetwork(info); } // FIXME Migrate old settings if available... if(!_networks.count()) { - QVariantMap networks = retrieveSessionData("Networks").toMap(); + QVariantMap networks = s.sessionValue("Networks").toMap(); if(networks.keys().count()) { qWarning() << "Migrating your old network settings to the new format!"; foreach(QString netname, networks.keys()) { @@ -161,7 +156,7 @@ void CoreSession::loadSettings() { slist << server; } info.serverList = slist; - createNetwork(info, true); + createNetwork(info); } } } @@ -196,22 +191,6 @@ void CoreSession::restoreSessionState() { } } - -void CoreSession::storeSessionData(const QString &key, const QVariant &data) { - CoreUserSettings s(user()); - s.setSessionValue(key, data); - sessionData[key] = data; - emit sessionDataChanged(key, data); - emit sessionDataChanged(key); -} - -QVariant CoreSession::retrieveSessionData(const QString &key, const QVariant &def) { - QVariant data; - if(!sessionData.contains(key)) data = def; - else data = sessionData[key]; - return data; -} - void CoreSession::updateBufferInfo(UserId uid, const BufferInfo &bufinfo) { if(uid == user()) emit bufferInfoUpdated(bufinfo); } @@ -287,7 +266,7 @@ SignalProxy *CoreSession::signalProxy() const { // FIXME we need a sane way for creating buffers! void CoreSession::networkConnected(NetworkId networkid) { - Core::bufferInfo(user(), networkConnection(networkid)->networkName()); // create status buffer + Core::bufferInfo(user(), networkid); // create status buffer } void CoreSession::networkDisconnected(NetworkId networkid) { @@ -302,7 +281,7 @@ void CoreSession::networkDisconnected(NetworkId networkid) { void CoreSession::msgFromClient(BufferInfo bufinfo, QString msg) { NetworkConnection *conn = networkConnection(bufinfo.networkId()); if(conn) { - conn->userInput(bufinfo.buffer(), msg); + conn->userInput(bufinfo.bufferName(), msg); } else { qWarning() << "Trying to send to unconnected network!"; } @@ -311,15 +290,11 @@ void CoreSession::msgFromClient(BufferInfo bufinfo, QString 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) { - NetworkConnection *s = qobject_cast(this->sender()); - Q_ASSERT(s); - BufferInfo buf; - if((flags & Message::PrivMsg) && !(flags & Message::Self)) { - buf = Core::bufferInfo(user(), s->networkName(), nickFromMask(sender)); - } else { - buf = Core::bufferInfo(user(), s->networkName(), target); - } - Message msg(buf, type, text, sender, flags); + NetworkConnection *netCon = qobject_cast(this->sender()); + Q_ASSERT(netCon); + + BufferInfo bufferInfo = Core::bufferInfo(user(), netCon->networkId(), target); + Message msg(bufferInfo, type, text, sender, flags); msg.setMsgId(Core::storeMessage(msg)); Q_ASSERT(msg.msgId() != 0); emit displayMsg(msg); @@ -359,9 +334,7 @@ QVariant CoreSession::sessionState() { foreach(Identity *i, _identities.values()) idlist << qVariantFromValue(*i); v["Identities"] = idlist; - v["SessionData"] = sessionData; - - //v["Payload"] = QByteArray(100000000, 'a'); // for testing purposes + //v["Payload"] = QByteArray(100000000, 'a'); // for testing purposes return v; } @@ -441,17 +414,18 @@ void CoreSession::removeIdentity(IdentityId id) { /*** Network Handling ***/ -void CoreSession::createNetwork(const NetworkInfo &_info, bool useId) { - NetworkInfo info = _info; +void CoreSession::createNetwork(const NetworkInfo &info_) { + NetworkInfo info = info_; int id; - if(useId && info.networkId > 0) id = info.networkId.toInt(); - else { - for(id = 1; id <= _networks.count(); id++) { - if(!_networks.keys().contains(id)) break; - } - //qDebug() << "found free id" << i; - info.networkId = id; - } + + if(!info.networkId.isValid()) + Core::createNetworkId(user(), info); + + Q_ASSERT(info.networkId.isValid()); + + id = info.networkId.toInt(); + Q_ASSERT(!_networks.contains(id)); + Network *net = new Network(id, this); connect(net, SIGNAL(connectRequested(NetworkId)), this, SLOT(connectToNetwork(NetworkId))); connect(net, SIGNAL(disconnectRequested(NetworkId)), this, SLOT(disconnectFromNetwork(NetworkId)));