This _should_ fix the bug, that users quitting the network won't be
[quassel.git] / src / common / ircchannel.cpp
index 95d0ed1..cff2e75 100644 (file)
@@ -21,6 +21,7 @@
 #include "ircchannel.h"
 
 #include "networkinfo.h"
+//#include "nicktreemodel.h"
 #include "signalproxy.h"
 #include "ircuser.h"
 
@@ -40,6 +41,10 @@ IrcChannel::IrcChannel(const QString &channelname, NetworkInfo *networkinfo)
   setObjectName(QString::number(networkInfo->networkId()) + "/" +  channelname);
 }
 
+IrcChannel::~IrcChannel() {
+
+}
+
 // ====================
 //  PUBLIC:
 // ====================
@@ -51,7 +56,7 @@ bool IrcChannel::isKnownUser(IrcUser *ircuser) const {
     isknown = false;
   }
   
-  if(!_userModes.contains(ircuser) && ircuser) {
+  if(!_userModes.contains(ircuser)) {
     qWarning() << "Channel" << name() << "received data for unknown User" << ircuser->nick();
     isknown = false;
   }
@@ -84,15 +89,15 @@ QList<IrcUser *> IrcChannel::ircUsers() const {
   return _userModes.keys();
 }
 
-QString IrcChannel::userMode(IrcUser *ircuser) const {
+QString IrcChannel::userModes(IrcUser *ircuser) const {
   if(_userModes.contains(ircuser))
     return _userModes[ircuser];
   else
     return QString();
 }
 
-QString IrcChannel::userMode(const QString &nick) const {
-  return userMode(networkInfo->ircUser(nick));
+QString IrcChannel::userModes(const QString &nick) const {
+  return userModes(networkInfo->ircUser(nick));
 }
 
 // ====================
@@ -107,7 +112,11 @@ 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(nickSet(QString)), this, SLOT(ircUserNickSet(QString)));
+    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 +128,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);
   }
 }
 
@@ -132,6 +143,7 @@ void IrcChannel::setUserModes(IrcUser *ircuser, const QString &modes) {
   if(isKnownUser(ircuser)) {
     _userModes[ircuser] = modes;
     emit userModesSet(ircuser->nick(), modes);
+    emit ircUserModesSet(ircuser, modes);
   }
 }
 
@@ -143,10 +155,11 @@ void IrcChannel::setUserModes(const QString &nick, const QString &modes) {
 void IrcChannel::addUserMode(IrcUser *ircuser, const QString &mode) {
   if(!isKnownUser(ircuser) || !isValidChannelUserMode(mode))
     return;
-  
+
   if(!_userModes[ircuser].contains(mode)) {
     _userModes[ircuser] += mode;
     emit userModeAdded(ircuser->nick(), mode);
+    emit ircUserModeAdded(ircuser, mode);
   }
 
 }
@@ -155,7 +168,6 @@ void IrcChannel::addUserMode(const QString &nick, const QString &mode) {
   addUserMode(networkInfo->ircUser(nick), mode);
 }
 
-
 // REMOVE USER MODE
 void IrcChannel::removeUserMode(IrcUser *ircuser, const QString &mode) {
   if(!isKnownUser(ircuser) || !isValidChannelUserMode(mode))
@@ -164,6 +176,7 @@ void IrcChannel::removeUserMode(IrcUser *ircuser, const QString &mode) {
   if(_userModes[ircuser].contains(mode)) {
     _userModes[ircuser].remove(mode);
     emit userModeRemoved(ircuser->nick(), mode);
+    emit ircUserModeRemoved(ircuser, mode);
   }
 
 }
@@ -175,10 +188,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 +205,16 @@ 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);
+  emit ircUserParted(ircUser);
+}
+
+void IrcChannel::ircUserNickSet(QString nick) {
+  IrcUser *ircUser = qobject_cast<IrcUser *>(sender());
+  Q_ASSERT(ircUser);
+  emit ircUserNickSet(ircUser, nick);
 }
 
 void IrcChannel::setInitialized() {