/***************************************************************************
- * 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 *
#include "ircchannel.h"
-#include "networkinfo.h"
+#include "network.h"
//#include "nicktreemodel.h"
#include "signalproxy.h"
#include "ircuser.h"
+#include "util.h"
#include <QMapIterator>
#include <QHashIterator>
+#include <QTextCodec>
#include <QDebug>
-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) && 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 {
return isvalid;
}
-bool IrcChannel::initialized() const {
- return _initialized;
-}
-
QString IrcChannel::name() const {
return _name;
}
}
QString IrcChannel::userModes(const QString &nick) const {
- return userModes(networkInfo->ircUser(nick));
+ return userModes(network->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 network->decodeString(text);
+ return ::decodeString(text, _codecForDecoding);
+}
+
+QByteArray IrcChannel::encodeString(const QString &string) const {
+ if(codecForEncoding()) {
+ return _codecForEncoding->fromUnicode(string);
+ }
+ return network->encodeString(string);
}
// ====================
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()));
// if you wonder why there is no counterpart to ircUserJoined:
}
void IrcChannel::join(const QString &nick) {
- join(networkInfo->ircUser(nick));
+ join(network->ircUser(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();
}
}
void IrcChannel::part(const QString &nick) {
- part(networkInfo->ircUser(nick));
+ part(network->ircUser(nick));
}
// SET USER MODE
}
void IrcChannel::setUserModes(const QString &nick, const QString &modes) {
- setUserModes(networkInfo->ircUser(nick), modes);
+ setUserModes(network->ircUser(nick), modes);
}
// ADD USER MODE
}
void IrcChannel::addUserMode(const QString &nick, const QString &mode) {
- addUserMode(networkInfo->ircUser(nick), mode);
+ addUserMode(network->ircUser(nick), mode);
}
// REMOVE USER MODE
}
void IrcChannel::removeUserMode(const QString &nick, const QString &mode) {
- removeUserMode(networkInfo->ircUser(nick), mode);
+ removeUserMode(network->ircUser(nick), mode);
}
// INIT SET USER MODES
IrcUser *ircUser = static_cast<IrcUser *>(sender());
Q_ASSERT(ircUser);
_userModes.remove(ircUser);
+ // no further propagation.
+ // this leads only to fuck ups.
}
void IrcChannel::ircUserNickSet(QString nick) {
emit ircUserNickSet(ircUser, nick);
}
-void IrcChannel::setInitialized() {
- _initialized = true;
- emit initDone();
-}
-