From 27be9c5a706bf690921617bf66614c4479550c4d Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Fri, 30 Nov 2007 13:15:30 +0000 Subject: [PATCH] figured this would probably be a good Idea for the ircusers too --- src/common/ircuser.cpp | 46 ++++++++++++++++++++++++++++++-------- src/common/ircuser.h | 13 ++++++----- src/common/networkinfo.cpp | 16 ++++++------- src/common/networkinfo.h | 4 ++-- 4 files changed, 55 insertions(+), 24 deletions(-) diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index a6146c5b..01bc9634 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.cpp @@ -70,7 +70,12 @@ QString IrcUser::userModes() const { } QStringList IrcUser::channels() const { - return _channels.toList(); + QStringList chanList; + IrcChannel *channel; + foreach(channel, _channels) { + chanList << channel->name(); + } + return chanList; } // ==================== @@ -118,22 +123,45 @@ void IrcUser::updateHostmask(const QString &mask) { setHost(host); } -void IrcUser::joinChannel(const QString &channel) { +void IrcUser::joinChannel(IrcChannel *channel) { + Q_ASSERT(channel); if(!_channels.contains(channel)) { + channel->join(this); + connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed())); _channels.insert(channel); - networkInfo->newIrcChannel(channel)->join(this); - emit channelJoined(channel); + emit channelJoined(channel->name()); } } -void IrcUser::partChannel(const QString &channel) { +void IrcUser::joinChannel(const QString &channelname) { + joinChannel(networkInfo->newIrcChannel(channelname)); +} + +void IrcUser::partChannel(IrcChannel *channel) { if(_channels.contains(channel)) { _channels.remove(channel); + disconnect(channel, 0, this, 0); + channel->part(this); + emit channelParted(channel->name()); + } +} - Q_ASSERT(networkInfo->ircChannel(channel)); - networkInfo->ircChannel(channel)->part(this); - - emit channelParted(channel); +void IrcUser::partChannel(const QString &channelname) { + IrcChannel *channel = networkInfo->ircChannel(channelname); + if(channel == 0) { + qWarning() << "IrcUser::partChannel(): received part for unknown Channel" << channelname; + } else { + partChannel(channel); + } +} + +void IrcUser::channelDestroyed() { + // private slot! + IrcChannel *channel = static_cast(sender()); + Q_ASSERT(channel); + if(_channels.contains(channel)) { + _channels.remove(channel); + disconnect(channel, 0, this, 0); } } diff --git a/src/common/ircuser.h b/src/common/ircuser.h index cba3d03c..e933fb61 100644 --- a/src/common/ircuser.h +++ b/src/common/ircuser.h @@ -63,9 +63,11 @@ public slots: void updateHostmask(const QString &mask); void setUserModes(const QString &modes); - - void joinChannel(const QString &channel); - void partChannel(const QString &channel); + + void joinChannel(IrcChannel *channel); + void joinChannel(const QString &channelname); + void partChannel(IrcChannel *channel); + void partChannel(const QString &channelname); void addUserMode(const QString &mode); void removeUserMode(const QString &mode); @@ -81,7 +83,6 @@ signals: void nickSet(QString newnick); void hostmaskUpdated(QString mask); - void channelsSet(QStringList channels); void userModesSet(QString modes); void channelJoined(QString channel); @@ -99,6 +100,7 @@ signals: private slots: void updateObjectName(); + void channelDestroyed(); private: inline bool operator==(const IrcUser &ircuser2) { @@ -115,7 +117,8 @@ private: QString _user; QString _host; - QSet _channels; + // QSet _channels; + QSet _channels; QString _userModes; NetworkInfo *networkInfo; diff --git a/src/common/networkinfo.cpp b/src/common/networkinfo.cpp index 918be516..6fc83593 100644 --- a/src/common/networkinfo.cpp +++ b/src/common/networkinfo.cpp @@ -163,7 +163,7 @@ QString NetworkInfo::support(const QString ¶m) const { } IrcUser *NetworkInfo::newIrcUser(const QString &hostmask) { - QString nick(nickFromMask(hostmask)); + QString nick(nickFromMask(hostmask).toLower()); if(!_ircUsers.contains(nick)) { IrcUser *ircuser = new IrcUser(hostmask, this); // mark IrcUser as already initialized to keep the SignalProxy from requesting initData @@ -180,7 +180,7 @@ IrcUser *NetworkInfo::newIrcUser(const QString &hostmask) { _ircUsers[nick] = ircuser; emit ircUserAdded(hostmask); } - return _ircUsers[nick]; + return _ircUsers[nick]; } void NetworkInfo::removeIrcUser(IrcUser *ircuser) { @@ -199,7 +199,8 @@ void NetworkInfo::removeIrcUser(QString nick) { removeIrcUser(ircuser); } -IrcUser *NetworkInfo::ircUser(const QString &nickname) const { +IrcUser *NetworkInfo::ircUser(QString nickname) const { + nickname = nickname.toLower(); if(_ircUsers.contains(nickname)) return _ircUsers[nickname]; else @@ -210,9 +211,8 @@ QList NetworkInfo::ircUsers() const { return _ircUsers.values(); } -IrcChannel *NetworkInfo::newIrcChannel(QString channelname) { - channelname = channelname.toLower(); - if(!_ircChannels.contains(channelname)) { +IrcChannel *NetworkInfo::newIrcChannel(const QString &channelname) { + if(!_ircChannels.contains(channelname.toLower())) { IrcChannel *channel = new IrcChannel(channelname, this); // mark IrcUser as already initialized to keep the SignalProxy from requesting initData if(initialized()) @@ -225,10 +225,10 @@ IrcChannel *NetworkInfo::newIrcChannel(QString channelname) { connect(channel, SIGNAL(initDone()), this, SIGNAL(ircChannelInitDone())); connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed())); - _ircChannels[channelname] = channel; + _ircChannels[channelname.toLower()] = channel; emit ircChannelAdded(channelname); } - return _ircChannels[channelname]; + return _ircChannels[channelname.toLower()]; } diff --git a/src/common/networkinfo.h b/src/common/networkinfo.h index 278053d5..e27c66b4 100644 --- a/src/common/networkinfo.h +++ b/src/common/networkinfo.h @@ -73,10 +73,10 @@ public: QString support(const QString ¶m) const; IrcUser *newIrcUser(const QString &hostmask); - IrcUser *ircUser(const QString &nickname) const; + IrcUser *ircUser(QString nickname) const; QList ircUsers() const; - IrcChannel *newIrcChannel(QString channelname); + IrcChannel *newIrcChannel(const QString &channelname); IrcChannel *ircChannel(QString channelname); QList ircChannels() const; -- 2.20.1