/***************************************************************************
- * 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 *
#include "ircuser.h"
#include "util.h"
-#include "networkinfo.h"
+#include "network.h"
#include "signalproxy.h"
#include "ircchannel.h"
+#include <QTextCodec>
#include <QDebug>
-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();
}
// ====================
// PUBLIC:
// ====================
-bool IrcUser::initialized() const {
- return _initialized;
-}
QString IrcUser::user() const {
return _user;
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);
+}
+
// ====================
// PUBLIC SLOTS:
// ====================
void IrcUser::setNick(const QString &nick) {
if(!nick.isEmpty() && nick != _nick) {
- QString oldnick(_nick);
_nick = nick;
updateObjectName();
emit nickSet(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;
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());
}
}
void IrcUser::joinChannel(const QString &channelname) {
- joinChannel(networkInfo->newIrcChannel(channelname));
+ joinChannel(network()->newIrcChannel(channelname));
}
void IrcUser::partChannel(IrcChannel *channel) {
}
void IrcUser::partChannel(const QString &channelname) {
- IrcChannel *channel = networkInfo->ircChannel(channelname);
+ IrcChannel *channel = network()->ircChannel(channelname);
if(channel == 0) {
qWarning() << "IrcUser::partChannel(): received part for unknown Channel" << channelname;
} else {
}
}
-void IrcUser::setInitialized() {
- _initialized = true;
- emit initDone();
-}
-