#include <QTextCodec>
#include <QDebug>
-IrcUser::IrcUser(const QString &hostmask, Network *network)
- : SyncableObject(network),
+IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(network),
_initialized(false),
_nick(nickFromMask(hostmask)),
_user(userFromMask(hostmask)),
}
IrcUser::~IrcUser() {
- QList<IrcChannel *> channels = _channels.toList();
- foreach(IrcChannel *channel, channels) {
- partChannel(channel);
- }
}
// ====================
return ::decodeString(text, codecForDecoding());
}
-QByteArray IrcUser::encodeString(const QString string) const {
+QByteArray IrcUser::encodeString(const QString &string) const {
if(codecForEncoding()) {
return codecForEncoding()->fromUnicode(string);
}
}
void IrcUser::updateObjectName() {
- QString newName = QString::number(network()->networkId().toInt()) + "/" + _nick;
- QString oldName = objectName();
- if(oldName != newName) {
- setObjectName(newName);
- emit renameObject(oldName, newName);
- }
+ renameObject(QString::number(network()->networkId().toInt()) + "/" + _nick);
}
void IrcUser::updateHostmask(const QString &mask) {
Q_ASSERT(channel);
if(!_channels.contains(channel)) {
_channels.insert(channel);
- channel->join(this);
+ channel->joinIrcUsers(this);
connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed()));
- emit channelJoined(channel->name());
}
}
disconnect(channel, 0, this, 0);
channel->part(this);
emit channelParted(channel->name());
+ if(_channels.isEmpty() && network()->isMe(this))
+ deleteLater();
}
}
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);
+ if(_channels.isEmpty())
+ deleteLater();
}
}
emit userModeRemoved(mode);
}
}
-
-void IrcUser::initSetChannels(const QStringList channels) {
- foreach(QString channel, channels) {
- joinChannel(channel);
- }
-}
-