X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircchannel.cpp;h=ba2fd3c2f8ed079462f4e8e13c90dc835f0e71ea;hp=2233861bd3f8f2d03f1e5bc4bf2bcaa929d2ad4a;hb=8699dd758516d0ded076811e8ea656adc95e69d0;hpb=988bcf1fc63b31947e3ce816c456c1b1a919d8ef diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 2233861b..ba2fd3c2 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by The Quassel 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 * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -21,11 +21,14 @@ #include "ircchannel.h" #include "networkinfo.h" +//#include "nicktreemodel.h" #include "signalproxy.h" #include "ircuser.h" +#include "util.h" #include #include +#include #include @@ -40,23 +43,25 @@ IrcChannel::IrcChannel(const QString &channelname, NetworkInfo *networkinfo) setObjectName(QString::number(networkInfo->networkId()) + "/" + 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) && ircuser) { + 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 { @@ -84,15 +89,51 @@ QList 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)); +} + +QTextCodec *IrcChannel::codecForEncoding() const { + return _codecForEncoding; +} + +void IrcChannel::setCodecForEncoding(const QString &name) { + setCodecForEncoding(QTextCodec::codecForName(name.toAscii())); +} + +void IrcChannel::setCodecForEncoding(QTextCodec *codec) { + _codecForEncoding = codec; +} + +QTextCodec *IrcChannel::codecForDecoding() const { + return _codecForDecoding; +} + +void IrcChannel::setCodecForDecoding(const QString &name) { + setCodecForDecoding(QTextCodec::codecForName(name.toAscii())); +} + +void IrcChannel::setCodecForDecoding(QTextCodec *codec) { + _codecForDecoding = codec; +} + +QString IrcChannel::decodeString(const QByteArray &text) const { + if(!codecForDecoding()) return networkInfo->decodeString(text); + return ::decodeString(text, _codecForDecoding); +} + +QByteArray IrcChannel::encodeString(const QString string) const { + if(codecForEncoding()) { + return _codecForEncoding->fromUnicode(string); + } + return networkInfo->encodeString(string); } // ==================== @@ -107,7 +148,12 @@ 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 + //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); } } @@ -119,7 +165,10 @@ void IrcChannel::part(IrcUser *ircuser) { if(isKnownUser(ircuser)) { _userModes.remove(ircuser); ircuser->partChannel(name()); - // no emit here since the part is propagated by IrcUser + //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); } } @@ -132,6 +181,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 +193,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 +206,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 +214,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 +226,10 @@ void IrcChannel::removeUserMode(const QString &nick, const QString &mode) { // INIT SET USER MODES QVariantMap IrcChannel::initUserModes() const { QVariantMap usermodes; - QHashIterator iter(_userModes); - while(iter.hasNext()) { - iter.next(); + QHash::const_iterator iter = _userModes.constBegin(); + while(iter != _userModes.constEnd()) { usermodes[iter.key()->nick()] = iter.value(); + iter++; } return usermodes; } @@ -192,11 +243,17 @@ void IrcChannel::initSetUserModes(const QVariantMap &usermodes) { } void IrcChannel::ircUserDestroyed() { + IrcUser *ircUser = static_cast(sender()); + Q_ASSERT(ircUser); + _userModes.remove(ircUser); + emit ircUserParted(ircUser); + //qDebug() << "DEST" << name() << ircUsers().count(); +} + +void IrcChannel::ircUserNickSet(QString nick) { IrcUser *ircUser = qobject_cast(sender()); - // in case this assert triggers we probably need a static_cast - // dynamic_casts seem to screw things up when using the destroyed signal Q_ASSERT(ircUser); - part(ircUser); + emit ircUserNickSet(ircUser, nick); } void IrcChannel::setInitialized() {