X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircuser.cpp;h=a313fc685ab110b49282c9903b15e854106b96f8;hp=333ee93b6f6be8471296edb30fb281cb14fc71b3;hb=b797e5f581b10a517c30f78cb53f813af741e261;hpb=8f6f3932998ffb3778e4e077dfb301da4cf34c1f diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index 333ee93b..a313fc68 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 * @@ -25,15 +25,18 @@ #include "signalproxy.h" #include "ircchannel.h" +#include #include IrcUser::IrcUser(const QString &hostmask, NetworkInfo *networkinfo) - : QObject(networkinfo), + : SyncableObject(networkinfo), _initialized(false), _nick(nickFromMask(hostmask)), _user(userFromMask(hostmask)), _host(hostFromMask(hostmask)), - networkInfo(networkinfo) + networkInfo(networkinfo), + _codecForEncoding(0), + _codecForDecoding(0) { updateObjectName(); } @@ -78,6 +81,42 @@ QStringList IrcUser::channels() const { 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); +} + // ==================== // PUBLIC SLOTS: // ==================== @@ -97,7 +136,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); @@ -105,14 +143,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(networkInfo->networkId()) + "/" + _nick; + QString oldName = objectName(); + if(oldName != newName) { + setObjectName(newName); + emit renameObject(oldName, newName); } } - void IrcUser::updateHostmask(const QString &mask) { if(mask == hostmask()) return; @@ -126,9 +164,9 @@ void IrcUser::updateHostmask(const QString &mask) { void IrcUser::joinChannel(IrcChannel *channel) { Q_ASSERT(channel); if(!_channels.contains(channel)) { + _channels.insert(channel); channel->join(this); connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed())); - _channels.insert(channel); emit channelJoined(channel->name()); } }