Commit 33b1fee3 authored by Ahmad Samir's avatar Ahmad Samir

[ChannelOptionsDialog] Port to QRegularExpression plus some optimisations

Summary:
- More const
- Use range-for
- Remove some redundant vars that weren't used anywhere
- Replace QString arg().arg() with QString::arg(string, string), (the
  latter is more safe to use)
- Where appropriate, move var declaration/definition to right where
  they'll be used

Test Plan:
make && a quick check with creating a channel on Freenode and setting
modes for it, seems to work well.

Reviewers: #konversation, psn, hein

Reviewed By: #konversation, psn

Differential Revision: https://phabricator.kde.org/D28357
parent 802eacbd
......@@ -21,7 +21,7 @@
#include <QCheckBox>
#include <QHeaderView>
#include <QPushButton>
#include <QRegExp>
#include <QRegularExpression>
#include <QStandardItemModel>
#include <QKeyEvent>
#include <QItemSelectionModel>
......@@ -183,33 +183,33 @@ namespace Konversation
m_channel->sendText(Preferences::self()->commandChar() + "TOPIC " + m_channel->getName() + ' ' + newTopic);
}
QStringList newModeList = modes();
QStringList currentModeList = m_channel->getModeList();
QStringList rmModes;
QStringList addModes;
QStringList tmp;
QString modeString;
bool plus;
const QStringList newModeList = modes();
const QStringList currentModeList = m_channel->getModeList();
QString command(QStringLiteral("MODE %1 %2%3 %4"));
for(QStringList::ConstIterator it = newModeList.constBegin(); it != newModeList.constEnd(); ++it)
for (const QString &mode : newModeList)
{
modeString = (*it).mid(1);
plus = ((*it)[0] == '+');
tmp = currentModeList.filter(QRegExp('^' + modeString));
const QString modeString = mode.mid(1);
const bool plus = mode.at(0) == QLatin1Char('+');
const QStringList tmp = currentModeList.filter(QRegularExpression(QLatin1Char('^') + modeString));
if(tmp.isEmpty() && plus)
{
m_channel->getServer()->queue(command.arg(m_channel->getName()).arg(QStringLiteral("+")).arg(modeString[0]).arg(modeString.mid(1)));
m_channel->getServer()->queue(command.arg(m_channel->getName(), QStringLiteral("+"),
modeString.at(0), modeString.mid(1)));
}
else if(!tmp.isEmpty() && !plus)
{
//FIXME: Bahamuth requires the key parameter for -k, but ircd breaks on -l with limit number.
//Hence two versions of this.
if (modeString[0] == 'k')
m_channel->getServer()->queue(command.arg(m_channel->getName()).arg(QStringLiteral("-")).arg(modeString[0]).arg(modeString.mid(1)));
else
m_channel->getServer()->queue(command.arg(m_channel->getName()).arg(QStringLiteral("-")).arg(modeString[0]).arg(QString()));
if (modeString.at(0) == QLatin1Char('k')) {
m_channel->getServer()->queue(command.arg(m_channel->getName(), QStringLiteral("-"),
modeString.at(0), modeString.mid(1)));
} else {
m_channel->getServer()->queue(command.arg(m_channel->getName(), QStringLiteral("-"),
modeString.at(0), QString()));
}
}
}
hide();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment