X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fnetwork.cpp;h=9c0f915b7a47868403e85b115a0c3d9cd7ced1c2;hp=ed66ee3a0bc3b108328a57f366b577f191ac2344;hb=fc83addb87b4b5cd9cc92f0dd3491c93e51d9ed9;hpb=e9a8478aa3546063dc39cbadb9280e5566416eeb diff --git a/src/common/network.cpp b/src/common/network.cpp index ed66ee3a..9c0f915b 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -64,7 +64,7 @@ Network::~Network() { bool Network::isChannelName(const QString &channelname) const { if(channelname.isEmpty()) return false; - + if(supports("CHANTYPES")) return support("CHANTYPES").contains(channelname[0]); else @@ -140,7 +140,7 @@ QStringList Network::nicks() const { QString Network::prefixes() { if(_prefixes.isNull()) determinePrefixes(); - + return _prefixes; } @@ -151,7 +151,7 @@ QString Network::prefixModes() { return _prefixModes; } -// example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG +// example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG Network::ChannelModeType Network::channelModeType(const QString &mode) { if(mode.isEmpty()) return NOT_A_CHANMODE; @@ -182,39 +182,37 @@ QString Network::support(const QString ¶m) const { return QString(); } -IrcUser *Network::newIrcUser(const QString &hostmask) { +IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initData) { QString nick(nickFromMask(hostmask).toLower()); if(!_ircUsers.contains(nick)) { IrcUser *ircuser = new IrcUser(hostmask, this); + if(!initData.isEmpty()) { + ircuser->fromVariantMap(initData); + ircuser->setInitialized(); + } if(proxy()) proxy()->synchronize(ircuser); else qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call Network::setProxy(SignalProxy *)?"; - + connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString))); - connect(ircuser, SIGNAL(initDone()), this, SLOT(ircUserInitDone())); - connect(ircuser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed())); + _ircUsers[nick] = ircuser; + emit ircUserAdded(hostmask); emit ircUserAdded(ircuser); } + return _ircUsers[nick]; } -void Network::ircUserDestroyed() { - IrcUser *ircUser = static_cast(sender()); - if(!ircUser) - return; - - QHash::iterator ircUserIter = _ircUsers.begin(); - while(ircUserIter != _ircUsers.end()) { - if(ircUser == *ircUserIter) { - ircUserIter = _ircUsers.erase(ircUserIter); - break; - } - ircUserIter++; - } +IrcUser *Network::ircUser(QString nickname) const { + nickname = nickname.toLower(); + if(_ircUsers.contains(nickname)) + return _ircUsers[nickname]; + else + return 0; } void Network::removeIrcUser(IrcUser *ircuser) { @@ -224,48 +222,51 @@ void Network::removeIrcUser(IrcUser *ircuser) { _ircUsers.remove(nick); disconnect(ircuser, 0, this, 0); - emit ircUserRemoved(nick); - emit ircUserRemoved(ircuser); ircuser->deleteLater(); } -void Network::removeIrcUser(const QString &nick) { - IrcUser *ircuser; - if((ircuser = ircUser(nick)) != 0) - removeIrcUser(ircuser); +void Network::removeIrcChannel(IrcChannel *channel) { + QString chanName = _ircChannels.key(channel); + if(chanName.isNull()) + return; + + _ircChannels.remove(chanName); + disconnect(channel, 0, this, 0); + channel->deleteLater(); } void Network::removeChansAndUsers() { QList users = ircUsers(); - foreach(IrcUser *user, users) { - removeIrcUser(user); - } + _ircUsers.clear(); QList channels = ircChannels(); + _ircChannels.clear(); + foreach(IrcChannel *channel, channels) { - removeIrcChannel(channel); + disconnect(channel, 0, this, 0); } + foreach(IrcUser *user, users) { + disconnect(user, 0, this, 0); + user->quit(); + } + qDeleteAll(users); + qDeleteAll(channels); } -IrcUser *Network::ircUser(QString nickname) const { - nickname = nickname.toLower(); - if(_ircUsers.contains(nickname)) - return _ircUsers[nickname]; - else - return 0; -} - -IrcChannel *Network::newIrcChannel(const QString &channelname) { +IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData) { if(!_ircChannels.contains(channelname.toLower())) { IrcChannel *channel = ircChannelFactory(channelname); + if(!initData.isEmpty()) { + channel->fromVariantMap(initData); + channel->setInitialized(); + } if(proxy()) proxy()->synchronize(channel); else qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?"; - connect(channel, SIGNAL(initDone()), this, SLOT(ircChannelInitDone())); - connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed())); _ircChannels[channelname.toLower()] = channel; + emit ircChannelAdded(channelname); emit ircChannelAdded(channel); } @@ -405,7 +406,7 @@ void Network::setCurrentServer(const QString ¤tServer) { void Network::setConnected(bool connected) { if(_connected == connected) return; - + _connected = connected; if(!connected) { setMyNick(QString()); @@ -552,56 +553,23 @@ void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) { 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 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); - + newIrcUser(userIter.key(), userIter.value().toMap()); 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 = ircChannelFactory(channelName); - 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); - + newIrcChannel(channelIter.key(), channelIter.value().toMap()); channelIter++; } - + } void Network::initSetSupports(const QVariantMap &supports) { @@ -615,7 +583,7 @@ void Network::initSetSupports(const QVariantMap &supports) { IrcUser *Network::updateNickFromMask(const QString &mask) { QString nick(nickFromMask(mask).toLower()); IrcUser *ircuser; - + if(_ircUsers.contains(nick)) { ircuser = _ircUsers[nick]; ircuser->updateHostmask(mask); @@ -637,45 +605,6 @@ void Network::ircUserNickChanged(QString newnick) { setMyNick(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); - disconnect(ircChannel, SIGNAL(initDone()), this, SLOT(ircChannelInitDone())); - emit ircChannelInitDone(ircChannel); -} - -void Network::removeIrcChannel(IrcChannel *channel) { - QString chanName = _ircChannels.key(channel); - if(chanName.isNull()) - return; - - _ircChannels.remove(chanName); - disconnect(channel, 0, this, 0); - emit ircChannelRemoved(chanName); - emit ircChannelRemoved(channel); - channel->deleteLater(); -} - -void Network::removeIrcChannel(const QString &channel) { - IrcChannel *chan; - if((chan = ircChannel(channel)) != 0) - removeIrcChannel(chan); -} - -void Network::channelDestroyed() { - IrcChannel *channel = static_cast(sender()); - Q_ASSERT(channel); - _ircChannels.remove(_ircChannels.key(channel)); - emit ircChannelRemoved(channel); -} - void Network::emitConnectionError(const QString &errorMsg) { emit connectionError(errorMsg); } @@ -686,7 +615,7 @@ void Network::emitConnectionError(const QString &errorMsg) { void Network::determinePrefixes() { // seems like we have to construct them first QString prefix = support("PREFIX"); - + if(prefix.startsWith("(") && prefix.contains(")")) { _prefixes = prefix.section(")", 1); _prefixModes = prefix.mid(1).section(")", 0, 0); @@ -710,7 +639,7 @@ void Network::determinePrefixes() { // check for success if(!_prefixes.isNull()) return; - + // well... our assumption was obviously wrong... // check if it's only prefix modes for(int i = 0; i < defaultPrefixes.size(); i++) {