X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircuser.cpp;h=32ff7944e0f9c0d56b7c8c8b7a7296d0242d0558;hp=be5f49abd0839fa29278bb944adf7cf0ec2c654c;hb=e56629542168c203cac8504085fc96c7f7b73d90;hpb=de9a7ec6b70c796182e0a7992aa380a58b954b94 diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index be5f49ab..32ff7944 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by The Quassel Team * + * Copyright (C) 2005-2015 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -15,100 +15,380 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "ircuser.h" #include "util.h" -IrcUser::IrcUser(QObject *parent) - : QObject(parent) { +#include "network.h" +#include "signalproxy.h" +#include "ircchannel.h" + +#include +#include + +INIT_SYNCABLE_OBJECT(IrcUser) +IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(network), + _initialized(false), + _nick(nickFromMask(hostmask)), + _user(userFromMask(hostmask)), + _host(hostFromMask(hostmask)), + _realName(), + _awayMessage(), + _away(false), + _server(), + // _idleTime(QDateTime::currentDateTime()), + _ircOperator(), + _lastAwayMessage(0), + _whoisServiceReply(), + _encrypted(false), + _network(network), + _codecForEncoding(0), + _codecForDecoding(0) +{ + updateObjectName(); +} + + +IrcUser::~IrcUser() +{ +} + + +// ==================== +// PUBLIC: +// ==================== + +QString IrcUser::hostmask() const +{ + return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host()); +} + + +QDateTime IrcUser::idleTime() +{ + if (QDateTime::currentDateTime().toTime_t() - _idleTimeSet.toTime_t() > 1200) + _idleTime = QDateTime(); + return _idleTime; +} + + +QStringList IrcUser::channels() const +{ + QStringList chanList; + IrcChannel *channel; + foreach(channel, _channels) { + chanList << channel->name(); + } + return chanList; +} + + +void IrcUser::setCodecForEncoding(const QString &name) +{ + setCodecForEncoding(QTextCodec::codecForName(name.toLatin1())); +} + + +void IrcUser::setCodecForEncoding(QTextCodec *codec) +{ + _codecForEncoding = codec; +} + + +void IrcUser::setCodecForDecoding(const QString &name) +{ + setCodecForDecoding(QTextCodec::codecForName(name.toLatin1())); +} + + +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; + 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; + SYNC(ARG(away)) + emit awaySet(away); + } } -IrcUser::IrcUser(const QString &hostmask, QObject *parent) - : QObject(parent), - nick_(nickFromMask(hostmask)), - user_(userFromMask(hostmask)), - host_(hostFromMask(hostmask)) { + +void IrcUser::setAwayMessage(const QString &awayMessage) +{ + if (!awayMessage.isEmpty() && _awayMessage != awayMessage) { + _awayMessage = awayMessage; + SYNC(ARG(awayMessage)) + } } -IrcUser::~IrcUser() { + +void IrcUser::setIdleTime(const QDateTime &idleTime) +{ + if (idleTime.isValid() && _idleTime != idleTime) { + _idleTime = idleTime; + _idleTimeSet = QDateTime::currentDateTime(); + SYNC(ARG(idleTime)) + } } -void IrcUser::setUser(const QString &user) { - user_ = user; + +void IrcUser::setLoginTime(const QDateTime &loginTime) +{ + if (loginTime.isValid() && _loginTime != loginTime) { + _loginTime = loginTime; + SYNC(ARG(loginTime)) + } } -QString IrcUser::user() const { - return user_; + +void IrcUser::setServer(const QString &server) +{ + if (!server.isEmpty() && _server != server) { + _server = server; + SYNC(ARG(server)) + } } -void IrcUser::setHost(const QString &host) { - host_ = host; + +void IrcUser::setIrcOperator(const QString &ircOperator) +{ + if (!ircOperator.isEmpty() && _ircOperator != ircOperator) { + _ircOperator = ircOperator; + SYNC(ARG(ircOperator)) + } } -QString IrcUser::host() const { - return host_; + +void IrcUser::setLastAwayMessage(const int &lastAwayMessage) +{ + if (lastAwayMessage > _lastAwayMessage) { + _lastAwayMessage = lastAwayMessage; + SYNC(ARG(lastAwayMessage)) + } } -void IrcUser::setNick(const QString &nick) { - nick_ = nick; + +void IrcUser::setHost(const QString &host) +{ + if (!host.isEmpty() && _host != host) { + _host = host; + SYNC(ARG(host)) + } } -QString IrcUser::nick() const { - return nick_; + +void IrcUser::setNick(const QString &nick) +{ + if (!nick.isEmpty() && nick != _nick) { + _nick = nick; + updateObjectName(); + SYNC(ARG(nick)) + emit nickSet(nick); + } } -void IrcUser::setUsermodes(const QSet &usermodes) { - usermodes_ = usermodes; + +void IrcUser::setWhoisServiceReply(const QString &whoisServiceReply) +{ + if (!whoisServiceReply.isEmpty() && whoisServiceReply != _whoisServiceReply) { + _whoisServiceReply = whoisServiceReply; + SYNC(ARG(whoisServiceReply)) + } } -QSet IrcUser::usermodes() const { - return usermodes_; + +void IrcUser::setSuserHost(const QString &suserHost) +{ + if (!suserHost.isEmpty() && suserHost != _suserHost) { + _suserHost = suserHost; + SYNC(ARG(suserHost)) + } } -void IrcUser::setChannelmode(const QString &channel, const QSet &channelmode) { - if(channelmodes_.contains(channel)) - channelmodes_[channel] |= channelmode; - else - channelmodes_[channel] = channelmode; + +void IrcUser::setEncrypted(bool encrypted) +{ + _encrypted = encrypted; + emit encryptedSet(encrypted); + SYNC(ARG(encrypted)) } -QSet IrcUser::channelmode(const QString &channel) const { - if(channelmodes_.contains(channel)) - //throw NoSuchChannelException(); - Q_ASSERT(false); // FIXME: exception disabled for qtopia testing - else - return QSet(); + +void IrcUser::updateObjectName() +{ + renameObject(QString::number(network()->networkId().toInt()) + "/" + _nick); } -void IrcUser::updateChannelmode(const QString &channel, const QString &channelmode, bool add) { - if(add) - addChannelmode(channel, channelmode); - else - removeChannelmode(channel, channelmode); + +void IrcUser::updateHostmask(const QString &mask) +{ + if (mask == hostmask()) + return; + + QString user = userFromMask(mask); + QString host = hostFromMask(mask); + setUser(user); + setHost(host); } -void IrcUser::addChannelmode(const QString &channel, const QString &channelmode) { - if(!channelmodes_.contains(channel)) - channelmodes_[channel] = QSet(); - channelmodes_[channel] << channelmode; + +void IrcUser::joinChannel(IrcChannel *channel, bool skip_channel_join) +{ + Q_ASSERT(channel); + if (!_channels.contains(channel)) { + _channels.insert(channel); + if (!skip_channel_join) + channel->joinIrcUser(this); + } } -void IrcUser::removeChannelmode(const QString &channel, const QString &channelmode) { - if(channelmodes_.contains(channel)) - channelmodes_[channel].remove(channelmode); + +void IrcUser::joinChannel(const QString &channelname) +{ + joinChannel(network()->newIrcChannel(channelname)); } -QStringList IrcUser::channels() const { - return channelmodes_.keys(); + +void IrcUser::partChannel(IrcChannel *channel) +{ + if (_channels.contains(channel)) { + _channels.remove(channel); + disconnect(channel, 0, this, 0); + channel->part(this); + QString channelName = channel->name(); + SYNC_OTHER(partChannel, ARG(channelName)) + if (_channels.isEmpty() && !network()->isMe(this)) + quit(); + } } -void IrcUser::joinChannel(const QString &channel) { - if(!channelmodes_.contains(channel)) - channelmodes_[channel] = QSet(); + +void IrcUser::partChannel(const QString &channelname) +{ + IrcChannel *channel = network()->ircChannel(channelname); + if (channel == 0) { + qWarning() << "IrcUser::partChannel(): received part for unknown Channel" << channelname; + } + else { + partChannel(channel); + } } -void IrcUser::partChannel(const QString &channel) { - channelmodes_.remove(channel); + +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()); + if (_channels.contains(channel)) { + _channels.remove(channel); + if (_channels.isEmpty() && !network()->isMe(this)) + quit(); + } +} + + +void IrcUser::setUserModes(const QString &modes) +{ + _userModes = modes; + SYNC(ARG(modes)) + emit userModesSet(modes); +} + + +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]; + } + + SYNC(ARG(modes)) + emit userModesAdded(modes); +} + + +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::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); }