Introducing Network::requestSetNetworkInfo() to simplify client-side updates
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 17 Aug 2008 22:04:42 +0000 (00:04 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 17 Aug 2008 22:05:17 +0000 (00:05 +0200)
src/client/client.cpp
src/client/client.h
src/common/network.h
src/core/corenetwork.cpp
src/core/corenetwork.h
src/core/coresession.cpp
src/core/coresession.h
src/qtui/settingspages/networkssettingspage.cpp

index 2b667e0..a2ffd8e 100644 (file)
@@ -115,7 +115,6 @@ void Client::init() {
   p->attachSlot(SIGNAL(identityRemoved(IdentityId)), this, SLOT(coreIdentityRemoved(IdentityId)));
 
   p->attachSignal(this, SIGNAL(requestCreateNetwork(const NetworkInfo &)), SIGNAL(createNetwork(const NetworkInfo &)));
-  p->attachSignal(this, SIGNAL(requestUpdateNetwork(const NetworkInfo &)), SIGNAL(updateNetwork(const NetworkInfo &)));
   p->attachSignal(this, SIGNAL(requestRemoveNetwork(NetworkId)), SIGNAL(removeNetwork(NetworkId)));
   p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, SLOT(coreNetworkCreated(NetworkId)));
   p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId)));
@@ -207,14 +206,19 @@ void Client::createNetwork(const NetworkInfo &info) {
   emit instance()->requestCreateNetwork(info);
 }
 
-void Client::updateNetwork(const NetworkInfo &info) {
-  emit instance()->requestUpdateNetwork(info);
-}
-
 void Client::removeNetwork(NetworkId id) {
   emit instance()->requestRemoveNetwork(id);
 }
 
+void Client::updateNetwork(const NetworkInfo &info) {
+  Network *netptr = instance()->_networks.value(info.networkId, 0);
+  if(!netptr) {
+    qWarning() << "Update for unknown network requested:" << info;
+    return;
+  }
+  netptr->requestSetNetworkInfo(info);
+}
+
 void Client::addNetwork(Network *net) {
   net->setProxy(signalProxy());
   signalProxy()->synchronize(net);
@@ -257,7 +261,6 @@ void Client::createIdentity(const Identity &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;
index 8b991bd..e626d75 100644 (file)
@@ -153,7 +153,6 @@ signals:
   void networkRemoved(NetworkId id);
 
   void requestCreateNetwork(const NetworkInfo &info);
-  void requestUpdateNetwork(const NetworkInfo &info);
   void requestRemoveNetwork(NetworkId);
 
 public slots:
index 1371231..5d272c5 100644 (file)
@@ -88,7 +88,7 @@ public:
     D_CHANMODE = 0x08
   };
 
-  
+
   Network(const NetworkId &networkid, QObject *parent = 0);
   ~Network();
 
@@ -113,7 +113,7 @@ public:
 
   ChannelModeType channelModeType(const QString &mode);
   inline ChannelModeType channelModeType(const QCharRef &mode) { return channelModeType(QString(mode)); }
-  
+
   inline const QString &networkName() const { return _networkName; }
   inline const QString &currentServer() const { return _currentServer; }
   inline const QString &myNick() const { return _myNick; }
@@ -216,14 +216,14 @@ public slots:
   virtual QVariantMap initIrcUsersAndChannels() const;
 //   QStringList initIrcUsers() const;
 //   QStringList initIrcChannels() const;
-  
+
   //init seters
   void initSetSupports(const QVariantMap &supports);
   inline void initSetServerList(const QVariantList &serverList) { setServerList(serverList); }
   virtual void initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels);
 //   void initSetIrcUsers(const QStringList &hostmasks);
 //   void initSetIrcChannels(const QStringList &channels);
-  
+
   IrcUser *updateNickFromMask(const QString &mask);
 
   // these slots are to keep the hashlists of all users and the
@@ -232,6 +232,7 @@ public slots:
 
   virtual inline void requestConnect() const { emit connectRequested(); }
   virtual inline void requestDisconnect() const { emit disconnectRequested(); }
+  virtual inline void requestSetNetworkInfo(const NetworkInfo &info) { emit setNetworkInfoRequested(info); }
 
   void emitConnectionError(const QString &);
 
@@ -292,6 +293,7 @@ signals:
 
   void connectRequested(NetworkId id = 0) const;
   void disconnectRequested(NetworkId id = 0) const;
+  void setNetworkInfoRequested(const NetworkInfo &) const;
 
 private:
   QPointer<SignalProxy> _proxy;
index e22a67d..6a2149d 100644 (file)
@@ -18,6 +18,7 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include "core.h"
 #include "corenetwork.h"
 #include "coresession.h"
 
@@ -44,3 +45,8 @@ void CoreNetwork::requestDisconnect() const {
   }
   emit disconnectRequested(networkId());
 }
+
+void CoreNetwork::requestSetNetworkInfo(const NetworkInfo &info) {
+  setNetworkInfo(info);
+  Core::updateNetwork(coreSession()->user(), info);
+}
index 4c956cf..fd96ff6 100644 (file)
@@ -38,6 +38,7 @@ public:
 public slots:
   virtual void requestConnect() const;
   virtual void requestDisconnect() const;
+  virtual void requestSetNetworkInfo(const NetworkInfo &info);
 
 private:
   CoreSession *_coreSession;
index efdad6e..5bdfefe 100644 (file)
@@ -71,7 +71,6 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
   p->attachSignal(this, SIGNAL(networkCreated(NetworkId)));
   p->attachSignal(this, SIGNAL(networkRemoved(NetworkId)));
   p->attachSlot(SIGNAL(createNetwork(const NetworkInfo &)), this, SLOT(createNetwork(const NetworkInfo &)));
-  p->attachSlot(SIGNAL(updateNetwork(const NetworkInfo &)), this, SLOT(updateNetwork(const NetworkInfo &)));
   p->attachSlot(SIGNAL(removeNetwork(NetworkId)), this, SLOT(removeNetwork(NetworkId)));
 
   loadSettings();
@@ -432,20 +431,10 @@ void CoreSession::createNetwork(const NetworkInfo &info_) {
     emit networkCreated(id);
   } else {
     quWarning() << qPrintable(tr("CoreSession::createNetwork(): Trying to create a network that already exists, updating instead!"));
-    updateNetwork(info);
+    _networks[info.networkId]->requestSetNetworkInfo(info);
   }
 }
 
-// FIXME: move to CoreNetwork
-void CoreSession::updateNetwork(const NetworkInfo &info) {
-  if(!_networks.contains(info.networkId)) {
-    quWarning() << "Update request for unknown network received!";
-    return;
-  }
-  _networks[info.networkId]->setNetworkInfo(info);
-  Core::updateNetwork(user(), info);
-}
-
 void CoreSession::removeNetwork(NetworkId id) {
   // Make sure the network is disconnected!
   NetworkConnection *conn = _connections.value(id, 0);
index 7dd03c4..492208a 100644 (file)
@@ -93,11 +93,6 @@ public slots:
    */
   void createNetwork(const NetworkInfo &info);
 
-  //! Update a network and propagate the changes to the clients.
-  /** \param info The updated network settings.
-   */
-  void updateNetwork(const NetworkInfo &info);
-
   //! Remove identity and propagate that fact to the clients.
   /** \param identity The identity to be removed.
    */
@@ -163,7 +158,6 @@ 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.
index 7c06ed4..1ed468f 100644 (file)
@@ -315,7 +315,7 @@ void NetworksSettingsPage::clientIdentityRemoved(IdentityId id) {
 }
 
 QListWidgetItem *NetworksSettingsPage::networkItem(NetworkId id) const {
-  for(int i = 0; i < ui.networkList->count(); i++) { 
+  for(int i = 0; i < ui.networkList->count(); i++) {
     QListWidgetItem *item = ui.networkList->item(i);
     if(item->data(Qt::UserRole).value<NetworkId>() == id) return item;
   }