/***************************************************************************
- * 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),
+ _realName(),
+ _awayMessage(),
+ _away(false),
+ _server(),
+ // _idleTime(QDateTime::currentDateTime()),
+ _ircOperator(),
+ _lastAwayMessage(0),
+ _whoisServiceReply(),
+ _network(network),
_codecForEncoding(0),
_codecForDecoding(0)
{
}
IrcUser::~IrcUser() {
- //qDebug() << nick() << "destroyed.";
}
// ====================
// PUBLIC:
// ====================
-bool IrcUser::initialized() const {
- return _initialized;
-}
-
-QString IrcUser::user() const {
- return _user;
-}
-
-QString IrcUser::host() const {
- return _host;
-}
-
-QString IrcUser::nick() const {
- return _nick;
-}
QString IrcUser::hostmask() const {
return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host());
}
-QString IrcUser::userModes() const {
- return _userModes;
+QDateTime IrcUser::idleTime() {
+ if(QDateTime::currentDateTime().toTime_t() - _idleTimeSet.toTime_t() > 1200)
+ _idleTime = QDateTime();
+ return _idleTime;
}
QStringList IrcUser::channels() const {
return chanList;
}
-QTextCodec *IrcUser::codecForEncoding() const {
- return _codecForEncoding;
-}
void IrcUser::setCodecForEncoding(const QString &name) {
setCodecForEncoding(QTextCodec::codecForName(name.toAscii()));
_codecForEncoding = codec;
}
-QTextCodec *IrcUser::codecForDecoding() const {
- return _codecForDecoding;
-}
-
void IrcUser::setCodecForDecoding(const QString &name) {
setCodecForDecoding(QTextCodec::codecForName(name.toAscii()));
}
}
QString IrcUser::decodeString(const QByteArray &text) const {
- if(!codecForDecoding()) return networkInfo->decodeString(text);
+ if(!codecForDecoding()) return network()->decodeString(text);
return ::decodeString(text, codecForDecoding());
}
-QByteArray IrcUser::encodeString(const QString string) const {
+QByteArray IrcUser::encodeString(const QString &string) const {
if(codecForEncoding()) {
return codecForEncoding()->fromUnicode(string);
}
- return networkInfo->encodeString(string);
+ return network()->encodeString(string);
}
// ====================
}
}
+void IrcUser::setRealName(const QString &realName) {
+ if (!realName.isEmpty() && _realName != realName) {
+ _realName = realName;
+ emit realNameSet(realName);
+ }
+}
+
+void IrcUser::setAway(const bool &away) {
+ if(away != _away) {
+ _away = away;
+ emit awaySet(away);
+ }
+}
+
+void IrcUser::setAwayMessage(const QString &awayMessage) {
+ if(!awayMessage.isEmpty() && _awayMessage != awayMessage) {
+ _awayMessage = awayMessage;
+ emit awayMessageSet(awayMessage);
+ }
+}
+
+void IrcUser::setIdleTime(const QDateTime &idleTime) {
+ if(idleTime.isValid() && _idleTime != idleTime) {
+ _idleTime = idleTime;
+ _idleTimeSet = QDateTime::currentDateTime();
+ emit idleTimeSet(idleTime);
+ }
+}
+
+void IrcUser::setLoginTime(const QDateTime &loginTime) {
+ if(loginTime.isValid() && _loginTime != loginTime) {
+ _loginTime = loginTime;
+ emit loginTimeSet(loginTime);
+ }
+}
+
+void IrcUser::setServer(const QString &server) {
+ if(!server.isEmpty() && _server != server) {
+ _server = server;
+ emit serverSet(server);
+ }
+}
+
+void IrcUser::setIrcOperator(const QString &ircOperator) {
+ if(!ircOperator.isEmpty() && _ircOperator != ircOperator) {
+ _ircOperator = ircOperator;
+ emit ircOperatorSet(ircOperator);
+ }
+}
+
+void IrcUser::setLastAwayMessage(const int &lastAwayMessage) {
+ if(lastAwayMessage > _lastAwayMessage) {
+ _lastAwayMessage = lastAwayMessage;
+ emit lastAwayMessageSet(lastAwayMessage);
+ }
+}
+
void IrcUser::setHost(const QString &host) {
if(!host.isEmpty() && _host != host) {
_host = host;
}
}
-void IrcUser::updateObjectName() {
- QString newName = QString::number(networkInfo->networkId()) + "/" + _nick;
- QString oldName = objectName();
- if(oldName != newName) {
- setObjectName(newName);
- emit renameObject(oldName, newName);
+void IrcUser::setWhoisServiceReply(const QString &whoisServiceReply) {
+ if(!whoisServiceReply.isEmpty() && whoisServiceReply != _whoisServiceReply) {
+ _whoisServiceReply = whoisServiceReply;
+ emit whoisServiceReplySet(whoisServiceReply);
+ }
+}
+
+void IrcUser::setSuserHost(const QString &suserHost) {
+ if(!suserHost.isEmpty() && suserHost != _suserHost) {
+ _suserHost = suserHost;
+ emit suserHostSet(suserHost);
}
}
+void IrcUser::updateObjectName() {
+ renameObject(QString::number(network()->networkId().toInt()) + "/" + _nick);
+}
+
void IrcUser::updateHostmask(const QString &mask) {
if(mask == hostmask())
return;
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());
}
}
void IrcUser::joinChannel(const QString &channelname) {
- joinChannel(networkInfo->newIrcChannel(channelname));
+ joinChannel(network()->newIrcChannel(channelname));
}
void IrcUser::partChannel(IrcChannel *channel) {
disconnect(channel, 0, this, 0);
channel->part(this);
emit channelParted(channel->name());
+ if(_channels.isEmpty() && !network()->isMe(this))
+ deleteLater();
}
}
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::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 userModesSet(modes);
}
-void IrcUser::addUserMode(const QString &mode) {
- if(!_userModes.contains(mode)) {
- _userModes += mode;
- emit userModeAdded(mode);
- }
-}
+void IrcUser::addUserModes(const QString &modes) {
+ if(modes.isEmpty())
+ return;
-void IrcUser::removeUserMode(const QString &mode) {
- if(_userModes.contains(mode)) {
- _userModes.remove(mode);
- emit userModeRemoved(mode);
+ for(int i = 0; i < modes.count(); i++) {
+ if(!_userModes.contains(modes[i]))
+ _userModes += modes[i];
}
-}
-void IrcUser::initSetChannels(const QStringList channels) {
- foreach(QString channel, channels) {
- joinChannel(channel);
- }
+ emit userModesAdded(modes);
}
-void IrcUser::setInitialized() {
- _initialized = true;
- emit initDone();
-}
+void IrcUser::removeUserModes(const QString &modes) {
+ if(modes.isEmpty())
+ return;
+ for(int i = 0; i < modes.count(); i++) {
+ _userModes.remove(modes[i]);
+ }
+ emit userModesRemoved(modes);
+}