X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircuser.cpp;h=181f1109b89d02c3f977193f577f50c8788b5878;hp=01bc963435b1f1937c45e3833258230ad69934dd;hb=a5db4ebf51fddc79cdd1f27b1d0178742c829a13;hpb=27be9c5a706bf690921617bf66614c4479550c4d diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index 01bc9634..181f1109 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-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -21,52 +21,49 @@ #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), +INIT_SYNCABLE_OBJECT(IrcUser) +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) { updateObjectName(); } 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 { @@ -78,40 +75,136 @@ QStringList IrcUser::channels() const { return chanList; } + +void IrcUser::setCodecForEncoding(const QString &name) { + setCodecForEncoding(QTextCodec::codecForName(name.toAscii())); +} + +void IrcUser::setCodecForEncoding(QTextCodec *codec) { + _codecForEncoding = codec; +} + +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::setUser(const QString &user) { if(!user.isEmpty() && _user != user) { _user = user; - emit userSet(user); + SYNC(ARG(user)); + } +} + +void IrcUser::setRealName(const QString &realName) { + if (!realName.isEmpty() && _realName != realName) { + _realName = realName; + SYNC(ARG(realName)) + } +} + +void IrcUser::setAway(const bool &away) { + if(away != _away) { + _away = away; + emit awaySet(away); + SYNC(ARG(away)) + } +} + +void IrcUser::setAwayMessage(const QString &awayMessage) { + if(!awayMessage.isEmpty() && _awayMessage != awayMessage) { + _awayMessage = awayMessage; + SYNC(ARG(awayMessage)) + } +} + +void IrcUser::setIdleTime(const QDateTime &idleTime) { + if(idleTime.isValid() && _idleTime != idleTime) { + _idleTime = idleTime; + _idleTimeSet = QDateTime::currentDateTime(); + SYNC(ARG(idleTime)) + } +} + +void IrcUser::setLoginTime(const QDateTime &loginTime) { + if(loginTime.isValid() && _loginTime != loginTime) { + _loginTime = loginTime; + SYNC(ARG(loginTime)) + } +} + +void IrcUser::setServer(const QString &server) { + if(!server.isEmpty() && _server != server) { + _server = server; + SYNC(ARG(server)) + } +} + +void IrcUser::setIrcOperator(const QString &ircOperator) { + if(!ircOperator.isEmpty() && _ircOperator != ircOperator) { + _ircOperator = ircOperator; + SYNC(ARG(ircOperator)) + } +} + +void IrcUser::setLastAwayMessage(const int &lastAwayMessage) { + if(lastAwayMessage > _lastAwayMessage) { + _lastAwayMessage = lastAwayMessage; + SYNC(ARG(lastAwayMessage)) } } void IrcUser::setHost(const QString &host) { if(!host.isEmpty() && _host != host) { _host = host; - emit hostSet(host); + SYNC(ARG(host)) } } void IrcUser::setNick(const QString &nick) { if(!nick.isEmpty() && nick != _nick) { - QString oldnick(_nick); _nick = nick; updateObjectName(); emit nickSet(nick); + SYNC(ARG(nick)) } } -void IrcUser::updateObjectName() { - QString oldName(objectName()); - setObjectName(QString::number(networkInfo->networkId()) + "/" + _nick); - if(!oldName.isEmpty()) { - emit renameObject(oldName, objectName()); +void IrcUser::setWhoisServiceReply(const QString &whoisServiceReply) { + if(!whoisServiceReply.isEmpty() && whoisServiceReply != _whoisServiceReply) { + _whoisServiceReply = whoisServiceReply; + SYNC(ARG(whoisServiceReply)) + } +} + +void IrcUser::setSuserHost(const QString &suserHost) { + if(!suserHost.isEmpty() && suserHost != _suserHost) { + _suserHost = suserHost; + SYNC(ARG(suserHost)) } } +void IrcUser::updateObjectName() { + renameObject(QString::number(network()->networkId().toInt()) + "/" + _nick); +} void IrcUser::updateHostmask(const QString &mask) { if(mask == hostmask()) @@ -126,15 +219,13 @@ void IrcUser::updateHostmask(const QString &mask) { void IrcUser::joinChannel(IrcChannel *channel) { Q_ASSERT(channel); if(!_channels.contains(channel)) { - channel->join(this); - connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed())); _channels.insert(channel); - emit channelJoined(channel->name()); + channel->joinIrcUser(this); } } void IrcUser::joinChannel(const QString &channelname) { - joinChannel(networkInfo->newIrcChannel(channelname)); + joinChannel(network()->newIrcChannel(channelname)); } void IrcUser::partChannel(IrcChannel *channel) { @@ -142,12 +233,15 @@ void IrcUser::partChannel(IrcChannel *channel) { _channels.remove(channel); disconnect(channel, 0, this, 0); channel->part(this); - emit channelParted(channel->name()); + QString channelName = channel->name(); + SYNC_OTHER(partChannel, ARG(channelName)) + if(_channels.isEmpty() && !network()->isMe(this)) + quit(); } } 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 { @@ -155,43 +249,64 @@ void IrcUser::partChannel(const QString &channelname) { } } +void IrcUser::quit() { + QList channels = _channels.toList(); + _channels.clear(); + foreach(IrcChannel *channel, channels) { + disconnect(channel, 0, this, 0); + channel->part(this); + } + network()->removeIrcUser(this); + SYNC(NO_ARG) + emit quited(); +} + 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); + if(_channels.isEmpty() && !network()->isMe(this)) + quit(); } } void IrcUser::setUserModes(const QString &modes) { _userModes = modes; + SYNC(ARG(modes)) 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]; } + + SYNC(ARG(modes)) + emit userModesAdded(modes); } -void IrcUser::initSetChannels(const QStringList channels) { - foreach(QString channel, channels) { - joinChannel(channel); +void IrcUser::removeUserModes(const QString &modes) { + if(modes.isEmpty()) + return; + + for(int i = 0; i < modes.count(); i++) { + _userModes.remove(modes[i]); } + SYNC(ARG(modes)) + emit userModesRemoved(modes); } -void IrcUser::setInitialized() { - _initialized = true; - emit initDone(); +void IrcUser::setLastChannelActivity(BufferId buffer, const QDateTime &time) { + _lastActivity[buffer] = time; + emit lastChannelActivityUpdated(buffer, time); } +void IrcUser::setLastSpokenTo(BufferId buffer, const QDateTime &time) { + _lastSpokenTo[buffer] = time; + emit lastSpokenToUpdated(buffer, time); +}