X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fnetwork.cpp;h=9c0f915b7a47868403e85b115a0c3d9cd7ced1c2;hp=23ce589f9a6551f8007acff50fdee38c7994c5c6;hb=c6fc5ae878a4f92b658c3da2861bcc7da9c2594f;hpb=d816b49993aa24d4d2e88975eb92a28cf329a381 diff --git a/src/common/network.cpp b/src/common/network.cpp index 23ce589f..9c0f915b 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -197,34 +197,22 @@ IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initDat 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(destroyed()), this, SLOT(ircUserDestroyed())); - if(!ircuser->isInitialized()) - connect(ircuser, SIGNAL(initDone()), this, SLOT(ircUserInitDone())); _ircUsers[nick] = ircuser; emit ircUserAdded(hostmask); emit ircUserAdded(ircuser); - if(ircuser->isInitialized()) - emit ircUserInitDone(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) { @@ -234,34 +222,34 @@ 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); } -} - -IrcUser *Network::ircUser(QString nickname) const { - nickname = nickname.toLower(); - if(_ircUsers.contains(nickname)) - return _ircUsers[nickname]; - else - return 0; + foreach(IrcUser *user, users) { + disconnect(user, 0, this, 0); + user->quit(); + } + qDeleteAll(users); + qDeleteAll(channels); } IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData) { @@ -277,16 +265,10 @@ IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap else qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?"; - connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed())); - if(!channel->isInitialized()) - connect(channel, SIGNAL(initDone()), this, SLOT(ircChannelInitDone())); - _ircChannels[channelname.toLower()] = channel; emit ircChannelAdded(channelname); emit ircChannelAdded(channel); - if(channel->isInitialized()) - emit ircChannelInitDone(channel); } return _ircChannels[channelname.toLower()]; } @@ -623,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); }