X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircchannel.cpp;h=b03f16ae65e9d0db6cfef97b37fae254a3d82c1c;hp=0684c665a8ebf93eaac35bb46129af52c7f4c955;hb=7298446b3e86140c4bbbfe7aeeb959c16c53363c;hpb=29252b7065315dfb5b4a226f7ab7998bfd08ee65 diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 0684c665..b03f16ae 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,56 +20,47 @@ #include "ircchannel.h" -#include "network.h" -#include "ircuser.h" -#include "util.h" - -#include +#include #include +#include #include -#include - -INIT_SYNCABLE_OBJECT(IrcChannel) -IrcChannel::IrcChannel(const QString &channelname, Network *network) - : SyncableObject(network), - _initialized(false), - _name(channelname), - _topic(QString()), - _encrypted(false), - _network(network), - _codecForEncoding(0), - _codecForDecoding(0) -{ - setObjectName(QString::number(network->networkId().toInt()) + "/" + channelname); -} - +#include "ircuser.h" +#include "network.h" +#include "util.h" -IrcChannel::~IrcChannel() +IrcChannel::IrcChannel(const QString& channelname, Network* network) + : SyncableObject(network) + , _initialized(false) + , _name(channelname) + , _topic(QString()) + , _encrypted(false) + , _network(network) + , _codecForEncoding(nullptr) + , _codecForDecoding(nullptr) { + setObjectName(QString::number(network->networkId().toInt()) + "/" + channelname); } - // ==================== // PUBLIC: // ==================== -bool IrcChannel::isKnownUser(IrcUser *ircuser) const +bool IrcChannel::isKnownUser(IrcUser* ircuser) const { - if (ircuser == 0) { + if (ircuser == nullptr) { qWarning() << "Channel" << name() << "received IrcUser Nullpointer!"; return false; } if (!_userModes.contains(ircuser)) { - qWarning() << "Channel" << name() << "received data for unknown User" << ircuser->nick(); + // This can happen e.g. when disconnecting from a network, so don't log a warning return false; } return true; } - -bool IrcChannel::isValidChannelUserMode(const QString &mode) const +bool IrcChannel::isValidChannelUserMode(const QString& mode) const { bool isvalid = true; if (mode.size() > 1) { @@ -79,8 +70,7 @@ bool IrcChannel::isValidChannelUserMode(const QString &mode) const return isvalid; } - -QString IrcChannel::userModes(IrcUser *ircuser) const +QString IrcChannel::userModes(IrcUser* ircuser) const { if (_userModes.contains(ircuser)) return _userModes[ircuser]; @@ -88,45 +78,39 @@ QString IrcChannel::userModes(IrcUser *ircuser) const return QString(); } - -QString IrcChannel::userModes(const QString &nick) const +QString IrcChannel::userModes(const QString& nick) const { return userModes(network()->ircUser(nick)); } - -void IrcChannel::setCodecForEncoding(const QString &name) +void IrcChannel::setCodecForEncoding(const QString& name) { setCodecForEncoding(QTextCodec::codecForName(name.toLatin1())); } - -void IrcChannel::setCodecForEncoding(QTextCodec *codec) +void IrcChannel::setCodecForEncoding(QTextCodec* codec) { _codecForEncoding = codec; } - -void IrcChannel::setCodecForDecoding(const QString &name) +void IrcChannel::setCodecForDecoding(const QString& name) { setCodecForDecoding(QTextCodec::codecForName(name.toLatin1())); } - -void IrcChannel::setCodecForDecoding(QTextCodec *codec) +void IrcChannel::setCodecForDecoding(QTextCodec* codec) { _codecForDecoding = codec; } - -QString IrcChannel::decodeString(const QByteArray &text) const +QString IrcChannel::decodeString(const QByteArray& text) const { - if (!codecForDecoding()) return network()->decodeString(text); + if (!codecForDecoding()) + return network()->decodeString(text); return ::decodeString(text, _codecForDecoding); } - -QByteArray IrcChannel::encodeString(const QString &string) const +QByteArray IrcChannel::encodeString(const QString& string) const { if (codecForEncoding()) { return _codecForEncoding->fromUnicode(string); @@ -134,19 +118,17 @@ QByteArray IrcChannel::encodeString(const QString &string) const return network()->encodeString(string); } - // ==================== // PUBLIC SLOTS: // ==================== -void IrcChannel::setTopic(const QString &topic) +void IrcChannel::setTopic(const QString& topic) { _topic = topic; SYNC(ARG(topic)) emit topicSet(topic); } - -void IrcChannel::setPassword(const QString &password) +void IrcChannel::setPassword(const QString& password) { _password = password; SYNC(ARG(password)) @@ -159,8 +141,7 @@ void IrcChannel::setEncrypted(bool encrypted) emit encryptedSet(encrypted); } - -void IrcChannel::joinIrcUsers(const QList &users, const QStringList &modes) +void IrcChannel::joinIrcUsers(const QList& users, const QStringList& modes) { if (users.isEmpty()) return; @@ -175,9 +156,9 @@ void IrcChannel::joinIrcUsers(const QList &users, const QStringList & QStringList newNicks; QStringList newModes; - QList newUsers; + QList newUsers; - IrcUser *ircuser; + IrcUser* ircuser; for (int i = 0; i < users.count(); i++) { ircuser = users[i]; if (!ircuser) @@ -189,7 +170,8 @@ void IrcChannel::joinIrcUsers(const QList &users, const QStringList & for (int i_m = 0; i_m < sortedModes[i].count(); ++i_m) { addUserMode(ircuser, sortedModes[i][i_m]); } - } else { + } + else { addUserMode(ircuser, sortedModes[i]); } continue; @@ -197,7 +179,7 @@ void IrcChannel::joinIrcUsers(const QList &users, const QStringList & _userModes[ircuser] = sortedModes[i]; ircuser->joinChannel(this, true); - connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickSet(QString))); + connect(ircuser, &IrcUser::nickSet, this, selectOverload(&IrcChannel::ircUserNickSet)); // connect(ircuser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed())); // If you wonder why there is no counterpart to ircUserJoined: @@ -215,44 +197,41 @@ void IrcChannel::joinIrcUsers(const QList &users, const QStringList & emit ircUsersJoined(newUsers); } - -void IrcChannel::joinIrcUsers(const QStringList &nicks, const QStringList &modes) +void IrcChannel::joinIrcUsers(const QStringList& nicks, const QStringList& modes) { - QList users; - foreach(QString nick, nicks) - users << network()->newIrcUser(nick); + QList users; + foreach (QString nick, nicks) + users << network()->newIrcUser(nick); joinIrcUsers(users, modes); } - -void IrcChannel::joinIrcUser(IrcUser *ircuser) +void IrcChannel::joinIrcUser(IrcUser* ircuser) { - QList users; + QList users; users << ircuser; QStringList modes; modes << QString(); joinIrcUsers(users, modes); } - -void IrcChannel::part(IrcUser *ircuser) +void IrcChannel::part(IrcUser* ircuser) { if (isKnownUser(ircuser)) { _userModes.remove(ircuser); ircuser->partChannel(this); // If you wonder why there is no counterpart to ircUserParted: // the joins are propagted by the ircuser. The signal ircUserParted is only for convenience - disconnect(ircuser, 0, this, 0); + disconnect(ircuser, nullptr, this, nullptr); emit ircUserParted(ircuser); if (network()->isMe(ircuser) || _userModes.isEmpty()) { // in either case we're no longer in the channel // -> clean up the channel and destroy it - QList users = _userModes.keys(); + QList users = _userModes.keys(); _userModes.clear(); - foreach(IrcUser *user, users) { - disconnect(user, 0, this, 0); - user->partChannel(this); + foreach (IrcUser* user, users) { + disconnect(user, nullptr, this, nullptr); + user->partChannelInternal(this, true); } emit parted(); network()->removeIrcChannel(this); @@ -260,15 +239,13 @@ void IrcChannel::part(IrcUser *ircuser) } } - -void IrcChannel::part(const QString &nick) +void IrcChannel::part(const QString& nick) { part(network()->ircUser(nick)); } - // SET USER MODE -void IrcChannel::setUserModes(IrcUser *ircuser, const QString &modes) +void IrcChannel::setUserModes(IrcUser* ircuser, const QString& modes) { if (isKnownUser(ircuser)) { // Keep user modes sorted @@ -279,15 +256,13 @@ void IrcChannel::setUserModes(IrcUser *ircuser, const QString &modes) } } - -void IrcChannel::setUserModes(const QString &nick, const QString &modes) +void IrcChannel::setUserModes(const QString& nick, const QString& modes) { setUserModes(network()->ircUser(nick), modes); } - // ADD USER MODE -void IrcChannel::addUserMode(IrcUser *ircuser, const QString &mode) +void IrcChannel::addUserMode(IrcUser* ircuser, const QString& mode) { if (!isKnownUser(ircuser) || !isValidChannelUserMode(mode)) return; @@ -301,15 +276,13 @@ void IrcChannel::addUserMode(IrcUser *ircuser, const QString &mode) } } - -void IrcChannel::addUserMode(const QString &nick, const QString &mode) +void IrcChannel::addUserMode(const QString& nick, const QString& mode) { addUserMode(network()->ircUser(nick), mode); } - // REMOVE USER MODE -void IrcChannel::removeUserMode(IrcUser *ircuser, const QString &mode) +void IrcChannel::removeUserMode(IrcUser* ircuser, const QString& mode) { if (!isKnownUser(ircuser) || !isValidChannelUserMode(mode)) return; @@ -323,18 +296,16 @@ void IrcChannel::removeUserMode(IrcUser *ircuser, const QString &mode) } } - -void IrcChannel::removeUserMode(const QString &nick, const QString &mode) +void IrcChannel::removeUserMode(const QString& nick, const QString& mode) { removeUserMode(network()->ircUser(nick), mode); } - // INIT SET USER MODES QVariantMap IrcChannel::initUserModes() const { QVariantMap usermodes; - QHash::const_iterator iter = _userModes.constBegin(); + QHash::const_iterator iter = _userModes.constBegin(); while (iter != _userModes.constEnd()) { usermodes[iter.key()->nick()] = iter.value(); ++iter; @@ -342,10 +313,9 @@ QVariantMap IrcChannel::initUserModes() const return usermodes; } - -void IrcChannel::initSetUserModes(const QVariantMap &usermodes) +void IrcChannel::initSetUserModes(const QVariantMap& usermodes) { - QList users; + QList users; QStringList modes; QVariantMap::const_iterator iter = usermodes.constBegin(); while (iter != usermodes.constEnd()) { @@ -357,7 +327,6 @@ void IrcChannel::initSetUserModes(const QVariantMap &usermodes) joinIrcUsers(users, modes); } - QVariantMap IrcChannel::initChanModes() const { QVariantMap channelModes; @@ -397,8 +366,7 @@ QVariantMap IrcChannel::initChanModes() const return channelModes; } - -void IrcChannel::initSetChanModes(const QVariantMap &channelModes) +void IrcChannel::initSetChanModes(const QVariantMap& channelModes) { QVariantMap::const_iterator iter = channelModes["A"].toMap().constBegin(); QVariantMap::const_iterator iterEnd = channelModes["A"].toMap().constEnd(); @@ -427,25 +395,22 @@ void IrcChannel::initSetChanModes(const QVariantMap &channelModes) } } - void IrcChannel::ircUserDestroyed() { - IrcUser *ircUser = static_cast(sender()); + auto* ircUser = static_cast(sender()); Q_ASSERT(ircUser); _userModes.remove(ircUser); // no further propagation. // this leads only to fuck ups. } - void IrcChannel::ircUserNickSet(QString nick) { - IrcUser *ircUser = qobject_cast(sender()); + auto* ircUser = qobject_cast(sender()); Q_ASSERT(ircUser); emit ircUserNickSet(ircUser, nick); } - /******************************************************************************* * * 3.3 CHANMODES @@ -491,7 +456,7 @@ void IrcChannel::ircUserNickSet(QString nick) // NOTE: the behavior of addChannelMode and removeChannelMode depends on the type of mode // see list above for chanmode types -void IrcChannel::addChannelMode(const QChar &mode, const QString &value) +void IrcChannel::addChannelMode(const QChar& mode, const QString& value) { Network::ChannelModeType modeType = network()->channelModeType(mode); @@ -520,8 +485,7 @@ void IrcChannel::addChannelMode(const QChar &mode, const QString &value) SYNC(ARG(mode), ARG(value)) } - -void IrcChannel::removeChannelMode(const QChar &mode, const QString &value) +void IrcChannel::removeChannelMode(const QChar& mode, const QString& value) { Network::ChannelModeType modeType = network()->channelModeType(mode); @@ -548,8 +512,7 @@ void IrcChannel::removeChannelMode(const QChar &mode, const QString &value) SYNC(ARG(mode), ARG(value)) } - -bool IrcChannel::hasMode(const QChar &mode) const +bool IrcChannel::hasMode(const QChar& mode) const { Network::ChannelModeType modeType = network()->channelModeType(mode); @@ -568,8 +531,7 @@ bool IrcChannel::hasMode(const QChar &mode) const return false; } - -QString IrcChannel::modeValue(const QChar &mode) const +QString IrcChannel::modeValue(const QChar& mode) const { Network::ChannelModeType modeType = network()->channelModeType(mode); @@ -589,8 +551,7 @@ QString IrcChannel::modeValue(const QChar &mode) const } } - -QStringList IrcChannel::modeValueList(const QChar &mode) const +QStringList IrcChannel::modeValueList(const QChar& mode) const { Network::ChannelModeType modeType = network()->channelModeType(mode); @@ -605,7 +566,6 @@ QStringList IrcChannel::modeValueList(const QChar &mode) const return {}; } - QString IrcChannel::channelModeString() const { QStringList params;