Use SyncableObject::requestUpdate() for updating Identities
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 17 Aug 2008 20:19:29 +0000 (22:19 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 17 Aug 2008 22:05:17 +0000 (00:05 +0200)
This makes things a bit cleaner and spares us another custom signal between
client and core.

src/client/client.cpp
src/client/client.h
src/common/identity.cpp
src/core/coresession.cpp
src/core/coresession.h
src/qtui/settingspages/identitiessettingspage.cpp

index 48c471c..2b667e0 100644 (file)
@@ -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(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(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);
 }
 
   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) {
 }
 
 void Client::removeIdentity(IdentityId id) {
index edda8c6..8b991bd 100644 (file)
@@ -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.
 
   //! 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.
 
   //! 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 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);
 
   //! Sent to the core when an identity shall be removed. Should not be used elsewhere.
   void requestRemoveIdentity(IdentityId);
 
index 7d19204..dcec2d9 100644 (file)
@@ -55,6 +55,7 @@ Identity::Identity(const Identity &other, QObject *parent) : SyncableObject(pare
 
 void Identity::init() {
   setObjectName(QString::number(id().toInt()));
 
 void Identity::init() {
   setObjectName(QString::number(id().toInt()));
+  setAllowClientUpdates(true);
 }
 
 void Identity::setToDefaults() {
 }
 
 void Identity::setToDefaults() {
@@ -269,7 +270,7 @@ for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(
     }
   }
 }
     }
   }
 }
-#include <QDebug>
+
 bool Identity::operator==(const Identity &other) {
   for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) {
     QMetaProperty metaProp = metaObject()->property(idx);
 bool Identity::operator==(const Identity &other) {
   for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) {
     QMetaProperty metaProp = metaObject()->property(idx);
index 73369a9..efdad6e 100644 (file)
@@ -56,7 +56,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
 
   SignalProxy *p = signalProxy();
   connect(p, SIGNAL(peerRemoved(QIODevice *)), this, SLOT(removeClient(QIODevice *)));
 
   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)));
   //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->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)));
   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<BufferId, MsgId> lastSeenHash = Core::bufferLastSeenMsgIds(user());
   foreach(BufferId id, lastSeenHash.keys())
     _bufferSyncer->requestSetLastSeenMsg(id, lastSeenHash[id]);
   QHash<BufferId, MsgId> 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)));
   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 alias manager
   p->synchronize(&aliasManager());
-  
+
   // init BacklogManager
   p->synchronize(_backlogManager);
 
   // init IrcListHelper
   p->synchronize(ircListHelper());
   // init BacklogManager
   p->synchronize(_backlogManager);
 
   // init IrcListHelper
   p->synchronize(ircListHelper());
-  
+
   // init CoreInfo
   p->synchronize(&_coreInfo);
   // init CoreInfo
   p->synchronize(&_coreInfo);
-  
+
   // Restore session state
   if(restoreState) restoreSessionState();
 
   // Restore session state
   if(restoreState) restoreSessionState();
 
@@ -153,6 +152,7 @@ void CoreSession::loadSettings() {
       delete i;
       continue;
     }
       delete i;
       continue;
     }
+    connect(i, SIGNAL(updated(const QVariantMap &)), this, SLOT(identityUpdated(const QVariantMap &)));
     _identities[i->id()] = i;
     signalProxy()->synchronize(i);
   }
     _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;
 void CoreSession::disconnectFromNetwork(NetworkId id) {
   if(!_connections.contains(id))
     return;
-  
+
   //_connections[id]->disconnectFromIrc();
   _connections[id]->userInputHandler()->handleQuit(BufferInfo(), QString());
 }
   //_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);
   signalProxy()->synchronize(newId);
   CoreUserSettings s(user());
   s.storeIdentity(*newId);
+  connect(newId, SIGNAL(updated(const QVariantMap &)), this, SLOT(identityUpdated(const QVariantMap &)));
   emit identityCreated(*newId);
 }
 
   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) {
 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<IdentityId>();
+  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_) {
 /*** 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;
   }
     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::StatusBuffer) {
     quWarning() << "CoreSession::removeBufferRequested(): Status Buffers cannot be removed!";
     return;
   }
-  
+
   if(bufferInfo.type() == BufferInfo::ChannelBuffer) {
     CoreNetwork *net = network(bufferInfo.networkId());
     if(!net) {
   if(bufferInfo.type() == BufferInfo::ChannelBuffer) {
     CoreNetwork *net = network(bufferInfo.networkId());
     if(!net) {
index 57c2a53..7dd03c4 100644 (file)
@@ -61,7 +61,7 @@ public:
   AliasManager &aliasManager() { return _aliasManager; }
 
   inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; }
   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
   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);
 
    */
   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.
    */
   //! 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 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)
   //! 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)
index 8102f00..1ca75b0 100644 (file)
@@ -463,9 +463,8 @@ SaveIdentitiesDlg::SaveIdentitiesDlg(const QList<Identity *> &toCreate, const QL
         numevents--;
         continue;
       }
         numevents--;
         continue;
       }
-      // FIXME this only checks for one changed item rather than all!
       connect(cid, SIGNAL(updatedRemotely()), this, SLOT(clientEvent()));
       connect(cid, SIGNAL(updatedRemotely()), this, SLOT(clientEvent()));
-      Client::updateIdentity(*id);
+      Client::updateIdentity(id->id(), id->toVariantMap());
     }
     foreach(IdentityId id, toRemove) {
       Client::removeIdentity(id);
     }
     foreach(IdentityId id, toRemove) {
       Client::removeIdentity(id);