#include "signalproxy.h"
#include "ircchannel.h"
+#include <QTextCodec>
#include <QDebug>
IrcUser::IrcUser(const QString &hostmask, NetworkInfo *networkinfo)
_nick(nickFromMask(hostmask)),
_user(userFromMask(hostmask)),
_host(hostFromMask(hostmask)),
- networkInfo(networkinfo)
+ networkInfo(networkinfo),
+ _codecForEncoding(0),
+ _codecForDecoding(0)
{
updateObjectName();
}
IrcUser::~IrcUser() {
- qDebug() << nick() << "destroyed.";
+ //qDebug() << nick() << "destroyed.";
}
// ====================
}
QStringList IrcUser::channels() const {
- return _channels.toList();
+ QStringList chanList;
+ IrcChannel *channel;
+ foreach(channel, _channels) {
+ chanList << channel->name();
+ }
+ return chanList;
+}
+
+QTextCodec *IrcUser::codecForEncoding() const {
+ return _codecForEncoding;
+}
+
+void IrcUser::setCodecForEncoding(const QString &name) {
+ setCodecForEncoding(QTextCodec::codecForName(name.toAscii()));
+}
+
+void IrcUser::setCodecForEncoding(QTextCodec *codec) {
+ _codecForEncoding = codec;
+}
+
+QTextCodec *IrcUser::codecForDecoding() const {
+ return _codecForDecoding;
+}
+
+void IrcUser::setCodecForDecoding(const QString &name) {
+ setCodecForDecoding(QTextCodec::codecForName(name.toAscii()));
+}
+
+void IrcUser::setCodecForDecoding(QTextCodec *codec) {
+ _codecForDecoding = codec;
+}
+
+QString IrcUser::decodeString(const QByteArray &text) const {
+ if(!codecForDecoding()) return networkInfo->decodeString(text);
+ return ::decodeString(text, codecForDecoding());
+}
+
+QByteArray IrcUser::encodeString(const QString string) const {
+ if(codecForEncoding()) {
+ return codecForEncoding()->fromUnicode(string);
+ }
+ return networkInfo->encodeString(string);
}
// ====================
setHost(host);
}
-void IrcUser::joinChannel(const QString &channel) {
+void IrcUser::joinChannel(IrcChannel *channel) {
+ Q_ASSERT(channel);
if(!_channels.contains(channel)) {
+ channel->join(this);
+ connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed()));
_channels.insert(channel);
- networkInfo->newIrcChannel(channel)->join(this);
- emit channelJoined(channel);
+ emit channelJoined(channel->name());
}
}
-void IrcUser::partChannel(const QString &channel) {
+void IrcUser::joinChannel(const QString &channelname) {
+ joinChannel(networkInfo->newIrcChannel(channelname));
+}
+
+void IrcUser::partChannel(IrcChannel *channel) {
if(_channels.contains(channel)) {
_channels.remove(channel);
+ disconnect(channel, 0, this, 0);
+ channel->part(this);
+ emit channelParted(channel->name());
+ }
+}
+
+void IrcUser::partChannel(const QString &channelname) {
+ IrcChannel *channel = networkInfo->ircChannel(channelname);
+ if(channel == 0) {
+ qWarning() << "IrcUser::partChannel(): received part for unknown Channel" << channelname;
+ } else {
+ partChannel(channel);
+ }
+}
- Q_ASSERT(networkInfo->ircChannel(channel));
- networkInfo->ircChannel(channel)->part(this);
-
- emit channelParted(channel);
+void IrcUser::channelDestroyed() {
+ // private slot!
+ IrcChannel *channel = static_cast<IrcChannel*>(sender());
+ Q_ASSERT(channel);
+ if(_channels.contains(channel)) {
+ _channels.remove(channel);
+ disconnect(channel, 0, this, 0);
}
}