X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fnetwork.cpp;h=0d367af292ef99884cc35583b58ff07439957c66;hp=da1be33aa2aab15d5d96395a351d7e99eb571077;hb=5b083e1f67c77ceb7d1d134e976cd6081b70bf12;hpb=6623fd2d46dadd0168e4e28d1db6944c26c2a773 diff --git a/src/common/network.cpp b/src/common/network.cpp index da1be33a..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(); @@ -95,7 +96,8 @@ bool Network::isConnected() const { return _connected; } -Network::ConnectionState Network::connectionState() const { +//Network::ConnectionState Network::connectionState() const { +int Network::connectionState() const { return _connectionState; } @@ -217,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); @@ -235,12 +236,24 @@ void Network::removeIrcUser(IrcUser *ircuser) { return; _ircUsers.remove(nick); + disconnect(ircuser, 0, this, 0); emit ircUserRemoved(nick); emit ircUserRemoved(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); @@ -366,11 +379,16 @@ void Network::setCurrentServer(const QString ¤tServer) { void Network::setConnected(bool connected) { _connected = connected; + if(!connected) + removeChansAndUsers(); emit connectedSet(connected); } -void Network::setConnectionState(ConnectionState state) { +//void Network::setConnectionState(ConnectionState state) { +void Network::setConnectionState(int state) { _connectionState = (ConnectionState)state; + //qDebug() << "netstate" << networkId() << networkName() << state; + emit connectionStateSet(state); emit connectionStateSet(_connectionState); } @@ -493,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 {