Added convenience signals ircUserJoined(IrcUser *) and ircUserParted(IrcUser *) to...
[quassel.git] / src / common / ircchannel.cpp
index 95d0ed1..28d6c6e 100644 (file)
@@ -107,7 +107,10 @@ void IrcChannel::join(IrcUser *ircuser) {
   if(!_userModes.contains(ircuser) && ircuser) {
     _userModes[ircuser] = QString();
     ircuser->joinChannel(name());
-    // no emit here since the join is propagated by IrcUser
+    connect(ircuser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed()));
+    // if you wonder why there is no counterpart to ircUserJoined:
+    // the joines are propagted by the ircuser. the signal ircUserJoined is only for convenience
+    emit ircUserJoined(ircuser);
   }
 }
 
@@ -119,7 +122,9 @@ void IrcChannel::part(IrcUser *ircuser) {
   if(isKnownUser(ircuser)) {
     _userModes.remove(ircuser);
     ircuser->partChannel(name());
-    // no emit here since the part is propagated by IrcUser
+    // if you wonder why there is no counterpart to ircUserParted:
+    // the joines are propagted by the ircuser. the signal ircUserParted is only for convenience
+    emit ircUserParted(ircuser);
   }
 }
 
@@ -175,10 +180,10 @@ void IrcChannel::removeUserMode(const QString &nick, const QString &mode) {
 // INIT SET USER MODES
 QVariantMap IrcChannel::initUserModes() const {
   QVariantMap usermodes;
-  QHashIterator<IrcUser *, QString> iter(_userModes);
-  while(iter.hasNext()) {
-    iter.next();
+  QHash<IrcUser *, QString>::const_iterator iter = _userModes.constBegin();
+  while(iter != _userModes.constEnd()) {
     usermodes[iter.key()->nick()] = iter.value();
+    iter++;
   }
   return usermodes;
 }
@@ -192,7 +197,9 @@ void IrcChannel::initSetUserModes(const QVariantMap &usermodes) {
 }
 
 void IrcChannel::ircUserDestroyed() {
-  part(qobject_cast<IrcUser *>(sender()));
+  IrcUser *ircUser = static_cast<IrcUser *>(sender());
+  Q_ASSERT(ircUser);
+  _userModes.remove(ircUser);
 }
 
 void IrcChannel::setInitialized() {