Core now remembers the channels you've joined if a disconnect happens, so you'll...
[quassel.git] / src / common / ircchannel.cpp
index 12f70c2..832a5a9 100644 (file)
 #include <QDebug>
 
 
-IrcChannel::IrcChannel(const QString &channelname, Network *network) 
-  : SyncableObject(network),
+IrcChannel::IrcChannel(const QString &channelname, Network *network) : SyncableObject(network),
     _initialized(false),
     _name(channelname),
     _topic(QString()),
-    network(network)
+    network(network),
+    _codecForEncoding(0),
+    _codecForDecoding(0)
 {
-  setObjectName(QString::number(network->networkId()) + "/" +  channelname);
+  setObjectName(QString::number(network->networkId().toInt()) + "/" +  channelname);
 }
 
 IrcChannel::~IrcChannel() {
-
 }
 
 // ====================
@@ -73,22 +73,6 @@ bool IrcChannel::isValidChannelUserMode(const QString &mode) const {
   return isvalid;
 }
 
-bool IrcChannel::initialized() const {
-  return _initialized;
-}
-
-QString IrcChannel::name() const {
-  return _name;
-}
-
-QString IrcChannel::topic() const {
-  return _topic;
-}
-
-QList<IrcUser *> IrcChannel::ircUsers() const {
-  return _userModes.keys();
-}
-
 QString IrcChannel::userModes(IrcUser *ircuser) const {
   if(_userModes.contains(ircuser))
     return _userModes[ircuser];
@@ -100,10 +84,6 @@ QString IrcChannel::userModes(const QString &nick) const {
   return userModes(network->ircUser(nick));
 }
 
-QTextCodec *IrcChannel::codecForEncoding() const {
-  return _codecForEncoding;
-}
-
 void IrcChannel::setCodecForEncoding(const QString &name) {
   setCodecForEncoding(QTextCodec::codecForName(name.toAscii()));
 }
@@ -112,10 +92,6 @@ void IrcChannel::setCodecForEncoding(QTextCodec *codec) {
   _codecForEncoding = codec;
 }
 
-QTextCodec *IrcChannel::codecForDecoding() const {
-  return _codecForDecoding;
-}
-
 void IrcChannel::setCodecForDecoding(const QString &name) {
   setCodecForDecoding(QTextCodec::codecForName(name.toAscii()));
 }
@@ -129,7 +105,7 @@ QString IrcChannel::decodeString(const QByteArray &text) const {
   return ::decodeString(text, _codecForDecoding);
 }
 
-QByteArray IrcChannel::encodeString(const QString string) const {
+QByteArray IrcChannel::encodeString(const QString &string) const {
   if(codecForEncoding()) {
     return _codecForEncoding->fromUnicode(string);
   }
@@ -144,10 +120,15 @@ void IrcChannel::setTopic(const QString &topic) {
   emit topicSet(topic);
 }
 
+void IrcChannel::setPassword(const QString &password) {
+  _password = password;
+  emit passwordSet(password);
+}
+
 void IrcChannel::join(IrcUser *ircuser) {
   if(!_userModes.contains(ircuser) && ircuser) {
     _userModes[ircuser] = QString();
-    ircuser->joinChannel(name());
+    ircuser->joinChannel(this);
     //qDebug() << "JOIN" << name() << ircuser->nick() << ircUsers().count();
     connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickSet(QString)));
     connect(ircuser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed()));
@@ -164,11 +145,14 @@ void IrcChannel::join(const QString &nick) {
 void IrcChannel::part(IrcUser *ircuser) {
   if(isKnownUser(ircuser)) {
     _userModes.remove(ircuser);
-    ircuser->partChannel(name());
+    ircuser->partChannel(this);
     //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
+    disconnect(ircuser, 0, this, 0);
     emit ircUserParted(ircuser);
+    if(network->isMe(ircuser))
+       deleteLater();
   }
 }
 
@@ -246,8 +230,8 @@ void IrcChannel::ircUserDestroyed() {
   IrcUser *ircUser = static_cast<IrcUser *>(sender());
   Q_ASSERT(ircUser);
   _userModes.remove(ircUser);
-  emit ircUserParted(ircUser);
-  //qDebug() << "DEST" << name() << ircUsers().count();
+  // no further propagation.
+  // this leads only to fuck ups.
 }
 
 void IrcChannel::ircUserNickSet(QString nick) {
@@ -256,8 +240,3 @@ void IrcChannel::ircUserNickSet(QString nick) {
   emit ircUserNickSet(ircUser, nick);
 }
 
-void IrcChannel::setInitialized() {
-  _initialized = true;
-  emit initDone();
-}
-