X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fnetwork.cpp;h=0d367af292ef99884cc35583b58ff07439957c66;hp=8f5680be1a6d21c5599842bbcdc51c0b653f2311;hb=5b083e1f67c77ceb7d1d134e976cd6081b70bf12;hpb=e2e5327ccade6baf433598b1b25dfe99cb360028 diff --git a/src/common/network.cpp b/src/common/network.cpp index 8f5680be..0d367af2 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -51,6 +51,7 @@ Network::Network(const NetworkId &networkid, QObject *parent) : SyncableObject(p // I think this is unnecessary since IrcUsers have us as their daddy :) Network::~Network() { + emit aboutToBeDestroyed(); // QHashIterator ircuser(_ircUsers); // while (ircuser.hasNext()) { // ircuser.next(); @@ -218,7 +219,6 @@ IrcUser *Network::newIrcUser(const QString &hostmask) { 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); @@ -242,7 +242,18 @@ void Network::removeIrcUser(IrcUser *ircuser) { ircuser->deleteLater(); } -void Network::removeIrcUser(QString nick) { +void Network::removeChansAndUsers() { + QList users = ircUsers(); + foreach(IrcUser *user, users) { + removeIrcUser(user); + } + QList channels = ircChannels(); + foreach(IrcChannel *channel, channels) { + removeIrcChannel(channel); + } +} + +void Network::removeIrcUser(const QString &nick) { IrcUser *ircuser; if((ircuser = ircUser(nick)) != 0) removeIrcUser(ircuser); @@ -368,6 +379,8 @@ void Network::setCurrentServer(const QString ¤tServer) { void Network::setConnected(bool connected) { _connected = connected; + if(!connected) + removeChansAndUsers(); emit connectedSet(connected); } @@ -498,17 +511,29 @@ void Network::ircChannelInitDone() { emit ircChannelInitDone(ircchannel); } -void Network::ircUserDestroyed() { - IrcUser *ircuser = static_cast(sender()); - Q_ASSERT(ircuser); - removeIrcUser(ircuser); +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); - emit ircChannelRemoved(sender()); _ircChannels.remove(_ircChannels.key(channel)); + emit ircChannelRemoved(channel); } void Network::requestConnect() const {