This branch introduces a new sync method which should use less bandwidth and might...
authorMarcus Eggenberger <egs@quassel-irc.org>
Sun, 6 Jul 2008 15:34:49 +0000 (17:34 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sun, 6 Jul 2008 15:34:49 +0000 (17:34 +0200)
This new method syncs whole networks as a bulk including all ircusers and channels.
The compression introduced in 0.3 should be more effective here. The sync dialog does not yet reflect
this change (users and channels are immediately and always at 100%).
Breaks protocol big time, which means, this needs client and core from this branch to make it work.
Feedback is welcome!

src/client/clientsyncer.cpp
src/client/networkmodel.cpp
src/common/network.cpp
src/common/network.h
version.inc

index be5c95b..e0b502b 100644 (file)
@@ -346,7 +346,8 @@ void ClientSyncer::ircUserRemoved(QObject *user) {
 }
 
 void ClientSyncer::checkSyncState() {
 }
 
 void ClientSyncer::checkSyncState() {
-  if(usersToSync.count() + channelsToSync.count() + netsToSync.count() == 0) {
+  // if(usersToSync.count() + channelsToSync.count() + netsToSync.count() == 0) {
+  if(netsToSync.isEmpty()) {
     // done syncing!
     /*
     qDebug() << "done";
     // done syncing!
     /*
     qDebug() << "done";
index c797179..2c2a038 100644 (file)
@@ -136,10 +136,8 @@ void BufferItem::attachIrcChannel(IrcChannel *ircChannel) {
   connect(ircChannel, SIGNAL(ircUserModeRemoved(IrcUser *, QString)),
          this, SLOT(userModeChanged(IrcUser *)));
 
   connect(ircChannel, SIGNAL(ircUserModeRemoved(IrcUser *, QString)),
          this, SLOT(userModeChanged(IrcUser *)));
 
-  if(!ircChannel->ircUsers().isEmpty()) {
-    qWarning() << "Channel" << ircChannel->name() << "has already users which is quite surprising :)";
+  if(!ircChannel->ircUsers().isEmpty())
     join(ircChannel->ircUsers());
     join(ircChannel->ircUsers());
-  }
   
   emit dataChanged();
 }
   
   emit dataChanged();
 }
index cfcda7d..bab066b 100644 (file)
@@ -513,22 +513,86 @@ QVariantMap Network::initSupports() const {
   return supports;
 }
 
   return supports;
 }
 
-QStringList Network::initIrcUsers() const {
-  QStringList hostmasks;
-  foreach(IrcUser *ircuser, ircUsers()) {
-    hostmasks << ircuser->hostmask();
+QVariantMap Network::initIrcUsersAndChannels() const {
+  QVariantMap usersAndChannels;
+  QVariantMap users;
+  QVariantMap channels;
+
+  QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
+  QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
+  while(userIter != userIterEnd) {
+    users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
+    userIter++;
   }
   }
-  return hostmasks;
+  usersAndChannels["users"] = users;
+
+  QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
+  QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
+  while(channelIter != channelIterEnd) {
+    channels[channelIter.key()] = channelIter.value()->toVariantMap();
+    channelIter++;
+  }
+  usersAndChannels["channels"] = channels;
+
+  return usersAndChannels;
 }
 
 }
 
-QStringList Network::initIrcChannels() const {
-  QStringList channels;
-  QHash<QString, IrcChannel *>::const_iterator iter = _ircChannels.constBegin();
-  while(iter != _ircChannels.constEnd()) {
-    channels << iter.value()->name();
-    iter++;
+void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) {
+  Q_ASSERT(proxy());
+  if(!_ircUsers.isEmpty() || !_ircChannels.isEmpty()) {
+    qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
+    return;
+  }
+    
+  QVariantMap users = usersAndChannels.value("users").toMap();
+
+  QVariantMap::const_iterator userIter = users.constBegin();
+  QVariantMap::const_iterator userIterEnd = users.constEnd();
+  IrcUser *ircUser = 0;
+  QString hostmask;
+  while(userIter != userIterEnd) {
+    hostmask = userIter.key();
+    ircUser = new IrcUser(hostmask, this);
+    ircUser->fromVariantMap(userIter.value().toMap());
+    ircUser->setInitialized();
+    proxy()->synchronize(ircUser);
+
+    connect(ircUser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
+    connect(ircUser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed()));
+
+    _ircUsers[nickFromMask(hostmask).toLower()] = ircUser;
+
+    emit ircUserAdded(hostmask);
+    emit ircUserAdded(ircUser);
+    emit ircUserInitDone(ircUser);
+
+    userIter++;
+  }
+
+
+  QVariantMap channels = usersAndChannels.value("channels").toMap();
+  QVariantMap::const_iterator channelIter = channels.constBegin();
+  QVariantMap::const_iterator channelIterEnd = channels.constEnd();
+  IrcChannel *ircChannel = 0;
+  QString channelName;
+
+  while(channelIter != channelIterEnd) {
+    channelName = channelIter.key();
+    ircChannel = new IrcChannel(channelName, this);
+    ircChannel->fromVariantMap(channelIter.value().toMap());
+    ircChannel->setInitialized();
+    proxy()->synchronize(ircChannel);
+      
+    connect(ircChannel, SIGNAL(destroyed()), this, SLOT(channelDestroyed()));
+    _ircChannels[channelName.toLower()] = ircChannel;
+
+    emit ircChannelAdded(channelName);
+    emit ircChannelAdded(ircChannel);
+    emit ircChannelInitDone(ircChannel);
+
+    channelIter++;
   }
   }
-  return channels;
+  
 }
 
 void Network::initSetSupports(const QVariantMap &supports) {
 }
 
 void Network::initSetSupports(const QVariantMap &supports) {
@@ -539,21 +603,6 @@ void Network::initSetSupports(const QVariantMap &supports) {
   }
 }
 
   }
 }
 
-void Network::initSetIrcUsers(const QStringList &hostmasks) {
-  if(!_ircUsers.empty())
-    return;
-  foreach(QString hostmask, hostmasks) {
-    newIrcUser(hostmask);
-  }
-}
-
-void Network::initSetIrcChannels(const QStringList &channels) {
-  if(!_ircChannels.empty())
-    return;
-  foreach(QString channel, channels)
-    newIrcChannel(channel);
-}
-
 IrcUser *Network::updateNickFromMask(const QString &mask) {
   QString nick(nickFromMask(mask).toLower());
   IrcUser *ircuser;
 IrcUser *Network::updateNickFromMask(const QString &mask) {
   QString nick(nickFromMask(mask).toLower());
   IrcUser *ircuser;
@@ -582,13 +631,15 @@ void Network::ircUserNickChanged(QString newnick) {
 void Network::ircUserInitDone() {
   IrcUser *ircuser = static_cast<IrcUser *>(sender());
   Q_ASSERT(ircuser);
 void Network::ircUserInitDone() {
   IrcUser *ircuser = static_cast<IrcUser *>(sender());
   Q_ASSERT(ircuser);
+  connect(ircuser, SIGNAL(initDone()), this, SLOT(ircUserInitDone()));
   emit ircUserInitDone(ircuser);
 }
 
 void Network::ircChannelInitDone() {
   emit ircUserInitDone(ircuser);
 }
 
 void Network::ircChannelInitDone() {
-  IrcChannel *ircchannel = static_cast<IrcChannel *>(sender());
-  Q_ASSERT(ircchannel);
-  emit ircChannelInitDone(ircchannel);
+  IrcChannel *ircChannel = static_cast<IrcChannel *>(sender());
+  Q_ASSERT(ircChannel);
+  disconnect(ircChannel, SIGNAL(initDone()), this, SLOT(ircChannelInitDone()));
+  emit ircChannelInitDone(ircChannel);
 }
 
 void Network::removeIrcChannel(IrcChannel *channel) {
 }
 
 void Network::removeIrcChannel(IrcChannel *channel) {
index 3759e56..2ff0a36 100644 (file)
@@ -210,14 +210,16 @@ public slots:
   //init geters
   QVariantMap initSupports() const;
   inline QVariantList initServerList() const { return serverList(); }
   //init geters
   QVariantMap initSupports() const;
   inline QVariantList initServerList() const { return serverList(); }
-  QStringList initIrcUsers() const;
-  QStringList initIrcChannels() const;
+  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); }
   
   //init seters
   void initSetSupports(const QVariantMap &supports);
   inline void initSetServerList(const QVariantList &serverList) { setServerList(serverList); }
-  void initSetIrcUsers(const QStringList &hostmasks);
-  void initSetIrcChannels(const QStringList &channels);
+  virtual void initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels);
+//   void initSetIrcUsers(const QStringList &hostmasks);
+//   void initSetIrcChannels(const QStringList &channels);
   
   IrcUser *updateNickFromMask(const QString &mask);
 
   
   IrcUser *updateNickFromMask(const QString &mask);
 
index 92fc5fd..7c981c8 100644 (file)
@@ -3,7 +3,7 @@
 
 //! This is the fallback version number in case we can't autogenerate one
 quasselBaseVersion = "0.3.0-pre";
 
 //! This is the fallback version number in case we can't autogenerate one
 quasselBaseVersion = "0.3.0-pre";
-protocolVersion = 1;       //< Version of the client/core protocol
+protocolVersion = 2;       //< Version of the client/core protocol
 
 
-coreNeedsProtocol   = 1;   //< Minimum protocol version the core needs
-clientNeedsProtocol = 1;   //< Minimum protocol version the client needs
+coreNeedsProtocol   = 2;   //< Minimum protocol version the core needs
+clientNeedsProtocol = 2;   //< Minimum protocol version the client needs