X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fnetwork.cpp;h=e763fb9520f28ec27623150a91f38bfc5d91b95d;hp=2e10c04889d5a089346678c25530376a29719848;hb=a1d785ae12b3ec04b43e243f3397bb6f8ecf60d5;hpb=3439fc6d10d49edb1af23fd2f4ebb688692475d7 diff --git a/src/common/network.cpp b/src/common/network.cpp index 2e10c048..e763fb95 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -36,6 +36,7 @@ Network::Network(const NetworkId &networkid, QObject *parent) _networkId(networkid), _identity(0), _myNick(QString()), + _latency(0), _networkName(QString("")), _currentServer(QString()), _connected(false), @@ -208,7 +209,6 @@ void Network::ircUserDestroyed() { QHash::iterator ircUserIter = _ircUsers.begin(); while(ircUserIter != _ircUsers.end()) { if(ircUser == *ircUserIter) { - emit deletedIrcUserRemoved(ircUserIter.key()); ircUserIter = _ircUsers.erase(ircUserIter); break; } @@ -216,30 +216,6 @@ void Network::ircUserDestroyed() { } } -void Network::removeDeletedIrcUser(const QString &username) { - // DO NOT CALL THIS SLOT EVER!!! - - // this slots purpose is only to remove deleted users that haven't been synced yet. - // Reason: - // as a user parting a channel results in it's deletion if it is no longer in any known channel - // this action can only be communicated if the slaves are allready in sync. - // so if such a deleted user isn't synced in slave mode, we kill and remove it. - - Q_ASSERT(proxy()); - - if(!_ircUsers.contains(username)) - return; - - IrcUser *ircUser = _ircUsers[username]; - - if(ircUser->isInitialized()) - return; - - _ircUsers.remove(username); - emit ircUserRemoved(username); - emit ircUserRemoved(ircUser); -} - void Network::removeIrcUser(IrcUser *ircuser) { QString nick = _ircUsers.key(ircuser); if(nick.isNull()) @@ -454,6 +430,13 @@ void Network::setMyNick(const QString &nickname) { emit myNickSet(nickname); } +void Network::setLatency(int latency) { + if(_latency == latency) + return; + _latency = latency; + emit latencySet(latency); +} + void Network::setIdentity(IdentityId id) { _identity = id; emit identitySet(id); @@ -538,22 +521,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.value()->name()] = 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; } - return channels; + + 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++; + } + } void Network::initSetSupports(const QVariantMap &supports) { @@ -564,21 +611,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; @@ -607,13 +639,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) { @@ -659,6 +693,12 @@ void Network::determinePrefixes() { QString defaultPrefixes("~&@%+"); QString defaultPrefixModes("qaohv"); + if(PREFIX.isEmpty()) { + _prefixes = defaultPrefixes; + _prefixModes = defaultPrefixModes; + return; + } + // we just assume that in PREFIX are only prefix chars stored for(int i = 0; i < defaultPrefixes.size(); i++) { if(PREFIX.contains(defaultPrefixes[i])) {