X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircuser.cpp;h=fa2069899a1c6344531c73352d4abfbbd8cff73f;hp=223a02f5c40943f4f3ea463c071210c2acb53aff;hb=e89cfe68c0b4d117ce79d0d38fcc085de77a3083;hpb=0268b7f62826dc48155866f7f27b2987449a29f5 diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index 223a02f5..fa206989 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -28,8 +28,7 @@ #include #include -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)), @@ -38,9 +37,10 @@ IrcUser::IrcUser(const QString &hostmask, Network *network) _awayMessage(), _away(false), _server(), - _idleTime(QDateTime::currentDateTime()), + // _idleTime(QDateTime::currentDateTime()), _ircOperator(), _lastAwayMessage(0), + _whoisServiceReply(), _network(network), _codecForEncoding(0), _codecForDecoding(0) @@ -55,54 +55,16 @@ IrcUser::~IrcUser() { // PUBLIC: // ==================== -QString IrcUser::user() const { - return _user; -} - -QString IrcUser::host() const { - return _host; -} - -QString IrcUser::nick() const { - return _nick; -} - -QString IrcUser::realName() const { - return _realName; -} - QString IrcUser::hostmask() const { return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host()); } -bool IrcUser::isAway() const { - return _away; -} - -QString IrcUser::awayMessage() const { - return _awayMessage; -} - -QString IrcUser::server() const { - return _server; -} - -QDateTime IrcUser::idleTime() const { +QDateTime IrcUser::idleTime() { + if(QDateTime::currentDateTime().toTime_t() - _idleTimeSet.toTime_t() > 1200) + _idleTime = QDateTime(); return _idleTime; } -QString IrcUser::ircOperator() const { - return _ircOperator; -} - -int IrcUser::lastAwayMessage() const { - return _lastAwayMessage; -} - -QString IrcUser::userModes() const { - return _userModes; -} - QStringList IrcUser::channels() const { QStringList chanList; IrcChannel *channel; @@ -112,13 +74,6 @@ QStringList IrcUser::channels() const { 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())); @@ -128,10 +83,6 @@ void IrcUser::setCodecForEncoding(QTextCodec *codec) { _codecForEncoding = codec; } -QTextCodec *IrcUser::codecForDecoding() const { - return _codecForDecoding; -} - void IrcUser::setCodecForDecoding(const QString &name) { setCodecForDecoding(QTextCodec::codecForName(name.toAscii())); } @@ -145,7 +96,7 @@ QString IrcUser::decodeString(const QByteArray &text) const { return ::decodeString(text, codecForDecoding()); } -QByteArray IrcUser::encodeString(const QString string) const { +QByteArray IrcUser::encodeString(const QString &string) const { if(codecForEncoding()) { return codecForEncoding()->fromUnicode(string); } @@ -186,10 +137,18 @@ void IrcUser::setAwayMessage(const QString &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; @@ -212,6 +171,7 @@ void IrcUser::setLastAwayMessage(const int &lastAwayMessage) { } void IrcUser::setHost(const QString &host) { + so_sync(so_arg_cast(host)); if(!host.isEmpty() && _host != host) { _host = host; emit hostSet(host); @@ -226,15 +186,24 @@ void IrcUser::setNick(const QString &nick) { } } -void IrcUser::updateObjectName() { - QString newName = QString::number(network()->networkId().toInt()) + "/" + _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; @@ -249,9 +218,7 @@ 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())); - emit channelJoined(channel->name()); + channel->joinIrcUsers(this); } } @@ -265,6 +232,8 @@ void IrcUser::partChannel(IrcChannel *channel) { disconnect(channel, 0, this, 0); channel->part(this); emit channelParted(channel->name()); + if(_channels.isEmpty() && !network()->isMe(this)) + quit(); } } @@ -277,11 +246,24 @@ 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); + emit quited(); +} + void IrcUser::channelDestroyed() { // private slot! IrcChannel *channel = static_cast(sender()); if(_channels.contains(channel)) { _channels.remove(channel); + if(_channels.isEmpty() && !network()->isMe(this)) + quit(); } } @@ -290,23 +272,34 @@ void IrcUser::setUserModes(const QString &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; + + for(int i = 0; i < modes.count(); i++) { + if(!_userModes.contains(modes[i])) + _userModes += modes[i]; } + + emit userModesAdded(modes); } -void IrcUser::removeUserMode(const QString &mode) { - if(_userModes.contains(mode)) { - _userModes.remove(mode); - emit userModeRemoved(mode); +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); } -void IrcUser::initSetChannels(const QStringList channels) { - foreach(QString channel, channels) { - joinChannel(channel); - } +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); +}