X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoresession.cpp;h=fd9a872e60c4adf03d2caab2862d1157f5375d15;hp=2649824a87a5cd7af2fbf5c3b9bed20f3edd8a62;hb=3c2914faeb01f3bc32e29f40179ae88040fbcf59;hpb=ac21cc48d22f0cf58a98b74754fa94564a8e3f45 diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 2649824a..fd9a872e 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -24,7 +24,7 @@ #include "coresession.h" #include "userinputhandler.h" #include "signalproxy.h" -#include "buffersyncer.h" +#include "corebuffersyncer.h" #include "corebacklogmanager.h" #include "corebufferviewmanager.h" #include "coreirclisthelper.h" @@ -44,7 +44,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) _user(uid), _signalProxy(new SignalProxy(SignalProxy::Server, 0, this)), _aliasManager(this), - _bufferSyncer(new BufferSyncer(this)), + _bufferSyncer(new CoreBufferSyncer(this)), _backlogManager(new CoreBacklogManager(this)), _bufferViewManager(new CoreBufferViewManager(_signalProxy, this)), _ircListHelper(new CoreIrcListHelper(this)), @@ -80,10 +80,8 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) foreach(BufferId id, lastSeenHash.keys()) _bufferSyncer->requestSetLastSeenMsg(id, lastSeenHash[id]); - connect(_bufferSyncer, SIGNAL(lastSeenMsgSet(BufferId, MsgId)), this, SLOT(storeBufferLastSeenMsg(BufferId, MsgId))); - connect(_bufferSyncer, SIGNAL(removeBufferRequested(BufferId)), this, SLOT(removeBufferRequested(BufferId))); - connect(this, SIGNAL(bufferRemoved(BufferId)), _bufferSyncer, SLOT(removeBuffer(BufferId))); - connect(this, SIGNAL(bufferRenamed(BufferId, QString)), _bufferSyncer, SLOT(renameBuffer(BufferId, QString))); + // connect(_bufferSyncer, SIGNAL(lastSeenMsgSet(BufferId, MsgId)), this, SLOT(storeBufferLastSeenMsg(BufferId, MsgId))); + connect(&(Core::instance()->syncTimer()), SIGNAL(timeout()), _bufferSyncer, SLOT(storeDirtyIds())); p->synchronize(_bufferSyncer); @@ -125,14 +123,34 @@ CoreIdentity *CoreSession::identity(IdentityId id) const { void CoreSession::loadSettings() { CoreUserSettings s(user()); - foreach(IdentityId id, s.identityIds()) { - createIdentity(s.identity(id)); + // migrate to db + QList ids = s.identityIds(); + QList networkInfos = Core::networks(user()); + foreach(IdentityId id, ids) { + CoreIdentity identity(s.identity(id)); + IdentityId newId = Core::createIdentity(user(), identity); + QList::iterator networkIter = networkInfos.begin(); + while(networkIter != networkInfos.end()) { + if(networkIter->identity == id) { + networkIter->identity = newId; + Core::updateNetwork(user(), *networkIter); + networkIter = networkInfos.erase(networkIter); + } else { + networkIter++; + } + } + s.removeIdentity(id); + } + // end of migration + + foreach(CoreIdentity identity, Core::identities(user())) { + createIdentity(identity); } if(!_identities.count()) { Identity identity; identity.setToDefaults(); identity.setIdentityName(tr("Default Identity")); - createIdentity(identity); + createIdentity(identity, QVariantMap()); } foreach(NetworkInfo info, Core::networks(user())) { @@ -141,6 +159,7 @@ void CoreSession::loadSettings() { } void CoreSession::saveSessionState() const { + _bufferSyncer->storeDirtyIds(); } void CoreSession::restoreSessionState() { @@ -264,45 +283,47 @@ void CoreSession::scriptRequest(QString script) { } /*** Identity Handling ***/ - void CoreSession::createIdentity(const Identity &identity, const QVariantMap &additional) { - if(_identities.contains(identity.id())) { - qWarning() << "duplicate Identity:" << identity.id(); - return; - } +#ifndef HAVE_SSL + Q_UNUSED(additional) +#endif - int id = identity.id().toInt(); - bool newId = !identity.isValid(); - CoreIdentity *coreIdentity = new CoreIdentity(identity, signalProxy(), this); + CoreIdentity coreIdentity(identity); +#ifdef HAVE_SSL if(additional.contains("KeyPem")) - coreIdentity->setSslKey(additional["KeyPem"].toByteArray()); + coreIdentity.setSslKey(additional["KeyPem"].toByteArray()); if(additional.contains("CertPem")) - coreIdentity->setSslCert(additional["CertPem"].toByteArray()); - if(newId) { - // find free ID - for(id = 1; id <= _identities.count(); id++) { - if(!_identities.keys().contains(id)) - break; - } - coreIdentity->setId(id); - coreIdentity->save(); - } + coreIdentity.setSslCert(additional["CertPem"].toByteArray()); +#endif + IdentityId id = Core::createIdentity(user(), coreIdentity); + if(!id.isValid()) + return; + else + createIdentity(coreIdentity); +} - _identities[id] = coreIdentity; - qDebug() << id << coreIdentity->id(); - signalProxy()->synchronize(coreIdentity); +void CoreSession::createIdentity(const CoreIdentity &identity) { + CoreIdentity *coreIdentity = new CoreIdentity(identity, this); + _identities[identity.id()] = coreIdentity; + // CoreIdentity has it's own synchronize method since it's "private" sslManager needs to be synced aswell + coreIdentity->synchronize(signalProxy()); + connect(coreIdentity, SIGNAL(updated(const QVariantMap &)), this, SLOT(updateIdentityBySender())); + emit identityCreated(*coreIdentity); +} - if(newId) - emit identityCreated(*coreIdentity); +void CoreSession::updateIdentityBySender() { + CoreIdentity *identity = qobject_cast(sender()); + if(!identity) + return; + Core::updateIdentity(user(), *identity); } void CoreSession::removeIdentity(IdentityId id) { - Identity *i = _identities.take(id); - if(i) { + CoreIdentity *identity = _identities.take(id); + if(identity) { emit identityRemoved(id); - CoreUserSettings s(user()); - s.removeIdentity(id); - i->deleteLater(); + Core::removeIdentity(user(), id); + identity->deleteLater(); } } @@ -364,40 +385,9 @@ void CoreSession::destroyNetwork(NetworkId id) { } } -void CoreSession::removeBufferRequested(BufferId bufferId) { - BufferInfo bufferInfo = Core::getBufferInfo(user(), bufferId); - if(!bufferInfo.isValid()) { - qWarning() << "CoreSession::removeBufferRequested(): invalid BufferId:" << bufferId << "for User:" << user(); - return; - } - - if(bufferInfo.type() == BufferInfo::StatusBuffer) { - qWarning() << "CoreSession::removeBufferRequested(): Status Buffers cannot be removed!"; - return; - } - - if(bufferInfo.type() == BufferInfo::ChannelBuffer) { - CoreNetwork *net = network(bufferInfo.networkId()); - if(!net) { - qWarning() << "CoreSession::removeBufferRequested(): Received BufferInfo with unknown networkId!"; - return; - } - IrcChannel *chan = net->ircChannel(bufferInfo.bufferName()); - if(chan) { - qWarning() << "CoreSession::removeBufferRequested(): Unable to remove Buffer for joined Channel:" << bufferInfo.bufferName(); - return; - } - } - if(Core::removeBuffer(user(), bufferId)) - emit bufferRemoved(bufferId); -} - -// FIXME: use a coreBufferSyncer for this void CoreSession::renameBuffer(const NetworkId &networkId, const QString &newName, const QString &oldName) { - BufferId bufferId = Core::renameBuffer(user(), networkId, newName, oldName); - if(bufferId.isValid()) { - emit bufferRenamed(bufferId, newName); - } + BufferInfo bufferInfo = Core::bufferInfo(user(), networkId, BufferInfo::QueryBuffer, oldName); + _bufferSyncer->renameBuffer(bufferInfo.bufferId(), newName); } void CoreSession::clientsConnected() {