From d4b7af7050bac6f894a05bff4eab1becaffa27ce Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Sun, 6 Jul 2008 17:34:49 +0200 Subject: [PATCH 1/1] This branch introduces a new sync method which should use less bandwidth and might be faster. (see long desc.) 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 | 3 +- src/client/networkmodel.cpp | 4 +- src/common/network.cpp | 111 ++++++++++++++++++++++++++---------- src/common/network.h | 10 ++-- version.inc | 6 +- 5 files changed, 93 insertions(+), 41 deletions(-) diff --git a/src/client/clientsyncer.cpp b/src/client/clientsyncer.cpp index be5c95b8..e0b502b6 100644 --- a/src/client/clientsyncer.cpp +++ b/src/client/clientsyncer.cpp @@ -346,7 +346,8 @@ void ClientSyncer::ircUserRemoved(QObject *user) { } 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"; diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index c7971791..2c2a0382 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -136,10 +136,8 @@ void BufferItem::attachIrcChannel(IrcChannel *ircChannel) { 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()); - } emit dataChanged(); } diff --git a/src/common/network.cpp b/src/common/network.cpp index cfcda7de..bab066b0 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -513,22 +513,86 @@ QVariantMap Network::initSupports() const { 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::const_iterator userIter = _ircUsers.constBegin(); + QHash::const_iterator userIterEnd = _ircUsers.constEnd(); + while(userIter != userIterEnd) { + users[userIter.value()->hostmask()] = userIter.value()->toVariantMap(); + userIter++; } - return hostmasks; + usersAndChannels["users"] = users; + + QHash::const_iterator channelIter = _ircChannels.constBegin(); + QHash::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::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) { @@ -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; @@ -582,13 +631,15 @@ void Network::ircUserNickChanged(QString newnick) { void Network::ircUserInitDone() { IrcUser *ircuser = static_cast(sender()); Q_ASSERT(ircuser); + connect(ircuser, SIGNAL(initDone()), this, SLOT(ircUserInitDone())); emit ircUserInitDone(ircuser); } void Network::ircChannelInitDone() { - IrcChannel *ircchannel = static_cast(sender()); - Q_ASSERT(ircchannel); - emit ircChannelInitDone(ircchannel); + IrcChannel *ircChannel = static_cast(sender()); + Q_ASSERT(ircChannel); + disconnect(ircChannel, SIGNAL(initDone()), this, SLOT(ircChannelInitDone())); + emit ircChannelInitDone(ircChannel); } void Network::removeIrcChannel(IrcChannel *channel) { diff --git a/src/common/network.h b/src/common/network.h index 3759e565..2ff0a363 100644 --- a/src/common/network.h +++ b/src/common/network.h @@ -210,14 +210,16 @@ public slots: //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); } - 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); diff --git a/version.inc b/version.inc index 92fc5fd5..7c981c8b 100644 --- a/version.inc +++ b/version.inc @@ -3,7 +3,7 @@ //! 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 -- 2.20.1