X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircchannel.cpp;h=eb63dd57da467f2cd6fbeda8081d2b683ca3f863;hp=5fad2eb549015ff8daf0d847f23929d97df4e593;hb=56607f81246f04db3a0e71c9a8757d7f75d6cfcf;hpb=d6b056e936ec441258d291b7a8af7b83f9f53016 diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 5fad2eb5..eb63dd57 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-07 by the Quassel IRC Team * + * Copyright (C) 2005-08 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,48 +20,48 @@ #include "ircchannel.h" -#include "networkinfo.h" +#include "network.h" //#include "nicktreemodel.h" #include "signalproxy.h" #include "ircuser.h" +#include "util.h" #include #include +#include #include -IrcChannel::IrcChannel(const QString &channelname, NetworkInfo *networkinfo) - : QObject(networkinfo), +IrcChannel::IrcChannel(const QString &channelname, Network *network) : SyncableObject(network), _initialized(false), _name(channelname), _topic(QString()), - networkInfo(networkinfo) + network(network), + _codecForEncoding(0), + _codecForDecoding(0) { - setObjectName(QString::number(networkInfo->networkId()) + "/" + channelname); + setObjectName(QString::number(network->networkId().toInt()) + "/" + channelname); } IrcChannel::~IrcChannel() { - } // ==================== // PUBLIC: // ==================== bool IrcChannel::isKnownUser(IrcUser *ircuser) const { - bool isknown = true; - if(ircuser == 0) { qWarning() << "Channel" << name() << "received IrcUser Nullpointer!"; - isknown = false; + return false; } if(!_userModes.contains(ircuser)) { qWarning() << "Channel" << name() << "received data for unknown User" << ircuser->nick(); - isknown = false; + return false; } - - return isknown; + + return true; } bool IrcChannel::isValidChannelUserMode(const QString &mode) const { @@ -73,31 +73,43 @@ bool IrcChannel::isValidChannelUserMode(const QString &mode) const { return isvalid; } -bool IrcChannel::initialized() const { - return _initialized; +QString IrcChannel::userModes(IrcUser *ircuser) const { + if(_userModes.contains(ircuser)) + return _userModes[ircuser]; + else + return QString(); +} + +QString IrcChannel::userModes(const QString &nick) const { + return userModes(network->ircUser(nick)); } -QString IrcChannel::name() const { - return _name; +void IrcChannel::setCodecForEncoding(const QString &name) { + setCodecForEncoding(QTextCodec::codecForName(name.toAscii())); } -QString IrcChannel::topic() const { - return _topic; +void IrcChannel::setCodecForEncoding(QTextCodec *codec) { + _codecForEncoding = codec; } -QList IrcChannel::ircUsers() const { - return _userModes.keys(); +void IrcChannel::setCodecForDecoding(const QString &name) { + setCodecForDecoding(QTextCodec::codecForName(name.toAscii())); } -QString IrcChannel::userModes(IrcUser *ircuser) const { - if(_userModes.contains(ircuser)) - return _userModes[ircuser]; - else - return QString(); +void IrcChannel::setCodecForDecoding(QTextCodec *codec) { + _codecForDecoding = codec; } -QString IrcChannel::userModes(const QString &nick) const { - return userModes(networkInfo->ircUser(nick)); +QString IrcChannel::decodeString(const QByteArray &text) const { + if(!codecForDecoding()) return network->decodeString(text); + return ::decodeString(text, _codecForDecoding); +} + +QByteArray IrcChannel::encodeString(const QString &string) const { + if(codecForEncoding()) { + return _codecForEncoding->fromUnicode(string); + } + return network->encodeString(string); } // ==================== @@ -108,36 +120,85 @@ 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()); - qDebug() << "JOIN" << name() << ircuser->nick() << ircUsers().count(); +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::join(const QString &nick) { - join(networkInfo->ircUser(nick)); +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::joinIrcUsers(const QString &nick) { + joinIrcUsers(network->newIrcUser(nick)); } void IrcChannel::part(IrcUser *ircuser) { if(isKnownUser(ircuser)) { _userModes.remove(ircuser); - ircuser->partChannel(name()); - qDebug() << "PART" << name() << ircuser->nick() << ircUsers().count(); + 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(); } } void IrcChannel::part(const QString &nick) { - part(networkInfo->ircUser(nick)); + part(network->ircUser(nick)); } // SET USER MODE @@ -150,7 +211,7 @@ void IrcChannel::setUserModes(IrcUser *ircuser, const QString &modes) { } void IrcChannel::setUserModes(const QString &nick, const QString &modes) { - setUserModes(networkInfo->ircUser(nick), modes); + setUserModes(network->ircUser(nick), modes); } // ADD USER MODE @@ -167,7 +228,7 @@ void IrcChannel::addUserMode(IrcUser *ircuser, const QString &mode) { } void IrcChannel::addUserMode(const QString &nick, const QString &mode) { - addUserMode(networkInfo->ircUser(nick), mode); + addUserMode(network->ircUser(nick), mode); } // REMOVE USER MODE @@ -184,7 +245,7 @@ void IrcChannel::removeUserMode(IrcUser *ircuser, const QString &mode) { } void IrcChannel::removeUserMode(const QString &nick, const QString &mode) { - removeUserMode(networkInfo->ircUser(nick), mode); + removeUserMode(network->ircUser(nick), mode); } // INIT SET USER MODES @@ -210,8 +271,8 @@ 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) { @@ -220,8 +281,3 @@ void IrcChannel::ircUserNickSet(QString nick) { emit ircUserNickSet(ircUser, nick); } -void IrcChannel::setInitialized() { - _initialized = true; - emit initDone(); -} -