X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircuser.cpp;h=f6818b9a2b52cc43981cc2df90b326a9f4c767a6;hp=a6146c5bdef14048de2b53df77f70a44daa2ed58;hb=f9fc50a5e043668a2525a6c0903ea339d4ba05b7;hpb=d6b056e936ec441258d291b7a8af7b83f9f53016 diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index a6146c5b..f6818b9a 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.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 * @@ -21,25 +21,28 @@ #include "ircuser.h" #include "util.h" -#include "networkinfo.h" +#include "network.h" #include "signalproxy.h" #include "ircchannel.h" +#include #include -IrcUser::IrcUser(const QString &hostmask, NetworkInfo *networkinfo) - : QObject(networkinfo), +IrcUser::IrcUser(const QString &hostmask, Network *network) + : SyncableObject(network), _initialized(false), _nick(nickFromMask(hostmask)), _user(userFromMask(hostmask)), _host(hostFromMask(hostmask)), - networkInfo(networkinfo) + _network(network), + _codecForEncoding(0), + _codecForDecoding(0) { updateObjectName(); } IrcUser::~IrcUser() { - qDebug() << nick() << "destroyed."; + //qDebug() << nick() << "destroyed."; } // ==================== @@ -70,7 +73,52 @@ QString IrcUser::userModes() const { } QStringList IrcUser::channels() const { - return _channels.toList(); + QStringList chanList; + IrcChannel *channel; + foreach(channel, _channels) { + chanList << channel->name(); + } + return chanList; +} + +Network* IrcUser::network() const { + return _network; +} + +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 network()->decodeString(text); + return ::decodeString(text, codecForDecoding()); +} + +QByteArray IrcUser::encodeString(const QString string) const { + if(codecForEncoding()) { + return codecForEncoding()->fromUnicode(string); + } + return network()->encodeString(string); } // ==================== @@ -92,7 +140,6 @@ void IrcUser::setHost(const QString &host) { void IrcUser::setNick(const QString &nick) { if(!nick.isEmpty() && nick != _nick) { - QString oldnick(_nick); _nick = nick; updateObjectName(); emit nickSet(nick); @@ -100,14 +147,14 @@ void IrcUser::setNick(const QString &nick) { } void IrcUser::updateObjectName() { - QString oldName(objectName()); - setObjectName(QString::number(networkInfo->networkId()) + "/" + _nick); - if(!oldName.isEmpty()) { - emit renameObject(oldName, objectName()); + QString newName = QString::number(network()->networkId()) + "/" + _nick; + QString oldName = objectName(); + if(oldName != newName) { + setObjectName(newName); + emit renameObject(oldName, newName); } } - void IrcUser::updateHostmask(const QString &mask) { if(mask == hostmask()) return; @@ -118,22 +165,45 @@ void IrcUser::updateHostmask(const QString &mask) { setHost(host); } -void IrcUser::joinChannel(const QString &channel) { +void IrcUser::joinChannel(IrcChannel *channel) { + Q_ASSERT(channel); if(!_channels.contains(channel)) { _channels.insert(channel); - networkInfo->newIrcChannel(channel)->join(this); - emit channelJoined(channel); + channel->join(this); + connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed())); + emit channelJoined(channel->name()); } } -void IrcUser::partChannel(const QString &channel) { +void IrcUser::joinChannel(const QString &channelname) { + joinChannel(network()->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()); + } +} - Q_ASSERT(networkInfo->ircChannel(channel)); - networkInfo->ircChannel(channel)->part(this); - - emit channelParted(channel); +void IrcUser::partChannel(const QString &channelname) { + IrcChannel *channel = network()->ircChannel(channelname); + if(channel == 0) { + qWarning() << "IrcUser::partChannel(): received part for unknown Channel" << channelname; + } else { + partChannel(channel); + } +} + +void IrcUser::channelDestroyed() { + // private slot! + IrcChannel *channel = static_cast(sender()); + Q_ASSERT(channel); + if(_channels.contains(channel)) { + _channels.remove(channel); + disconnect(channel, 0, this, 0); } }