X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircchannel.cpp;h=57be4e79c3c64087e0e42cf7b8f2cb822319177e;hp=1e567b5c70fe94672ad8de68c9cdfa75f8fa3a3e;hb=ef12cc4010e853348474b4ea15c383dd596d4858;hpb=50706d89d4d60e258ebb6873d3778383621898e4 diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 1e567b5c..57be4e79 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -33,18 +33,18 @@ #include -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 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,32 +120,79 @@ void IrcChannel::setTopic(const QString &topic) { emit topicSet(topic); } -void IrcChannel::join(IrcUser *ircuser) { - if(!_userModes.contains(ircuser) && ircuser) { - _userModes[ircuser] = QString(); - ircuser->joinChannel(name()); +void IrcChannel::setPassword(const QString &password) { + _password = password; + emit passwordSet(password); +} + +void IrcChannel::joinIrcUsers(const QList &users, const QStringList &modes) { + if(users.isEmpty()) + return; + + if(users.count() != modes.count()) { + qWarning() << "IrcChannel::addUsers(): number of nicks does not match number of modes!"; + return; + } + + QStringList newNicks; + QStringList newModes; + QList newUsers; + + IrcUser *ircuser; + for(int i = 0; i < users.count(); i++) { + ircuser = users[i]; + if(!ircuser || _userModes.contains(ircuser)) + continue; + + _userModes[ircuser] = modes[i]; + 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())); // 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); + + newNicks << ircuser->nick(); + newModes << modes[i]; + newUsers << ircuser; } + + if(newNicks.isEmpty()) + return; + + emit ircUsersJoined(newUsers); + emit ircUsersJoined(newNicks, newModes); +} + +void IrcChannel::joinIrcUsers(const QStringList &nicks, const QStringList &modes) { + QList users; + foreach(QString nick, nicks) + users << network->newIrcUser(nick); + joinIrcUsers(users, modes); +} + +void IrcChannel::joinIrcUsers(IrcUser *ircuser) { + QList users; + users << ircuser; + QStringList modes; + modes << QString(); + joinIrcUsers(users, modes); } -void IrcChannel::join(const QString &nick) { - join(network->ircUser(nick)); +void IrcChannel::joinIrcUsers(const QString &nick) { + joinIrcUsers(network->newIrcUser(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->isMyNick(ircuser)) + if(network->isMe(ircuser)) deleteLater(); } } @@ -237,19 +260,23 @@ QVariantMap IrcChannel::initUserModes() const { } void IrcChannel::initSetUserModes(const QVariantMap &usermodes) { - QMapIterator iter(usermodes); - while(iter.hasNext()) { - iter.next(); - setUserModes(iter.key(), iter.value().toString()); + QList users; + QStringList modes; + QVariantMap::const_iterator iter = usermodes.constBegin(); + while(iter != usermodes.constEnd()) { + users << network->newIrcUser(iter.key()); + modes << iter.value().toString(); + iter++; } + joinIrcUsers(users, modes); } void IrcChannel::ircUserDestroyed() { IrcUser *ircUser = static_cast(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) { @@ -258,8 +285,3 @@ void IrcChannel::ircUserNickSet(QString nick) { emit ircUserNickSet(ircUser, nick); } -void IrcChannel::setInitialized() { - _initialized = true; - emit initDone(); -} -