X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircuser.cpp;h=cf1aedaafe90b98dbb7332ed5ea78098e563b7ff;hp=9e792ba965c840d652f0c3a1ba866ba363c9bfa7;hb=8582c2ad5708a1972c85bea1cf8d81ad3ece4814;hpb=694f9bfbf7f1af19108461c7e00d133e55082bce diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index 9e792ba9..cf1aedaa 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,7 +15,7 @@ * 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" @@ -28,7 +28,6 @@ #include #include -INIT_SYNCABLE_OBJECT(IrcUser) IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(network), _initialized(false), _nick(nickFromMask(hostmask)), @@ -40,18 +39,16 @@ IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(net _server(), // _idleTime(QDateTime::currentDateTime()), _ircOperator(), - _lastAwayMessage(0), + _lastAwayMessageTime(), _whoisServiceReply(), + _encrypted(false), _network(network), - _codecForEncoding(0), - _codecForDecoding(0) + _codecForEncoding(nullptr), + _codecForDecoding(nullptr) { updateObjectName(); -} - - -IrcUser::~IrcUser() -{ + _lastAwayMessageTime.setTimeSpec(Qt::UTC); + _lastAwayMessageTime.setMSecsSinceEpoch(0); } @@ -67,8 +64,12 @@ QString IrcUser::hostmask() const QDateTime IrcUser::idleTime() { - if (QDateTime::currentDateTime().toTime_t() - _idleTimeSet.toTime_t() > 1200) + if ((QDateTime::currentDateTime().toMSecsSinceEpoch() - _idleTimeSet.toMSecsSinceEpoch()) + > 1200000) { + // 20 * 60 * 1000 = 1200000 + // 20 minutes have elapsed, clear the known idle time as it's likely inaccurate by now _idleTime = QDateTime(); + } return _idleTime; } @@ -86,7 +87,7 @@ QStringList IrcUser::channels() const void IrcUser::setCodecForEncoding(const QString &name) { - setCodecForEncoding(QTextCodec::codecForName(name.toAscii())); + setCodecForEncoding(QTextCodec::codecForName(name.toLatin1())); } @@ -98,7 +99,7 @@ void IrcUser::setCodecForEncoding(QTextCodec *codec) void IrcUser::setCodecForDecoding(const QString &name) { - setCodecForDecoding(QTextCodec::codecForName(name.toAscii())); + setCodecForDecoding(QTextCodec::codecForName(name.toLatin1())); } @@ -145,10 +146,20 @@ void IrcUser::setRealName(const QString &realName) } -void IrcUser::setAway(const bool &away) +void IrcUser::setAccount(const QString &account) +{ + if (_account != account) { + _account = account; + SYNC(ARG(account)) + } +} + + +void IrcUser::setAway(bool away) { if (away != _away) { _away = away; + markAwayChanged(); SYNC(ARG(away)) emit awaySet(away); } @@ -159,6 +170,7 @@ void IrcUser::setAwayMessage(const QString &awayMessage) { if (!awayMessage.isEmpty() && _awayMessage != awayMessage) { _awayMessage = awayMessage; + markAwayChanged(); SYNC(ARG(awayMessage)) } } @@ -201,11 +213,27 @@ void IrcUser::setIrcOperator(const QString &ircOperator) } -void IrcUser::setLastAwayMessage(const int &lastAwayMessage) +// This function is only ever called by SYNC calls from legacy cores (pre-0.13). +// Therefore, no SYNC call is needed here. +void IrcUser::setLastAwayMessage(int lastAwayMessage) +{ +#if QT_VERSION >= 0x050800 + QDateTime lastAwayMessageTime = QDateTime::fromSecsSinceEpoch(lastAwayMessage); +#else + // toSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for now. + // See https://doc.qt.io/qt-5/qdatetime.html#toMSecsSinceEpoch + QDateTime lastAwayMessageTime = QDateTime::fromMSecsSinceEpoch(lastAwayMessage * 1000); +#endif + lastAwayMessageTime.setTimeSpec(Qt::UTC); + setLastAwayMessageTime(lastAwayMessageTime); +} + + +void IrcUser::setLastAwayMessageTime(const QDateTime &lastAwayMessageTime) { - if (lastAwayMessage > _lastAwayMessage) { - _lastAwayMessage = lastAwayMessage; - SYNC(ARG(lastAwayMessage)) + if (lastAwayMessageTime > _lastAwayMessageTime) { + _lastAwayMessageTime = lastAwayMessageTime; + SYNC(ARG(lastAwayMessageTime)) } } @@ -248,6 +276,14 @@ void IrcUser::setSuserHost(const QString &suserHost) } +void IrcUser::setEncrypted(bool encrypted) +{ + _encrypted = encrypted; + emit encryptedSet(encrypted); + SYNC(ARG(encrypted)) +} + + void IrcUser::updateObjectName() { renameObject(QString::number(network()->networkId().toInt()) + "/" + _nick); @@ -266,12 +302,13 @@ void IrcUser::updateHostmask(const QString &mask) } -void IrcUser::joinChannel(IrcChannel *channel) +void IrcUser::joinChannel(IrcChannel *channel, bool skip_channel_join) { Q_ASSERT(channel); if (!_channels.contains(channel)) { _channels.insert(channel); - channel->joinIrcUser(this); + if (!skip_channel_join) + channel->joinIrcUser(this); } } @@ -286,7 +323,7 @@ void IrcUser::partChannel(IrcChannel *channel) { if (_channels.contains(channel)) { _channels.remove(channel); - disconnect(channel, 0, this, 0); + disconnect(channel, nullptr, this, nullptr); channel->part(this); QString channelName = channel->name(); SYNC_OTHER(partChannel, ARG(channelName)) @@ -299,7 +336,7 @@ void IrcUser::partChannel(IrcChannel *channel) void IrcUser::partChannel(const QString &channelname) { IrcChannel *channel = network()->ircChannel(channelname); - if (channel == 0) { + if (channel == nullptr) { qWarning() << "IrcUser::partChannel(): received part for unknown Channel" << channelname; } else { @@ -313,7 +350,7 @@ void IrcUser::quit() QList channels = _channels.toList(); _channels.clear(); foreach(IrcChannel *channel, channels) { - disconnect(channel, 0, this, 0); + disconnect(channel, nullptr, this, nullptr); channel->part(this); } network()->removeIrcUser(this); @@ -325,7 +362,7 @@ void IrcUser::quit() void IrcUser::channelDestroyed() { // private slot! - IrcChannel *channel = static_cast(sender()); + auto *channel = static_cast(sender()); if (_channels.contains(channel)) { _channels.remove(channel); if (_channels.isEmpty() && !network()->isMe(this)) @@ -336,9 +373,11 @@ void IrcUser::channelDestroyed() void IrcUser::setUserModes(const QString &modes) { - _userModes = modes; - SYNC(ARG(modes)) - emit userModesSet(modes); + if (_userModes != modes) { + _userModes = modes; + SYNC(ARG(modes)) + emit userModesSet(modes); + } } @@ -347,13 +386,19 @@ void IrcUser::addUserModes(const QString &modes) if (modes.isEmpty()) return; + // Don't needlessly sync when no changes are made + bool changesMade = false; for (int i = 0; i < modes.count(); i++) { - if (!_userModes.contains(modes[i])) + if (!_userModes.contains(modes[i])) { _userModes += modes[i]; + changesMade = true; + } } - SYNC(ARG(modes)) - emit userModesAdded(modes); + if (changesMade) { + SYNC(ARG(modes)) + emit userModesAdded(modes); + } }