From c0c8cea57282c56951562e427bc1acb3ee2028a3 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sun, 17 Aug 2008 22:19:29 +0200 Subject: [PATCH] Use SyncableObject::requestUpdate() for updating Identities This makes things a bit cleaner and spares us another custom signal between client and core. --- src/client/client.cpp | 11 +++-- src/client/client.h | 7 ++-- src/common/identity.cpp | 3 +- src/core/coresession.cpp | 40 +++++++++---------- src/core/coresession.h | 10 ++--- .../settingspages/identitiessettingspage.cpp | 3 +- 6 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 48c471c5..2b667e0c 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -110,7 +110,6 @@ void Client::init() { 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))); @@ -257,8 +256,14 @@ void Client::createIdentity(const Identity &id) { emit instance()->requestCreateIdentity(id); } -void Client::updateIdentity(const Identity &id) { - emit instance()->requestUpdateIdentity(id); +void Client::updateIdentity(IdentityId id, const QVariantMap &ser) { + //emit instance()->requestUpdateIdentity(id); + Identity *idptr = instance()->_identities.value(id, 0); + if(!idptr) { + qWarning() << "Update for unknown identity requested:" << id; + return; + } + idptr->requestUpdate(ser); } void Client::removeIdentity(IdentityId id) { diff --git a/src/client/client.h b/src/client/client.h index edda8c6b..8b991bda 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -82,9 +82,10 @@ public: //! Request update of an identity with the given data. /** The request will be sent to the core, and will be propagated back to all the clients. - * \param identity The identity to be updated. + * \param id The identity to be updated. + * \param serializedData The identity's content (cf. SyncableObject::toVariantMap()) */ - static void updateIdentity(const Identity &identity); + static void updateIdentity(IdentityId id, const QVariantMap &serializedData); //! Request removal of the identity with the given ID from the core (and all the clients, of course). /** \param id The ID of the identity to be removed. @@ -145,8 +146,6 @@ signals: //! Sent to the core when an identity shall be created. Should not be used elsewhere. void requestCreateIdentity(const Identity &); - //! Sent to the core when an identity shall be updated. Should not be used elsewhere. - void requestUpdateIdentity(const Identity &); //! Sent to the core when an identity shall be removed. Should not be used elsewhere. void requestRemoveIdentity(IdentityId); diff --git a/src/common/identity.cpp b/src/common/identity.cpp index 7d19204e..dcec2d92 100644 --- a/src/common/identity.cpp +++ b/src/common/identity.cpp @@ -55,6 +55,7 @@ Identity::Identity(const Identity &other, QObject *parent) : SyncableObject(pare void Identity::init() { setObjectName(QString::number(id().toInt())); + setAllowClientUpdates(true); } void Identity::setToDefaults() { @@ -269,7 +270,7 @@ for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount( } } } -#include + bool Identity::operator==(const Identity &other) { for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) { QMetaProperty metaProp = metaObject()->property(idx); diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 73369a96..efdad6e4 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -56,7 +56,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) SignalProxy *p = signalProxy(); connect(p, SIGNAL(peerRemoved(QIODevice *)), this, SLOT(removeClient(QIODevice *))); - + //p->attachSlot(SIGNAL(disconnectFromNetwork(NetworkId)), this, SLOT(disconnectFromNetwork(NetworkId))); // FIXME p->attachSlot(SIGNAL(sendInput(BufferInfo, QString)), this, SLOT(msgFromClient(BufferInfo, QString))); p->attachSignal(this, SIGNAL(displayMsg(Message))); @@ -66,7 +66,6 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) p->attachSignal(this, SIGNAL(identityCreated(const Identity &))); p->attachSignal(this, SIGNAL(identityRemoved(IdentityId))); p->attachSlot(SIGNAL(createIdentity(const Identity &)), this, SLOT(createIdentity(const Identity &))); - p->attachSlot(SIGNAL(updateIdentity(const Identity &)), this, SLOT(updateIdentity(const Identity &))); p->attachSlot(SIGNAL(removeIdentity(IdentityId)), this, SLOT(removeIdentity(IdentityId))); p->attachSignal(this, SIGNAL(networkCreated(NetworkId))); @@ -82,7 +81,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) QHash lastSeenHash = Core::bufferLastSeenMsgIds(user()); 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))); @@ -92,16 +91,16 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent) // init alias manager p->synchronize(&aliasManager()); - + // init BacklogManager p->synchronize(_backlogManager); // init IrcListHelper p->synchronize(ircListHelper()); - + // init CoreInfo p->synchronize(&_coreInfo); - + // Restore session state if(restoreState) restoreSessionState(); @@ -153,6 +152,7 @@ void CoreSession::loadSettings() { delete i; continue; } + connect(i, SIGNAL(updated(const QVariantMap &)), this, SLOT(identityUpdated(const QVariantMap &))); _identities[i->id()] = i; signalProxy()->synchronize(i); } @@ -222,7 +222,7 @@ void CoreSession::attachNetworkConnection(NetworkConnection *conn) { void CoreSession::disconnectFromNetwork(NetworkId id) { if(!_connections.contains(id)) return; - + //_connections[id]->disconnectFromIrc(); _connections[id]->userInputHandler()->handleQuit(BufferInfo(), QString()); } @@ -382,20 +382,10 @@ void CoreSession::createIdentity(const Identity &id) { signalProxy()->synchronize(newId); CoreUserSettings s(user()); s.storeIdentity(*newId); + connect(newId, SIGNAL(updated(const QVariantMap &)), this, SLOT(identityUpdated(const QVariantMap &))); emit identityCreated(*newId); } -void CoreSession::updateIdentity(const Identity &id) { - if(!_identities.contains(id.id())) { - quWarning() << "Update request for unknown identity received!"; - return; - } - _identities[id.id()]->update(id); - - CoreUserSettings s(user()); - s.storeIdentity(id); -} - void CoreSession::removeIdentity(IdentityId id) { Identity *i = _identities.take(id); if(i) { @@ -406,6 +396,16 @@ void CoreSession::removeIdentity(IdentityId id) { } } +void CoreSession::identityUpdated(const QVariantMap &data) { + IdentityId id = data.value("identityId", 0).value(); + if(!id.isValid() || !_identities.contains(id)) { + quWarning() << "Update request for unknown identity received!"; + return; + } + CoreUserSettings s(user()); + s.storeIdentity(*_identities.value(id)); +} + /*** Network Handling ***/ void CoreSession::createNetwork(const NetworkInfo &info_) { @@ -484,12 +484,12 @@ void CoreSession::removeBufferRequested(BufferId bufferId) { quWarning() << "CoreSession::removeBufferRequested(): invalid BufferId:" << bufferId << "for User:" << user(); return; } - + if(bufferInfo.type() == BufferInfo::StatusBuffer) { quWarning() << "CoreSession::removeBufferRequested(): Status Buffers cannot be removed!"; return; } - + if(bufferInfo.type() == BufferInfo::ChannelBuffer) { CoreNetwork *net = network(bufferInfo.networkId()); if(!net) { diff --git a/src/core/coresession.h b/src/core/coresession.h index 57c2a530..7dd03c4b 100644 --- a/src/core/coresession.h +++ b/src/core/coresession.h @@ -61,7 +61,7 @@ public: AliasManager &aliasManager() { return _aliasManager; } inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; } - + void attachNetworkConnection(NetworkConnection *conn); //! Return necessary data for restoring the session after restarting the core @@ -83,11 +83,6 @@ public slots: */ void createIdentity(const Identity &identity); - //! Update an identity and propagate the changes to the clients. - /** \param identity The identity to be updated. - */ - void updateIdentity(const Identity &identity); - //! Remove identity and propagate that fact to the clients. /** \param identity The identity to be removed. */ @@ -167,6 +162,9 @@ private slots: void destroyNetwork(NetworkId); + void identityUpdated(const QVariantMap &); + //void networkUpdated(const QVariantMap &); + //! Called when storage updated a BufferInfo. /** This emits bufferInfoUpdated() via SignalProxy, iff it's one of our buffers. * \param user The buffer's owner (not necessarily us) diff --git a/src/qtui/settingspages/identitiessettingspage.cpp b/src/qtui/settingspages/identitiessettingspage.cpp index 8102f00c..1ca75b0c 100644 --- a/src/qtui/settingspages/identitiessettingspage.cpp +++ b/src/qtui/settingspages/identitiessettingspage.cpp @@ -463,9 +463,8 @@ SaveIdentitiesDlg::SaveIdentitiesDlg(const QList &toCreate, const QL numevents--; continue; } - // FIXME this only checks for one changed item rather than all! connect(cid, SIGNAL(updatedRemotely()), this, SLOT(clientEvent())); - Client::updateIdentity(*id); + Client::updateIdentity(id->id(), id->toVariantMap()); } foreach(IdentityId id, toRemove) { Client::removeIdentity(id); -- 2.20.1