This should fix a bug resulting in a crash, when a IrcUser object was not destroyed...
[quassel.git] / src / common / ircchannel.cpp
index 906f4f0..499e1f7 100644 (file)
@@ -21,6 +21,7 @@
 #include "ircchannel.h"
 
 #include "networkinfo.h"
+//#include "nicktreemodel.h"
 #include "signalproxy.h"
 #include "ircuser.h"
 
@@ -55,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;
   }
@@ -88,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));
 }
 
 // ====================
@@ -111,6 +112,8 @@ void IrcChannel::join(IrcUser *ircuser) {
   if(!_userModes.contains(ircuser) && ircuser) {
     _userModes[ircuser] = QString();
     ircuser->joinChannel(name());
+    qDebug() << "JOIN" << name() << ircuser->nick() << ircUsers().count();
+    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
@@ -126,6 +129,7 @@ void IrcChannel::part(IrcUser *ircuser) {
   if(isKnownUser(ircuser)) {
     _userModes.remove(ircuser);
     ircuser->partChannel(name());
+    qDebug() << "PART" << name() << ircuser->nick() << ircUsers().count();
     // 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);
@@ -141,6 +145,7 @@ void IrcChannel::setUserModes(IrcUser *ircuser, const QString &modes) {
   if(isKnownUser(ircuser)) {
     _userModes[ircuser] = modes;
     emit userModesSet(ircuser->nick(), modes);
+    emit ircUserModesSet(ircuser, modes);
   }
 }
 
@@ -152,10 +157,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);
   }
 
 }
@@ -164,7 +170,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))
@@ -173,6 +178,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);
   }
 
 }
@@ -204,6 +210,14 @@ void IrcChannel::ircUserDestroyed() {
   IrcUser *ircUser = static_cast<IrcUser *>(sender());
   Q_ASSERT(ircUser);
   _userModes.remove(ircUser);
+  emit ircUserParted(ircUser);
+  qDebug() << "DEST" << name() << ircUsers().count();
+}
+
+void IrcChannel::ircUserNickSet(QString nick) {
+  IrcUser *ircUser = qobject_cast<IrcUser *>(sender());
+  Q_ASSERT(ircUser);
+  emit ircUserNickSet(ircUser, nick);
 }
 
 void IrcChannel::setInitialized() {